Skip to content

Commit

Permalink
Merge pull request #187 from OpenBioSim/fix_186
Browse files Browse the repository at this point in the history
Fix issue #186
  • Loading branch information
chryswoods authored Apr 16, 2024
2 parents 1428ac0 + 8858c28 commit 33fa840
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ organisation on `GitHub <https://github.com/openbiosim/sire>`__.
-----------------------------------------------------------------------------------------

* Please add an item to this changelog when you create your PR
* Correctly set the ``element1`` property in ``sire.morph.create_from_pertfile``.

`2024.1.0 <https://github.com/openbiosim/sire/compare/2023.5.2...2024.1.0>`__ - April 2024
------------------------------------------------------------------------------------------
Expand Down
12 changes: 10 additions & 2 deletions src/sire/morph/_pertfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def create_from_pertfile(mol, pertfile, map=None):
from ..legacy.IO import PerturbationsLibrary

from ..base import create_map
from ..mol import Element

map = create_map(map)

Expand Down Expand Up @@ -65,6 +66,7 @@ def create_from_pertfile(mol, pertfile, map=None):
chg_prop = map["charge"].source()
lj_prop = map["LJ"].source()
typ_prop = map["ambertype"].source()
elem_prop = map["element"].source()

c["charge0"] = c[chg_prop]
c["charge1"] = c[chg_prop]
Expand All @@ -75,6 +77,9 @@ def create_from_pertfile(mol, pertfile, map=None):
c["ambertype0"] = c[typ_prop]
c["ambertype1"] = c[typ_prop]

c["element0"] = c[elem_prop]
c["element1"] = c[elem_prop]

for atom in c.atoms():
atomname = atom.name

Expand All @@ -97,6 +102,8 @@ def create_from_pertfile(mol, pertfile, map=None):
atom["ambertype0"] = typ0
atom["ambertype1"] = typ1

atom["element1"] = Element.biological_element(typ1)

# now update all of the internals
bond_prop = map["bond"].source()
ang_prop = map["angle"].source()
Expand Down Expand Up @@ -251,8 +258,8 @@ def create_from_pertfile(mol, pertfile, map=None):
c["improper0"] = impropers0
c["improper1"] = impropers1

# duplicate the coordinates, mass, and element properties
for prop in ["coordinates", "mass", "element", "forcefield", "intrascale"]:
# duplicate unperturbed properties
for prop in ["coordinates", "mass", "forcefield", "intrascale"]:
orig_prop = map[prop].source()
c[prop + "0"] = c[orig_prop]
c[prop + "1"] = c[orig_prop]
Expand All @@ -262,6 +269,7 @@ def create_from_pertfile(mol, pertfile, map=None):
del c[chg_prop]
del c[lj_prop]
del c[typ_prop]
del c[elem_prop]
del c[bond_prop]
del c[ang_prop]
del c[dih_prop]
Expand Down
18 changes: 18 additions & 0 deletions tests/morph/test_pert.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,21 @@ def test_extract_and_link_solv(solvated_neopentane_methane, openmm_platform):
nrg_pert = pert_mols.dynamics(map=map).current_potential_energy().value()

assert nrg_1_1 == pytest.approx(nrg_pert, 1e-3)


def test_ambertype_to_element(neopentane_methane):
from sire.mol import Element

mols = neopentane_methane.clone()

mols = sr.morph.link_to_reference(mols)

mols2 = sr.morph.extract_reference(mols)

mol = sr.morph.create_from_pertfile(mols2[0], neopentane_methane_pert)

element1 = mol.property("element1")
ambertype1 = mol.property("ambertype1")

for a, e in zip(ambertype1, element1):
assert e == Element.biological_element(a)

0 comments on commit 33fa840

Please sign in to comment.