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