From c401394fa2ec137969e1bf60fa6ae20bc193bb90 Mon Sep 17 00:00:00 2001 From: Lester Hedges Date: Tue, 16 Apr 2024 14:24:14 +0100 Subject: [PATCH 1/3] Infer element1 property from ambertype1. [closes #186] --- src/sire/morph/_pertfile.py | 13 +++++++++++-- tests/morph/test_pert.py | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/sire/morph/_pertfile.py b/src/sire/morph/_pertfile.py index d85c37f57..7506d6c65 100644 --- a/src/sire/morph/_pertfile.py +++ b/src/sire/morph/_pertfile.py @@ -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) @@ -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] @@ -75,9 +77,13 @@ def create_from_pertfile(mol, pertfile, map=None): c["ambertype0"] = c[typ_prop] c["ambertype1"] = c[typ_prop] + c["element0"] = c[elem_prop] + for atom in c.atoms(): atomname = atom.name + atom["element1"] = atom["element"] + try: q0 = template.get_init_charge(atomname) q1 = template.get_final_charge(atomname) @@ -97,6 +103,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() @@ -251,8 +259,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] @@ -262,6 +270,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] diff --git a/tests/morph/test_pert.py b/tests/morph/test_pert.py index 535830194..36e76b240 100644 --- a/tests/morph/test_pert.py +++ b/tests/morph/test_pert.py @@ -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) From 7da7ce622400b0ac77ae069f5db9f142460dcc29 Mon Sep 17 00:00:00 2001 From: Lester Hedges Date: Tue, 16 Apr 2024 14:28:18 +0100 Subject: [PATCH 2/3] Added CHANGELOG entry. --- doc/source/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/changelog.rst b/doc/source/changelog.rst index 3645708a8..5e528c5d1 100644 --- a/doc/source/changelog.rst +++ b/doc/source/changelog.rst @@ -16,6 +16,7 @@ organisation on `GitHub `__. ----------------------------------------------------------------------------------------- * 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 `__ - April 2024 ------------------------------------------------------------------------------------------ From 8858c28cf1779ec84765406b8baa16bdeb2d3a3e Mon Sep 17 00:00:00 2001 From: Lester Hedges Date: Tue, 16 Apr 2024 15:35:38 +0100 Subject: [PATCH 3/3] Simplify. [ci skip] --- src/sire/morph/_pertfile.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sire/morph/_pertfile.py b/src/sire/morph/_pertfile.py index 7506d6c65..ccd594cc6 100644 --- a/src/sire/morph/_pertfile.py +++ b/src/sire/morph/_pertfile.py @@ -78,12 +78,11 @@ def create_from_pertfile(mol, pertfile, map=None): c["ambertype1"] = c[typ_prop] c["element0"] = c[elem_prop] + c["element1"] = c[elem_prop] for atom in c.atoms(): atomname = atom.name - atom["element1"] = atom["element"] - try: q0 = template.get_init_charge(atomname) q1 = template.get_final_charge(atomname)