1
2
3
4
5
6 """Atom class, used in Structure objects."""
7
8 import numpy
9 import warnings
10 import copy
11
12 from Bio.PDB.Entity import DisorderedEntityWrapper
13 from Bio.PDB.PDBExceptions import PDBConstructionWarning
14 from Bio.PDB.Vector import Vector
15 from Bio.Data import IUPACData
16
17
19 - def __init__(self, name, coord, bfactor, occupancy, altloc, fullname, serial_number,
20 element=None):
21 """
22 Atom object.
23
24 The Atom object stores atom name (both with and without spaces),
25 coordinates, B factor, occupancy, alternative location specifier
26 and (optionally) anisotropic B factor and standard deviations of
27 B factor and positions.
28
29 @param name: atom name (eg. "CA"). Note that spaces are normally stripped.
30 @type name: string
31
32 @param coord: atomic coordinates (x,y,z)
33 @type coord: Numeric array (Float0, size 3)
34
35 @param bfactor: isotropic B factor
36 @type bfactor: number
37
38 @param occupancy: occupancy (0.0-1.0)
39 @type occupancy: number
40
41 @param altloc: alternative location specifier for disordered atoms
42 @type altloc: string
43
44 @param fullname: full atom name, including spaces, e.g. " CA ". Normally
45 these spaces are stripped from the atom name.
46 @type fullname: string
47
48 @param element: atom element, e.g. "C" for Carbon, "HG" for mercury,
49 @type fullname: uppercase string (or None if unknown)
50 """
51 self.level="A"
52
53 self.parent=None
54
55 self.name=name
56 self.fullname=fullname
57 self.coord=coord
58 self.bfactor=bfactor
59 self.occupancy=occupancy
60 self.altloc=altloc
61 self.full_id=None
62 self.id=name
63 self.disordered_flag=0
64 self.anisou_array=None
65 self.siguij_array=None
66 self.sigatm_array=None
67 self.serial_number=serial_number
68
69 self.xtra={}
70 assert not element or element == element.upper(), element
71 self.element = self._assign_element(element)
72 self.mass = self._assign_atom_mass()
73
75 """Tries to guess element from atom name if not recognised."""
76 if not element or element.capitalize() not in IUPACData.atom_weights:
77
78
79
80
81
82 if self.fullname[0] != " " and not self.fullname[2:].isdigit():
83 putative_element = self.name.strip()
84 else:
85
86 if self.name[0].isdigit():
87 putative_element = self.name[1]
88 else:
89 putative_element = self.name[0]
90
91 if putative_element.capitalize() in IUPACData.atom_weights:
92 msg = "Used element %r for Atom (name=%s) with given element %r" \
93 % (putative_element, self.name, element)
94 element = putative_element
95 else:
96 msg = "Could not assign element %r for Atom (name=%s) with given element %r" \
97 % (putative_element, self.name, element)
98 element = ""
99 warnings.warn(msg, PDBConstructionWarning)
100
101 return element
102
104
105 if self.element:
106 return IUPACData.atom_weights[self.element.capitalize()]
107 else:
108 return float('NaN')
109
110
111
113 "Print Atom object as <Atom atom_name>."
114 return "<Atom %s>" % self.get_id()
115
117 """
118 Calculate distance between two atoms.
119
120 Example:
121 >>> distance=atom1-atom2
122
123 @param other: the other atom
124 @type other: L{Atom}
125 """
126 diff=self.coord-other.coord
127 return numpy.sqrt(numpy.dot(diff,diff))
128
129
130
133
136
139
142
144 self.occupancy=occupancy
145
147 """
148 Set standard deviation of atomic parameters.
149
150 The standard deviation of atomic parameters consists
151 of 3 positional, 1 B factor and 1 occupancy standard
152 deviation.
153
154 @param sigatm_array: standard deviations of atomic parameters.
155 @type sigatm_array: Numeric array (length 5)
156 """
157 self.sigatm_array=sigatm_array
158
160 """
161 Set standard deviations of anisotropic temperature factors.
162
163 @param siguij_array: standard deviations of anisotropic temperature factors.
164 @type siguij_array: Numeric array (length 6)
165 """
166 self.siguij_array=siguij_array
167
169 """
170 Set anisotropic B factor.
171
172 @param anisou_array: anisotropic B factor.
173 @type anisou_array: Numeric array (length 6)
174 """
175 self.anisou_array=anisou_array
176
177
178
180 """Set the disordered flag to 1.
181
182 The disordered flag indicates whether the atom is disordered or not.
183 """
184 self.disordered_flag=1
185
187 "Return the disordered flag (1 if disordered, 0 otherwise)."
188 return self.disordered_flag
189
191 """Set the parent residue.
192
193 Arguments:
194 o parent - Residue object
195 """
196 self.parent=parent
197
199 "Remove reference to parent."
200 self.parent=None
201
203 "Return standard deviation of atomic parameters."
204 return self.sigatm_array
205
207 "Return standard deviations of anisotropic temperature factors."
208 return self.siguij_array
209
211 "Return anisotropic B factor."
212 return self.anisou_array
213
215 "Return parent residue."
216 return self.parent
217
219 return self.serial_number
220
222 "Return atom name."
223 return self.name
224
226 "Return the id of the atom (which is its atom name)."
227 return self.id
228
230 """Return the full id of the atom.
231
232 The full id of an atom is the tuple
233 (structure id, model id, chain id, residue id, atom name, altloc).
234 """
235 return self.parent.get_full_id()+((self.name, self.altloc),)
236
238 "Return atomic coordinates."
239 return self.coord
240
242 "Return B factor."
243 return self.bfactor
244
246 "Return occupancy."
247 return self.occupancy
248
250 "Return the atom name, including leading and trailing spaces."
251 return self.fullname
252
254 "Return alternative location specifier."
255 return self.altloc
256
259
276
278 """
279 Return coordinates as Vector.
280
281 @return: coordinates as 3D vector
282 @rtype: Vector
283 """
284 x,y,z=self.coord
285 return Vector(x,y,z)
286
298
299
301 """
302 This class contains all Atom objects that represent the same disordered
303 atom. One of these atoms is "selected" and all method calls not caught
304 by DisorderedAtom are forwarded to the selected Atom object. In that way, a
305 DisorderedAtom behaves exactly like a normal Atom. By default, the selected
306 Atom object represents the Atom object with the highest occupancy, but a
307 different Atom object can be selected by using the disordered_select(altloc)
308 method.
309 """
317
318
319
321 return "<Disordered Atom %s>" % self.get_id()
322
336