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

Merged
merged 14 commits into from
Jun 21, 2024
Merged

filter molecule for templates #339

merged 14 commits into from
Jun 21, 2024

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.

@fgrunewald fgrunewald requested a review from pckroon June 14, 2024 13:36
@fgrunewald
Copy link
Member Author

@csbrasnett this PR should fix the issue with the residue names; I think it is about time that we added this functionality

Copy link
Member

@pckroon pckroon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comments

polyply/src/backmap.py Outdated Show resolved Hide resolved
polyply/src/check_residue_equivalence.py Outdated Show resolved Hide resolved
polyply/src/check_residue_equivalence.py Outdated Show resolved Hide resolved
polyply/src/check_residue_equivalence.py Outdated Show resolved Hide resolved
polyply/src/check_residue_equivalence.py Outdated Show resolved Hide resolved
polyply/src/check_residue_equivalence.py Outdated Show resolved Hide resolved
polyply/src/generate_templates.py Show resolved Hide resolved
@fgrunewald fgrunewald requested a review from pckroon June 21, 2024 08:16
Copy link
Member

@pckroon pckroon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comments, mostly related to out-of-date docstrings

polyply/src/check_residue_equivalence.py Outdated Show resolved Hide resolved
polyply/src/check_residue_equivalence.py Show resolved Hide resolved
polyply/src/gen_coords.py Show resolved Hide resolved
polyply/src/generate_templates.py Show resolved Hide resolved
@fgrunewald fgrunewald requested a review from pckroon June 21, 2024 09:56
Copy link
Member

@pckroon pckroon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nitpick, looks good otherwise!

polyply/tests/test_generate_templates.py Outdated Show resolved Hide resolved
@fgrunewald fgrunewald requested a review from pckroon June 21, 2024 10:45
@fgrunewald fgrunewald merged commit 160e970 into master Jun 21, 2024
8 checks passed
@fgrunewald fgrunewald deleted the master_copy branch June 21, 2024 11:09
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.

2 participants