Skip to content

Commit

Permalink
add: get_all_energies() for DFTB+ calculator
Browse files Browse the repository at this point in the history
and added test
  • Loading branch information
Johannes Steinmetzer committed Oct 2, 2024
1 parent b8b3af1 commit f5fdd14
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pysisyphus/calculators/DFTBp.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def get_gen_str(atoms, coords):

@staticmethod
def get_excited_state_str(track, root, nroots, forces=False):
if root is None and (track == False):
if (nroots is None) and (root is None) and (track == False):
return ""

casida_tpl = jinja2.Template(
Expand All @@ -230,6 +230,7 @@ def get_excited_state_str(track, root, nroots, forces=False):
return es_str

def prepare_input(self, atoms, coords, calc_type):
atoms = [atom.capitalize() for atom in atoms]
path = self.prepare_path(use_in_run=True)
gen_str = self.get_gen_str(atoms, coords)
with open(path / self.gen_geom_fn, "w") as handle:
Expand Down Expand Up @@ -290,6 +291,9 @@ def get_energy(self, atoms, coords, **prepare_kwargs):
)
return results

def get_all_energies(self, atoms, coords, **prepare_kwargs):
return self.get_energy(atoms, coords, **prepare_kwargs)

def get_forces(self, atoms, coords, **prepare_kwargs):
inp, path = self.prepare_input(atoms, coords, "forces")
run_kwargs = {
Expand Down
30 changes: 30 additions & 0 deletions tests/test_es_capabilities/test_es_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,33 @@ def test_h2o_all_energies(mult, ref_energies, calc_cls, calc_kwargs, this_dir):
for root in range(4):
root_en = geom.get_root_energy(root)
assert root_en == pytest.approx(ref_energies[root])


@using("dftbp")
def test_dftbp_h2o_all_energies():
geom = geom_loader("lib:h2o.xyz")
nroots = 4
calc_kwargs = {
"mult": 1,
"parameter": "mio-ext",
"nroots": nroots,
}
calc = DFTBp(**calc_kwargs)
geom.set_calculator(calc)
all_energies = geom.all_energies
ref_energies = (
-4.07775075,
-3.39575683,
-3.33313599,
-3.24453337,
-3.21035650,
)
np.testing.assert_allclose(all_energies, ref_energies)

# As we did not set any root the geometries energy should correspond to the GS energy
energy = geom.energy
assert energy == pytest.approx(ref_energies[0])

for root in range(nroots + 1):
root_en = geom.get_root_energy(root)
assert root_en == pytest.approx(ref_energies[root])

0 comments on commit f5fdd14

Please sign in to comment.