######################################################################
# BioSimSpace: Making biomolecular simulation a breeze!
#
# Copyright: 2017-2023
#
# 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 production protocols."""
__author__ = "Lester Hedges"
__email__ = "lester.hedges@gmail.com"
__all__ = ["Production"]
import math as _math
import warnings as _warnings
from .. import Types as _Types
from ._protocol import Protocol as _Protocol
[docs]
class Production(_Protocol):
"""A class for storing production protocols."""
[docs]
def __init__(
self,
timestep=_Types.Time(2, "femtosecond"),
runtime=_Types.Time(1, "nanosecond"),
temperature=_Types.Temperature(300, "kelvin"),
pressure=_Types.Pressure(1, "atmosphere"),
report_interval=100,
restart_interval=100,
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.
report_interval : int
The frequency at which statistics are recorded. (In integration steps.)
restart_interval : int
The frequency at which restart configurations and trajectory
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 report interval.
self.setReportInterval(report_interval)
# Set the restart interval.
self.setRestartInterval(restart_interval)
# Set the restart flag.
self.setRestart(restart)
# Set the first time step.
self.setFirstStep(first_step)
def __str__(self):
"""Return a human readable string representation of the object."""
if self._is_customised:
return "<BioSimSpace.Protocol.Custom>"
else:
return (
"<BioSimSpace.Protocol.Production: timestep=%s, runtime=%s, "
"temperature=%s, pressure=%s, report_interval=%d, "
"restart_interval=%d, first_step=%d, restart=%r>"
) % (
self._timestep,
self._runtime,
self._temperature,
self._pressure,
self._report_interval,
self._restart_interval,
self._first_step,
self._restart,
)
def __repr__(self):
"""Return a string showing how to instantiate the object."""
if self._is_customised:
return "<BioSimSpace.Protocol.Custom>"
else:
return (
"BioSimSpace.Protocol.Production(timestep=%s, runtime=%s, "
"temperature=%s, pressure=%s, report_interval=%d, "
"restart_interval=%d, first_step=%d, restart=%r)"
) % (
self._timestep,
self._runtime,
self._temperature,
self._pressure,
self._report_interval,
self._restart_interval,
self._first_step,
self._restart,
)
[docs]
def getTimeStep(self):
"""
Return the time step.
Returns
-------
timestep : :class:`Time <BioSimSpace.Types.Time>`
The integration time step.
"""
return self._timestep
[docs]
def setTimeStep(self, timestep):
"""
Set the time step.
Parameters
----------
timestep : :class:`Time <BioSimSpace.Types.Time>`
The integration time step.
"""
if isinstance(timestep, _Types.Time):
self._timestep = timestep
else:
raise TypeError("'timestep' must be of type 'BioSimSpace.Types.Time'")
[docs]
def getRunTime(self):
"""
Return the running time.
Returns
-------
runtime : :class:`Time <BioSimSpace.Types.Time>`
The simulation run time.
"""
return self._runtime
[docs]
def setRunTime(self, runtime):
"""
Set the running time.
Parameters
----------
runtime : :class:`Time <BioSimSpace.Types.Time>`
The simulation run time.
"""
if isinstance(runtime, _Types.Time):
self._runtime = runtime
else:
raise TypeError("'runtime' must be of type 'BioSimSpace.Types.Time'")
[docs]
def getTemperature(self):
"""
Return temperature.
Returns
-------
temperature : :class:`Temperature <BioSimSpace.Types.Temperature>`
The simulation temperature.
"""
return self._temperature
[docs]
def setTemperature(self, temperature):
"""
Set the temperature.
Parameters
----------
temperature : :class:`Temperature <BioSimSpace.Types.Temperature>`
The simulation temperature.
"""
if isinstance(temperature, _Types.Temperature):
self._temperature = temperature
else:
raise TypeError(
"'temperature' must be of type 'BioSimSpace.Types.Temperature'"
)
[docs]
def getPressure(self):
"""
Return the pressure.
Returns
-------
pressure : :class:`Pressure <BioSimSpace.Types.Pressure>`
The pressure.
"""
return self._pressure
[docs]
def setPressure(self, pressure):
"""
Set the pressure.
Parameters
----------
pressure : :class:`Pressure <BioSimSpace.Types.Pressure>`
The pressure.
"""
if isinstance(pressure, _Types.Pressure):
self._pressure = pressure
else:
raise TypeError("'pressure' must be of type 'BioSimSpace.Types.Pressure'")
[docs]
def getReportInterval(self):
"""
Return the interval between reporting statistics. (In integration steps.).
Returns
-------
report_interval : int
The number of integration steps between reporting statistics.
"""
return self._report_interval
[docs]
def setReportInterval(self, report_interval):
"""
Set the interval at which statistics are reported. (In integration steps.).
Parameters
----------
report_interval : int
The number of integration steps between reporting statistics.
"""
if not type(report_interval) is int:
raise TypeError("'report_interval' must be of type 'int'")
if report_interval <= 0:
_warnings.warn("'report_interval' must be positive. Using default (100).")
report_interval = 100
self._report_interval = report_interval
[docs]
def getRestartInterval(self):
"""
Return the interval between saving restart confiugrations, and/or
trajectory frames. (In integration steps.).
Returns
-------
restart_interval : int
The number of integration steps between saving restart
configurations and/or trajectory frames.
"""
return self._restart_interval
[docs]
def setRestartInterval(self, restart_interval):
"""
Set the interval between saving restart confiugrations, and/or
trajectory frames. (In integration steps.).
Parameters
----------
restart_interval : int
The number of integration steps between saving restart
configurations and/or trajectory frames.
"""
if not type(restart_interval) is int:
raise TypeError("'restart_interval' must be of type 'int'")
if restart_interval <= 0:
_warnings.warn("'restart_interval' must be positive. Using default (500).")
restart_interval = 500
self._restart_interval = restart_interval
[docs]
def getFirstStep(self):
"""
Return the first time step.
Returns
-------
step : int
The first time step.
"""
return self._first_step
[docs]
def setFirstStep(self, first_step):
"""
Set the initial time step.
Parameters
----------
step : int
The first time step.
"""
if not type(first_step) is int:
raise TypeError("'first_step' must be of type 'int'")
if first_step < 0:
_warnings.warn("The initial time step must be positive. Using default (0).")
self._first_step = 0
else:
self._first_step = _math.ceil(first_step)
[docs]
def isRestart(self):
"""
Return whether this restart simulation.
Returns
-------
is_restart : bool
Whether this is a restart simulation.
"""
return self._restart
[docs]
def setRestart(self, restart):
"""
Set the restart flag.
Parameters
----------
restart : bool
Whether this is a restart simulation.
"""
if isinstance(restart, bool):
self._restart = restart
else:
_warnings.warn("Non-boolean restart flag. Defaulting to False!")
self._restart = False