1
2
3
4
5
6 """Atom class, used in Structure objects."""
7
8 import warnings
9
10 import numpy
11
12 from Bio.PDB.Entity import DisorderedEntityWrapper
13 from Bio.PDB.PDBExceptions import PDBConstructionWarning
14 from Bio.PDB.Vector import Vector
15
16
18 - def __init__(self, name, coord, bfactor, occupancy, altloc, fullname, serial_number,
19 element=None):
20 """
21 Atom object.
22
23 The Atom object stores atom name (both with and without spaces),
24 coordinates, B factor, occupancy, alternative location specifier
25 and (optionally) anisotropic B factor and standard deviations of
26 B factor and positions.
27
28 @param name: atom name (eg. "CA"). Note that spaces are normally stripped.
29 @type name: string
30
31 @param coord: atomic coordinates (x,y,z)
32 @type coord: Numeric array (Float0, size 3)
33
34 @param bfactor: isotropic B factor
35 @type bfactor: number
36
37 @param occupancy: occupancy (0.0-1.0)
38 @type occupancy: number
39
40 @param altloc: alternative location specifier for disordered atoms
41 @type altloc: string
42
43 @param fullname: full atom name, including spaces, e.g. " CA ". Normally
44 these spaces are stripped from the atom name.
45 @type fullname: string
46
47 @param element: atom element, e.g. "C" for Carbon, "HG" for mercury,
48 @type fullname: uppercase string (or None if unknown)
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 if not element:
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
79
81 "Print Atom object as <Atom atom_name>."
82 return "<Atom %s>" % self.get_id()
83
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
98
101
104
107
110
112 self.occupancy=occupancy
113
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
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
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
147
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
156 "Return the disordered flag (1 if disordered, 0 otherwise)."
157 return self.disordered_flag
158
160 """Set the parent residue.
161
162 Arguments:
163 o parent - Residue object
164 """
165 self.parent=parent
166
168 "Remove reference to parent."
169 self.parent=None
170
172 "Return standard deviation of atomic parameters."
173 return self.sigatm_array
174
176 "Return standard deviations of anisotropic temperature factors."
177 return self.siguij_array
178
180 "Return anisotropic B factor."
181 return self.anisou_array
182
184 "Return parent residue."
185 return self.parent
186
188 return self.serial_number
189
191 "Return atom name."
192 return self.name
193
195 "Return the id of the atom (which is its atom name)."
196 return self.id
197
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
207 "Return atomic coordinates."
208 return self.coord
209
211 "Return B factor."
212 return self.bfactor
213
215 "Return occupancy."
216 return self.occupancy
217
219 "Return the atom name, including leading and trailing spaces."
220 return self.fullname
221
223 "Return alternative location specifier."
224 return self.altloc
225
228
245
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
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 """
274
275
276
278 return "<Disordered Atom %s>" % self.get_id()
279
293