Skip to content

Commit

Permalink
Merge pull request #247 from OpenBioSim/fix_240_246
Browse files Browse the repository at this point in the history
Fix issues #240 and #246
  • Loading branch information
lohedges authored Feb 23, 2024
2 parents d94c19b + 50b5bb6 commit 0334e54
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ def getCorrection(
volume = _Volume(_math.pi * result, "nanometers cubed")

# Estimate the average area of the restraint (in Angstrom squared).
area = (volume / proj_max).angstroms2()
area = (volume / (proj_max - proj_min)).angstroms2()

# Compute the correction. (1/1660 A-3 is the standard concentration.)
correction = _Energy(_math.log((area / 1660).value()), "kt")
Expand Down
8 changes: 4 additions & 4 deletions python/BioSimSpace/Parameters/_Protocol/_openforcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ def run(self, molecule, work_dir=None, queue=None):

# Export AMBER format files.
try:
interchange.to_prmtop(prefix + "interchange.prmtop")
interchange.to_inpcrd(prefix + "interchange.inpcrd")
interchange.to_prmtop(prefix + "interchange.prm7")
interchange.to_inpcrd(prefix + "interchange.rst7")
except Exception as e:
msg = "Unable to write Interchange object to AMBER format!"
if _isVerbose():
Expand All @@ -342,13 +342,13 @@ def run(self, molecule, work_dir=None, queue=None):
# Load the parameterised molecule. (This could be a system of molecules.)
try:
par_mol = _IO.readMolecules(
[prefix + "interchange.prmtop", prefix + "interchange.inpcrd"]
[prefix + "interchange.prm7", prefix + "interchange.rst7"]
)
# Extract single molecules.
if par_mol.nMolecules() == 1:
par_mol = par_mol.getMolecules()[0]
except Exception as e:
msg = "Failed to read molecule from: 'interchange.prmtop', 'interchange.inpcrd'"
msg = "Failed to read molecule from: 'interchange.prm7', 'interchange.rst7'"
if _isVerbose():
msg += ": " + getattr(e, "message", repr(e))
raise IOError(msg) from e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ def getCorrection(
volume = _Volume(_math.pi * result, "nanometers cubed")

# Estimate the average area of the restraint (in Angstrom squared).
area = (volume / proj_max).angstroms2()
area = (volume / (proj_max - proj_min)).angstroms2()

# Compute the correction. (1/1660 A-3 is the standard concentration.)
correction = _Energy(_math.log((area / 1660).value()), "kt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ def run(self, molecule, work_dir=None, queue=None):

# Export AMBER format files.
try:
interchange.to_prmtop(prefix + "interchange.prmtop")
interchange.to_inpcrd(prefix + "interchange.inpcrd")
interchange.to_prmtop(prefix + "interchange.prm7")
interchange.to_inpcrd(prefix + "interchange.rst7")
except Exception as e:
msg = "Unable to write Interchange object to AMBER format!"
if _isVerbose():
Expand All @@ -342,13 +342,13 @@ def run(self, molecule, work_dir=None, queue=None):
# Load the parameterised molecule. (This could be a system of molecules.)
try:
par_mol = _IO.readMolecules(
[prefix + "interchange.prmtop", prefix + "interchange.inpcrd"]
[prefix + "interchange.prm7", prefix + "interchange.rst7"]
)
# Extract single molecules.
if par_mol.nMolecules() == 1:
par_mol = par_mol.getMolecules()[0]
except Exception as e:
msg = "Failed to read molecule from: 'interchange.prmtop', 'interchange.inpcrd'"
msg = "Failed to read molecule from: 'interchange.prm7', 'interchange.rst7'"
if _isVerbose():
msg += ": " + getattr(e, "message", repr(e))
raise IOError(msg) from e
Expand Down
28 changes: 6 additions & 22 deletions python/BioSimSpace/Sandpit/Exscientia/_SireWrappers/_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,16 @@ def __init__(self, molecule):
if isinstance(molecule, _SireMol._Mol.Molecule):
super().__init__(molecule)
if self._sire_object.hasProperty("is_perturbable"):
self._convertFromMergedMolecule()
# Flag that the molecule is perturbable.
self._is_perturbable = True

# Extract the end states.
if molecule.hasProperty("molecule0"):
self._molecule = Molecule(molecule.property("molecule0"))
self._molecule0 = Molecule(molecule.property("molecule0"))
else:
self._molecule0, _ = self._extractMolecule()
if molecule.hasProperty("molecule1"):
self._molecule = Molecule(molecule.property("molecule1"))
self._molecule1 = Molecule(molecule.property("molecule1"))
else:
self._molecule1, _ = self._extractMolecule(is_lambda1=True)

Expand Down Expand Up @@ -1565,25 +1568,6 @@ def _getPropertyMap1(self):

return property_map

def _convertFromMergedMolecule(self):
"""Convert from a merged molecule."""

# Extract the components of the merged molecule.
try:
mol0 = self._sire_object.property("molecule0")
mol1 = self._sire_object.property("molecule1")
except:
raise _IncompatibleError(
"The merged molecule doesn't have the required properties!"
)

# Store the components.
self._molecule0 = Molecule(mol0)
self._molecule1 = Molecule(mol1)

# Flag that the molecule is perturbable.
self._is_perturbable = True

def _fixCharge(self, property_map={}):
"""
Make the molecular charge an integer value.
Expand Down
28 changes: 6 additions & 22 deletions python/BioSimSpace/_SireWrappers/_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,16 @@ def __init__(self, molecule):
if isinstance(molecule, _SireMol._Mol.Molecule):
super().__init__(molecule)
if self._sire_object.hasProperty("is_perturbable"):
self._convertFromMergedMolecule()
# Flag that the molecule is perturbable.
self._is_perturbable = True

# Extract the end states.
if molecule.hasProperty("molecule0"):
self._molecule = Molecule(molecule.property("molecule0"))
self._molecule0 = Molecule(molecule.property("molecule0"))
else:
self._molecule0, _ = self._extractMolecule()
if molecule.hasProperty("molecule1"):
self._molecule = Molecule(molecule.property("molecule1"))
self._molecule1 = Molecule(molecule.property("molecule1"))
else:
self._molecule1, _ = self._extractMolecule(is_lambda1=True)

Expand Down Expand Up @@ -1521,25 +1524,6 @@ def _getPropertyMap1(self):

return property_map

def _convertFromMergedMolecule(self):
"""Convert from a merged molecule."""

# Extract the components of the merged molecule.
try:
mol0 = self._sire_object.property("molecule0")
mol1 = self._sire_object.property("molecule1")
except:
raise _IncompatibleError(
"The merged molecule doesn't have the required properties!"
)

# Store the components.
self._molecule0 = Molecule(mol0)
self._molecule1 = Molecule(mol1)

# Flag that the molecule is perturbable.
self._is_perturbable = True

def _fixCharge(self, property_map={}):
"""
Make the molecular charge an integer value.
Expand Down

0 comments on commit 0334e54

Please sign in to comment.