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