31
31
"Boolean" ,
32
32
"Integer" ,
33
33
"Float" ,
34
- "String" , # Regular types.
34
+ "String" ,
35
35
"File" ,
36
- "FileSet" , # File types.
36
+ "FileSet" ,
37
37
"Length" ,
38
38
"Area" ,
39
- "Volume" , # Length types.
39
+ "Volume" ,
40
40
"Angle" ,
41
41
"Charge" ,
42
42
"Energy" ,
43
+ "Mass" ,
43
44
"Pressure" ,
44
45
"Temperature" ,
45
46
"Time" ,
@@ -744,16 +745,20 @@ class Length(Requirement):
744
745
for the default.
745
746
746
747
>>> 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
+ ... )
749
752
750
753
Create a length requirement with a default of 10 Angstrom and a maximum
751
754
of 50 nanometers. Note that the unit is taken from the default value.
752
755
753
756
>>> 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
+ ... )
757
762
"""
758
763
759
764
# Set the argparse argument type.
@@ -866,9 +871,11 @@ class Area(Requirement):
866
871
of 50 square nanometers. Note that the unit is taken from the default value.
867
872
868
873
>>> 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
+ ... )
872
879
"""
873
880
874
881
# Set the argparse argument type.
@@ -981,9 +988,11 @@ class Volume(Requirement):
981
988
of 50 cubed nanometers. Note that the unit is taken from the default value.
982
989
983
990
>>> 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
+ ... )
987
996
"""
988
997
989
998
# Set the argparse argument type.
@@ -1096,9 +1105,11 @@ class Angle(Requirement):
1096
1105
of 360 degrees. Note that the unit is taken from the default value.
1097
1106
1098
1107
>>> 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
+ ... )
1102
1113
"""
1103
1114
1104
1115
# Set the argparse argument type.
@@ -1211,9 +1222,11 @@ class Charge(Requirement):
1211
1222
maximum of -10 Coulomb. Note that the unit is taken from the default value.
1212
1223
1213
1224
>>> 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
+ ... )
1217
1230
"""
1218
1231
1219
1232
# Set the argparse argument type.
@@ -1326,9 +1339,11 @@ class Energy(Requirement):
1326
1339
maximum of 50 kJ per mol. Note that the unit is taken from the default value.
1327
1340
1328
1341
>>> 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
+ ... )
1332
1347
"""
1333
1348
1334
1349
# Set the argparse argument type.
@@ -1419,6 +1434,122 @@ def _validate(self, value):
1419
1434
return _Types .Energy (value , unit )._convert_to (self ._unit )
1420
1435
1421
1436
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
+
1422
1553
class Pressure (Requirement ):
1423
1554
"""A pressure requirement.
1424
1555
@@ -1440,9 +1571,11 @@ class Pressure(Requirement):
1440
1571
maximum of 10 bar. Note that the unit is taken from the default value.
1441
1572
1442
1573
>>> 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
+ ... )
1446
1579
"""
1447
1580
1448
1581
# Set the argparse argument type.
@@ -1555,9 +1688,11 @@ class Temperature(Requirement):
1555
1688
maximum of 100 Celsius. Note that the unit is taken from the default value.
1556
1689
1557
1690
>>> 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
+ ... )
1561
1696
"""
1562
1697
1563
1698
# Set the argparse argument type.
@@ -1670,9 +1805,11 @@ class Time(Requirement):
1670
1805
of 5 hours. Note that the unit is taken from the default value.
1671
1806
1672
1807
>>> 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
+ ... )
1676
1813
"""
1677
1814
1678
1815
# Set the argparse argument type.
0 commit comments