Skip to content

Commit

Permalink
mod: keep BSON instead of JSON in ORCA calcs
Browse files Browse the repository at this point in the history
enabled track: True for ORCA.get_all_energies()
  • Loading branch information
Johannes Steinmetzer committed Sep 26, 2023
1 parent e2b2ff0 commit d755903
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions pysisyphus/calculators/ORCA.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ class ORCA(OverlapCalculator):
"cis",
"densities",
("molden", "mwfn_wf"),
"json",
"bson",
)

def __init__(
Expand Down Expand Up @@ -573,7 +573,7 @@ def __init__(
json_dump : bool, optional, deprecated
Use 'wavefunction_dump' instead.
wavefunction_dump : bool, optional
Whether to dump the wavefunction to JSON via orca_2json. The JSON can become
Whether to dump the wavefunction to BSON via orca_2json. The BSON can become
very large in calculations comprising many basis functions.
"""
super().__init__(**kwargs)
Expand Down Expand Up @@ -619,7 +619,7 @@ def __init__(
"hess",
"pcgrad",
"densities:orca.densities",
"json",
"bson",
)

self.orca_input = """!{keywords} {calc_type}
Expand Down Expand Up @@ -742,21 +742,27 @@ def store_and_track(self, results, func, atoms, coords, **prepare_kwargs):
return results

def get_energy(self, atoms, coords, **prepare_kwargs):
calc_type = ""

if self.do_stable:
self.get_stable_wavefunction(atoms, coords)

inp = self.prepare_input(atoms, coords, calc_type, **prepare_kwargs)
inp = self.prepare_input(atoms, coords, calc_type="", **prepare_kwargs)
results = self.run(inp, calc="energy")
results = self.store_and_track(
results, self.get_energy, atoms, coords, **prepare_kwargs
)
return results

def get_all_energies(self, atoms, coords, **prepare_kwargs):
# Calculating a stable wavfunction in this method may lead to unnecessary
# ES calculation.
if self.do_stable:
self.get_stable_wavefunction(atoms, coords)

inp = self.prepare_input(atoms, coords, calc_type="", **prepare_kwargs)
results = self.run(inp, calc="all_energies")
results = self.store_and_track(
results, self.get_all_energies, atoms, coords, **prepare_kwargs
)
return results

def get_forces(self, atoms, coords, **prepare_kwargs):
Expand All @@ -765,30 +771,28 @@ def get_forces(self, atoms, coords, **prepare_kwargs):

calc_type = "engrad"
inp = self.prepare_input(atoms, coords, calc_type, **prepare_kwargs)
kwargs = {
"calc": "grad",
}
results = self.run(inp, **kwargs)
results = self.run(inp, calc="grad")
results = self.store_and_track(
results, self.get_forces, atoms, coords, **prepare_kwargs
)
return results

def get_hessian(self, atoms, coords, **prepare_kwargs):
calc_type = self.freq_keyword

if self.do_stable:
self.get_stable_wavefunction(atoms, coords)

inp = self.prepare_input(atoms, coords, calc_type, **prepare_kwargs)
# self.freq_keyword maybe numfreq/anfreq
inp = self.prepare_input(
atoms, coords, calc_type=self.freq_keyword, **prepare_kwargs
)
results = self.run(inp, calc="hessian")
results = self.store_and_track(
results, self.get_hessian, atoms, coords, **prepare_kwargs
)
return results

def get_stored_wavefunction(self, **kwargs):
return self.load_wavefunction_from_file(self.json, **kwargs)
return self.load_wavefunction_from_file(self.bson, **kwargs)

def run_calculation(self, atoms, coords, **prepare_kwargs):
"""Basically some kind of dummy method that can be called
Expand All @@ -811,7 +815,7 @@ def run_after(self, path):

if self.wavefunction_dump:
# Will silently fail with ECPs
cmd = "orca_2json orca"
cmd = "orca_2json orca -bson"
proc = self.popen(cmd, cwd=path)
if (ret := proc.returncode) != 0:
self.log(f"orca_2json call failed with return-code {ret}!")
Expand Down

0 comments on commit d755903

Please sign in to comment.