diff --git a/polyply/src/gen_dna.py b/polyply/src/gen_dna.py index 20078a3e..bd4178ee 100644 --- a/polyply/src/gen_dna.py +++ b/polyply/src/gen_dna.py @@ -69,7 +69,7 @@ def complement_dsDNA(meta_molecule): """ last_node = list(meta_molecule.nodes)[-1] resname = BASE_LIBRARY[meta_molecule.nodes[last_node]["resname"]] - meta_molecule.add_monomer(last_node+1, resname, [], last_node+2) + meta_molecule.add_monomer(last_node+1, resname, []) correspondance = {last_node: last_node+1} total = last_node+1 @@ -91,7 +91,7 @@ def complement_dsDNA(meta_molecule): if next_node not in correspondance: new_node = total + 1 - meta_molecule.add_monomer(total+1, resname, [(correspondance[prev_node], total+1)], resid=total+2) + meta_molecule.add_monomer(total+1, resname, [(correspondance[prev_node], total+1)]) correspondance[next_node] = new_node else: new_node = correspondance[next_node] diff --git a/polyply/src/meta_molecule.py b/polyply/src/meta_molecule.py index db6a5d63..31d637c2 100644 --- a/polyply/src/meta_molecule.py +++ b/polyply/src/meta_molecule.py @@ -103,6 +103,7 @@ def __init__(self, *args, **kwargs): self.__search_tree = None self.root = None self.dfs = False + self.max_resid = 0 # add resids to polyply meta-molecule nodes if they are not # present. All algorithms rely on proper resids @@ -116,6 +117,13 @@ def __init__(self, *args, **kwargs): msg = "Couldn't add 1 to node. Either provide resids or use integers as node keys." raise IOError(msg) + if self.max_resid < self.nodes[node]["resid"]: + self.max_resid = self.nodes[node]["resid"] + + def add_node(self, *args, **kwargs): + self.max_resid = self.max_resid + 1 + kwargs["resid"] = self.max_resid + super().add_node(*args, **kwargs) def add_monomer(self, current, resname, connections): """ @@ -124,14 +132,7 @@ def add_monomer(self, current, resname, connections): that matches may only refer to already existing nodes. But connections can be an empty list. """ - resids = nx.get_node_attributes(self, "resid") - - if resids: - resid = max(resids.values()) + 1 - else: - resid = 1 - - self.add_node(current, resname=resname, resid=resid, build=True) + self.add_node(current, resname=resname, build=True) for edge in connections: if self.has_node(edge[0]) and self.has_node(edge[1]): self.add_edge(edge[0], edge[1]) @@ -154,7 +155,7 @@ def relabel_and_redo_res_graph(self, mapping): mapping of node-key to new residue name """ # find the maximum resiude id - max_resid = max(nx.get_node_attributes(self.molecule, "resid").values()) + max_resid = self.max_resid # resname the residues and increase with pseudo-resid for node, resname in mapping.items(): self.molecule.nodes[node]["resname"] = resname diff --git a/polyply/tests/test_gen_params.py b/polyply/tests/test_gen_params.py index aa0fa78b..218eb36a 100644 --- a/polyply/tests/test_gen_params.py +++ b/polyply/tests/test_gen_params.py @@ -86,6 +86,9 @@ def test_gen_params(args_in, ref_file): ff_group.add_argument('-list-links', action='store_true', dest='list_links', help='List all Links known to the' ' force field, and exit.') + dna_group = parser.add_argument_group('DNA specifc options') + dna_group.add_argument('-dsdna', dest='dsdna', action='store_true', + help='complement single sequence to dsDNA sequence') args = parser.parse_args(args_in) gen_params(args)