Skip to content

Commit

Permalink
Merge pull request #537 from marrink-lab/box_attr
Browse files Browse the repository at this point in the history
add box attribute to molecule and propagate from pdb parser
  • Loading branch information
fgrunewald authored Aug 23, 2023
2 parents 54e933d + 42ed32d commit 621b5d9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions vermouth/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 4 additions & 0 deletions vermouth/pdb/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']/10.,
self.cryst['b']/10.,
self.cryst['b']/10.])
self.molecules.append(self.active_molecule)
self.active_molecule = Molecule()

Expand Down
1 change: 1 addition & 0 deletions vermouth/tests/pdb/test_read_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 621b5d9

Please sign in to comment.