Skip to content

Commit 89147a2

Browse files
committed
respect interface: changes
1 parent 79f52ed commit 89147a2

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

ash/interfaces/interface_ReSpect.py

+38-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def __init__(self, respectdir=None, filename='respect', printlevel=2, label="ReS
2929
self.scf_inputkeywords=scf_inputkeywords
3030
self.jobtype_inputkeywords=jobtype_inputkeywords
3131
self.parallelization=parallelization
32+
33+
# Store optional properties of ReSpect run job in a dict
34+
self.properties = {}
35+
3236
#
3337
if scf_inputkeywords is None:
3438
print("Error: You must pass a dictionary to scf_inputkeywords option")
@@ -111,7 +115,13 @@ def run(self, current_coords=None, current_MM_coords=None, MMcharges=None, qm_el
111115
print("SCF calculation done")
112116
#Grab energy. Note: no analytic gradient in ReSpect yet
113117
self.energy = grab_energy(f"{self.filename}.out_scf", Grad=Grad)
114-
#Grab properties
118+
119+
if self.energy is None:
120+
print(f"No energy was found in ReSpect SCF outputfile: {self.filename}.out_scf")
121+
print(f"Something went wrong in calculation. Inspect {self.filename}.out_scf for reason")
122+
ashexit()
123+
124+
print(f"Single-point {self.theorynamelabel} energy:", self.energy)
115125

116126
# if jobtype has been set
117127
if self.jobtype is not None:
@@ -121,10 +131,23 @@ def run(self, current_coords=None, current_MM_coords=None, MMcharges=None, qm_el
121131
for job in self.jobtype:
122132
print("Running job:", job)
123133
run_respect(respectdir=self.respectdir, jobtype=self.jobtype, inputfile=self.filename, numcores=self.numcores, scratchdir=f'{os.getcwd()}/respect_calc_scratch')
134+
# Grab properties
135+
if job == "gt":
136+
gvalues = grab_gtensor(f"{self.filename}.out_gt")
137+
self.properties = {'g_values':gvalues}
124138
else:
125139
run_respect(respectdir=self.respectdir, jobtype=self.jobtype, inputfile=self.filename, numcores=self.numcores, scratchdir=f'{os.getcwd()}/respect_calc_scratch')
140+
# Grab properties
141+
if self.jobtype == "gt":
142+
gvalues = grab_gtensor(f"{self.filename}.out_gt")
143+
self.properties = {'g_values':gvalues}
126144

127-
print(f"Single-point {self.theorynamelabel} energy:", self.energy)
145+
146+
print("Calculated and stored ReSpect properties:")
147+
for p_k,p_v in self.properties.items():
148+
print(f"{p_k} : {p_v}")
149+
150+
print()
128151
print(BC.OKBLUE, BC.BOLD, f"------------ENDING {self.theorynamelabel} INTERFACE-------------", BC.END)
129152

130153
print_time_rel(module_init_time, modulename=f'{self.theorynamelabel} run', moduleindex=2)
@@ -183,3 +206,16 @@ def create_respect_inputfile(filename,elems, coords, charge,mult, scf_inputkeywo
183206
f.write(f"{indent}{subj_k}: {subj_val}\n")
184207

185208
f.close()
209+
210+
def grab_gtensor(filename):
211+
grab=False
212+
g_values=[]
213+
with open(filename) as f:
214+
for line in f:
215+
if grab is True:
216+
if 'g_11' in line or 'g_22' in line or 'g_33' in line:
217+
g_values.append(float(line.split()[1]))
218+
if ' Principal values of the g-tensor' in line:
219+
grab=True
220+
if ' Determinant of the g-tensor' in line:
221+
grab=False

0 commit comments

Comments
 (0)