From 98e9f8543c10c4df3a28f38e4420e826adf92043 Mon Sep 17 00:00:00 2001 From: Fabian Gruenewald Date: Wed, 14 Aug 2024 17:27:31 +0200 Subject: [PATCH] remove leftovers --- polyply/src/big_smile_mol_processor.py | 154 ------------------ polyply/src/ff_directive_writer.py | 2 - polyply/src/new.py | 76 --------- ...e.Fabians-MacBook-Pro-2.local.12994.014937 | Bin 53248 -> 0 bytes polyply/tests/start.txt | 6 - 5 files changed, 238 deletions(-) delete mode 100644 polyply/src/big_smile_mol_processor.py delete mode 100644 polyply/src/ff_directive_writer.py delete mode 100644 polyply/src/new.py delete mode 100644 polyply/tests/.coverage.Fabians-MacBook-Pro-2.local.12994.014937 delete mode 100644 polyply/tests/start.txt diff --git a/polyply/src/big_smile_mol_processor.py b/polyply/src/big_smile_mol_processor.py deleted file mode 100644 index 0956daf9..00000000 --- a/polyply/src/big_smile_mol_processor.py +++ /dev/null @@ -1,154 +0,0 @@ -import re -import networkx as nx -import pysmiles -import vermouth -from polyply.src.big_smile_parsing import (res_pattern_to_meta_mol, - force_field_from_fragments) -from polyply.src.map_to_molecule import MapToMolecule - -VALENCES = pysmiles.smiles_helper.VALENCES -VALENCES.update({"H":(1,)}) - -def compatible(left, right): - """ - Check bonding descriptor compatibility according - to the BigSmiles syntax convetions. - - Parameters - ---------- - left: str - right: str - - Returns - ------- - bool - """ - if left == right and left not in '> <': - return True - l, r = left[0], right[0] - if (l, r) == ('<', '>') or (l, r) == ('>', '<'): - return left[1:] == right[1:] - return False - -def generate_edge(source, target, bond_attribute="bonding"): - """ - Given a source and a target graph, which have bonding - descriptors stored as node attributes, find a pair of - matching descriptors and return the respective nodes. - The function also returns the bonding descriptors. If - no bonding descriptor is found an instance of LookupError - is raised. - - Parameters - ---------- - source: :class:`nx.Graph` - target: :class:`nx.Graph` - bond_attribute: `abc.hashable` - under which attribute are the bonding descriptors - stored. - - Returns - ------- - ((abc.hashable, abc.hashable), (str, str)) - the nodes as well as bonding descriptors - - Raises - ------ - LookupError - if no match is found - """ - source_nodes = nx.get_node_attributes(source, bond_attribute) - target_nodes = nx.get_node_attributes(target, bond_attribute) - for source_node in source_nodes: - for target_node in target_nodes: - #print(source_node, target_node) - bond_sources = source_nodes[source_node] - bond_targets = target_nodes[target_node] - for bond_source in bond_sources: - for bond_target in bond_targets: - #print(bond_source, bond_target) - if compatible(bond_source, bond_target): - return ((source_node, target_node), (bond_source, bond_target)) - raise LookupError - -class DefBigSmileParser: - """ - Parse an a string instance of a defined BigSmile, - which describes a polymer molecule. - """ - - def __init__(self, force_field): - self.force_field = force_field - self.meta_molecule = None - self.molecule = None - - def edges_from_bonding_descrpt(self): - """ - Make edges according to the bonding descriptors stored - in the node attributes of meta_molecule residue graph. - If a bonding descriptor is consumed it is removed from the list, - however, the meta_molecule edge gets an attribute with the - bonding descriptors that formed the edge. Later uncomsumed - bonding descriptors are replaced by hydrogen atoms. - """ - for prev_node, node in nx.dfs_edges(self.meta_molecule): - prev_graph = self.meta_molecule.nodes[prev_node]['graph'] - node_graph = self.meta_molecule.nodes[node]['graph'] - edge, bonding = generate_edge(prev_graph, - node_graph) - # this is a bit of a workaround because at this stage the - # bonding list is actually shared between all residues of - # of the same type; so we first make a copy then we replace - # the list sans used bonding descriptor - prev_bond_list = prev_graph.nodes[edge[0]]['bonding'].copy() - prev_bond_list.remove(bonding[0]) - prev_graph.nodes[edge[0]]['bonding'] = prev_bond_list - node_bond_list = node_graph.nodes[edge[1]]['bonding'].copy() - node_bond_list.remove(bonding[1]) - node_graph.nodes[edge[1]]['bonding'] = node_bond_list - order = re.findall("\d+\.\d+", bonding[0]) - # bonding descriptors are assumed to have bonding order 1 - # unless they are specifically annotated - if not order: - order = 1 - self.meta_molecule.molecule.add_edge(edge[0], edge[1], bonding=bonding, order=order) - - def replace_unconsumed_bonding_descrpt(self): - """ - We allow multiple bonding descriptors per atom, which - however, are not always consumed. In this case the left - over bonding descriptors are replaced by hydrogen atoms. - """ - for meta_node in self.meta_molecule.nodes: - graph = self.meta_molecule.nodes[meta_node]['graph'] - bonding = nx.get_node_attributes(graph, "bonding") - for node, bondings in bonding.items(): - element = graph.nodes[node]['element'] - bonds = round(sum([self.meta_molecule.molecule.edges[(node, neigh)]['order'] for neigh in\ - self.meta_molecule.molecule.neighbors(node)])) - hcount = VALENCES[element][0] - bonds + 1 - attrs = {attr: graph.nodes[node][attr] for attr in ['resname', 'resid', 'charge_group']} - attrs['element'] = 'H' - for new_id in range(1, hcount): - new_node = len(self.meta_molecule.molecule.nodes) + 1 - graph.add_edge(node, new_node) - attrs['atomname'] = "H" + str(len(graph.nodes)-1) - graph.nodes[new_node].update(attrs) - self.meta_molecule.molecule.add_edge(node, new_node, order=1) - self.meta_molecule.molecule.nodes[new_node].update(attrs) - # now we want to sort the atoms - vermouth.SortMoleculeAtoms().run_molecule(self.meta_molecule.molecule) - # and redo the meta molecule - self.meta_molecule.relabel_and_redo_res_graph(mapping={}) - - def parse(self, big_smile_str): - res_pattern, residues = re.findall(r"\{[^\}]+\}", big_smile_str) - self.meta_molecule = res_pattern_to_meta_mol(res_pattern) - self.force_field = force_field_from_fragments(residues) - MapToMolecule(self.force_field).run_molecule(self.meta_molecule) - self.edges_from_bonding_descrpt() - self.replace_unconsumed_bonding_descrpt() - return self.meta_molecule - -# ToDo -# - clean copying of bond-list attributes L100 diff --git a/polyply/src/ff_directive_writer.py b/polyply/src/ff_directive_writer.py deleted file mode 100644 index 139597f9..00000000 --- a/polyply/src/ff_directive_writer.py +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/polyply/src/new.py b/polyply/src/new.py deleted file mode 100644 index 4ed025ec..00000000 --- a/polyply/src/new.py +++ /dev/null @@ -1,76 +0,0 @@ -import re - -PATTERNS = {"bond_anchor": "\[\$.*?\]", - "place_holder": "\[\#.*?\]", - "annotation": "\|.*?\|", - "fragment": r'#(\w+)=((?:\[.*?\]|[^,\[\]]+)*)', - "seq_pattern": r'\{([^}]*)\}(?:\.\{([^}]*)\})?'} - -def read_big_smile(line): - res_graphs = [] - seq_str, patterns = re.findall(PATTERNS['seq_pattern'], line)[0] - fragments = dict(re.findall(PATTERNS['fragment'], patterns)) - for fragment in fragments: - res_graphs.append(read_smile_w_bondtypes(fragment_smile)) - - # now stitch together .. - # 1 segement the seq_str - # allocate any leftover atoms - # add the residues - targets = set() - for match in re.finditer(PATTERNS['place_holder'], seq_str): - targets.add(match.group(0)) - for target in targets: - seq_str = seq_str.replace(target, fragments[target[2:-1]]) - - return seq_str - -def read_smile_w_bondtypes(line): - smile = line - bonds=[] - # find all bond types and remove them from smile - for bond in re.finditer(PATTERNS['bond_anchor'], ex_str): - smile=smile.replace(bond.group(0), "") - bonds.append((bond.span(0), bond.group(0)[1:-1])) - - # read smile and make molecule - mol = read_smiles(smile) - pos_to_node = position_to_node(smile) - - # strip the first terminal anchor if there is any // - - # associate the bond atoms with the smile atoms - for bond in bonds: - # the bondtype contains the zero index so it - # referes to the first smile node - if bond[0][0] == 0: - mol.nodes[0]['bondtype'] = bond[1] - else: - anchor = find_anchor(smile, bond[0][0]) - mol.nodes[anchor]['bondtype'] = bond[1] - - return mol - - -def find_anchor(smile, start): - branch = False - sub_smile=smile[:start] - for idx, token in enumerate(sub_smile[::-1]): - if token == ")": - branch = True - continue - if token == "(" and branch: - branch = False - continue - if not branch: - return start-idx - raise IndexError - -def position_to_node(smile): - count=0 - pos_to_node={} - for idx, token in enumerate(smile): - if token not in ['[', ']', '$', '@', '(', ')']: - pos_to_node[idx] = count - count+=1 - return pos_to_node diff --git a/polyply/tests/.coverage.Fabians-MacBook-Pro-2.local.12994.014937 b/polyply/tests/.coverage.Fabians-MacBook-Pro-2.local.12994.014937 deleted file mode 100644 index f4dad49e93cb2af337886f8c965533e4be2213fe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 53248 zcmeI)O>Y}T7zgm(tm}v{^H!eKS?v7uQxb3aQ`mbVVy*o2I^P6X8Y;W4n z@85GHDLQ`8vm35Oc>dGjv9T_Cg z3m-k$+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_0D=Di^Fu9r diff --git a/polyply/tests/start.txt b/polyply/tests/start.txt deleted file mode 100644 index d99499a7..00000000 --- a/polyply/tests/start.txt +++ /dev/null @@ -1,6 +0,0 @@ -store resname hash mapping -assing volumes if given - -else: - -template gets generated then