Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter molecule for templates #339

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

filter molecule for templates #339

wants to merge 1 commit into from

Conversation

fgrunewald
Copy link
Member

@fgrunewald fgrunewald commented Aug 12, 2023

This PR sets the stage for some important changes:

  • instead of matching templates by resnames each residue now requires a template_name attribute. This allows matching of non-identical residues that has the same resname
  • extract blocks now takes a template graph as input to extract the interactions, which is also used in PR Convert itp files to ff files #327

To Do

  • move ExtractBlock to separate file something like manipulate_molecules.py
  • speed up equivalence check or at least enable a bypass

@pckroon do you have any idea how to do the code below in faster?

def group_by_isomorphism(meta_molecule, template_graphs={}):
"""
Extract all unique fragment graphs from meta_molecule
using the full subgraph isomorphism check.
"""
template_graphs = {}
for node in meta_molecule.nodes:
resname = meta_molecule.nodes[node]["resname"]
graph = meta_molecule.nodes[node]["graph"]
if resname in template_graphs and not nx.is_isomorphic(graph,
template_graphs[resname],
node_match=_atoms_match,
):
template_name = resname + str(len(template_graphs))
meta_molecule.nodes[node]["template"] = template_name
template_graphs[template_name] = graph
else:
meta_molecule.nodes[node]["template"] = resname
template_graphs[resname] = graph
return template_graphs

@fgrunewald
Copy link
Member Author

note to self vf2pp from networkx 3 might speed up matching process also proper line by line benchmark is needed

@pckroon
Copy link
Member

pckroon commented Aug 14, 2023

Not fundamentally, no. I'm also not sure what the goal you're trying to achieve is.

@fgrunewald
Copy link
Member Author

Currently polyply assumes all residues are unique. That is mostly true but not quite at least at the all-atom level. For example, there might be a hydrogen extra or less depending on if a residue is located in the center or at the terminal. This functionality checks each residue against a collection of unique residues in order to find those that have the same resname but deviate as graphs. It makes generating the templates more robust for complicated AA structures

@pckroon
Copy link
Member

pckroon commented Aug 15, 2023

Alright. I don't think there's really a faster way then. Unless you are willing to accept approximation, e.g. only check atom names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants