From 4148f85bd8f229e5d2b59e581f7d89b6fa8c7ef2 Mon Sep 17 00:00:00 2001 From: "f.grunewald" Date: Thu, 17 Aug 2023 13:25:56 +0200 Subject: [PATCH 1/3] add box attribute to molecule and propagate from pdb parser --- vermouth/molecule.py | 2 ++ vermouth/pdb/pdb.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/vermouth/molecule.py b/vermouth/molecule.py index 45f7a4ec1..ea47a2c28 100644 --- a/vermouth/molecule.py +++ b/vermouth/molecule.py @@ -360,6 +360,8 @@ def __init__(self, *args, **kwargs): # {loglevel: {entry: [fmt_args]}} self.log_entries = defaultdict(lambda: defaultdict(list)) self.max_node = None + # box of the system the molecule is in + self.box = None def __eq__(self, other): return ( diff --git a/vermouth/pdb/pdb.py b/vermouth/pdb/pdb.py index 144ad70ad..8682dead3 100644 --- a/vermouth/pdb/pdb.py +++ b/vermouth/pdb/pdb.py @@ -341,6 +341,10 @@ def _finish_molecule(self, line="", lineno=0): # since there's a very good chance it's CONECT records have not been # parsed yet, and the molecule won't have any edges. if self.active_molecule: + if {"a", "b", "c"}.issubset(set(self.cryst.keys())): + self.active_molecule.box = np.array([self.cryst['a'], + self.cryst['b'], + self.cryst['b']]) self.molecules.append(self.active_molecule) self.active_molecule = Molecule() From 6c2e28184e1bf93d36a4925235f61c7b07f98bfb Mon Sep 17 00:00:00 2001 From: "f.grunewald" Date: Tue, 22 Aug 2023 16:38:17 +0200 Subject: [PATCH 2/3] change unit of box in pdb reader to nm --- vermouth/pdb/pdb.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vermouth/pdb/pdb.py b/vermouth/pdb/pdb.py index 8682dead3..715a3ac56 100644 --- a/vermouth/pdb/pdb.py +++ b/vermouth/pdb/pdb.py @@ -342,9 +342,9 @@ def _finish_molecule(self, line="", lineno=0): # parsed yet, and the molecule won't have any edges. if self.active_molecule: if {"a", "b", "c"}.issubset(set(self.cryst.keys())): - self.active_molecule.box = np.array([self.cryst['a'], - self.cryst['b'], - self.cryst['b']]) + self.active_molecule.box = np.array([self.cryst['a']/10., + self.cryst['b']/10., + self.cryst['b']/10.]) self.molecules.append(self.active_molecule) self.active_molecule = Molecule() From 42ed32d423f6cb48acae97f8f7bae965d222a668 Mon Sep 17 00:00:00 2001 From: "f.grunewald" Date: Tue, 22 Aug 2023 16:38:36 +0200 Subject: [PATCH 3/3] check that box is propagated with correct units --- vermouth/tests/pdb/test_read_pdb.py | 1 + 1 file changed, 1 insertion(+) diff --git a/vermouth/tests/pdb/test_read_pdb.py b/vermouth/tests/pdb/test_read_pdb.py index 4088cb7ea..86e6c844f 100644 --- a/vermouth/tests/pdb/test_read_pdb.py +++ b/vermouth/tests/pdb/test_read_pdb.py @@ -260,6 +260,7 @@ def test_atom_attributes(): def test_cryst1(caplog, pdbstr, cryst_dict): parser = PDBParser() mols = list(parser.parse(pdbstr.splitlines())) + assert np.all(np.isclose(mols[0].box, np.array([7.7987, 7.7987, 7.7987]))) assert parser.cryst == cryst_dict if len(cryst_dict) < 8: assert any(rec.levelname == 'WARNING' for rec in caplog.records)