#!/usr/bin/python ''' This small python script lists atoms of a given pdb file that are in the proximity of given coordinates. Usage: closeup.py ''' import sys, math __copyright__ = """ ----------------------------------------------------------------- (c) Copyright by Christian Fufezan, 2007 (christian@fufezan.net) Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee or royalty is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation or portions thereof, including modifications, that you make. """ __version__ = '1.0' __author__ = 'Christian Fufezan' __date__ = '7th March 2007' __url__ = 'http://www.fufezan.net/contact.php' class ATOM: def __init__(self,x,y,z): self.x = x self.y = y self.z = z def distanceTo(self, zeOther): SumOfSquares = ((self.x-zeOther.x)**2) + ((self.y-zeOther.y)**2) + ((self.z-zeOther.z)**2) formated = '%(d).3f' % {'d' :math.sqrt(SumOfSquares) } return float(formated) def bp(): sys.exit(0) if (__name__ == "__main__"): if (len(sys.argv)) != 6: print __doc__ print " script location:",str(sys.argv[0]) print " Version",__version__,"\n" bp() else: pdbfile = sys.argv[1] x = float(sys.argv[2]) y = float(sys.argv[3]) z = float(sys.argv[4]) d = float(sys.argv[5]) centre = ATOM(x,y,z) complete_pdb=open(pdbfile).xreadlines() neighbours = [] for line in complete_pdb: if (line[:6] == 'HETATM') or (line[:6] == 'ATOM '): tmpAtom=ATOM(float(line[31:38]),float(line[39:46]),float(line[47:54])) distance = tmpAtom.distanceTo(centre) if distance < d: tmpAtom.idx = int(line[6:11]) tmpAtom.atype = str(line[11:16]).strip() tmpAtom.aa = str(line[17:20]).strip() tmpAtom.chain = str(line[21:22]) tmpAtom.resid = int(line[22:26]) tmpAtom.distance = distance neighbours.append(tmpAtom) for atom in neighbours: print '%(distance).2f %(idx)5s %(atype)3s %(aa)s %(chain)s%(resid)4s %(x).3f %(y).3f %(z).3f' % { 'distance' : atom.distance, 'idx' : atom.idx, 'atype' : atom.atype, 'aa' : atom.aa, 'chain' : atom.chain, 'resid' : atom.resid, 'x' : atom.x, 'y' : atom.y, 'z' : atom.z }