Created
March 21, 2014 15:59
-
-
Save JoaoRodrigues/9689449 to your computer and use it in GitHub Desktop.
Sort the ATOM/HETATM lines of a PDB file
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
#!/usr/bin/env python | |
import sys | |
if len(sys.argv[1:]) != 1: | |
print "usage: sort_pdb.py <pdb file>" | |
sys.exit(1) | |
try: | |
with open(sys.argv[1]) as handle: | |
atom_lines = [l.strip() for l in handle if l.startswith(('ATOM', 'HETATM'))] | |
sorted_atoms = sorted(atom_lines, key = lambda l: (l[0:6], l[21], int(l[22:26]), l[26], l[16])) | |
print '\n'.join(sorted_atoms) | |
except IOError: | |
print "Could not open input file: {0}".format(sys.argv[1]) | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment