Package Bio :: Package PDB :: Module Atom
[hide private]
[frames] | no frames]

Source Code for Module Bio.PDB.Atom

  1  # Copyright (C) 2002, Thomas Hamelryck (thamelry@binf.ku.dk) 
  2  # This code is part of the Biopython distribution and governed by its 
  3  # license.  Please see the LICENSE file that should have been included 
  4  # as part of this package.            
  5   
  6  # Python stuff 
  7  import numpy 
  8   
  9  # My stuff 
 10  from Entity import DisorderedEntityWrapper 
 11  from Vector import Vector 
 12   
 13  __doc__="Atom class, used in Structure objects." 
 14   
15 -class Atom:
16 - def __init__(self, name, coord, bfactor, occupancy, altloc, fullname, serial_number, 17 element=None):
18 """ 19 Atom object. 20 21 The Atom object stores atom name (both with and without spaces), 22 coordinates, B factor, occupancy, alternative location specifier 23 and (optionally) anisotropic B factor and standard deviations of 24 B factor and positions. 25 26 @param name: atom name (eg. "CA"). Note that spaces are normally stripped. 27 @type name: string 28 29 @param coord: atomic coordinates (x,y,z) 30 @type coord: Numeric array (Float0, size 3) 31 32 @param bfactor: isotropic B factor 33 @type bfactor: number 34 35 @param occupancy: occupancy (0.0-1.0) 36 @type occupancy: number 37 38 @param altloc: alternative location specifier for disordered atoms 39 @type altloc: string 40 41 @param fullname: full atom name, including spaces, e.g. " CA ". Normally 42 these spaces are stripped from the atom name. 43 @type fullname: string 44 45 @param element: atom element, e.g. "C" for Carbon, "HG" for mercury, 46 @type fullname: uppercase string (or None if unknown) 47 """ 48 self.level="A" 49 # Reference to the residue 50 self.parent=None 51 # the atomic data 52 self.name=name # eg. CA, spaces are removed from atom name 53 self.fullname=fullname # e.g. " CA ", spaces included 54 self.coord=coord 55 self.bfactor=bfactor 56 self.occupancy=occupancy 57 self.altloc=altloc 58 self.full_id=None # (structure id, model id, chain id, residue id, atom id) 59 self.id=name # id of atom is the atom name (e.g. "CA") 60 self.disordered_flag=0 61 self.anisou_array=None 62 self.siguij_array=None 63 self.sigatm_array=None 64 self.serial_number=serial_number 65 # Dictionary that keeps addictional properties 66 self.xtra={} 67 if element is None : 68 import warnings 69 from PDBExceptions import PDBConstructionWarning 70 warnings.warn("Atom object (name=%s) without element" % name, 71 PDBConstructionWarning) 72 element = "?" 73 print name, "--> ?" 74 elif len(element)>2 or element != element.upper() or element != element.strip(): 75 raise ValueError(element) 76 self.element=element
77 78 # Special methods 79
80 - def __repr__(self):
81 "Print Atom object as <Atom atom_name>." 82 return "<Atom %s>" % self.get_id()
83
84 - def __sub__(self, other):
85 """ 86 Calculate distance between two atoms. 87 88 Example: 89 >>> distance=atom1-atom2 90 91 @param other: the other atom 92 @type other: L{Atom} 93 """ 94 diff=self.coord-other.coord 95 return numpy.sqrt(numpy.dot(diff,diff))
96 97 # set methods 98
99 - def set_serial_number(self, n):
100 self.serial_number=n
101
102 - def set_bfactor(self, bfactor):
103 self.bfactor=bfactor
104
105 - def set_coord(self, coord):
106 self.coord=coord
107
108 - def set_altloc(self, altloc):
109 self.altloc=altloc
110
111 - def set_occupancy(self, occupancy):
112 self.occupancy=occupancy
113
114 - def set_sigatm(self, sigatm_array):
115 """ 116 Set standard deviation of atomic parameters. 117 118 The standard deviation of atomic parameters consists 119 of 3 positional, 1 B factor and 1 occupancy standard 120 deviation. 121 122 @param sigatm_array: standard deviations of atomic parameters. 123 @type sigatm_array: Numeric array (length 5) 124 """ 125 self.sigatm_array=sigatm_array
126
127 - def set_siguij(self, siguij_array):
128 """ 129 Set standard deviations of anisotropic temperature factors. 130 131 @param siguij_array: standard deviations of anisotropic temperature factors. 132 @type siguij_array: Numeric array (length 6) 133 """ 134 self.siguij_array=siguij_array
135
136 - def set_anisou(self, anisou_array):
137 """ 138 Set anisotropic B factor. 139 140 @param anisou_array: anisotropic B factor. 141 @type anisou_array: Numeric array (length 6) 142 """ 143 self.anisou_array=anisou_array
144 145 146 # Public methods 147
148 - def flag_disorder(self):
149 """Set the disordered flag to 1. 150 151 The disordered flag indicates whether the atom is disordered or not. 152 """ 153 self.disordered_flag=1
154
155 - def is_disordered(self):
156 "Return the disordered flag (1 if disordered, 0 otherwise)." 157 return self.disordered_flag
158
159 - def set_parent(self, parent):
160 """Set the parent residue. 161 162 Arguments: 163 o parent - Residue object 164 """ 165 self.parent=parent
166
167 - def detach_parent(self):
168 "Remove reference to parent." 169 self.parent=None
170
171 - def get_sigatm(self):
172 "Return standard deviation of atomic parameters." 173 return self.sigatm_array
174
175 - def get_siguij(self):
176 "Return standard deviations of anisotropic temperature factors." 177 return self.siguij_array
178
179 - def get_anisou(self):
180 "Return anisotropic B factor." 181 return self.anisou_array
182
183 - def get_parent(self):
184 "Return parent residue." 185 return self.parent
186
187 - def get_serial_number(self):
188 return self.serial_number
189
190 - def get_name(self):
191 "Return atom name." 192 return self.name
193
194 - def get_id(self):
195 "Return the id of the atom (which is its atom name)." 196 return self.id
197
198 - def get_full_id(self):
199 """Return the full id of the atom. 200 201 The full id of an atom is the tuple 202 (structure id, model id, chain id, residue id, atom name, altloc). 203 """ 204 return self.parent.get_full_id()+((self.name, self.altloc),)
205
206 - def get_coord(self):
207 "Return atomic coordinates." 208 return self.coord
209
210 - def get_bfactor(self):
211 "Return B factor." 212 return self.bfactor
213
214 - def get_occupancy(self):
215 "Return occupancy." 216 return self.occupancy
217
218 - def get_fullname(self):
219 "Return the atom name, including leading and trailing spaces." 220 return self.fullname
221
222 - def get_altloc(self):
223 "Return alternative location specifier." 224 return self.altloc
225
226 - def get_level(self):
227 return self.level
228
229 - def transform(self, rot, tran):
230 """ 231 Apply rotation and translation to the atomic coordinates. 232 233 Example: 234 >>> rotation=rotmat(pi, Vector(1,0,0)) 235 >>> translation=array((0,0,1), 'f') 236 >>> atom.transform(rotation, translation) 237 238 @param rot: A right multiplying rotation matrix 239 @type rot: 3x3 Numeric array 240 241 @param tran: the translation vector 242 @type tran: size 3 Numeric array 243 """ 244 self.coord=numpy.dot(self.coord, rot)+tran
245
246 - def get_vector(self):
247 """ 248 Return coordinates as Vector. 249 250 @return: coordinates as 3D vector 251 @rtype: Vector 252 """ 253 x,y,z=self.coord 254 return Vector(x,y,z)
255 256
257 -class DisorderedAtom(DisorderedEntityWrapper):
258 """ 259 This class contains all Atom objects that represent the same disordered 260 atom. One of these atoms is "selected" and all method calls not caught 261 by DisorderedAtom are forwarded to the selected Atom object. In that way, a 262 DisorderedAtom behaves exactly like a normal Atom. By default, the selected 263 Atom object represents the Atom object with the highest occupancy, but a 264 different Atom object can be selected by using the disordered_select(altloc) 265 method. 266 """
267 - def __init__(self, id):
268 """ 269 Arguments: 270 o id - string, atom name 271 """ 272 self.last_occupancy=-1 273 DisorderedEntityWrapper.__init__(self, id)
274 275 # Special methods 276
277 - def __repr__(self):
278 return "<Disordered Atom %s>" % self.get_id()
279
280 - def disordered_add(self, atom):
281 "Add a disordered atom." 282 # Add atom to dict, use altloc as key 283 atom.flag_disorder() 284 # set the residue parent of the added atom 285 residue=self.get_parent() 286 atom.set_parent(residue) 287 altloc=atom.get_altloc() 288 occupancy=atom.get_occupancy() 289 self[altloc]=atom 290 if occupancy>self.last_occupancy: 291 self.last_occupancy=occupancy 292 self.disordered_select(altloc)
293