From 548aee18db14512c2bd73165a43b17f5d58685b4 Mon Sep 17 00:00:00 2001 From: Marat Valiev Date: Thu, 9 Feb 2012 03:30:02 +0000 Subject: [PATCH] connected to pdbrecord --- contrib/marat/nwchem-python/GenericAtom.py | 48 +++++++++++++++++----- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/contrib/marat/nwchem-python/GenericAtom.py b/contrib/marat/nwchem-python/GenericAtom.py index cd04051253..39d099c833 100644 --- a/contrib/marat/nwchem-python/GenericAtom.py +++ b/contrib/marat/nwchem-python/GenericAtom.py @@ -5,28 +5,56 @@ Created on Feb 7, 2012 ''' import sys from types import * +from pdbrecord import PDBAtomRecord +from numpy import * -class GenericAtom: +class GenericAtom(object): ''' classdocs ''' - - def __init__(self,d=None): + def __init__(self,d): ''' Constructor ''' - if d is None: - self.dict = {} - else: + self.dct = d + + if d: if type(d) is not type({}): print "wrong type ", type(d) print "expecting", type({}) sys.exit(1) else: - self.dict = d + self.dct = d + try: + self.coord=array(self.dct.pop("coord")) + except: + self.coord=None + + @classmethod + def fromPDBrecord(cls,buf): + ''' + alternative constructor from PDB record + ''' + d=PDBAtomRecord.dct(buf) + if d: + return cls(d) + return None + @staticmethod + def bondlength(a1,a2): + dr=a1.coord-a2.coord + return linalg.norm(dr) + if __name__ == '__main__': - a=GenericAtom({}) - print a - \ No newline at end of file + aline1="ATOM 588 1HG GLU 18 -13.363 -4.163 -2.372 1.00 0.00 H" + aline2="ATOM 1 I1 IO3 1 -1.555 -0.350 0.333 1.39 I" + aline3="ATOM 2 O1 IO3 1 -0.985 -1.156 1.840 -0.80 O" + + a=GenericAtom.fromPDBrecord(aline2) + print a.coord + print a.dct + b=GenericAtom.fromPDBrecord(aline3) + print b.coord + print b.dct + print GenericAtom.bondlength(a,b) \ No newline at end of file