7
from pdbrecord import PDBAtomRecord
10
from atom_params import *
12
class GenericAtom(object):
24
if type(d) is not type({}):
25
print "wrong type ", type(d)
26
print "expecting", type({})
31
self.coord=numpy.array(self.dct.pop("coord"))
36
def fromPDBrecord(cls,buf):
38
alternative constructor from PDB record
40
d=PDBAtomRecord.dct(buf)
46
def fromXYZrecord(cls,aline):
47
atomstr = string.split(aline)[0:4]
52
coord=[float(x) for x in atomstr[1:]]
53
return cls({"grouptag":"XYZ", "coord":coord,"name":name})
56
def bondlength(a1,a2):
58
return numpy.linalg.norm(dr)
64
c = numpy.dot(u,v)/numpy.linalg.norm(u)/numpy.linalg.norm(v)
65
return math.degrees(math.acos(c))
67
def translate(self,v):
68
self.coord=self.coord-v
71
name = self.dct["name"]
72
return AtomParams.covRadius(name)
75
name = self.dct["name"]
76
return AtomParams.elementName(name)
79
return self.dct["name"]
84
return self.dct.get("resname","UNK").strip()
88
returns that identifies group association of an atom
89
based on residue name and residue id (e.g. "ASP_1")
90
Default values of "UNK" and "0" are used should
91
residue name and residue id be absent
93
tag = self.dct.get("grouptag")
95
resname = self.dct.get("resname","UNK").strip()
96
resid = str(self.dct.get("resid",0)).strip()
97
tag ="_".join((resname,resid))
101
def setGroupTag(self,tag):
103
returns that identifies group association of an atom
104
based on residue name and residue id (e.g. "ASP_1")
105
Default values of "UNK" and "0" are used should
106
residue name and residue id be absent
108
self.dct["grouptag"]=tag
112
returns that identifies res association of an atom
113
based on residue name and residue id (e.g. "ASP_1")
116
resname = self.dct.get("resname","UNK").strip()
117
resid = str(self.dct.get("resid",0)).strip()
118
tag ="_".join((resname,resid))
123
returns that identifies group association of an atom
124
based on residue name and residue id (e.g. "ASP_1")
125
Default values of "UNK" and "0" are used should
126
residue name and residue id be absent
128
bond = self.dct.setdefault("bond",set())
133
return str(self.dct) + " " + str(self.coord)
138
dr = numpy.linalg.norm(a1.coord-a2.coord)
139
return dr <= (a1.covRadius()+a2.covRadius())
141
if __name__ == '__main__':
142
# aline1="ATOM 588 1HG GLU 18 -13.363 -4.163 -2.372 1.00 0.00 H"
143
# aline2="ATOM 1 I1 IO3 1 -1.555 -0.350 0.333 1.39 I"
144
# aline3="ATOM 2 O1 IO3 1 -0.985 -1.156 1.840 -0.80 O"
145
# aline4="ATOM 2 O1 -0.985 -1.156 1.840 -0.80 O"
147
# a=GenericAtom.fromPDBrecord(aline2)
151
# b=GenericAtom.fromPDBrecord(aline3)
154
# print GenericAtom.bondlength(a,b),GenericAtom.bonded(a,b)
155
# print a.covRadius()+b.covRadius()
156
# c=GenericAtom.fromPDBrecord(aline1)
157
# print GenericAtom.bondlength(a,c),GenericAtom.bonded(a,c)
158
# c=GenericAtom.fromPDBrecord(aline4)
160
aline6="O1 -0.985 -1.156 1.140 0.0 0.0 "
161
aline5="O1 -0.985 -1.156 "
162
d=GenericAtom.fromXYZrecord(aline6)
163
d.translate([1.0,1.0,1.0])