Skip to content

Commit

Permalink
safety checks for ffevaluate dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
stefdoerr committed Jan 3, 2024
1 parent 085d823 commit 08313b6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ffevaluation/ffevaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def __init__(
args.append(rfa)
args.append(solventDielectric)
self._args = args
self._numAtoms = mol.numAtoms

def calculateEnergies(self, coords, box=None, formatted=True):
"""Utility method which calls `calculate` to calculate energies and returns them.
Expand All @@ -184,6 +185,15 @@ def calculateEnergies(self, coords, box=None, formatted=True):
energies : dict or np.ndarray
The energies as a dictionary or np.array depending on option `formatted`
"""
if coords.ndim not in (2, 3) or coords.shape[1] != 3:
raise RuntimeError(
"FFEvaluate requires a 3D coordinate array of shape [n_atoms, 3, n_frames]"
)
if coords.ndim == 2:
coords = coords[:, :, np.newaxis].copy()
if coords.shape[0] != self._numAtoms:
raise RuntimeError("Number of atoms in coordinates does not match Molecule")

energies, _, _ = self.calculate(coords, box)
if formatted:
energies = self.formatEnergies(energies)
Expand Down

0 comments on commit 08313b6

Please sign in to comment.