7
class PDBAtomRecord(object):
9
Class PDBAtomRecord processes ATOM or HETATM line in PDB file.
10
For all other records None value will be returned.
11
PDBAtomRecord.test is used to verify PDB line is of ATOM or HETATM type.
12
PDBAtomRecord.dct will return all available records in a dictionary with the keys
15
# Dictionary for column locations (see at the end for more info)
16
irec=dict(record=[0,6],atomid=[6,11],name=[12,16],resname=[17,20],
17
resid=[22,26],coord=[30,54],element=[76,78])
18
# Dictionary for types of fields
19
atype=dict(record="string",atomid="int",name="string",resname="string",
20
resid="int",coord="float array",element="string")
32
returns value of the "name" field in the provided "buf" buffer
33
always returns None value if buffer is not of ATOM or HETATM type
35
# print inspect.getsource(PDBAtomRecord.fieldName)
36
if not PDBAtomRecord.test(buf):
38
ir=PDBAtomRecord.irec[name]
39
atype=PDBAtomRecord.atype[name]
40
value = buf[ir[0]:ir[1]]
55
elif atype=='float array':
57
value = [float(x) for x in value.split()]
61
raise ValueError("unknown type definition")
68
returns all the available fields in a dictionary
70
if not PDBAtomRecord.test(buf):
74
for name in PDBAtomRecord.irec.iterkeys():
75
value=PDBAtomRecord.field(name,buf)
84
tests whether buffer is of ATOM or HETATM type
86
return buf[0:6] in ("ATOM ","HETATM")
89
if __name__ == '__main__':
90
aline1="ATOM 588 1HG GLU 18 -13.363 -4.163 -2.372 1.00 0.00 H"
91
aline2="ATOM 588 GLU -13.363 -4.163 -2.372 1.00 0.00"
92
aline3="ATTM 588 GLU -13.363 -4.163 -2.372 1.00 0.00"
94
print PDBAtomRecord.field("name",'')
95
print PDBAtomRecord.field("name",aline3)
96
print PDBAtomRecord.dct(aline1)
97
print PDBAtomRecord.dct(aline2)
98
print PDBAtomRecord.dct(aline3)
99
print PDBAtomRecord.dct('')
102
# 1 - 6 Record name "ATOM "
103
# 7 - 11 Integer serial Atom serial number.
104
# 13 - 16 Atom name Atom name.
105
# 17 Character altLoc Alternate location indicator.
106
# 18 - 20 Residue name resName Residue name.
107
# 22 Character chainID Chain identifier.
108
# 23 - 26 Integer resSeq Residue sequence number.
109
# 27 AChar iCode Code for insertion of residues.
110
# 31 - 38 Real(8.3) x Orthogonal coordinates for X in
112
# 39 - 46 Real(8.3) y Orthogonal coordinates for Y in
114
# 47 - 54 Real(8.3) z Orthogonal coordinates for Z in
116
# 55 - 60 Real(6.2) occupancy Occupancy.
117
# 61 - 66 Real(6.2) tempFactor Temperature factor.
118
# 77 - 78 LString(2) element Element symbol, right-justified.
119
# 79 - 80 LString(2) charge Charge on the atom.
123
# 12345678901234567890123456789012345678901234567890123456789012345678901234567890
125
# ATOM 1 N ALA 1 11.104 6.134 -6.504 1.00 0.00 N
126
# ATOM 2 CA ALA 1 11.639 6.071 -5.147 1.00 0.00 C
129
# ATOM 293 1HG GLU 18 -14.861 -4.847 0.361 1.00 0.00 H
130
# ATOM 294 2HG GLU 18 -13.518 -3.769 0.084 1.00 0.00 H
b'\\ No newline at end of file'