-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenorb.py
40 lines (38 loc) · 1.36 KB
/
genorb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import re
import json
import sys
def grep_cp2k_basis_molopt(data):
element = data['element']
basis_type = data.setdefault('basis_type', 'DZVP')
basis_file = os.path.join(data['cp2k_path'], 'data', 'BASIS_MOLOPT')
is_sr=data.setdefault('short_range', False)
short_range=""
if is_sr:
short_range="SR-"
pattern=fr'^\s*{element}\s*{basis_type}-MOLOPT-{short_range}GTH.*'
content=[]
found=False
with open(basis_file, 'r') as f:
lines = f.readlines()
for line in lines:
if re.match(pattern, line):
found=True
content.append(line)
continue
if found:
if not re.match(r'^\s*\d', line):
break
print("line: ", line)
content.append(line)
writefile=f"{element}-{basis_type}-MOLOPOT-{short_range}GTH"
with open(writefile, 'w') as f:
f.writelines(content)
return writefile, short_range
if __name__ == '__main__':
file_path = sys.argv[1]
with open(file_path, 'r') as file:
data = json.load(file)
writefile, short_range = grep_cp2k_basis_molopt(data)
orb_submodule_pth=f"{os.path.dirname(os.path.abspath(__file__))}/deps/gaussian_orbital_for_ABACUS/cp2k2abacus_gaussian.py"
os.system(f"python {orb_submodule_pth} {writefile} {writefile} {data['basis_rcut']} MOLOPT-{short_range}GTH")