1
2
3
4
5
6
7 import numpy
8
9
10 from Entity import DisorderedEntityWrapper
11 from Vector import Vector
12
13 __doc__="Atom class, used in Structure objects."
14
16 - def __init__(self, name, coord, bfactor, occupancy, altloc, fullname, serial_number,
17 element=None):
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 @param element: atom element, e.g. "C" for Carbon, "HG" for mercury,
46 @type fullname: uppercase string (or None if unknown)
47 """
48 self.level="A"
49
50 self.parent=None
51
52 self.name=name
53 self.fullname=fullname
54 self.coord=coord
55 self.bfactor=bfactor
56 self.occupancy=occupancy
57 self.altloc=altloc
58 self.full_id=None
59 self.id=name
60 self.disordered_flag=0
61 self.anisou_array=None
62 self.siguij_array=None
63 self.sigatm_array=None
64 self.serial_number=serial_number
65
66 self.xtra={}
67 if element is None :
68 import warnings
69 from PDBExceptions import PDBConstructionWarning
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