1
2
3
4
5
6 """Atom class, used in Structure objects."""
7
8 import numpy
9 import warnings
10
11 from Bio.PDB.Entity import DisorderedEntityWrapper
12 from Bio.PDB.PDBExceptions import PDBConstructionWarning
13 from Bio.PDB.Vector import Vector
14 from Bio.Data import IUPACData
15
17 - def __init__(self, name, coord, bfactor, occupancy, altloc, fullname, serial_number,
18 element=None):
19 """
20 Atom object.
21
22 The Atom object stores atom name (both with and without spaces),
23 coordinates, B factor, occupancy, alternative location specifier
24 and (optionally) anisotropic B factor and standard deviations of
25 B factor and positions.
26
27 @param name: atom name (eg. "CA"). Note that spaces are normally stripped.
28 @type name: string
29
30 @param coord: atomic coordinates (x,y,z)
31 @type coord: Numeric array (Float0, size 3)
32
33 @param bfactor: isotropic B factor
34 @type bfactor: number
35
36 @param occupancy: occupancy (0.0-1.0)
37 @type occupancy: number
38
39 @param altloc: alternative location specifier for disordered atoms
40 @type altloc: string
41
42 @param fullname: full atom name, including spaces, e.g. " CA ". Normally
43 these spaces are stripped from the atom name.
44 @type fullname: string
45
46 @param element: atom element, e.g. "C" for Carbon, "HG" for mercury,
47 @type fullname: uppercase string (or None if unknown)
48
49 """
50 self.level="A"
51
52 self.parent=None
53
54 self.name=name
55 self.fullname=fullname
56 self.coord=coord
57 self.bfactor=bfactor
58 self.occupancy=occupancy
59 self.altloc=altloc
60 self.full_id=None
61 self.id=name
62 self.disordered_flag=0
63 self.anisou_array=None
64 self.siguij_array=None
65 self.sigatm_array=None
66 self.serial_number=serial_number
67
68 self.xtra={}
69 assert not element or element == element.upper(), element
70 self.element = self._assign_element(element)
71 self.mass = self._assign_atom_mass()
72
74 """Tries to guess element from atom name if not recognised."""
75 if not element or element.capitalize() not in IUPACData.atom_weights:
76
77
78
79
80
81 if self.fullname[0] != " " and not self.fullname[2:].isdigit():
82 putative_element = self.name.strip()
83 else:
84
85 if self.name[0].isdigit():
86 putative_element = self.name[1]
87 else:
88 putative_element = self.name[0]
89
90 if putative_element.capitalize() in IUPACData.atom_weights:
91 msg = "Used element %r for Atom (name=%s) with given element %r" \
92 % (putative_element, self.name, element)
93 element = putative_element
94 else:
95 msg = "Could not assign element %r for Atom (name=%s) with given element %r" \
96 % (putative_element, self.name, element)
97 element = ""
98 warnings.warn(msg, PDBConstructionWarning)
99
100 return element
101
103
104 if self.element:
105 return IUPACData.atom_weights[self.element.capitalize()]
106 else:
107 return float('NaN')
108
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
179
181 """Set the disordered flag to 1.
182
183 The disordered flag indicates whether the atom is disordered or not.
184 """
185 self.disordered_flag=1
186
188 "Return the disordered flag (1 if disordered, 0 otherwise)."
189 return self.disordered_flag
190
192 """Set the parent residue.
193
194 Arguments:
195 o parent - Residue object
196 """
197 self.parent=parent
198
200 "Remove reference to parent."
201 self.parent=None
202
204 "Return standard deviation of atomic parameters."
205 return self.sigatm_array
206
208 "Return standard deviations of anisotropic temperature factors."
209 return self.siguij_array
210
212 "Return anisotropic B factor."
213 return self.anisou_array
214
216 "Return parent residue."
217 return self.parent
218
220 return self.serial_number
221
223 "Return atom name."
224 return self.name
225
227 "Return the id of the atom (which is its atom name)."
228 return self.id
229
231 """Return the full id of the atom.
232
233 The full id of an atom is the tuple
234 (structure id, model id, chain id, residue id, atom name, altloc).
235 """
236 return self.parent.get_full_id()+((self.name, self.altloc),)
237
239 "Return atomic coordinates."
240 return self.coord
241
243 "Return B factor."
244 return self.bfactor
245
247 "Return occupancy."
248 return self.occupancy
249
251 "Return the atom name, including leading and trailing spaces."
252 return self.fullname
253
255 "Return alternative location specifier."
256 return self.altloc
257
260
277
279 """
280 Return coordinates as Vector.
281
282 @return: coordinates as 3D vector
283 @rtype: Vector
284 """
285 x,y,z=self.coord
286 return Vector(x,y,z)
287
288
290 """
291 This class contains all Atom objects that represent the same disordered
292 atom. One of these atoms is "selected" and all method calls not caught
293 by DisorderedAtom are forwarded to the selected Atom object. In that way, a
294 DisorderedAtom behaves exactly like a normal Atom. By default, the selected
295 Atom object represents the Atom object with the highest occupancy, but a
296 different Atom object can be selected by using the disordered_select(altloc)
297 method.
298 """
306
307
308
310 return "<Disordered Atom %s>" % self.get_id()
311
325