Skip to content

Commit f3e3a9c

Browse files
authored
Merge pull request #385 from OpenBioSim/fix_381
Fix issues 381, 382, and add a Mass type
2 parents 92662d6 + 08697f4 commit f3e3a9c

File tree

15 files changed

+1323
-65
lines changed

15 files changed

+1323
-65
lines changed

python/BioSimSpace/Gateway/_node.py

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
from ._requirements import Energy as _Energy
6161
from ._requirements import Integer as _Integer
6262
from ._requirements import Length as _Length
63+
from ._requirements import Mass as _Mass
6364
from ._requirements import Pressure as _Pressure
6465
from ._requirements import Requirement as _Requirement
6566
from ._requirements import String as _String
@@ -74,6 +75,7 @@
7475
_Energy,
7576
_Pressure,
7677
_Length,
78+
_Mass,
7779
_Area,
7880
_Volume,
7981
_Temperature,
@@ -86,6 +88,7 @@
8688
_Energy,
8789
_Pressure,
8890
_Length,
91+
_Mass,
8992
_Area,
9093
_Volume,
9194
_Temperature,

python/BioSimSpace/Gateway/_requirements.py

+169-32
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@
3131
"Boolean",
3232
"Integer",
3333
"Float",
34-
"String", # Regular types.
34+
"String",
3535
"File",
36-
"FileSet", # File types.
36+
"FileSet",
3737
"Length",
3838
"Area",
39-
"Volume", # Length types.
39+
"Volume",
4040
"Angle",
4141
"Charge",
4242
"Energy",
43+
"Mass",
4344
"Pressure",
4445
"Temperature",
4546
"Time",
@@ -744,16 +745,20 @@ class Length(Requirement):
744745
for the default.
745746
746747
>>> import BioSimSpace as BSS
747-
>>> my_length = BSS.Gateway.Length(help="A length requirement",
748-
... default=10*BSS.Units.Length.angstrom)
748+
>>> my_length = BSS.Gateway.Length(
749+
... help="A length requirement",
750+
... default=10*BSS.Units.Length.angstrom
751+
... )
749752
750753
Create a length requirement with a default of 10 Angstrom and a maximum
751754
of 50 nanometers. Note that the unit is taken from the default value.
752755
753756
>>> import BioSimSpace as BSS
754-
>>> my_length = BSS.Gateway.Length(help="A length requirement",
755-
... default=10*BSS.Units.Length.angstrom,
756-
... maximum=50*BSS.Units.Length.nanometer)
757+
>>> my_length = BSS.Gateway.Length(
758+
... help="A length requirement",
759+
... default=10*BSS.Units.Length.angstrom,
760+
... maximum=50*BSS.Units.Length.nanometer
761+
... )
757762
"""
758763

759764
# Set the argparse argument type.
@@ -866,9 +871,11 @@ class Area(Requirement):
866871
of 50 square nanometers. Note that the unit is taken from the default value.
867872
868873
>>> import BioSimSpace as BSS
869-
>>> my_area = BSS.Gateway.Area(help="An area requirement",
870-
... default=100*BSS.Units.Area.angstrom2,
871-
... maximum=50*BSS.Units.Area.nanometer2)
874+
>>> my_area = BSS.Gateway.Area(
875+
... help="An area requirement",
876+
... default=100*BSS.Units.Area.angstrom2,
877+
... maximum=50*BSS.Units.Area.nanometer2
878+
... )
872879
"""
873880

874881
# Set the argparse argument type.
@@ -981,9 +988,11 @@ class Volume(Requirement):
981988
of 50 cubed nanometers. Note that the unit is taken from the default value.
982989
983990
>>> import BioSimSpace as BSS
984-
>>> my_volume = BSS.Gateway.Volume(help="A volume requirement",
985-
... default=10*BSS.Units.Volume.angstrom3,
986-
... maximum=50*BSS.Units.Volume.nanometer3)
991+
>>> my_volume = BSS.Gateway.Volume(
992+
... help="A volume requirement",
993+
... default=10*BSS.Units.Volume.angstrom3,
994+
... maximum=50*BSS.Units.Volume.nanometer3
995+
... )
987996
"""
988997

989998
# Set the argparse argument type.
@@ -1096,9 +1105,11 @@ class Angle(Requirement):
10961105
of 360 degrees. Note that the unit is taken from the default value.
10971106
10981107
>>> import BioSimSpace as BSS
1099-
>>> my_angle = BSS.Gateway.Angle(help="An angle requirement",
1100-
... default=3.14*BSS.Units.Angle.radian,
1101-
... maximum=360*BSS.Units.Angle.degree)
1108+
>>> my_angle = BSS.Gateway.Angle(
1109+
... help="An angle requirement",
1110+
... default=3.14*BSS.Units.Angle.radian,
1111+
... maximum=360*BSS.Units.Angle.degree
1112+
... )
11021113
"""
11031114

11041115
# Set the argparse argument type.
@@ -1211,9 +1222,11 @@ class Charge(Requirement):
12111222
maximum of -10 Coulomb. Note that the unit is taken from the default value.
12121223
12131224
>>> import BioSimSpace as BSS
1214-
>>> my_charge = BSS.Gateway.Charge(help="A charge requirement",
1215-
... default=3*BSS.Units.Charge.electron_charge,
1216-
... maximum=10*BSS.Units.Charge.coulomb)
1225+
>>> my_charge = BSS.Gateway.Charge(
1226+
... help="A charge requirement",
1227+
... default=3*BSS.Units.Charge.electron_charge,
1228+
... maximum=10*BSS.Units.Charge.coulomb
1229+
... )
12171230
"""
12181231

12191232
# Set the argparse argument type.
@@ -1326,9 +1339,11 @@ class Energy(Requirement):
13261339
maximum of 50 kJ per mol. Note that the unit is taken from the default value.
13271340
13281341
>>> import BioSimSpace as BSS
1329-
>>> my_energy = BSS.Gateway.Energy(help="An energy requirement",
1330-
... default=3*BSS.Units.Energy.kcal_per_mol,
1331-
... maximum=50*BSS.Units.Energy.kj_per_mol)
1342+
>>> my_energy = BSS.Gateway.Energy(
1343+
... help="An energy requirement",
1344+
... default=3*BSS.Units.Energy.kcal_per_mol,
1345+
... maximum=50*BSS.Units.Energy.kj_per_mol
1346+
... )
13321347
"""
13331348

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

14211436

1437+
class Mass(Requirement):
1438+
"""A mass requirement.
1439+
1440+
Examples
1441+
--------
1442+
1443+
Create a mass requirement with a default of 10 grams.
1444+
1445+
>>> import BioSimSpace as BSS
1446+
>>> my_mass = BSS.Gateway.Mass(help="A mass requirement with a default of 10 grams", default=10, unit="gram")
1447+
1448+
The same, but explicitly passing a :class:`Mass <BioSimSpace.Types.Mass>`
1449+
1450+
>>> import BioSimSpace as BSS
1451+
>>> my_mass = BSS.Gateway.Mass(help="A mass requirement with a default of 10 grams", default=10*BSS.Units.Mass.gram)
1452+
1453+
Create a mass requirement with a default of 10 grams and a maximum of 10 kilograms.
1454+
Note that the unit is taken from the default value.
1455+
1456+
>>> import BioSimSpace as BSS
1457+
>>> my_mass = BSS.Gateway.Mass(
1458+
... help="A mass requirement with a default of 10 grams",
1459+
... default=10*BSS.Units.Mass.gram,
1460+
... maximum=10*BSS.Units.Mass.kilogram
1461+
... )
1462+
"""
1463+
1464+
# Set the argparse argument type.
1465+
_arg_type = str
1466+
1467+
def __init__(
1468+
self,
1469+
help=None,
1470+
default=None,
1471+
unit=None,
1472+
minimum=None,
1473+
maximum=None,
1474+
allowed=None,
1475+
):
1476+
"""
1477+
Constructor.
1478+
1479+
Parameters
1480+
----------
1481+
1482+
help : str
1483+
The help string.
1484+
1485+
default : :class:`Mass <BioSimSpace.Types.Mass>`
1486+
The default value.
1487+
1488+
unit : str
1489+
The unit.
1490+
1491+
minimum : :class:`Mass <BioSimSpace.Types.Mass>`
1492+
The minimum allowed value.
1493+
1494+
maximum : :class:`Mass <BioSimSpace.Types.Mass>`
1495+
The maximum allowed value.
1496+
1497+
allowed : [:class:`Mass <BioSimSpace.Types.Mass>`]
1498+
A list of allowed values.
1499+
"""
1500+
1501+
# Validate the unit.
1502+
if unit is not None:
1503+
mass = _Types.Mass("1 %s" % unit)
1504+
self._unit = mass.unit()
1505+
self._print_unit = mass._print_format[mass.unit()]
1506+
else:
1507+
try:
1508+
self._unit = default.unit()
1509+
except:
1510+
raise ValueError("No unit or default value has been specified!")
1511+
1512+
# Call the base class constructor.
1513+
super().__init__(
1514+
help=help,
1515+
default=default,
1516+
unit=self._unit,
1517+
minimum=minimum,
1518+
maximum=maximum,
1519+
allowed=allowed,
1520+
)
1521+
1522+
def getValue(self):
1523+
"""
1524+
Return the value.
1525+
1526+
Returns
1527+
-------
1528+
1529+
value : :class:`Mass <BioSimSpace.Types.Mass>`
1530+
The value of the requirement.
1531+
"""
1532+
if self._value is None:
1533+
return None
1534+
else:
1535+
return _copy.deepcopy(self._value)
1536+
1537+
def _validate(self, value):
1538+
"""Validate that the value is of the correct type."""
1539+
1540+
if isinstance(value, _Types.Mass):
1541+
return value._convert_to(self._unit)
1542+
1543+
else:
1544+
# Extract the value and unit from the argument string.
1545+
value, unit = _validate_unit_requirement(value, "pressure")
1546+
1547+
if unit is None:
1548+
return _Types.Mass(value, self._unit)
1549+
else:
1550+
return _Types.Mass(value, unit)._convert_to(self._unit)
1551+
1552+
14221553
class Pressure(Requirement):
14231554
"""A pressure requirement.
14241555
@@ -1440,9 +1571,11 @@ class Pressure(Requirement):
14401571
maximum of 10 bar. Note that the unit is taken from the default value.
14411572
14421573
>>> import BioSimSpace as BSS
1443-
>>> my_pressure = BSS.Gateway.Pressure(help="A pressure requirement",
1444-
... default=BSS.Units.Pressure.atm,
1445-
... maximum=10*BSS.Units.Pressure.bar)
1574+
>>> my_pressure = BSS.Gateway.Pressure(
1575+
... help="A pressure requirement",
1576+
... default=BSS.Units.Pressure.atm,
1577+
... maximum=10*BSS.Units.Pressure.bar
1578+
... )
14461579
"""
14471580

14481581
# Set the argparse argument type.
@@ -1555,9 +1688,11 @@ class Temperature(Requirement):
15551688
maximum of 100 Celsius. Note that the unit is taken from the default value.
15561689
15571690
>>> import BioSimSpace as BSS
1558-
>>> my_temperature = BSS.Gateway.Temperature(help="A temperature requirement",
1559-
... default=300*BSS.Units.Temperature.kelvin,
1560-
... maximum=100*BSS.Units.Temperature.celsius)
1691+
>>> my_temperature = BSS.Gateway.Temperature(
1692+
... help="A temperature requirement",
1693+
... default=300*BSS.Units.Temperature.kelvin,
1694+
... maximum=100*BSS.Units.Temperature.celsius
1695+
... )
15611696
"""
15621697

15631698
# Set the argparse argument type.
@@ -1670,9 +1805,11 @@ class Time(Requirement):
16701805
of 5 hours. Note that the unit is taken from the default value.
16711806
16721807
>>> import BioSimSpace as BSS
1673-
>>> my_time = BSS.Gateway.Time(help="A time requirement",
1674-
... default=35*BSS.Units.Time.minute,
1675-
... maximum=5*BSS.Units.Time.hour)
1808+
>>> my_time = BSS.Gateway.Time(
1809+
... help="A time requirement",
1810+
... default=35*BSS.Units.Time.minute,
1811+
... maximum=5*BSS.Units.Time.hour
1812+
... )
16761813
"""
16771814

16781815
# Set the argparse argument type.

python/BioSimSpace/Process/_amber.py

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ def __init__(
102102
103103
explicit_dummies : bool
104104
Whether to keep dummy atoms explicit at alchemical end states, or remove them.
105+
This option is provided for legacy support of alchemical free energy calculations
106+
using the old PMEMD CPU implementation. The default is False, which should be
107+
used for any recent AMBER version or for GPU accelerated PMEMD.
105108
106109
exe : str
107110
The full path to the AMBER executable.

python/BioSimSpace/Sandpit/Exscientia/Gateway/_node.py

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
from ._requirements import Energy as _Energy
6161
from ._requirements import Integer as _Integer
6262
from ._requirements import Length as _Length
63+
from ._requirements import Mass as _Mass
6364
from ._requirements import Pressure as _Pressure
6465
from ._requirements import Requirement as _Requirement
6566
from ._requirements import String as _String
@@ -74,6 +75,7 @@
7475
_Energy,
7576
_Pressure,
7677
_Length,
78+
_Mass,
7779
_Area,
7880
_Volume,
7981
_Temperature,
@@ -86,6 +88,7 @@
8688
_Energy,
8789
_Pressure,
8890
_Length,
91+
_Mass,
8992
_Area,
9093
_Volume,
9194
_Temperature,

0 commit comments

Comments
 (0)