Skip to content

Commit

Permalink
Merge pull request #260 from OpenBioSim/fix_258_259
Browse files Browse the repository at this point in the history
Fix issues #258 and #259
  • Loading branch information
lohedges authored Mar 20, 2024
2 parents 9a0e253 + 4e8bc6e commit 4480a5a
Show file tree
Hide file tree
Showing 32 changed files with 615 additions and 481 deletions.
2 changes: 1 addition & 1 deletion python/BioSimSpace/Protocol/_position_restraint_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def setForceConstant(self, force_constant):
)

# Validate the dimensions.
if force_constant.dimensions() != (0, 0, 0, 1, -1, 0, -2):
if force_constant.dimensions() != (1, 0, -2, 0, 0, -1, 0):
raise ValueError(
"'force_constant' has invalid dimensions! "
f"Expected dimensions are 'M Q-1 T-2', found '{force_constant.unit()}'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def __init__(self, system, restraint_dict, temperature, restraint_type="Boresch"
for key in ["kthetaA", "kthetaB", "kphiA", "kphiB", "kphiC"]:
if restraint_dict["force_constants"][key] != 0:
dim = restraint_dict["force_constants"][key].dimensions()
if dim != (-2, 0, 2, 1, -1, 0, -2):
if dim != (1, 2, -2, 0, 0, -1, -2):
raise ValueError(
f"restraint_dict['force_constants']['{key}'] must be of type "
f"'BioSimSpace.Types.Energy'/'BioSimSpace.Types.Angle^2'"
Expand Down Expand Up @@ -202,7 +202,7 @@ def __init__(self, system, restraint_dict, temperature, restraint_type="Boresch"
# Test if the force constant of the bond r1-l1 is the correct unit
# Such as kcal/mol/angstrom^2
dim = restraint_dict["force_constants"]["kr"].dimensions()
if dim != (0, 0, 0, 1, -1, 0, -2):
if dim != (1, 0, -2, 0, 0, -1, 0):
raise ValueError(
"restraint_dict['force_constants']['kr'] must be of type "
"'BioSimSpace.Types.Energy'/'BioSimSpace.Types.Length^2'"
Expand Down Expand Up @@ -290,13 +290,13 @@ def __init__(self, system, restraint_dict, temperature, restraint_type="Boresch"
"'BioSimSpace.Types.Length'"
)
if not single_restraint_dict["kr"].dimensions() == (
1,
0,
-2,
0,
0,
1,
-1,
0,
-2,
):
raise ValueError(
"distance_restraint_dict['kr'] must be of type "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ def analyse(

if force_constant:
dim = force_constant.dimensions()
if dim != (0, 0, 0, 1, -1, 0, -2):
if dim != (1, 0, -2, 0, 0, -1, 0):
raise ValueError(
"force_constant must be of type "
"'BioSimSpace.Types.Energy'/'BioSimSpace.Types.Length^2'"
Expand Down
4 changes: 2 additions & 2 deletions python/BioSimSpace/Sandpit/Exscientia/Protocol/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ def generateAmberConfig(self, extra_options=None, extra_lines=None):
]
restraint_mask = "@" + ",".join(restraint_atom_names)
elif restraint == "heavy":
restraint_mask = "!:WAT & !@H="
restraint_mask = "!:WAT & !@%NA,CL & !@H="
elif restraint == "all":
restraint_mask = "!:WAT"
restraint_mask = "!:WAT & !@%NA,CL"

# We can't do anything about a custom restraint, since we don't
# know anything about the atoms.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def setForceConstant(self, force_constant):
)

# Validate the dimensions.
if force_constant.dimensions() != (0, 0, 0, 1, -1, 0, -2):
if force_constant.dimensions() != (1, 0, -2, 0, 0, -1, 0):
raise ValueError(
"'force_constant' has invalid dimensions! "
f"Expected dimensions are 'M Q-1 T-2', found '{force_constant.unit()}'"
Expand Down
16 changes: 8 additions & 8 deletions python/BioSimSpace/Sandpit/Exscientia/Types/_angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ class Angle(_Type):
# Null type unit for avoiding issue printing configargparse help.
_default_unit = "RADIAN"

# The dimension mask:
# Angle, Charge, Length, Mass, Quantity, Temperature, Time
_dimensions = (1, 0, 0, 0, 0, 0, 0)
# The dimension mask.
_dimensions = tuple(list(_supported_units.values())[0].dimensions())

def __init__(self, *args):
"""
Expand Down Expand Up @@ -188,7 +187,8 @@ def _convert_to(self, unit):
"Supported units are: '%s'" % list(self._supported_units.keys())
)

def _validate_unit(self, unit):
@classmethod
def _validate_unit(cls, unit):
"""Validate that the unit are supported."""

# Strip whitespace and convert to upper case.
Expand All @@ -210,13 +210,13 @@ def _validate_unit(self, unit):
unit = unit.replace("AD", "")

# Check that the unit is supported.
if unit in self._supported_units:
if unit in cls._supported_units:
return unit
elif unit in self._abbreviations:
return self._abbreviations[unit]
elif unit in cls._abbreviations:
return cls._abbreviations[unit]
else:
raise ValueError(
"Supported units are: '%s'" % list(self._supported_units.keys())
"Supported units are: '%s'" % list(cls._supported_units.keys())
)

@staticmethod
Expand Down
16 changes: 8 additions & 8 deletions python/BioSimSpace/Sandpit/Exscientia/Types/_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ class Area(_Type):
# Null type unit for avoiding issue printing configargparse help.
_default_unit = "ANGSTROM2"

# The dimension mask:
# Angle, Charge, Length, Mass, Quantity, Temperature, Time
_dimensions = (0, 0, 2, 0, 0, 0, 0)
# The dimension mask.
_dimensions = tuple(list(_supported_units.values())[0].dimensions())

def __init__(self, *args):
"""
Expand Down Expand Up @@ -330,7 +329,8 @@ def _convert_to(self, unit):
"Supported units are: '%s'" % list(self._supported_units.keys())
)

def _validate_unit(self, unit):
@classmethod
def _validate_unit(cls, unit):
"""Validate that the unit is supported."""

# Strip whitespace and convert to upper case.
Expand Down Expand Up @@ -360,13 +360,13 @@ def _validate_unit(self, unit):
unit = unit[0:index] + unit[index + 1 :] + "2"

# Check that the unit is supported.
if unit in self._supported_units:
if unit in cls._supported_units:
return unit
elif unit in self._abbreviations:
return self._abbreviations[unit]
elif unit in cls._abbreviations:
return cls._abbreviations[unit]
else:
raise ValueError(
"Supported units are: '%s'" % list(self._supported_units.keys())
"Supported units are: '%s'" % list(cls._supported_units.keys())
)

@staticmethod
Expand Down
14 changes: 7 additions & 7 deletions python/BioSimSpace/Sandpit/Exscientia/Types/_charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ class Charge(_Type):
# Null type unit for avoiding issue printing configargparse help.
_default_unit = "ELECTRON CHARGE"

# The dimension mask:
# Angle, Charge, Length, Mass, Quantity, Temperature, Time
_dimensions = (0, 1, 0, 0, 0, 0, 0)
# The dimension mask.
_dimensions = tuple(list(_supported_units.values())[0].dimensions())

def __init__(self, *args):
"""
Expand Down Expand Up @@ -182,7 +181,8 @@ def _convert_to(self, unit):
"Supported units are: '%s'" % list(self._supported_units.keys())
)

def _validate_unit(self, unit):
@classmethod
def _validate_unit(cls, unit):
"""Validate that the unit are supported."""

# Strip whitespace and convert to upper case.
Expand Down Expand Up @@ -213,11 +213,11 @@ def _validate_unit(self, unit):
unit = unit.replace("COUL", "C")

# Check that the unit is supported.
if unit in self._abbreviations:
return self._abbreviations[unit]
if unit in cls._abbreviations:
return cls._abbreviations[unit]
else:
raise ValueError(
"Supported units are: '%s'" % list(self._supported_units.keys())
"Supported units are: '%s'" % list(cls._supported_units.keys())
)

@staticmethod
Expand Down
14 changes: 7 additions & 7 deletions python/BioSimSpace/Sandpit/Exscientia/Types/_energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ class Energy(_Type):
# Null type unit for avoiding issue printing configargparse help.
_default_unit = "KILO CALORIES PER MOL"

# The dimension mask:
# Angle, Charge, Length, Mass, Quantity, Temperature, Time
_dimensions = (0, 0, 2, 1, -1, 0, -2)
# The dimension mask.
_dimensions = tuple(list(_supported_units.values())[0].dimensions())

def __init__(self, *args):
"""
Expand Down Expand Up @@ -213,7 +212,8 @@ def _convert_to(self, unit):
"Supported units are: '%s'" % list(self._supported_units.keys())
)

def _validate_unit(self, unit):
@classmethod
def _validate_unit(cls, unit):
"""Validate that the unit are supported."""

# Strip whitespace and convert to upper case.
Expand All @@ -235,11 +235,11 @@ def _validate_unit(self, unit):
unit = unit.replace("JOULES", "J")

# Check that the unit is supported.
if unit in self._abbreviations:
return self._abbreviations[unit]
if unit in cls._abbreviations:
return cls._abbreviations[unit]
else:
raise ValueError(
"Supported units are: '%s'" % list(self._supported_units.keys())
"Supported units are: '%s'" % list(cls._supported_units.keys())
)

@staticmethod
Expand Down
Loading

0 comments on commit 4480a5a

Please sign in to comment.