Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues 381, 382, and add a Mass type #385

Merged
merged 7 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python/BioSimSpace/Gateway/_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
from ._requirements import Energy as _Energy
from ._requirements import Integer as _Integer
from ._requirements import Length as _Length
from ._requirements import Mass as _Mass
from ._requirements import Pressure as _Pressure
from ._requirements import Requirement as _Requirement
from ._requirements import String as _String
Expand All @@ -74,6 +75,7 @@
_Energy,
_Pressure,
_Length,
_Mass,
_Area,
_Volume,
_Temperature,
Expand All @@ -86,6 +88,7 @@
_Energy,
_Pressure,
_Length,
_Mass,
_Area,
_Volume,
_Temperature,
Expand Down
201 changes: 169 additions & 32 deletions python/BioSimSpace/Gateway/_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@
"Boolean",
"Integer",
"Float",
"String", # Regular types.
"String",
"File",
"FileSet", # File types.
"FileSet",
"Length",
"Area",
"Volume", # Length types.
"Volume",
"Angle",
"Charge",
"Energy",
"Mass",
"Pressure",
"Temperature",
"Time",
Expand Down Expand Up @@ -744,16 +745,20 @@ class Length(Requirement):
for the default.

>>> import BioSimSpace as BSS
>>> my_length = BSS.Gateway.Length(help="A length requirement",
... default=10*BSS.Units.Length.angstrom)
>>> my_length = BSS.Gateway.Length(
... help="A length requirement",
... default=10*BSS.Units.Length.angstrom
... )

Create a length requirement with a default of 10 Angstrom and a maximum
of 50 nanometers. Note that the unit is taken from the default value.

>>> import BioSimSpace as BSS
>>> my_length = BSS.Gateway.Length(help="A length requirement",
... default=10*BSS.Units.Length.angstrom,
... maximum=50*BSS.Units.Length.nanometer)
>>> my_length = BSS.Gateway.Length(
... help="A length requirement",
... default=10*BSS.Units.Length.angstrom,
... maximum=50*BSS.Units.Length.nanometer
... )
"""

# Set the argparse argument type.
Expand Down Expand Up @@ -866,9 +871,11 @@ class Area(Requirement):
of 50 square nanometers. Note that the unit is taken from the default value.

>>> import BioSimSpace as BSS
>>> my_area = BSS.Gateway.Area(help="An area requirement",
... default=100*BSS.Units.Area.angstrom2,
... maximum=50*BSS.Units.Area.nanometer2)
>>> my_area = BSS.Gateway.Area(
... help="An area requirement",
... default=100*BSS.Units.Area.angstrom2,
... maximum=50*BSS.Units.Area.nanometer2
... )
"""

# Set the argparse argument type.
Expand Down Expand Up @@ -981,9 +988,11 @@ class Volume(Requirement):
of 50 cubed nanometers. Note that the unit is taken from the default value.

>>> import BioSimSpace as BSS
>>> my_volume = BSS.Gateway.Volume(help="A volume requirement",
... default=10*BSS.Units.Volume.angstrom3,
... maximum=50*BSS.Units.Volume.nanometer3)
>>> my_volume = BSS.Gateway.Volume(
... help="A volume requirement",
... default=10*BSS.Units.Volume.angstrom3,
... maximum=50*BSS.Units.Volume.nanometer3
... )
"""

# Set the argparse argument type.
Expand Down Expand Up @@ -1096,9 +1105,11 @@ class Angle(Requirement):
of 360 degrees. Note that the unit is taken from the default value.

>>> import BioSimSpace as BSS
>>> my_angle = BSS.Gateway.Angle(help="An angle requirement",
... default=3.14*BSS.Units.Angle.radian,
... maximum=360*BSS.Units.Angle.degree)
>>> my_angle = BSS.Gateway.Angle(
... help="An angle requirement",
... default=3.14*BSS.Units.Angle.radian,
... maximum=360*BSS.Units.Angle.degree
... )
"""

# Set the argparse argument type.
Expand Down Expand Up @@ -1211,9 +1222,11 @@ class Charge(Requirement):
maximum of -10 Coulomb. Note that the unit is taken from the default value.

>>> import BioSimSpace as BSS
>>> my_charge = BSS.Gateway.Charge(help="A charge requirement",
... default=3*BSS.Units.Charge.electron_charge,
... maximum=10*BSS.Units.Charge.coulomb)
>>> my_charge = BSS.Gateway.Charge(
... help="A charge requirement",
... default=3*BSS.Units.Charge.electron_charge,
... maximum=10*BSS.Units.Charge.coulomb
... )
"""

# Set the argparse argument type.
Expand Down Expand Up @@ -1326,9 +1339,11 @@ class Energy(Requirement):
maximum of 50 kJ per mol. Note that the unit is taken from the default value.

>>> import BioSimSpace as BSS
>>> my_energy = BSS.Gateway.Energy(help="An energy requirement",
... default=3*BSS.Units.Energy.kcal_per_mol,
... maximum=50*BSS.Units.Energy.kj_per_mol)
>>> my_energy = BSS.Gateway.Energy(
... help="An energy requirement",
... default=3*BSS.Units.Energy.kcal_per_mol,
... maximum=50*BSS.Units.Energy.kj_per_mol
... )
"""

# Set the argparse argument type.
Expand Down Expand Up @@ -1419,6 +1434,122 @@ def _validate(self, value):
return _Types.Energy(value, unit)._convert_to(self._unit)


class Mass(Requirement):
"""A mass requirement.

Examples
--------

Create a mass requirement with a default of 10 grams.

>>> import BioSimSpace as BSS
>>> my_mass = BSS.Gateway.Mass(help="A mass requirement with a default of 10 grams", default=10, unit="gram")

The same, but explicitly passing a :class:`Mass <BioSimSpace.Types.Mass>`

>>> import BioSimSpace as BSS
>>> my_mass = BSS.Gateway.Mass(help="A mass requirement with a default of 10 grams", default=10*BSS.Units.Mass.gram)

Create a mass requirement with a default of 10 grams and a maximum of 10 kilograms.
Note that the unit is taken from the default value.

>>> import BioSimSpace as BSS
>>> my_mass = BSS.Gateway.Mass(
... help="A mass requirement with a default of 10 grams",
... default=10*BSS.Units.Mass.gram,
... maximum=10*BSS.Units.Mass.kilogram
... )
"""

# Set the argparse argument type.
_arg_type = str

def __init__(
self,
help=None,
default=None,
unit=None,
minimum=None,
maximum=None,
allowed=None,
):
"""
Constructor.

Parameters
----------

help : str
The help string.

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

unit : str
The unit.

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

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

allowed : [:class:`Mass <BioSimSpace.Types.Mass>`]
A list of allowed values.
"""

# Validate the unit.
if unit is not None:
mass = _Types.Mass("1 %s" % unit)
self._unit = mass.unit()
self._print_unit = mass._print_format[mass.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 getValue(self):
"""
Return the value.

Returns
-------

value : :class:`Mass <BioSimSpace.Types.Mass>`
The value of the requirement.
"""
if self._value is None:
return None
else:
return _copy.deepcopy(self._value)

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

if isinstance(value, _Types.Mass):
return value._convert_to(self._unit)

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

if unit is None:
return _Types.Mass(value, self._unit)
else:
return _Types.Mass(value, unit)._convert_to(self._unit)


class Pressure(Requirement):
"""A pressure requirement.

Expand All @@ -1440,9 +1571,11 @@ class Pressure(Requirement):
maximum of 10 bar. Note that the unit is taken from the default value.

>>> import BioSimSpace as BSS
>>> my_pressure = BSS.Gateway.Pressure(help="A pressure requirement",
... default=BSS.Units.Pressure.atm,
... maximum=10*BSS.Units.Pressure.bar)
>>> my_pressure = BSS.Gateway.Pressure(
... help="A pressure requirement",
... default=BSS.Units.Pressure.atm,
... maximum=10*BSS.Units.Pressure.bar
... )
"""

# Set the argparse argument type.
Expand Down Expand Up @@ -1555,9 +1688,11 @@ class Temperature(Requirement):
maximum of 100 Celsius. Note that the unit is taken from the default value.

>>> import BioSimSpace as BSS
>>> my_temperature = BSS.Gateway.Temperature(help="A temperature requirement",
... default=300*BSS.Units.Temperature.kelvin,
... maximum=100*BSS.Units.Temperature.celsius)
>>> my_temperature = BSS.Gateway.Temperature(
... help="A temperature requirement",
... default=300*BSS.Units.Temperature.kelvin,
... maximum=100*BSS.Units.Temperature.celsius
... )
"""

# Set the argparse argument type.
Expand Down Expand Up @@ -1670,9 +1805,11 @@ class Time(Requirement):
of 5 hours. Note that the unit is taken from the default value.

>>> import BioSimSpace as BSS
>>> my_time = BSS.Gateway.Time(help="A time requirement",
... default=35*BSS.Units.Time.minute,
... maximum=5*BSS.Units.Time.hour)
>>> my_time = BSS.Gateway.Time(
... help="A time requirement",
... default=35*BSS.Units.Time.minute,
... maximum=5*BSS.Units.Time.hour
... )
"""

# Set the argparse argument type.
Expand Down
3 changes: 3 additions & 0 deletions python/BioSimSpace/Process/_amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def __init__(

explicit_dummies : bool
Whether to keep dummy atoms explicit at alchemical end states, or remove them.
This option is provided for legacy support of alchemical free energy calculations
using the old PMEMD CPU implementation. The default is False, which should be
used for any recent AMBER version or for GPU accelerated PMEMD.

exe : str
The full path to the AMBER executable.
Expand Down
3 changes: 3 additions & 0 deletions python/BioSimSpace/Sandpit/Exscientia/Gateway/_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
from ._requirements import Energy as _Energy
from ._requirements import Integer as _Integer
from ._requirements import Length as _Length
from ._requirements import Mass as _Mass
from ._requirements import Pressure as _Pressure
from ._requirements import Requirement as _Requirement
from ._requirements import String as _String
Expand All @@ -74,6 +75,7 @@
_Energy,
_Pressure,
_Length,
_Mass,
_Area,
_Volume,
_Temperature,
Expand All @@ -86,6 +88,7 @@
_Energy,
_Pressure,
_Length,
_Mass,
_Area,
_Volume,
_Temperature,
Expand Down
Loading