pKaTool/pKaIO.py
def read_MEADfile(self,lines,mode='pKa'):
        """Parse a MEAD pKa calculation file"""
        # Some residues have different names
        MEADtranslate={'ASH1':'ASP','GLH1':'GLU'}
        #
        count=0
        while count<len(lines):
            line=lines[count]
            print line.strip()
            if line.strip()=='<****CALCULATION RESULTS>' and mode=='pKa':
                pKas={}
                while line[:10]!='--------------'[:10] or count==len(lines):
                    count=count+1
                    line=lines[count]
                if line[:10]!='---------------'[:10]:
                    raise Exception('Could not parse MEAD file')
                #
                count=count+1
                line=lines[count]
                while line.strip()!='':
                    sp=line.split()
                    residue=sp[0].split('-')
                    import string
                    residue='%s:%s:%s' %('',string.zfill(int(residue[1]),4),residue[0])
                    modelpk=float(sp[1])
                    desolv=float(sp[3])
                    backgr=float(sp[2])
                    intpka=float(sp[4])
                    pka=float(sp[5])
                    site=pka-intpka
                    titgroup=residue.split(':')[2]
                    if MEADtranslate.has_key(titgroup):
                        titgroup=MEADtranslate[titgroup]
                    pKas[residue]={'pKa':pka,'modelpK':modelpk,'desolv':desolv,'backgr':backgr,'delec':site,
                          'acidbase':self.acidbase[titgroup],'intpka':intpka}
                    count=count+1
                    line=lines[count]
                return pKas
            #
            # Code for reading the titration curves
            #
            elif line.strip()=='<****SITE_INFOS>' and mode=='titcurv':
                self.titdata={}
                count=count+1
                #print lines[count].strip()
                #stop
                titcurvs=eval(lines[count])
                for item in titcurvs:
                    residue=item['site'][0].split('-')
                    import string
                    residue='%s:%s:%s' %('',string.zfill(int(residue[1]),4),residue[0])
                    tc=item['tit_curve']
                    this_tc={}
                    #
                    import pKadata
                    acidbase=pKadata.acidbase
                    for pH,charge in tc:
                        titgroup=residue.split(':')[2]
                        if MEADtranslate.has_key(titgroup):
                            titgroup=MEADtranslate[titgroup]
                        if not acidbase.has_key(titgroup):
                            raise Exception('Unknown titratable group: %s\nPlease add this titratable group to pKaTool/pKaData.py' %titgroup)
                        this_tc[float(pH)]=float(acidbase[titgroup])*float(charge)
                    self.titdata[residue]=this_tc.copy()
                return self.titdata
            #
            # Code for reading the interaction matrix
            #
            elif line.strip()=='<****SITE_INFOS>' and mode=='matrix':
                self.matrix={}
                count=count+1
                infodict=eval(lines[count])
                #
                # Get all the titgroups first
                #
                titgroups=[]
                for item in infodict:
                    residue=item['site'][0].split('-')
                    import string
                    residue='%s:%s:%s' %('',string.zfill(int(residue[1]),4),residue[0])
                    titgroups.append(residue)
                #
                # Now we can read the matrix
                #
                for item in infodict:
                    residue=item['site'][0].split('-')
                    import string
                    residue='%s:%s:%s' %('',string.zfill(int(residue[1]),4),residue[0])
                    self.matrix[residue]={}
                    ints=item['interactions']
                    count=0
                    for interaction in ints:
                        import pKadata
                        acidbase=pKadata.acidbase
                        titgroup1=residue.split(':')[2]
                        if MEADtranslate.has_key(titgroup1):
                            titgroup1=MEADtranslate[titgroup1]
                        group1=acidbase[titgroup1]
                        #
                        titgroup2=titgroups[count].split(':')[2]
                        if MEADtranslate.has_key(titgroup2):
                            titgroup2=MEADtranslate[titgroup2]
                        group2=acidbase[titgroup2]
                        #
                        self.matrix[residue][titgroups[count]]=[331.842/0.592*interaction*float(group1)*float(group2),0.0,0.0,0.0] # Multiply to get the sign right
                        # 331.842 is a conversion factor to go from internal MEAD energies to kcal/mol
                        count=count+1
                return self.matrix
            #
            # Read the coordinates from the file
            #
            elif line.strip()=='<****ATOMS>' and mode=='pdb':
                count=count+2
                line=lines[count]
                pdblines=[]
                while line.strip()!='' and line.strip()!='<****CONNECT>':
                    sp=line.split()
                    number=int(sp[0])
                    resnumber=sp[1]
                    resname=sp[2]
                    #chainid=sp[3]
                    chainid=' '
                    atomname=sp[4]
                    X=float(sp[6])
                    Y=float(sp[7])
                    Z=float(sp[8])
                    pdbline='ATOM  %5i %4s %-4s%1s%4s    %8.3f%8.3f%8.3f %5s %5s' %(number,atomname,resname,chainid,resnumber,X,Y,Z,0,0)
                    pdblines.append(pdbline)
                    count=count+1
                    line=lines[count]
                return pdblines
            count=count+1
        raise Exception('Could not parse MEAD file')
Parse a MEAD pKa calculation file
Parse a MEAD pKa calculation file
Parse a MEAD pKa calculation file
def read_MEADfile(self,lines,mode='pKa'):
        MEADtranslate={'ASH1':'ASP','GLH1':'GLU'}
        count=0
        while count<len(lines):
            line=lines[count]
            print line.strip()
            if line.strip()=='<****CALCULATION RESULTS>' and mode=='pKa':
                pKas={}
                while line[:10]!='--------------'[:10] or count==len(lines):
                    count=count+1
                    line=lines[count]
                if line[:10]!='---------------'[:10]:
                    raise Exception('Could not parse MEAD file')
                count=count+1
                line=lines[count]
                while line.strip()!='':
                    sp=line.split()
                    residue=sp[0].split('-')
                    import string
                    residue='%s:%s:%s' %('',string.zfill(int(residue[1]),4),residue[0])
                    modelpk=float(sp[1])
                    desolv=float(sp[3])
                    backgr=float(sp[2])
                    intpka=float(sp[4])
                    pka=float(sp[5])
                    site=pka-intpka
                    titgroup=residue.split(':')[2]
                    if MEADtranslate.has_key(titgroup):
                        titgroup=MEADtranslate[titgroup]
                    pKas[residue]={'pKa':pka,'modelpK':modelpk,'desolv':desolv,'backgr':backgr,'delec':site,
                          'acidbase':self.acidbase[titgroup],'intpka':intpka}
                    count=count+1
                    line=lines[count]
                return pKas
             Code for reading the titration curves
            elif line.strip()=='<****SITE_INFOS>' and mode=='titcurv':
                self.titdata={}
                count=count+1
                print lines[count].strip()
                stop
                titcurvs=eval(lines[count])
                for item in titcurvs:
                    residue=item['site'][0].split('-')
                    import string
                    residue='%s:%s:%s' %('',string.zfill(int(residue[1]),4),residue[0])
                    tc=item['tit_curve']
                    this_tc={}
                    import pKadata
                    acidbase=pKadata.acidbase
                    for pH,charge in tc:
                        titgroup=residue.split(':')[2]
                        if MEADtranslate.has_key(titgroup):
                            titgroup=MEADtranslate[titgroup]
                        if not acidbase.has_key(titgroup):
                            raise Exception('Unknown titratable group: %s\nPlease add this titratable group to pKaTool/pKaData.py' %titgroup)
                        this_tc[float(pH)]=float(acidbase[titgroup])*float(charge)
                    self.titdata[residue]=this_tc.copy()
                return self.titdata
             Code for reading the interaction matrix
            elif line.strip()=='<****SITE_INFOS>' and mode=='matrix':
                self.matrix={}
                count=count+1
                infodict=eval(lines[count])
                 Get all the titgroups first
                titgroups=[]
                for item in infodict:
                    residue=item['site'][0].split('-')
                    import string
                    residue='%s:%s:%s' %('',string.zfill(int(residue[1]),4),residue[0])
                    titgroups.append(residue)
                 Now we can read the matrix
                for item in infodict:
                    residue=item['site'][0].split('-')
                    import string
                    residue='%s:%s:%s' %('',string.zfill(int(residue[1]),4),residue[0])
                    self.matrix[residue]={}
                    ints=item['interactions']
                    count=0
                    for interaction in ints:
                        import pKadata
                        acidbase=pKadata.acidbase
                        titgroup1=residue.split(':')[2]
                        if MEADtranslate.has_key(titgroup1):
                            titgroup1=MEADtranslate[titgroup1]
                        group1=acidbase[titgroup1]
                        titgroup2=titgroups[count].split(':')[2]
                        if MEADtranslate.has_key(titgroup2):
                            titgroup2=MEADtranslate[titgroup2]
                        group2=acidbase[titgroup2]
                        self.matrix[residue][titgroups[count]]=[331.842/0.592*interaction*float(group1)*float(group2),0.0,0.0,0.0]  Multiply to get the sign right
                         331.842 is a conversion factor to go from internal MEAD energies to kcal/mol
                        count=count+1
                return self.matrix
             Read the coordinates from the file
            elif line.strip()=='<****ATOMS>' and mode=='pdb':
                count=count+2
                line=lines[count]
                pdblines=[]
                while line.strip()!='' and line.strip()!='<****CONNECT>':
                    sp=line.split()
                    number=int(sp[0])
                    resnumber=sp[1]
                    resname=sp[2]
                    chainid=sp[3]
                    chainid=' '
                    atomname=sp[4]
                    X=float(sp[6])
                    Y=float(sp[7])
                    Z=float(sp[8])
                    pdbline='ATOM  %5i %4s %-4s%1s%4s    %8.3f%8.3f%8.3f %5s %5s' %(number,atomname,resname,chainid,resnumber,X,Y,Z,0,0)
                    pdblines.append(pdbline)
                    count=count+1
                    line=lines[count]
                return pdblines
            count=count+1
        raise Exception('Could not parse MEAD file')
def read_MEADfile ( self , lines , mode = 'pKa' ) : MEADtranslate = { 'ASH1' : 'ASP' , 'GLH1' : 'GLU' } count = 0 while count < len ( lines ) : line = lines [ count ] print line . strip ( ) if line . strip ( ) == '<****CALCULATION RESULTS>' and mode == 'pKa' : pKas = { } while line [ : 10 ] != '--------------' [ : 10 ] or count == len ( lines ) : count = count + 1 line = lines [ count ] if line [ : 10 ] != '---------------' [ : 10 ] : raise Exception ( 'Could not parse MEAD file' ) count = count + 1 line = lines [ count ] while line . strip ( ) != '' : sp = line . split ( ) residue = sp [ 0 ] . split ( '-' ) import string residue = '%s:%s:%s' % ( '' , string . zfill ( int ( residue [ 1 ] ) , 4 ) , residue [ 0 ] ) modelpk = float ( sp [ 1 ] ) desolv = float ( sp [ 3 ] ) backgr = float ( sp [ 2 ] ) intpka = float ( sp [ 4 ] ) pka = float ( sp [ 5 ] ) site = pka - intpka titgroup = residue . split ( ':' ) [ 2 ] if MEADtranslate . has_key ( titgroup ) : titgroup = MEADtranslate [ titgroup ] pKas [ residue ] = { 'pKa' : pka , 'modelpK' : modelpk , 'desolv' : desolv , 'backgr' : backgr , 'delec' : site , 'acidbase' : self . acidbase [ titgroup ] , 'intpka' : intpka } count = count + 1 line = lines [ count ] return pKas elif line . strip ( ) == '<****SITE_INFOS>' and mode == 'titcurv' : self . titdata = { } count = count + 1 titcurvs = eval ( lines [ count ] ) for item in titcurvs : residue = item [ 'site' ] [ 0 ] . split ( '-' ) import string residue = '%s:%s:%s' % ( '' , string . zfill ( int ( residue [ 1 ] ) , 4 ) , residue [ 0 ] ) tc = item [ 'tit_curve' ] this_tc = { } import pKadata acidbase = pKadata . acidbase for pH , charge in tc : titgroup = residue . split ( ':' ) [ 2 ] if MEADtranslate . has_key ( titgroup ) : titgroup = MEADtranslate [ titgroup ] if not acidbase . has_key ( titgroup ) : raise Exception ( 'Unknown titratable group: %s\nPlease add this titratable group to pKaTool/pKaData.py' % titgroup ) this_tc [ float ( pH ) ] = float ( acidbase [ titgroup ] ) * float ( charge ) self . titdata [ residue ] = this_tc . copy ( ) return self . titdata elif line . strip ( ) == '<****SITE_INFOS>' and mode == 'matrix' : self . matrix = { } count = count + 1 infodict = eval ( lines [ count ] ) titgroups = [ ] for item in infodict : residue = item [ 'site' ] [ 0 ] . split ( '-' ) import string residue = '%s:%s:%s' % ( '' , string . zfill ( int ( residue [ 1 ] ) , 4 ) , residue [ 0 ] ) titgroups . append ( residue ) for item in infodict : residue = item [ 'site' ] [ 0 ] . split ( '-' ) import string residue = '%s:%s:%s' % ( '' , string . zfill ( int ( residue [ 1 ] ) , 4 ) , residue [ 0 ] ) self . matrix [ residue ] = { } ints = item [ 'interactions' ] count = 0 for interaction in ints : import pKadata acidbase = pKadata . acidbase titgroup1 = residue . split ( ':' ) [ 2 ] if MEADtranslate . has_key ( titgroup1 ) : titgroup1 = MEADtranslate [ titgroup1 ] group1 = acidbase [ titgroup1 ] titgroup2 = titgroups [ count ] . split ( ':' ) [ 2 ] if MEADtranslate . has_key ( titgroup2 ) : titgroup2 = MEADtranslate [ titgroup2 ] group2 = acidbase [ titgroup2 ] self . matrix [ residue ] [ titgroups [ count ] ] = [ 331.842 / 0.592 * interaction * float ( group1 ) * float ( group2 ) , 0.0 , 0.0 , 0.0 ] count = count + 1 return self . matrix elif line . strip ( ) == '<****ATOMS>' and mode == 'pdb' : count = count + 2 line = lines [ count ] pdblines = [ ] while line . strip ( ) != '' and line . strip ( ) != '<****CONNECT>' : sp = line . split ( ) number = int ( sp [ 0 ] ) resnumber = sp [ 1 ] resname = sp [ 2 ] chainid = ' ' atomname = sp [ 4 ] X = float ( sp [ 6 ] ) Y = float ( sp [ 7 ] ) Z = float ( sp [ 8 ] ) pdbline = 'ATOM  %5i %4s %-4s%1s%4s    %8.3f%8.3f%8.3f %5s %5s' % ( number , atomname , resname , chainid , resnumber , X , Y , Z , 0 , 0 ) pdblines . append ( pdbline ) count = count + 1 line = lines [ count ] return pdblines count = count + 1 raise Exception ( 'Could not parse MEAD file' )
Parse a MEAD pKa calculation file
Parse a MEAD pKa calculation file
"""Parse a MEAD pKa calculation file""" # Some residues have different names # # # # Code for reading the titration curves # #print lines[count].strip() #stop # # # Code for reading the interaction matrix # # # Get all the titgroups first # # # Now we can read the matrix # # # # Multiply to get the sign right # 331.842 is a conversion factor to go from internal MEAD energies to kcal/mol # # Read the coordinates from the file # #chainid=sp[3]
self
lines
mode