Skip to content

Commit

Permalink
General improvements
Browse files Browse the repository at this point in the history
- Cleaned up unneeded comments.
- Added support for HF method.
- Parallel computation support using %pal.
- Black beautification.
  • Loading branch information
muammar committed Dec 10, 2019
1 parent 1e96ea0 commit 006afb8
Showing 1 changed file with 15 additions and 31 deletions.
46 changes: 15 additions & 31 deletions qcengine/programs/orca.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@ class OrcaHarness(ProgramHarness):
}
# fmt: on

# Different open-shell scenarios:
# - Restricted references
# RHF-RMP2 (like RHF-UMP2 using Molpro's naming convention for CC methods)
# RHF-UCCSD
# RHF-UCCSD(T)
# RHF-RCCSD
# RHF-RCCSD(T)
# - Unrestricted references (Only supported up to UMP2, no CC support)
# UHF-UMP2
# NOTE: Unrestricted SCF methods must be specified by using keyword reference
_hf_methods: Set[str] = {"HF", "RHF"}
_restricted_post_hf_methods: Set[str] = {"MP2", "CCSD", "CCSD(T)"} # RMP2, RCCSD, RCCSD(T)}
Expand Down Expand Up @@ -183,20 +174,8 @@ def build_input(
if "reference" in caseless_keywords and caseless_keywords["reference"] == "unrestricted":
unrestricted = True

# Memory is in megawords per core for Molpro
# memory_mw_core = int(config.memory * (1024 ** 3) / 8e6 / config.ncores)
# input_file.append("memory,{},M".format(memory_mw_core))
# input_file.append("")

# Write the geom
xyz_block = input_model.molecule.to_string(dtype="orca", units="Angstrom")
# input_file.append(xyz_block)

# Write the basis set
# input_file.append("basis={")
# input_file.append(f"default,{input_model.model.basis}")
# input_file.append("}")
# input_file.append("")

# Determine what SCF type (restricted vs. unrestricted)
hf_type = "RHF"
Expand All @@ -207,19 +186,20 @@ def build_input(

# Write energy call
energy_call = []
# If post-hf method is called then make sure to write a HF call first

if input_model.model.method.upper() in self._post_hf_methods: # post SCF case
energy_call.append(f"{{{hf_type}}}")
energy_call.append("")
energy_call.append(f"{{{input_model.model.method}}}")
# If DFT call make sure to write {rks,method}

elif input_model.model.method.upper() in self._dft_functionals: # DFT case
input_file.append("! SP {} {}".format(input_model.model.method, input_model.model.basis))
input_file.append(xyz_block)

# energy_call.append(f"{{{dft_type},{input_model.model.method}}}")
elif input_model.model.method.upper() in self._hf_methods: # HF case
energy_call.append(f"{{{hf_type}}}")
input_file.append("! SP {} {}".format(input_model.model.method, input_model.model.basis))
input_file.append(xyz_block)

else:
raise InputError(f"Method {input_model.model.method} not implemented for Molpro.")

Expand All @@ -231,6 +211,9 @@ def build_input(
else:
raise InputError(f"Driver {input_model.driver} not implemented for Molpro.")

parallel = "%pal nproc {} end".format(config.ncores)
input_file.append(parallel)

input_file = "\n".join(input_file)
else:
# Some of the potential different template options
Expand Down Expand Up @@ -262,6 +245,7 @@ def parse_output(self, outfiles: Dict[str, str], input_model: "AtomicInput") ->

properties = {}
extras = {}
extras["ev_to_hartrees"] = 0.0367493

# Process basis set data
properties["calcinfo_nbasis"] = data.nbasis
Expand All @@ -275,7 +259,7 @@ def parse_output(self, outfiles: Dict[str, str], input_model: "AtomicInput") ->
# Determining the final energy
# Throws an error if the energy isn't found for the method specified from the input_model.
try:
final_energy = data.scfenergies[-1] * 0.0367493
final_energy = data.scfenergies[-1] * extras["ev_to_hartrees"]
except:
raise KeyError(f"Could not find {method} total energy")

Expand All @@ -284,7 +268,7 @@ def parse_output(self, outfiles: Dict[str, str], input_model: "AtomicInput") ->

# Determining return_result
if input_model.driver == "energy":
output_data["return_result"] = final_energy
output_data["return_result"] = final_energy
extras["CURRENT ENERGY"] = final_energy

elif input_model.driver == "gradient":
Expand All @@ -302,6 +286,7 @@ def parse_output(self, outfiles: Dict[str, str], input_model: "AtomicInput") ->
output_data["success"] = True

import uuid

myid = str(uuid.uuid4())
with open("/tmp/orcafiles/{}".format(myid), "wb") as handle:
handle.write(outfiles["outfiles"]["dispatch.gbw"])
Expand All @@ -310,8 +295,7 @@ def parse_output(self, outfiles: Dict[str, str], input_model: "AtomicInput") ->
return AtomicResult(**output_data)

def get_gradient(self, gradient_file):
"""Get gradient from engrad Orca file
"""
"""Get gradient from engrad Orca file"""
copy = False
found = False
gradient = []
Expand All @@ -325,7 +309,7 @@ def get_gradient(self, gradient_file):
gradient.append(float(line))
except ValueError:
pass

dim = np.sqrt(len(gradient)).astype(int)

return np.array(gradient).reshape(dim, dim)
return np.array(gradient).reshape(dim, dim)

0 comments on commit 006afb8

Please sign in to comment.