Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orca Harness. #178

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6b26a41
Small advances to Orca Harness.
muammar Nov 22, 2019
2657c79
Merge branch 'master' into orca
muammar Dec 3, 2019
97c63cc
Cleaned up print statements and output file is parsed by cclib.
muammar Dec 4, 2019
e6c00c2
General improvements.
muammar Dec 5, 2019
ca4f623
Cleaning up print statement and addition of more properties.
muammar Dec 5, 2019
bd28893
Removed commented files.
muammar Dec 5, 2019
d257a35
Gradient is returned as result.
muammar Dec 9, 2019
e9ff4a6
Current energy added to gradient extras.
muammar Dec 9, 2019
1e96ea0
Merge remote-tracking branch 'upstream/master' into orca
muammar Dec 9, 2019
006afb8
General improvements
muammar Dec 10, 2019
5620a66
Fixed gradient dimensionality.
muammar Dec 10, 2019
4a125bc
Merge branch 'master' into orca
muammar Dec 11, 2019
9dfc4e6
Merge branch 'master' into orca
muammar Dec 18, 2019
ec3702e
Remove unneeded code.
muammar Jan 9, 2020
d668346
Merge branch 'master' into orca
muammar Jan 9, 2020
426c36a
General improvements:
muammar Jan 9, 2020
2624581
Pyflakes clean.
muammar Jan 9, 2020
0e3d699
Bohr by default.
muammar Jan 9, 2020
21ae056
General improvements following reviews.
muammar Jan 10, 2020
c74b32d
More changes based on review.
muammar Jan 16, 2020
adba913
Merge remote-tracking branch 'origin/master' into orca
muammar Jan 16, 2020
d160f3d
First steps to post-HF methods.
muammar Jan 17, 2020
e192143
Remove print.
muammar Jan 17, 2020
d505c4b
Merge branch 'master' into orca
muammar Feb 7, 2020
892b502
Added Orca canonical example.
muammar Feb 7, 2020
2b69b56
Registered orca in testing module.
muammar Feb 7, 2020
2958358
Merge branch 'master' into orca
muammar Mar 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Gradient is returned as result.
  • Loading branch information
muammar committed Dec 9, 2019
commit d257a35312338f76d85b1976493cc461090fafd1
63 changes: 46 additions & 17 deletions qcengine/programs/orca.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import string
import cclib
muammar marked this conversation as resolved.
Show resolved Hide resolved
import io
import numpy as np
from typing import Any, Dict, List, Optional, Set, Tuple

from qcelemental.models import AtomicResult
Expand Down Expand Up @@ -106,20 +107,21 @@ def compute(self, input_data: "AtomicInput", config: "JobConfig") -> "AtomicResu
# Check if Molpro executable is found
self.found(raise_error=True)

# Check Molpro version
# Check Orca version
if parse_version(self.get_version()) < parse_version("4.2.1"):
raise TypeError("Orca version '{}' not supported".format(self.get_version()))

# Setup the job
job_inputs = self.build_input(input_data, config)

# Run Orca
exe_success, proc = self.execute(job_inputs)
binary = ["dispatch.gbw"]
exe_success, proc = self.execute(job_inputs, as_binary=binary)

# Determine whether the calculation succeeded
if exe_success:
# If execution succeeded, collect results
result = self.parse_output(proc["stdout"], input_data)
result = self.parse_output(proc, input_data)
return result
else:
# Return UnknownError for error propagation
Expand All @@ -139,14 +141,13 @@ def execute(
"""
For option documentation go look at qcengine/util.execute
"""

# Collect all input files and update with extra_infiles
infiles = inputs["infiles"]
if extra_infiles is not None:
infiles.update(extra_infiles)

# Collect all output files and update with extra_outfiles
outfiles = []
outfiles = ["dispatch.gbw", "dispatch.engrad"]

if extra_outfiles is not None:
outfiles.extend(extra_outfiles)

Expand All @@ -155,7 +156,7 @@ def execute(
if extra_commands is not None:
commands = extra_commands

# Run the Molpro program
# Run the Orca program
exe_success, proc = execute(
commands,
infiles=infiles,
Expand Down Expand Up @@ -226,9 +227,7 @@ def build_input(
if input_model.driver == "energy":
input_file.extend(energy_call)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is energy_call var ever non-empty?

elif input_model.driver == "gradient":
input_file.extend(energy_call)
input_file.append("")
input_file.append("{force}")
input_file[0] = "{} {}".format(input_file[0], "engrad")
else:
raise InputError(f"Driver {input_model.driver} not implemented for Molpro.")

Expand Down Expand Up @@ -258,12 +257,12 @@ def build_input(
}

def parse_output(self, outfiles: Dict[str, str], input_model: "AtomicInput") -> "AtomicResult":
data = cclib.io.ccread(io.StringIO(outfiles))

data = cclib.io.ccread(io.StringIO(outfiles["stdout"]))

properties = {}
extras = {}


# Process basis set data
properties["calcinfo_nbasis"] = data.nbasis
properties["calcinfo_nmo"] = data.nmo
Expand All @@ -276,7 +275,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]
final_energy = data.scfenergies[-1] * 0.0367493
except:
raise KeyError(f"Could not find {method} total energy")

Expand All @@ -285,16 +284,46 @@ 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":
raise KeyError(f"Could not find {method} gradient")
# output_data["return_result"] = properties.pop("gradient")
gradient = self.get_gradient(outfiles["outfiles"]["dispatch.engrad"])
output_data["return_result"] = gradient
extras["CURRENT GRADIENT"] = gradient

# Final output_data assignments needed for the AtomicResult object

output_data["properties"] = properties
output_data["extras"].update(extras)
output_data["schema_name"] = "qcschema_output"
output_data["stdout"] = outfiles
output_data["stdout"] = outfiles["stdout"]
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"])
output_data["extras"]["gbw"] = myid

return AtomicResult(**output_data)

def get_gradient(self, gradient_file):
muammar marked this conversation as resolved.
Show resolved Hide resolved
"""Get gradient from engrad Orca file
"""
copy = False
found = False
gradient = []

for line in gradient_file.splitlines():
if "gradient" in line:
found = True
copy = True
if found and copy:
try:
gradient.append(float(line))
except ValueError:
pass

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

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