Skip to content

Commit

Permalink
Allows attribute redirection to wrapped OpenMM forces (#90)
Browse files Browse the repository at this point in the history
* Implemented openmm force wrapper redirection

* Fixed code formatting
  • Loading branch information
craabreu committed Apr 10, 2024
1 parent 861fb47 commit 3aebba9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cvpack/openmm_force_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,22 @@ def __init__( # pylint: disable=super-init-not-called
if isinstance(openmmForce, openmm.Force):
openmmForce = openmm.XmlSerializer.serialize(openmmForce)
unit = Unit(unit)
self.this = openmm.XmlSerializer.deserialize(openmmForce).this
self._wrapped_force = openmm.XmlSerializer.deserialize(openmmForce)
self.this = self._wrapped_force.this
self._registerCV(name, unit, openmmForce, unit, periodicBounds)
if periodicBounds is not None:
self._registerPeriodicBounds(*periodicBounds)

def __getattr__(self, name: str) -> t.Any:
attr = getattr(self._wrapped_force, name)
if callable(attr):

def _wrapped_method(*args, **kwargs):
return attr(*args, **kwargs)

return _wrapped_method

return attr


OpenMMForceWrapper.registerTag("!cvpack.OpenMMForceWrapper")

0 comments on commit 3aebba9

Please sign in to comment.