Created
April 30, 2015 21:42
-
-
Save evanfeinberg/e7d3ab9e15505e872fe9 to your computer and use it in GitHub Desktop.
"Merges" Residues in MDTraj Topology Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fix_topology(topology): | |
new_top = topology.copy() | |
residues = {} | |
for chain in new_top.chains: | |
#print chain | |
for residue in chain.residues: | |
resname = str(residue) | |
if resname in residues.keys(): | |
residues[resname].append(residue) | |
else: | |
residues[resname] = [residue] | |
for resname in residues.keys(): | |
fragments = residues[resname] | |
if len(fragments) > 1: | |
main_fragment = fragments[0] | |
new_atom_list = [] | |
new_atom_list += main_fragment._atoms | |
for i in range(1,len(fragments)): | |
fragment = fragments[i] | |
for atom in fragment.atoms: | |
atom.residue = main_fragment | |
new_atom_list += fragment._atoms | |
fragment._atoms = [] | |
fragment.chain = main_fragment.chain | |
main_fragment._atoms = new_atom_list | |
return new_top |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment