####################################################################### 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 grids for metadynamics simulation."""__author__="Lester Hedges"__email__="lester.hedges@gmail.com"__all__=["Grid"]from..Types._typeimportTypeas_Type
[docs]def__init__(self,minimum,maximum,num_bins=None):""" Constructor. Define a grid for use in metadynamics simulation. Parameters ---------- mimumum : int, float, :class:`Type <BioSimSpace.Types>` The minimum value of the grid. Use 'int' or 'float' for dimensionless collective variables. maximum : int, float, :class:`Type <BioSimSpace.Types>` The maximum value of the grid. Use 'int' or 'float' for dimensionless collective variables. num_bins : int The number of bins in the grid. If None, then the number will be automatically generated from the metadynamics hill width. """ifnum_binsisnotNone:try:num_bins=int(num_bins)except:raiseTypeError("'num_bins' must be of type 'int'")self.setMinimum(minimum)self.setMaximum(maximum)ifnum_binsisnotNone:self.setBins(num_bins)else:self._num_bins=None
def__str__(self):"""Return a human readable string representation of the object."""return("<BioSimSpace.Metadynamics.Grid: minimum=%s, maximum=%s, num_bins=%s>"%(self._minimum,self._maximum,self._num_bins))def__repr__(self):"""Return a human readable string representation of the object."""returnself.__str__()def__eq__(self,other):"""Equality operator."""return(self._minimum==other._minimumandself._maximum==other._maximumandself._num_bins==other._num_bins)
[docs]defsetMinimum(self,minimum):""" Set the minimum value of the grid. Parameters ---------- minimum : int, float, :class:`Type <BioSimSpace.Types>` The minimum value of the grid. """ifnotisinstance(minimum,(float,_Type))andnottype(minimum)isint:raiseTypeError("'minimum' must be of type 'int', 'float', or 'BioSimSpace.Types._type.Type'")self._minimum=minimumifhasattr(self,"_maximum"):iftype(self._minimum)isnottype(self._maximum):raiseTypeError("'minimum' and 'maximum' must be of the same type.")ifself._minimum>self._maximum:raiseValueError("'minimum' must be less than 'maximum'")
[docs]defgetMinimum(self):""" Get the minimum value of the grid. Returns ------- minimum : int, float, :class:`Type <BioSimSpace.Types>` The minimum value of the grid. """returnself._minimum
[docs]defsetMaximum(self,maximum):""" Set the maximum value of the grid. Parameters ---------- maximum : int, float, :class:`Type <BioSimSpace.Types>` The maximum value of the grid. """ifnotisinstance(maximum,(float,_Type))andnottype(maximum)isint:raiseTypeError("'maximum' must be of type 'int', 'float', or 'BioSimSpace.Types._type.Type'")self._maximum=maximumifhasattr(self,"_minimum"):iftype(self._minimum)isnottype(self._maximum):raiseTypeError("'minimum' and 'maximum' must be of the same type.")ifself._minimum>self._maximum:raiseValueError("'minimum' must be less than 'maximum'")
[docs]defgetMaximum(self):""" Get the maximum value of the grid. Returns ------- maximum : int, float, :class:`Type <BioSimSpace.Types>` The maximum value of the grid. """returnself._maximum
[docs]defsetBins(self,num_bins):""" Set the number of bins in the grid. Parameters ---------- num_bins : int The number of bins in the grid. """try:num_bins=int(num_bins)except:raiseTypeError("'num_bins' must be of type 'int'")ifnum_bins<1:raiseValueError("'num_bins' must be a positive integer.")self._num_bins=num_bins
[docs]defgetBins(self):""" Get the number of bins in the grid. Returns ------- num_bins : int The number of bins in the grid. """returnself._num_bins