Source code for BioSimSpace.Metadynamics._restraint
####################################################################### BioSimSpace: Making biomolecular simulation a breeze!## Copyright: 2017-2024## Authors: Lester Hedges <lester.hedges@gmail.com>## BioSimSpace is free software: you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation, either version 3 of the License, or# (at your option) any later version.## BioSimSpace is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with BioSimSpace. If not, see <http://www.gnu.org/licenses/>.#####################################################################"""Functionality for configuring restraints on collective variables."""__author__="Lester Hedges"__email__="lester.hedges@gmail.com"__all__=["Restraint"]from..Types._typeimportTypeas_Type
[docs]def__init__(self,value,force_constant=100.0,slope=0.0):""" Constructor. Set a restraint on the value of a collective variable. The expression for the bias is: .. math:: k/2 (x - a)^2 + m (x - a) The default restraint is purely harmonic. Parameters ---------- value : int, float, :class:`Type <BioSimSpace.Types>` The value of the restraint. Use 'int' or 'float' for dimensionless collective variables. force_constant : float The force constant (k) for the harmonic term of the restraint. slope : float The slope (m) for the linar term of the restraint. """self.setValue(value)self.setForceConstant(force_constant)self.setSlope(slope)
def__str__(self):"""Return a human readable string representation of the object."""return("<BioSimSpace.Metadynamics.Restraint: value=%s, force_constant=%s, slope=%s>"%(self._value,self._force_constant,self._slope))def__repr__(self):"""Return a human readable string representation of the object."""returnself.__str__()def__eq__(self,other):"""Equality operator."""return(self._value==other._valueandself._force_constant==other._force_constantandself._slope==other._slope)
[docs]defsetValue(self,value):""" Set the value of the bound. Parameters ---------- value : int, float, :class:`Type <BioSimSpace.Types>` The value of the bound. """ifnotisinstance(value,(float,_Type))andnottype(value)isint:raiseTypeError("'value' must be of type 'int', 'float', or 'BioSimSpace.Types._type.Type'")self._value=value
[docs]defgetValue(self):""" Get the value of the bound. Returns ------- value : int, float, :class:`Type <BioSimSpace.Types>` The value of the bound. """returnself._value
[docs]defsetForceConstant(self,force_constant):""" Set the force constant (k) for the harmonic term of the restraint. Parameters ---------- force_constant : float The force constant for the harmonic term of the restraint. """try:self._force_constant=float(force_constant)except:raiseTypeError("'force_constant' must be of type 'float'")
[docs]defgetForceConstant(self):""" Get the force constant (k) for the harmonic term of the restraint. Returns ------- force_constant : float The force constant for the harmonic term of the restraint. """returnself._force_constant
[docs]defsetSlope(self,slope):""" Set the slope (m) for the linear term of the restraint. Parameters ---------- slope : float The slope for the linear term of the restraint. """try:self._slope=float(slope)except:raiseTypeError("'slope' must be of type 'float'")
[docs]defgetSlope(self):""" Get the slope (m) for the linear term of the restraint. Returns ------- slope : float The slope for the linear term of the restraint. """returnself._slope