Esempio n. 1
0
    def _validate(self, value):
        """Validate that the value is of the correct type."""

        if type(value) is _Types.Time:
            return value._convert_to(self._unit)

        else:
            # Extract the value and unit from the argument string.
            value, unit = _validate_unit_requirement(value, "time")

            if unit is None:
                return _Types.Time(value, self._unit)
            else:
                return _Types.Time(value, unit)._convert_to(self._unit)
Esempio n. 2
0
    def __init__(self,
                 help=None,
                 default=None,
                 unit=None,
                 minimum=None,
                 maximum=None,
                 allowed=None):
        """Constructor.

           Parameters
           ----------

           help : str
               The help string.

           default : :class:`Time <BioSimSpace.Types.Time>`
               The default value.

           unit : str
               The unit.

           minimum : :class:`Time <BioSimSpace.Types.Time>`
               The minimum allowed value.

           maximum : :class:`Time <BioSimSpace.Types.Time>`
               The maximum allowed value.

           allowed : [:class:`Time <BioSimSpace.Types.Time>`]
               The list of allowed values.
        """

        # Validate the unit.
        if unit is not None:
            time = _Types.Time("1 %s" % unit)
            self._unit = time.unit()
            self._print_unit = time._print_format[time.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)
Esempio n. 3
0
    def __init__(self,
                 timestep=_Types.Time(2, "femtosecond"),
                 runtime=_Types.Time(0.2, "nanoseconds"),
                 temperature_start=_Types.Temperature(300, "kelvin"),
                 temperature_end=_Types.Temperature(300, "kelvin"),
                 temperature=None,
                 pressure=None,
                 frames=20,
                 restrain_backbone=False):
        """Constructor.

           Parameters
           ----------

           timestep : :class:`Time <BioSimSpace.Types.Time>`
               The integration timestep.

           runtime : :class:`Time <BioSimSpace.Types.Time>`
               The running time.

           temperature_start : :class:`Temperature <BioSimSpace.Types.Temperature>`
               The starting temperature.

           temperature_end : :class:`Temperature <BioSimSpace.Types.Temperature>`
               The final temperature.

           temperature : :class:`Temperature <BioSimSpace.Types.Temperature>`
               The equilibration temperature. This takes precedence of over
               the other temperatures, i.e. to run at fixed temperature.

           pressure : :class:`Pressure <BioSimSpace.Types.Pressure>`
               The pressure. If this argument is omitted then the simulation
               is run using the NVT ensemble.

           frames : int
               The number of trajectory frames to record.

           restrain_backbone : bool
               Whether the atoms in the backbone are fixed.
        """

        # Call the base class constructor.
        super().__init__()

        # Set the time step.
        self.setTimeStep(timestep)

        # Set the running time.
        self.setRunTime(runtime)

        # Constant temperature equilibration.
        if temperature is not None:
            self.setStartTemperature(temperature)
            self.setEndTemperature(temperature)
            self._is_const_temp = True

        # Heating / cooling simulation.
        else:
            self._is_const_temp = False

            # Set the start temperature.
            self.setStartTemperature(temperature_start)

            # Set the final temperature.
            self.setEndTemperature(temperature_end)

            # Constant temperature simulation.
            if self._temperature_start == self._temperature_end:
                self._is_const_temp = True

        # Constant pressure simulation.
        if pressure is not None:
            self.setPressure(pressure)
        else:
            self._pressure = None

        # Set the number of trajectory frames.
        self.setFrames(frames)

        # Set the backbone restraint.
        self.setRestraint(restrain_backbone)
Esempio n. 4
0
    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
Esempio n. 5
0
    def __init__(self,
                 timestep=_Types.Time(2, "femtosecond"),
                 runtime=_Types.Time(1, "nanosecond"),
                 temperature=_Types.Temperature(300, "kelvin"),
                 pressure=_Types.Pressure(1, "atmosphere"),
                 frames=20,
                 first_step=0,
                 restart=False
                ):
        """Constructor.

           Parameters
           ----------

           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.

           frames : int
               The number of trajectory frames to record.

           first_step : int
               The initial time step (for restart simulations).

           restart : bool
               Whether this is a continuation of a previous simulation.
        """

        # Call the base class constructor.
        super().__init__()

        # 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 number of trajectory frames.
        self.setFrames(frames)

        # Set the restart flag.
        self.setRestart(restart)

        # Set the first time step.
        self.setFirstStep(first_step)
Esempio n. 6
0
    def __init__(self,
                 lam=0.0,
                 lam_vals=None,
                 min_lam=0.0,
                 max_lam=1.0,
                 num_lam=11,
                 timestep=_Types.Time(2, "femtosecond"),
                 runtime=_Types.Time(1, "nanosecond"),
                 temperature=_Types.Temperature(300, "kelvin"),
                 pressure=_Types.Pressure(1, "atmosphere")):
        """Constructor.

           Parameters
           ----------

           lam : float
               The perturbation parameter: [0.0, 1.0]

           lam_vals : [float]
               The list of lambda parameters.

           min_lam : float
               The minimum lambda value.

           max_lam : float
               The maximum lambda value.

           num_lam : int
               The number of lambda values.

           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.
        """

        # Call the base class constructor.
        super().__init__()

        # Validate and set the lambda values.
        self.setLambdaValues(lam, lam_vals, min_lam, max_lam, num_lam)

        # 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