Skip to content

Commit

Permalink
Merge pull request #16 from chemle/fix_no_backend_interpolation
Browse files Browse the repository at this point in the history
Zero in vacuo MM energy and gradient when interpolating with no backend
  • Loading branch information
lohedges authored May 8, 2024
2 parents cda72e8 + fffdf7f commit 403e8e2
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions emle/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1457,11 +1457,16 @@ def run(self, path=None):
# Interpolate between the MM and ML/MM potential.
if self._is_interpolate:
# Compute the in vacuo MM energy and gradients for the QM region.
E_mm_qm_vac, grad_mm_qm_vac = self._run_pysander(
atoms=atoms,
parm7=self._parm7,
is_gas=True,
)
if self._backend != None:
E_mm_qm_vac, grad_mm_qm_vac = self._run_pysander(
atoms=atoms,
parm7=self._parm7,
is_gas=True,
)

# If no backend is specified, then the MM energy and gradients are zero.
else:
E_mm_qm_vac, grad_mm_qm_vac = 0.0, _np.zeros_like(xyz_qm)

# Swap the method to MM.
method = self._method
Expand Down Expand Up @@ -1849,16 +1854,21 @@ def _sire_callback(self, atomic_numbers, charges_mm, xyz_qm, xyz_mm):

# Interpolate between the MM and ML/MM potential.
if self._is_interpolate:
# Create the ASE atoms object if it wasn't already created by the backend.
if atoms is None:
atoms = _ase.Atoms(positions=xyz_qm, numbers=atomic_numbers)

# Compute the in vacuo MM energy and gradients for the QM region.
E_mm_qm_vac, grad_mm_qm_vac = self._run_pysander(
atoms=atoms,
parm7=self._parm7,
is_gas=True,
)
if self._backend != None:
# Create the ASE atoms object if it wasn't already created by the backend.
if atoms is None:
atoms = _ase.Atoms(positions=xyz_qm, numbers=atomic_numbers)

E_mm_qm_vac, grad_mm_qm_vac = self._run_pysander(
atoms=atoms,
parm7=self._parm7,
is_gas=True,
)

# If no backend is specified, then the MM energy and gradients are zero.
else:
E_mm_qm_vac, grad_mm_qm_vac = 0.0, _np.zeros_like(xyz_qm)

# Swap the method to MM.
method = self._method
Expand Down

0 comments on commit 403e8e2

Please sign in to comment.