Skip to content

Commit

Permalink
Ensure that molecule orientation remains fixed for MDI (#428)
Browse files Browse the repository at this point in the history
* Ensure that molecule orientation remains fixed for MDI

* Fix MDI test

* Lint MDI files

* Update MDI error message

* Reformat mdi_server.py with black
  • Loading branch information
taylor-a-barnes authored Oct 24, 2023
1 parent 1b27a14 commit c7ba717
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 9 additions & 1 deletion qcengine/mdi_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ def send_energy(self) -> float:
if not self.molecule_validated:
raise Exception("MDI attempting to compute energy on an unvalidated molecule")
self.run_energy()

# Confirm that the calculation completed successfully
if not hasattr(self.compute_return, "properties"):
raise Exception("MDI Calculation failed: \n\n" + str(self.compute_return.error.error_message))

properties = self.compute_return.properties.dict()
energy = properties["return_energy"]
MDI_Send(energy, 1, MDI_DOUBLE, self.comm)
Expand Down Expand Up @@ -305,8 +310,11 @@ def send_forces(self) -> np.ndarray:

# Respond to the SCF command
def run_energy(self) -> None:

if not self.energy_is_current:
"""Ensure that the orientation of the molecule remains fixed"""
self.update_molecule("fix_com", True)
self.update_molecule("fix_orientation", True)

"""Run an energy calculation"""
input = qcel.models.AtomicInput(
molecule=self.molecule, driver="gradient", model=self.model, keywords=self.keywords
Expand Down
12 changes: 11 additions & 1 deletion qcengine/tests/test_mdi.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,17 @@ def test_mdi_water():

# Test the <FORCES command
forces = engine.send_forces()
expected = [0.0, 0.0, 0.00073827952, 0.0, 0.020208584243, -0.00036913976, 0.0, -0.020208584243, -0.00036913976]
expected = [
-0.0000635769828,
0.0,
0.000735537025,
0.0000317884914,
0.0202085843,
-0.000367768513,
0.0000317884914,
-0.0202085843,
-0.000367768513,
]
assert compare_values(expected, forces, atol=1.0e-6)

# Test the >MASSES command
Expand Down

0 comments on commit c7ba717

Please sign in to comment.