@@ -44,7 +44,7 @@ class ResidueCoordination(openmm.CustomCentroidBondForce, AbstractCollectiveVari
4444 ----------
4545 residueGroup1
4646 The residues in the first group
47- group2
47+ residueGroup2
4848 The residues in the second group
4949 pbc
5050 Whether the system has periodic boundary conditions
@@ -97,6 +97,10 @@ class ResidueCoordination(openmm.CustomCentroidBondForce, AbstractCollectiveVari
9797 >>> context.setPositions(model.positions)
9898 >>> print(residue_coordination.getValue(context))
9999 26.0 dimensionless
100+ >>> residue_coordination.setReferenceValue(26 * unit.dimensionless)
101+ >>> context.reinitialize(preserveState=True)
102+ >>> print(residue_coordination.getValue(context, digits=6))
103+ 1.0 dimensionless
100104 """
101105
102106 @mmunit .convert_quantities
@@ -114,10 +118,13 @@ def __init__( # pylint: disable=too-many-arguments
114118 ) -> None :
115119 nr1 = len (residueGroup1 )
116120 nr2 = len (residueGroup2 )
117- if {res .index for res in residueGroup1 } & {res .index for res in residueGroup2 }:
118- raise ValueError ("The two groups of residues must be disjoint" )
119- energy = f"({ stepFunction } )/{ nr1 * nr2 } " if normalize else stepFunction
120- super ().__init__ (2 , energy + f"; x=distance(g1,g2)/{ thresholdDistance } " )
121+ self ._ref_val = nr1 * nr2 if normalize else 1.0
122+ expression = (
123+ f"({ stepFunction } )/refval"
124+ f"; x=distance(g1,g2)/{ thresholdDistance } "
125+ f"; refval={ self ._ref_val } "
126+ )
127+ super ().__init__ (2 , expression )
121128 self .setUsesPeriodicBoundaryConditions (pbc )
122129 for res in residueGroup1 + residueGroup2 :
123130 self .addGroup (
@@ -137,3 +144,30 @@ def __init__( # pylint: disable=too-many-arguments
137144 normalize ,
138145 weighByMass ,
139146 )
147+
148+ def getReferenceValue (self ) -> mmunit .Quantity :
149+ """
150+ Get the reference value used for normalizing the residue coordination.
151+
152+ Returns
153+ -------
154+ mmunit.Quantity
155+ The reference value.
156+ """
157+ return self ._ref_val * self .getUnit ()
158+
159+ @mmunit .convert_quantities
160+ def setReferenceValue (self , value : mmunit .ScalarQuantity ) -> None :
161+ """
162+ Set the reference value used for normalizing the residue coordination.
163+
164+ Parameters
165+ ----------
166+ value
167+ The reference value.
168+ """
169+ expression = self .getEnergyFunction ()
170+ self .setEnergyFunction (
171+ expression .replace (f"refval={ self ._ref_val } " , f"refval={ value } " )
172+ )
173+ self ._ref_val = value
0 commit comments