Skip to content

Commit

Permalink
Sets CollectiveVariable as first superclass to inherit from (#100)
Browse files Browse the repository at this point in the history
* Changed MRO to priotitize CollectiveVariables's __copy__ method

* CollectiveVariable no longer a Force subclass
  • Loading branch information
craabreu authored May 8, 2024
1 parent 9f708b0 commit 937780f
Show file tree
Hide file tree
Showing 22 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ignored-modules=openmm.unit
ignore=_version.py
extension-pkg-whitelist=openmm.app.internal.compiled
extension-pkg-whitelist=openmm.app.internal.compiled,openmm._openmm

[DESIGN]

Expand Down
2 changes: 1 addition & 1 deletion cvpack/angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .collective_variable import CollectiveVariable


class Angle(openmm.CustomAngleForce, CollectiveVariable):
class Angle(CollectiveVariable, openmm.CustomAngleForce):
r"""
The angle formed by three atoms:
Expand Down
2 changes: 1 addition & 1 deletion cvpack/atomic_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .units import ScalarQuantity, VectorQuantity


class AtomicFunction(openmm.CustomCompoundBondForce, BaseCustomFunction):
class AtomicFunction(BaseCustomFunction, openmm.CustomCompoundBondForce):
r"""
A generic function of the coordinates of :math:`m` groups of :math:`n` atoms:
Expand Down
2 changes: 1 addition & 1 deletion cvpack/attraction_strength.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
ONE_4PI_EPS0 = 138.93545764438198


class AttractionStrength(openmm.CustomNonbondedForce, CollectiveVariable):
class AttractionStrength(CollectiveVariable, openmm.CustomNonbondedForce):
r"""
The strength of the attraction between two atom groups:
Expand Down
2 changes: 1 addition & 1 deletion cvpack/base_path_cv.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .path import Metric, deviation, progress


class BasePathCV(openmm.CustomCVForce, CollectiveVariable):
class BasePathCV(CollectiveVariable, openmm.CustomCVForce):
"""
A base class for path-related collective variables
Expand Down
2 changes: 1 addition & 1 deletion cvpack/base_radius_of_gyration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .collective_variable import CollectiveVariable


class BaseRadiusOfGyration(openmm.CustomCentroidBondForce, CollectiveVariable):
class BaseRadiusOfGyration(CollectiveVariable, openmm.CustomCentroidBondForce):
"""
Abstract class for the radius of gyration of a group of `n` atoms.
"""
Expand Down
2 changes: 1 addition & 1 deletion cvpack/base_rmsd_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from .units import ScalarQuantity, value_in_md_units


class BaseRMSDContent(openmm.CustomCVForce, CollectiveVariable):
class BaseRMSDContent(CollectiveVariable, openmm.CustomCVForce):
"""
Abstract class for secondary-structure RMSD content of a sequence of `n` residues.
"""
Expand Down
2 changes: 1 addition & 1 deletion cvpack/centroid_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .units import ScalarQuantity, VectorQuantity


class CentroidFunction(openmm.CustomCentroidBondForce, BaseCustomFunction):
class CentroidFunction(BaseCustomFunction, openmm.CustomCentroidBondForce):
r"""
A generic function of the centroids of :math:`m \times n` atoms groups split
into `m` collections of `n` groups:
Expand Down
9 changes: 5 additions & 4 deletions cvpack/collective_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

import openmm
import yaml
from openmm import _openmm as mmswig
from openmm import unit as mmunit

from .serialization import Serializable
from .units import Quantity, ScalarQuantity, Unit
from .utils import compute_effective_mass, get_single_force_state, preprocess_args


class CollectiveVariable(openmm.Force, Serializable):
class CollectiveVariable(Serializable):
r"""
An abstract class with common attributes and method for all CVs.
"""
Expand Down Expand Up @@ -63,7 +64,7 @@ def _registerCV(
kwargs
The keyword arguments needed to construct this collective variable
"""
self.setName(name)
mmswig.Force_setName(self, name)
self._unit = cvUnit
self._mass_unit = Unit(mmunit.dalton * (mmunit.nanometers / self._unit) ** 2)
self._args = {"name": name}
Expand Down Expand Up @@ -116,13 +117,13 @@ def _setUnusedForceGroup(self, system: openmm.System) -> None:
new_group = next(filter(lambda i: i not in used_groups, range(32)), None)
if new_group is None:
raise RuntimeError("All force groups are already in use.")
self.setForceGroup(new_group)
mmswig.Force_setForceGroup(self, new_group)

def getName(self) -> str: # pylint: disable=useless-parent-delegation
"""
Get the name of this collective variable.
"""
return super().getName()
return mmswig.Force_getName(self)

def getUnit(self) -> Unit:
"""
Expand Down
2 changes: 1 addition & 1 deletion cvpack/composite_rmsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, _):
CompositeRMSDForce = _Stub


class CompositeRMSD(CompositeRMSDForce, BaseRMSD):
class CompositeRMSD(BaseRMSD, CompositeRMSDForce):
r"""
The composite root-mean-square deviation (RMSD) between the current and reference
coordinates of :math:`m` groups of atoms:
Expand Down
2 changes: 1 addition & 1 deletion cvpack/distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .collective_variable import CollectiveVariable


class Distance(openmm.CustomBondForce, CollectiveVariable):
class Distance(CollectiveVariable, openmm.CustomBondForce):
r"""
The distance between two atoms:
Expand Down
2 changes: 1 addition & 1 deletion cvpack/helix_angle_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .units import Quantity, ScalarQuantity


class HelixAngleContent(openmm.CustomAngleForce, CollectiveVariable):
class HelixAngleContent(CollectiveVariable, openmm.CustomAngleForce):
r"""
The alpha-helix angle content of a sequence of `n` residues:
Expand Down
2 changes: 1 addition & 1 deletion cvpack/helix_hbond_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .units import Quantity, ScalarQuantity


class HelixHBondContent(openmm.CustomBondForce, CollectiveVariable):
class HelixHBondContent(CollectiveVariable, openmm.CustomBondForce):
r"""
The alpha-helix hydrogen-bond content of a sequence of `n` residues:
Expand Down
2 changes: 1 addition & 1 deletion cvpack/helix_torsion_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .units import Quantity, ScalarQuantity


class HelixTorsionContent(openmm.CustomTorsionForce, CollectiveVariable):
class HelixTorsionContent(CollectiveVariable, openmm.CustomTorsionForce):
r"""
The alpha-helix Ramachandran content of a sequence of `n` residues:
Expand Down
2 changes: 1 addition & 1 deletion cvpack/meta_collective_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .utils import compute_effective_mass, get_single_force_state


class MetaCollectiveVariable(openmm.CustomCVForce, CollectiveVariable):
class MetaCollectiveVariable(CollectiveVariable, openmm.CustomCVForce):
r"""
A collective variable that is a function of other collective variables:
Expand Down
2 changes: 1 addition & 1 deletion cvpack/number_of_contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .utils import evaluate_in_context


class NumberOfContacts(openmm.CustomNonbondedForce, CollectiveVariable):
class NumberOfContacts(CollectiveVariable, openmm.CustomNonbondedForce):
r"""
The number of contacts between two atom groups:
Expand Down
2 changes: 1 addition & 1 deletion cvpack/openmm_force_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .units import Unit, VectorQuantity


class OpenMMForceWrapper(CollectiveVariable):
class OpenMMForceWrapper(CollectiveVariable, openmm.Force):
r"""
A collective variable whose numerical value is computed from the potential energy,
in kJ/mol, of an OpenMM force object.
Expand Down
2 changes: 1 addition & 1 deletion cvpack/residue_coordination.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .units import Quantity, ScalarQuantity, value_in_md_units


class ResidueCoordination(openmm.CustomCentroidBondForce, CollectiveVariable):
class ResidueCoordination(CollectiveVariable, openmm.CustomCentroidBondForce):
r"""
The number of contacts between two disjoint groups of residues:
Expand Down
2 changes: 1 addition & 1 deletion cvpack/rmsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .units import MatrixQuantity, VectorQuantity


class RMSD(openmm.RMSDForce, BaseRMSD):
class RMSD(BaseRMSD, openmm.RMSDForce):
r"""
The root-mean-square deviation (RMSD) between the current and reference
coordinates of a group of `n` atoms:
Expand Down
2 changes: 1 addition & 1 deletion cvpack/shortest_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .units import Quantity


class ShortestDistance(openmm.CustomCVForce, CollectiveVariable):
class ShortestDistance(CollectiveVariable, openmm.CustomCVForce):
r"""
A smooth approximation of the shortest distance between two atom groups:
Expand Down
2 changes: 1 addition & 1 deletion cvpack/torsion.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .collective_variable import CollectiveVariable


class Torsion(openmm.CustomTorsionForce, CollectiveVariable):
class Torsion(CollectiveVariable, openmm.CustomTorsionForce):
r"""
The torsion angle formed by four atoms:
Expand Down
2 changes: 1 addition & 1 deletion cvpack/torsion_similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .collective_variable import CollectiveVariable


class TorsionSimilarity(openmm.CustomCompoundBondForce, CollectiveVariable):
class TorsionSimilarity(CollectiveVariable, openmm.CustomCompoundBondForce):
r"""
The degree of similarity between `n` pairs of torsion angles:
Expand Down

0 comments on commit 937780f

Please sign in to comment.