Skip to content

Commit

Permalink
mod: factored out Gaussian16.parse_all_energies
Browse files Browse the repository at this point in the history
  • Loading branch information
eljost authored and Johannes Steinmetzer committed Mar 11, 2024
1 parent 5141406 commit 0b393a2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
34 changes: 31 additions & 3 deletions pysisyphus/calculators/Gaussian16.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,35 @@ def parse_ci_coeffs(text, restricted_same_ab=False):
return Xa, Ya, Xb, Yb


def noparse(path):
return dict()


@file_or_str(".fchk")
def parse_all_energies(text):
float_ = r"([\d\-\+Ee\.]+)"
gs_re = re.compile(r"SCF Energy\s+R\s+" + float_)
gs_mobj = gs_re.search(text)
gs_energy = float(gs_mobj[1])
# cis_re = re.compile(r"CIS Energy\s+R\s+" + float_)
# cis_mobj = cis_re.search(text)
# cis_energy = float(cis_mobj[1])
etrans_re = re.compile(
r"ETran state values\s+R\s+N=\s+(\d+)([\d\-\.Ee\+\s]+)", re.DOTALL
)
etrans_mobj = etrans_re.search(text)
try:
etrans = etrans_mobj[2].strip().split()
etrans = np.array(etrans, dtype=float).reshape(-1, 16)
exc_energies = etrans[:, 0]
all_energies = np.zeros(exc_energies.size + 1)
all_energies[0] = gs_energy
all_energies[1:] = exc_energies
except TypeError:
all_energies = np.array((gs_energy,))
return all_energies


class Gaussian16(OverlapCalculator):
conf_key = "gaussian16"
_set_plans = (
Expand Down Expand Up @@ -215,7 +244,7 @@ def __init__(
"force": self.parse_force,
"hessian": self.parse_hessian,
"stable": self.parse_stable,
"noparse": lambda path: None,
"noparse": noparse,
"double_mol": self.parse_double_mol,
}

Expand Down Expand Up @@ -538,8 +567,7 @@ def run_calculation(self, atoms, coords, **prepare_kwargs):
self.store_overlap_data(atoms, coords)
self.track_root()
self.log(
"This track_root() call is a bit superfluous as the "
"as the result is ignored :)"
"This track_root() call is a bit superfluous as the result is ignored."
)
return results

Expand Down
13 changes: 13 additions & 0 deletions pysisyphus/calculators/ORCA.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ def parse_orca_all_energies(text, triplets=False, do_tddft=False, do_ice=False):
)
if did_triplets:
roots = len(states) // 2
<<<<<<< HEAD
if triplets:
exc_ens = exc_ens[-roots:]
states = states[-roots:]
Expand All @@ -447,6 +448,18 @@ def parse_orca_all_energies(text, triplets=False, do_tddft=False, do_ice=False):
exc_ens = exc_ens[:roots]
states = states[:roots]
assert len(exc_ens) == len(set(states))
||||||| parent of bc929a7d (mod: factored out Gaussian16.parse_all_energies)
exc_ens = exc_ens[-roots:]
states = states[-roots:]
assert len(exc_ens) == len(set(states))
=======
exc_ens = exc_ens[-roots:]
states = states[-roots:]
assert len(exc_ens) == len(set(states)), (
f"Found {len(exc_ens)} excitaiton energies, but {len(set(states))} state labels. "
"Is this a singlet-triplet calculation? If so, set triplets=True!"
)
>>>>>>> bc929a7d (mod: factored out Gaussian16.parse_all_energies)
all_energies = np.full(1 + len(exc_ens), gs_energy)
all_energies[1:] += exc_ens
elif do_ice:
Expand Down

0 comments on commit 0b393a2

Please sign in to comment.