Skip to content

Commit 86473e9

Browse files
authored
Merge pull request #272 from marrink-lab/fix/coordreading
Fix/coordreading
2 parents fd55c4e + e07658d commit 86473e9

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

polyply/src/topology.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,11 @@ def add_positions_from_file(self, path, skip_res=[], resolution='mol'):
388388
for meta_mol in self.molecules:
389389
for meta_node in meta_mol.nodes:
390390
resname = meta_mol.nodes[meta_node]["resname"]
391-
mol_nodes = meta_mol.nodes[meta_node]['graph'].nodes
391+
# the fragment graph nodes are not sorted so we sort them by index
392+
# as defined in the itp-file to capture cases, where the molecule
393+
# graph nodes are permuted with respect to the index
394+
idx_nodes = nx.get_node_attributes(meta_mol.nodes[meta_node]['graph'], "index")
395+
mol_nodes = sorted(idx_nodes, key=idx_nodes.get)
392396
# skip residue if resname is to be skipped or
393397
# if the no more coordinates are available
394398
# in that case we want to build the node and

polyply/tests/test_topology.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
import textwrap
1919
import pytest
2020
import math
21+
import numpy as np
2122
import vermouth.forcefield
2223
import vermouth.molecule
2324
from vermouth.molecule import Interaction
25+
from vermouth.pdb.pdb import read_pdb
2426
import polyply.src.meta_molecule
2527
from polyply import TEST_DATA
2628
from polyply.src.topology import Topology
@@ -87,9 +89,12 @@ def test_add_positions_from_pdb():
8789
"""
8890
top = Topology.from_gmx_topfile(TEST_DATA + "/topology_test/pdb.top", "test")
8991
top.add_positions_from_file(TEST_DATA + "/topology_test/test.pdb")
90-
for meta_mol in top.molecules:
92+
93+
pdb_mols = read_pdb(TEST_DATA + "/topology_test/test.pdb")
94+
for idx, meta_mol in enumerate(top.molecules):
9195
for node in meta_mol.molecule.nodes:
92-
assert "position" in meta_mol.molecule.nodes[node].keys()
96+
ref_pos = pdb_mols[idx].nodes[node]['position']
97+
assert np.all(ref_pos == meta_mol.molecule.nodes[node]['position'])
9398

9499
for meta_mol in top.molecules:
95100
for node in meta_mol.nodes:

0 commit comments

Comments
 (0)