From 95efef8382a1b641bc3deb08ddd693926f7f7cb9 Mon Sep 17 00:00:00 2001 From: "f.grunewald" Date: Thu, 8 Sep 2022 17:00:24 +0200 Subject: [PATCH 1/8] fix bug in topology reading --- polyply/src/topology.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/polyply/src/topology.py b/polyply/src/topology.py index 1435413c..b46c0d64 100644 --- a/polyply/src/topology.py +++ b/polyply/src/topology.py @@ -388,7 +388,8 @@ 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 + mol_nodes = sorted(meta_mol.nodes[meta_node]['graph'].nodes) # 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 @@ -413,6 +414,7 @@ def add_positions_from_file(self, path, skip_res=[], resolution='mol'): # based on a non-complete residue try: meta_mol.molecule.nodes[mol_node]["position"] = positions[total] + print(mol_node, positions[total]) except IndexError: resid = meta_mol.nodes[meta_node]['resid'] mol_name = meta_mol.mol_name From 5df76eebd5d98345e061f25cd2f177c1e7b12e14 Mon Sep 17 00:00:00 2001 From: "f.grunewald" Date: Thu, 8 Sep 2022 17:08:26 +0200 Subject: [PATCH 2/8] fix bug in topology reading and add test --- polyply/src/topology.py | 1 - polyply/tests/test_topology.py | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/polyply/src/topology.py b/polyply/src/topology.py index b46c0d64..684ea378 100644 --- a/polyply/src/topology.py +++ b/polyply/src/topology.py @@ -414,7 +414,6 @@ def add_positions_from_file(self, path, skip_res=[], resolution='mol'): # based on a non-complete residue try: meta_mol.molecule.nodes[mol_node]["position"] = positions[total] - print(mol_node, positions[total]) except IndexError: resid = meta_mol.nodes[meta_node]['resid'] mol_name = meta_mol.mol_name diff --git a/polyply/tests/test_topology.py b/polyply/tests/test_topology.py index 76230c89..92b7810b 100644 --- a/polyply/tests/test_topology.py +++ b/polyply/tests/test_topology.py @@ -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 @@ -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: From b84edc5e5cd138227fa88338faf26fd81cf89bad Mon Sep 17 00:00:00 2001 From: "f.grunewald" Date: Sat, 10 Sep 2022 19:52:24 +0200 Subject: [PATCH 3/8] sort graph nodes of meta-mol node attribute by index when reading positions --- polyply/src/topology.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/polyply/src/topology.py b/polyply/src/topology.py index 684ea378..704e9f46 100644 --- a/polyply/src/topology.py +++ b/polyply/src/topology.py @@ -388,8 +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"] - # the fragment graph nodes are not sorted - mol_nodes = sorted(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 = [node for _, node in sorted(zip(idx_nodes.values(), idx_nodes.keys()))] # 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 From 718e58c583697eee97f9c98414a2ca4d4989336c Mon Sep 17 00:00:00 2001 From: Fabian Grunewald <32294573+fgrunewald@users.noreply.github.com> Date: Mon, 12 Sep 2022 15:41:29 +0200 Subject: [PATCH 4/8] Update polyply/src/topology.py Co-authored-by: Peter C Kroon --- polyply/src/topology.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polyply/src/topology.py b/polyply/src/topology.py index 704e9f46..71624797 100644 --- a/polyply/src/topology.py +++ b/polyply/src/topology.py @@ -392,7 +392,7 @@ def add_positions_from_file(self, path, skip_res=[], resolution='mol'): # 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 = [node for _, node in sorted(zip(idx_nodes.values(), idx_nodes.keys()))] + mol_nodes = sorted(meta_mol, key=idx_nodex.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 From d7aa901a7b7d150bd4c320edf0fd76a75063711c Mon Sep 17 00:00:00 2001 From: Fabian Grunewald <32294573+fgrunewald@users.noreply.github.com> Date: Tue, 13 Sep 2022 10:21:02 +0200 Subject: [PATCH 5/8] Update topology.py Fox minor spelling bug --- polyply/src/topology.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polyply/src/topology.py b/polyply/src/topology.py index 71624797..3d0cf627 100644 --- a/polyply/src/topology.py +++ b/polyply/src/topology.py @@ -392,7 +392,7 @@ def add_positions_from_file(self, path, skip_res=[], resolution='mol'): # 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(meta_mol, key=idx_nodex.get) + mol_nodes = sorted(meta_mol, 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 From 4ae11bba653f6a4b8b297e8b06c196edd84d85bb Mon Sep 17 00:00:00 2001 From: Fabian Grunewald <32294573+fgrunewald@users.noreply.github.com> Date: Tue, 13 Sep 2022 10:35:43 +0200 Subject: [PATCH 6/8] Update topology.py --- polyply/src/topology.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polyply/src/topology.py b/polyply/src/topology.py index 3d0cf627..f32d93d0 100644 --- a/polyply/src/topology.py +++ b/polyply/src/topology.py @@ -392,7 +392,7 @@ def add_positions_from_file(self, path, skip_res=[], resolution='mol'): # 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(meta_mol, key=idx_nodes.get) + mol_nodes = sorted(meta_mol.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 From 80233dd50a5a3ac1903df26ba0dfa7a738afb7a0 Mon Sep 17 00:00:00 2001 From: Fabian Grunewald <32294573+fgrunewald@users.noreply.github.com> Date: Tue, 13 Sep 2022 11:00:33 +0200 Subject: [PATCH 7/8] Update topology.py --- polyply/src/topology.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/polyply/src/topology.py b/polyply/src/topology.py index f32d93d0..125fcf08 100644 --- a/polyply/src/topology.py +++ b/polyply/src/topology.py @@ -390,9 +390,9 @@ def add_positions_from_file(self, path, skip_res=[], resolution='mol'): resname = meta_mol.nodes[meta_node]["resname"] # 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 + # 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(meta_mol.nodes, key=idx_nodes.get) + 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 From e07658d1af43bed0a93ef4c33057b5fc841e9c4b Mon Sep 17 00:00:00 2001 From: Fabian Grunewald <32294573+fgrunewald@users.noreply.github.com> Date: Tue, 13 Sep 2022 11:02:23 +0200 Subject: [PATCH 8/8] Update polyply/src/topology.py Co-authored-by: Peter C Kroon --- polyply/src/topology.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polyply/src/topology.py b/polyply/src/topology.py index 125fcf08..6101d3d7 100644 --- a/polyply/src/topology.py +++ b/polyply/src/topology.py @@ -390,7 +390,7 @@ def add_positions_from_file(self, path, skip_res=[], resolution='mol'): resname = meta_mol.nodes[meta_node]["resname"] # 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] + # 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