Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for idx in reversed(range(line_scf_header, line_final_energy)):
mobj = re.search(
r"^\s*\d+\s+" + DECIMAL + r"\s+" + DECIMAL + r"\s+" + DECIMAL + r"\s+" + DECIMAL,
output_lines[idx],
re.VERBOSE,
)
if mobj:
last_scf_line = output_lines[idx]
break
if len(last_scf_line) > 0:
properties["scf_iterations"] = int(last_scf_line.split()[0])
if "XC Energy" in output_lines:
properties["scf_xc_energy"] = float(last_scf_line.split()[4])
else:
raise UnknownError("SCF iteration lines not found in TeraChem output")
if len(gradients) > 0:
output_data["return_result"] = gradients
# Commented out the properties currently not supported by QCSchema
# properites["spin_S2"] = 1 # calculated S(S+1)
# elif "SPIN S-SQUARED" in line:
# properties["spin_S2"] = float(line.strip('\n').split()[2])
# Parse files in scratch folder
# properties["atomic_charge"] = []
# atomic_charge_lines = open(outfiles["charge.xls"]).readlines()
# for line in atomic_charge_lines:
# properties["atomic_charge"].append(line.strip('\n').split()[-1])
if "return_result" not in output_data:
if "scf_total_energy" in properties:
"KCAL/MOL/ANGSTROM": self.extras["bohr_to_angstroms"] / self.extras["hartree_to_kcalmol"],
"EV": 1 / self.extras["hartree_to_ev"],
"DEBYE": 1 / self.extras["au_to_debye"],
"AMU": 1,
None: 1,
}
data = {}
last_key = None
# Parse the weird structure
if outfiles["dispatch.aux"] is None:
error = "An unknown error occured and no results were captured."
if outfiles["dispatch.out"] is not None:
error = outfiles["dispatch.out"]
raise UnknownError(error)
for line in outfiles["dispatch.aux"].splitlines():
if ("START" in line) or ("END" in line) or ("#" in line):
continue
if "=" in line:
# Primary split
key, value = line.split("=", 1)
# Format key, may have units
# IONIZATION_POTENTIAL:EV
# GRADIENTS:KCAL/MOL/ANGSTROM[09]
key_list = key.split(":", 1)
if len(key_list) == 1:
key, units = key_list[0], None
real = np.array(input_model.molecule.real)
full_nat = real.shape[0]
real_nat = np.sum(real)
for ln in stdout.splitlines():
if re.match(" Edisp /kcal,au", ln):
ene = Decimal(ln.split()[3])
elif re.match(r" E6\(ABC\) \" :", ln): # c. v3.2.0
raise ResourceError("Cannot process ATM results from DFTD3 prior to v3.2.1.")
elif re.match(r""" E6\(ABC\) /kcal,au:""", ln):
atm = Decimal(ln.split()[-1])
elif re.match(" normal termination of dftd3", ln):
break
else:
if not ((real_nat == 1) and (input_model.driver == "gradient")):
raise UnknownError(
f"Unsuccessful run. Check input, particularly geometry in [a0]. Model: {input_model.model}"
)
# parse gradient output
# * DFTD3 crashes on one-atom gradients. Avoid the error (above) and just force the correct result (below).
if outfiles["dftd3_gradient"] is not None:
srealgrad = outfiles["dftd3_gradient"].replace("D", "E")
realgrad = np.fromstring(srealgrad, count=3 * real_nat, sep=" ").reshape((-1, 3))
elif real_nat == 1:
realgrad = np.zeros((1, 3))
if outfiles["dftd3_abc_gradient"] is not None:
srealgrad = outfiles["dftd3_abc_gradient"].replace("D", "E")
realgradabc = np.fromstring(srealgrad, count=3 * real_nat, sep=" ").reshape((-1, 3))
elif real_nat == 1:
realgradabc = np.zeros((1, 3))
# LOG text += f'\n MP2D scratch file {fl} has been read.\n'
pass
# parse energy output (could go further and break into UCHF, CKS)
real = np.array(input_model.molecule.real)
full_nat = real.shape[0]
real_nat = np.sum(real)
for ln in stdout.splitlines():
if re.match(" MP2D dispersion correction Eh", ln):
ene = Decimal(ln.split()[4])
elif re.match("Atomic Coordinates in Angstroms", ln):
break
else:
if not ((real_nat == 1) and (input_model.driver == "gradient")):
raise UnknownError("Unknown issue occured.")
# parse gradient output
if outfiles["mp2d_gradient"] is not None:
srealgrad = outfiles["mp2d_gradient"]
realgrad = np.fromstring(srealgrad, count=3 * real_nat, sep=" ").reshape((-1, 3))
if input_model.driver == "gradient":
ireal = np.argwhere(real).reshape((-1))
fullgrad = np.zeros((full_nat, 3))
try:
fullgrad[ireal, :] = realgrad
except NameError as exc:
raise UnknownError("Unsuccessful gradient collection.") from exc
qcvkey = input_model.extras["info"]["fctldash"].upper()
job_inputs = self.build_input(input_model, config)
success, dexe = self.execute(job_inputs)
if "There is an error in the input file" in dexe["stdout"]:
raise InputError(dexe["stdout"])
if "not compiled" in dexe["stdout"]:
# recoverable with a different compilation with optional modules
raise InputError(dexe["stdout"])
if success:
dexe["outfiles"]["stdout"] = dexe["stdout"]
dexe["outfiles"]["stderr"] = dexe["stderr"]
return self.parse_output(dexe["outfiles"], input_model)
else:
raise UnknownError(dexe["stdout"])
Runs Psi4 in API mode
"""
self.found(raise_error=True)
exec_command = self.build_input(input_model, config)
success, output = self.execute(exec_command)
ret = self.parse_output(output["outfiles"], input_model)
# Determine whether the calculation succeeded
if success:
# raise Exception()
return ret
else:
return UnknownError(ret["stderr"])
raise TypeError(f"entos version {self.get_version()} not supported")
# Setup the job
job_inputs = self.build_input(input_data, config)
# Run entos
exe_success, proc = self.execute(job_inputs)
# Determine whether the calculation succeeded
if exe_success:
# If execution succeeded, collect results
result = self.parse_output(proc["outfiles"], input_data)
return result
else:
# Return UnknownError for error propagation
return UnknownError(proc["stderr"])
raise TypeError("Molpro version '{}' not supported".format(self.get_version()))
# Setup the job
job_inputs = self.build_input(input_data, config)
# Run Molpro
exe_success, proc = self.execute(job_inputs)
# Determine whether the calculation succeeded
if exe_success:
# If execution succeeded, collect results
result = self.parse_output(proc["outfiles"], input_data)
return result
else:
# Return UnknownError for error propagation
return UnknownError(proc["stderr"])