def _validate(self, value): """Validate that the value is of the correct type.""" if type(value) is _Types.Energy: return value._convert_to(self._unit) else: # Extract the value and unit from the argument string. value, unit = _validate_unit_requirement(value, "energy") if unit is None: return _Types.Energy(value, self._unit) else: return _Types.Energy(value, unit)._convert_to(self._unit)
def __init__(self, help=None, default=None, unit=None, minimum=None, maximum=None, allowed=None): """Constructor. Parameters ---------- help : str The help string. default : :class:`Energy <BioSimSpace.Types.Energy>` The default value. unit : str The unit. minimum : :class:`Energy <BioSimSpace.Types.Energy>` The minimum allowed value. maximum : :class:`Energy <BioSimSpace.Types.Energy>` The maximum allowed value. allowed : [:class:`Energy <BioSimSpace.Types.Energy>`] A list of allowed values. """ # Validate the unit. if unit is not None: nrg = _Types.Energy("1 %s" % unit) self._unit = nrg.unit() self._print_unit = nrg._print_format[nrg.unit()] else: try: self._unit = default.unit() except: raise ValueError( "No unit or default value has been specified!") # Call the base class constructor. super().__init__(help=help, default=default, unit=self._unit, minimum=minimum, maximum=maximum, allowed=allowed)
def __init__(self, collective_variable, timestep=_Types.Time(2, "femtosecond"), runtime=_Types.Time(1, "nanosecond"), temperature=_Types.Temperature(300, "kelvin"), pressure=_Types.Pressure(1, "atmosphere"), hill_height=_Types.Energy(1, "kj per mol"), hill_frequency=1000, bias_factor=None, hills_file=None, grid_file=None, colvar_file=None ): """Constructor. Parameters ---------- collective_variable : :class:`CollectiveVariable <BioSimSpace.Metadynamics.CollectiveVariable>`, \ [:class:`CollectiveVariable <BioSimSpace.Metadynamics.CollectiveVariable>`] The collective variable (or variables) for the simulation. timestep : :class:`Time <BioSimSpace.Types.Time>` The integration timestep. runtime : :class:`Time <BioSimSpace.Types.Time>` The running time. temperature : :class:`Temperature <BioSimSpace.Types.Temperature>` The temperature. pressure : :class:`Pressure <BioSimSpace.Types.Pressure>` The pressure. Pass pressure=None to use the NVT ensemble. hill_height : :class:`Energy <BioSimSpace.Types.Energy>` The height of the Gaussian hills. hill_frequency : int The frequency at which hills are deposited. bias_factor : float The bias factor for well tempered metadynamics. hills_file : str The path to a HILLS file from a previous simulation. This can be used to restart in order to contiune sampling. The information in the file must be consistent with the 'collective_variable' argument. grid_file : str The path to a GRID file from a previous simulation. This can be used to restart in order to continue sampling. The information in the file must be consistent with the 'collective_variable' argument. colvar_file : str The path to a COLVAR file from a previous simulation. The information in the file must be consistent with the 'collective_variable' argument. """ # Call the base class constructor. super().__init__() # Whether this is a newly created object. self._is_new_object = True # Set the collective variable. self.setCollectiveVariable(collective_variable) # Set the time step. self.setTimeStep(timestep) # Set the runtime. self.setRunTime(runtime) # Set the system temperature. self.setTemperature(temperature) # Set the system pressure. if pressure is not None: self.setPressure(pressure) else: self._pressure = None # Set the hill parameters: height, frequency. self.setHillHeight(hill_height) self.setHillFrequency(hill_frequency) # Set the bias factor for well tempered metadynamics. if bias_factor is not None: self.setBiasFactor(bias_factor) else: self._bias_factor = None # Set the restart files. if hills_file is not None: self.setHillsFile(hills_file) else: self._hills_file = None if grid_file is not None: self.setGridFile(grid_file) else: self._grid_file = None if colvar_file is not None: self.setColvarFile(colvar_file) else: self._colvar_file = None # Flag that the object has been created. self._is_new_object = False