-
Notifications
You must be signed in to change notification settings - Fork 824
Closed
Description
Is your feature request related to a problem?
I have an edgy case, where I have two small molecules, they share a common substructure. I want to superimpose them based on the common substructure. The difficulty is that the common substructure doesn't have the same order of atoms.
Given a mapping dictionary which maps atoms from molecule 1 (key) to molecule 2 (value), the superimposition is done like this, where I need to manually reorder the ordered atomgroup.
from MDAnalysis.analysis.align import alignto
substructure_1 = []
substructure_2 = []
for id1, id2 in mapping.items():
substructure_1.append(molecule_1.select_atoms('bynum {}'.format(id1))
substructure_2.append(molecule_2.select_atoms('bynum {}'.format(id2))
substructure_1 = sum(substructure_1)
substructure_2 = sum(substructure_2)
alignto(substructure_1, substructure_2)
# move to the original rank
new_substructure_1 = []
for id in sorted(substructure_1.ids):
new_substructure_1.append(substructure_1.select_atoms('bynum {}'.format(id))
substructure_1 = sum(new_substructure_1)
alignto(molecule_1, substructure_1, select='bynum {}'.format(' '.join(substructure_1.ids)))Describe the solution you'd like
So if the atomgroup has a sort method, I could then just sort the atomgroup with one line. substructure_1.sort(key=lambda atom: atom.id)
from MDAnalysis.analysis.align import alignto
substructure_1 = []
substructure_2 = []
for id1, id2 in mapping.items():
substructure_1.append(molecule_1.select_atoms('bynum {}'.format(id1))
substructure_2.append(molecule_2.select_atoms('bynum {}'.format(id2))
substructure_1 = sum(substructure_1)
substructure_2 = sum(substructure_2)
alignto(substructure_1, substructure_2)
# move to the original rank
substructure_1.sort(key=lambda atom: atom.id)
alignto(molecule_1, substructure_1, select='bynum {}'.format(' '.join(substructure_1.ids)))Reactions are currently unavailable