Personal tools
Document Actions

removeAltLoc.py

Removes atoms with alternate locations.

sargis

Miscellaneous Python programming topics.
Page 2 of 2.

The following is listing for removeAltLoc.py.

 1  #!/usr/bin/env python 
2 "Removes atoms with alternate locations"
3 import sys
4
5 try:
6 import MolKit
7 except ImportError, inst:
8 print inst
9 print "Please install MolKit - http://mgltools.scripps.edu"
10 sys.exit(1)
11 12 def usage():
13 "Print helpful usage statement to stdout."
14 print __file__ +": no input file\n"
15 print "\tUsage: removeAlt.py input molecule supported by MolKit\n"
16
17
18 if len(sys.argv) < 2:
19 usage()
20 sys.exit(1) #help(sys.exit) for more info
21
22 mol = MolKit.Read(sys.argv[1]) #FIXME: check if file sys.argv[1] exists
23 for chain in mol.chains:
24 for residue in chain.residues:
25 altDict = {} #to keep atoms with
26 for atom in residue.atoms:
27 if '@' in atom.name:
28 list = atom.name.split('@') #'CB@B'=>['CB', 'B']
29 if list[-1] in altDict:
30 altDict[list[-1]].append(atom)
31 else:
32 altDict[list[-1]] = [atom]
33 if altDict:
34 keys = altDict.keys()
35 print "\nResidue %s altLoc:"%residue.name,
36 print keys,
37 print ' Removing ',
38 for key in keys[1:]:
39 for atom in altDict[key]:
40 print atom.name,
41 residue.remove(atom)
42
43 from MolKit.pdbWriter import PdbWriter
44 writer = PdbWriter()
45 writer.write('out.pdb',mol)

Run with 1DM2.pdb as input, for instance, to see it in action.

 
by Sargis Dallakyan last modified 2007-11-02 16:43 Molecular Graphics Laboratory, TSRI

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: