Skip to content

Commit

Permalink
Merge pull request #272 from marrink-lab/fix/coordreading
Browse files Browse the repository at this point in the history
Fix/coordreading
  • Loading branch information
fgrunewald committed Sep 13, 2022
2 parents fd55c4e + e07658d commit 86473e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion polyply/src/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,11 @@ def add_positions_from_file(self, path, skip_res=[], resolution='mol'):
for meta_mol in self.molecules:
for meta_node in meta_mol.nodes:
resname = meta_mol.nodes[meta_node]["resname"]
mol_nodes = meta_mol.nodes[meta_node]['graph'].nodes
# the fragment graph nodes are not sorted so we sort them by index
# as defined in the itp-file to capture cases, where the molecule
# graph nodes are permuted with respect to the index
idx_nodes = nx.get_node_attributes(meta_mol.nodes[meta_node]['graph'], "index")
mol_nodes = sorted(idx_nodes, key=idx_nodes.get)
# skip residue if resname is to be skipped or
# if the no more coordinates are available
# in that case we want to build the node and
Expand Down
9 changes: 7 additions & 2 deletions polyply/tests/test_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
import textwrap
import pytest
import math
import numpy as np
import vermouth.forcefield
import vermouth.molecule
from vermouth.molecule import Interaction
from vermouth.pdb.pdb import read_pdb
import polyply.src.meta_molecule
from polyply import TEST_DATA
from polyply.src.topology import Topology
Expand Down Expand Up @@ -87,9 +89,12 @@ def test_add_positions_from_pdb():
"""
top = Topology.from_gmx_topfile(TEST_DATA + "/topology_test/pdb.top", "test")
top.add_positions_from_file(TEST_DATA + "/topology_test/test.pdb")
for meta_mol in top.molecules:

pdb_mols = read_pdb(TEST_DATA + "/topology_test/test.pdb")
for idx, meta_mol in enumerate(top.molecules):
for node in meta_mol.molecule.nodes:
assert "position" in meta_mol.molecule.nodes[node].keys()
ref_pos = pdb_mols[idx].nodes[node]['position']
assert np.all(ref_pos == meta_mol.molecule.nodes[node]['position'])

for meta_mol in top.molecules:
for node in meta_mol.nodes:
Expand Down

0 comments on commit 86473e9

Please sign in to comment.