Exemple #1
0
 def read_WIfile(self,lines,dict,format):
     """
     # Read a DESOLV file or a BACKGR file
     """
     import string
     x=1
     done=None
     Nterm=0
     while not done:
         x=x+1
         #
         # Read first line for this residue
         #
         term=None
         if lines[x].strip()=='TERMINAL GROUP:':
             Nterm=abs(Nterm-1)
             term=True
             x=x+1
         nline=string.replace(lines[x],'(','')
         nline=string.replace(nline,')','')
         list=string.split(nline)
         resid=pKaUT.getWI_resid2(lines[x])
         if term:
             #
             # Replace the residue name by the terminal name
             #
             resname=resid.split(':')[-1]
             d={1:'NTERM',0:'CTERM'}
             resid=resid.replace(resname,d[Nterm])
         #
         dict[resid]=string.atof(list[-1])
         if string.strip(lines[x+1])=='End of file':
             done=1
     return dict
Exemple #2
0
 def read_WIfile(self, lines, dict, format):
     """
     # Read a DESOLV file or a BACKGR file
     """
     import string
     x = 1
     done = None
     Nterm = 0
     while not done:
         x = x + 1
         #
         # Read first line for this residue
         #
         term = None
         if lines[x].strip() == 'TERMINAL GROUP:':
             Nterm = abs(Nterm - 1)
             term = True
             x = x + 1
         nline = string.replace(lines[x], '(', '')
         nline = string.replace(nline, ')', '')
         list = string.split(nline)
         resid = pKaUT.getWI_resid2(lines[x])
         if term:
             #
             # Replace the residue name by the terminal name
             #
             resname = resid.split(':')[-1]
             d = {1: 'NTERM', 0: 'CTERM'}
             resid = resid.replace(resname, d[Nterm])
         #
         dict[resid] = string.atof(list[-1])
         if string.strip(lines[x + 1]) == 'End of file':
             done = 1
     return dict
Exemple #3
0
 def read_matrix(self,filename=None):
     """
     # This subroutine read a MATRIX file
     """
     if not filename:
         if self.matrix_file:
             filename=self.matrix_file
         else:
             raise Exception('No matrix filename given')
     #
     import os, string
     if not os.path.isfile(filename):
         raise Exception("File not found: "+filename)
     fd=open(filename)
     lines=fd.readlines()
     fd.close()
     #
     # Initialise dictionary
     #
     self.matrix={}
     #
     # Read title lines
     #
     if string.lower(string.strip(lines[0]))==string.lower('WHAT IF Interaction Matrix File'):
         format='WHAT IF'
     elif string.lower(string.strip(lines[0]))==string.lower('pdb2pka Interaction Matrix File'):
         format='WHAT IF'
     elif lines[2].strip()=='#pKa initialization':
         return self.read_MEADfile(lines,mode='matrix')
     else:
         raise Exception('Unknown format')
     if not string.strip(lines[1])=='Format 1.0':
         raise Exception('Wrong format'+str(lines[1]))
     x=1
     done=None
     partners=None
     Nterm=0
     while not done:
         x=x+1
         #
         # Read first line for this partner residue
         #
         if format=='WHAT IF':
             term=None
             if string.strip(lines[x])=='TERMINAL GROUP:':
                 term=1
                 Nterm=abs(Nterm-1)
                 x=x+1
             nline=string.replace(lines[x],'(','')
             nline=string.replace(nline,')','')
             resid=pKaUT.getWI_resid2(lines[x])
             if term:
                 #
                 # Replace the residue name by the terminal name
                 #
                 resname=resid.split(':')[-1]
                 d={1:'NTERM',0:'CTERM'}
                 resid=resid.replace(resname,d[Nterm])
             #
             # Get the number of interaction partners
             #
             np=int(float(nline.split()[-1]))
             if not partners:
                 partners=np
             else:
                 if partners!=np:
                     raise Exception('Number of partners changes: %d' %np)
             self.matrix[resid]={}
             #
             # Now read all the interactions with the partners
             #
             Nterm_partner=0
             for count in range(partners):
                 x=x+1
                 term2=None
                 if string.strip(lines[x])=='TERMINAL GROUP:':
                     Nterm_partner=abs(Nterm_partner-1)
                     term2=1
                     x=x+1
                 nline=string.replace(lines[x],'(','')
                 nline=string.replace(nline,')','')
                 list=string.split(nline)
                 partid=pKaUT.getWI_resid2(lines[x])
                 if term2:
                     #
                     # Replace the residue name by the terminal name
                     #
                     resname=partid.split(':')[-1]
                     d={1:'NTERM',0:'CTERM'}
                     partid=partid.replace(resname,d[Nterm_partner])
                 #
                 # New name?
                 #
                 chacha=string.atof(string.strip(list[-1]))
                 x=x+1
                 i2=float(lines[x])
                 x=x+1
                 i3=float(lines[x])
                 x=x+1
                 i4=float(lines[x])
                 energies=[chacha,i2,i3,i4]
                 self.matrix[resid][partid]=energies
                 term2=None
         elif format=='pdb2pka':
             #
             # pseudo-pdb2pka format
             #
             list=lines[x].split()
             resid=string.strip(list[0])
             self.matrix[resid]={}
             partners=int(float(list[-1]))
             #
             # Now read all the interactions with the partners
             #
             for count in range(partners):
                 x=x+1
                 list=lines[x].split()
                 partid=list[0]
                 chacha=string.atof(string.strip(list[-1]))
                 x=x+1
                 i2=string.atof(lines[x])
                 x=x+1
                 i3=string.atof(lines[x])
                 x=x+1
                 i4=string.atof(lines[x])
                 energies=[chacha,i2,i3,i4]
                 self.matrix[resid][partid]=energies
         x=x+1
         if string.strip(lines[x+1])=='End of file':
             done=1
     return self.matrix
Exemple #4
0
 def readtitcurv(self,filename=None):
     #
     # Syntax: readtitcurv(self,<titration curve filename>)
     # This function reads a WHAT IF titration curve file and
     # creates self.titdata, which is a dictionary:
     # self.titdata={<residue>:{'pKa':<pka>,<ph1>:<charge1>,<ph2>:<charge2>.....}}
     #
     if not filename:
         filename=self.titcurvfile
     import os, string
     if not os.path.isfile(filename):
         raise Exception('File does not exist: %s' %filename)
     fd=open(filename)
     lines=fd.readlines()
     fd.close()
     #
     # Parse
     #
     if string.lower(string.strip(lines[0]))==string.lower('WHAT IF Titration Curve File'):
         format='WHAT IF'
     elif string.lower(string.strip(lines[0]))==string.lower('pdb2pka Titration Curve File'):
         format='WHAT IF'
     elif lines[2].strip()=='#pKa initialization':
         return self.read_MEADfile(lines,mode='titcurv')
     else:
         raise Exception('Unknown format')
     if string.lower(string.strip(lines[1]))!=string.lower('Format 1.0'):
         raise Exception('unknown format: '+str(lines[1]))
     #
     # Get the pH start, stop and step
     #
     phvals=string.split(lines[2])
     phstart=string.atof(phvals[0])
     phend=string.atof(phvals[1])
     phstep=string.atof(phvals[2])
     titdata={}
     linenumber=3
     done=0
     terms=['NTERM','CTERM']
     term_count=-1
     while not done:
         Term=False
         if string.strip(lines[linenumber])=='TERMINAL GROUP:':
             linenumber=linenumber+1
             Term=1
         residue=pKaUT.getWI_resid2(lines[linenumber],format)
         if Term:
             term_count=term_count+1
             #
             # Get rid of the residue name and just add the term
             #
             aaname=residue.split(':')[-1]
             residue=residue.replace(aaname,terms[term_count])
             if term_count==1:
                 term_count=-1
         pKa=float(string.split(lines[linenumber])[-1])
         linenumber=linenumber+1
         #
         # --------------
         #
         charge={'pKa':pKa}
         for pH in range(int(100*phstart),int(100*phend+100*phstep),int(100*phstep)):
             rpH=float(pH)/100.0
             line=string.split(lines[linenumber])
             if string.atof(line[0])==rpH:
                 charge[rpH]=string.atof(line[1])
                 linenumber=linenumber+1
         titdata[residue]=charge
         linenumber=linenumber+1
         if string.strip(string.lower(lines[linenumber]))==string.lower('End of file'):
             done=1
     self.titdata=titdata
     return self.titdata
Exemple #5
0
 def read_matrix(self, filename=None):
     """
     # This subroutine read a MATRIX file
     """
     if not filename:
         if self.matrix_file:
             filename = self.matrix_file
         else:
             raise Exception('No matrix filename given')
     #
     import os, string
     if not os.path.isfile(filename):
         raise Exception("File not found: " + filename)
     fd = open(filename)
     lines = fd.readlines()
     fd.close()
     #
     # Initialise dictionary
     #
     self.matrix = {}
     #
     # Read title lines
     #
     if string.lower(string.strip(
             lines[0])) == string.lower('WHAT IF Interaction Matrix File'):
         format = 'WHAT IF'
     elif string.lower(string.strip(
             lines[0])) == string.lower('pdb2pka Interaction Matrix File'):
         format = 'WHAT IF'
     elif lines[2].strip() == '#pKa initialization':
         return self.read_MEADfile(lines, mode='matrix')
     else:
         raise Exception('Unknown format')
     if not string.strip(lines[1]) == 'Format 1.0':
         raise Exception('Wrong format' + str(lines[1]))
     x = 1
     done = None
     partners = None
     Nterm = 0
     while not done:
         x = x + 1
         #
         # Read first line for this partner residue
         #
         if format == 'WHAT IF':
             term = None
             if string.strip(lines[x]) == 'TERMINAL GROUP:':
                 term = 1
                 Nterm = abs(Nterm - 1)
                 x = x + 1
             nline = string.replace(lines[x], '(', '')
             nline = string.replace(nline, ')', '')
             resid = pKaUT.getWI_resid2(lines[x])
             if term:
                 #
                 # Replace the residue name by the terminal name
                 #
                 resname = resid.split(':')[-1]
                 d = {1: 'NTERM', 0: 'CTERM'}
                 resid = resid.replace(resname, d[Nterm])
             #
             # Get the number of interaction partners
             #
             np = int(float(nline.split()[-1]))
             if not partners:
                 partners = np
             else:
                 if partners != np:
                     raise Exception('Number of partners changes: %d' % np)
             self.matrix[resid] = {}
             #
             # Now read all the interactions with the partners
             #
             Nterm_partner = 0
             for count in range(partners):
                 x = x + 1
                 term2 = None
                 if string.strip(lines[x]) == 'TERMINAL GROUP:':
                     Nterm_partner = abs(Nterm_partner - 1)
                     term2 = 1
                     x = x + 1
                 nline = string.replace(lines[x], '(', '')
                 nline = string.replace(nline, ')', '')
                 list = string.split(nline)
                 partid = pKaUT.getWI_resid2(lines[x])
                 if term2:
                     #
                     # Replace the residue name by the terminal name
                     #
                     resname = partid.split(':')[-1]
                     d = {1: 'NTERM', 0: 'CTERM'}
                     partid = partid.replace(resname, d[Nterm_partner])
                 #
                 # New name?
                 #
                 chacha = string.atof(string.strip(list[-1]))
                 x = x + 1
                 i2 = float(lines[x])
                 x = x + 1
                 i3 = float(lines[x])
                 x = x + 1
                 i4 = float(lines[x])
                 energies = [chacha, i2, i3, i4]
                 self.matrix[resid][partid] = energies
                 term2 = None
         elif format == 'pdb2pka':
             #
             # pseudo-pdb2pka format
             #
             list = lines[x].split()
             resid = string.strip(list[0])
             self.matrix[resid] = {}
             partners = int(float(list[-1]))
             #
             # Now read all the interactions with the partners
             #
             for count in range(partners):
                 x = x + 1
                 list = lines[x].split()
                 partid = list[0]
                 chacha = string.atof(string.strip(list[-1]))
                 x = x + 1
                 i2 = string.atof(lines[x])
                 x = x + 1
                 i3 = string.atof(lines[x])
                 x = x + 1
                 i4 = string.atof(lines[x])
                 energies = [chacha, i2, i3, i4]
                 self.matrix[resid][partid] = energies
         x = x + 1
         if string.strip(lines[x + 1]) == 'End of file':
             done = 1
     return self.matrix
Exemple #6
0
 def readtitcurv(self, filename=None):
     #
     # Syntax: readtitcurv(self,<titration curve filename>)
     # This function reads a WHAT IF titration curve file and
     # creates self.titdata, which is a dictionary:
     # self.titdata={<residue>:{'pKa':<pka>,<ph1>:<charge1>,<ph2>:<charge2>.....}}
     #
     if not filename:
         filename = self.titcurvfile
     import os, string
     if not os.path.isfile(filename):
         raise Exception('File does not exist: %s' % filename)
     fd = open(filename)
     lines = fd.readlines()
     fd.close()
     #
     # Parse
     #
     if string.lower(string.strip(
             lines[0])) == string.lower('WHAT IF Titration Curve File'):
         format = 'WHAT IF'
     elif string.lower(string.strip(
             lines[0])) == string.lower('pdb2pka Titration Curve File'):
         format = 'WHAT IF'
     elif lines[2].strip() == '#pKa initialization':
         return self.read_MEADfile(lines, mode='titcurv')
     else:
         raise Exception('Unknown format')
     if string.lower(string.strip(lines[1])) != string.lower('Format 1.0'):
         raise Exception('unknown format: ' + str(lines[1]))
     #
     # Get the pH start, stop and step
     #
     phvals = string.split(lines[2])
     phstart = string.atof(phvals[0])
     phend = string.atof(phvals[1])
     phstep = string.atof(phvals[2])
     titdata = {}
     linenumber = 3
     done = 0
     terms = ['NTERM', 'CTERM']
     term_count = -1
     while not done:
         Term = False
         if string.strip(lines[linenumber]) == 'TERMINAL GROUP:':
             linenumber = linenumber + 1
             Term = 1
         residue = pKaUT.getWI_resid2(lines[linenumber], format)
         if Term:
             term_count = term_count + 1
             #
             # Get rid of the residue name and just add the term
             #
             aaname = residue.split(':')[-1]
             residue = residue.replace(aaname, terms[term_count])
             if term_count == 1:
                 term_count = -1
         pKa = float(string.split(lines[linenumber])[-1])
         linenumber = linenumber + 1
         #
         # --------------
         #
         charge = {'pKa': pKa}
         for pH in range(int(100 * phstart),
                         int(100 * phend + 100 * phstep),
                         int(100 * phstep)):
             rpH = float(pH) / 100.0
             line = string.split(lines[linenumber])
             if string.atof(line[0]) == rpH:
                 charge[rpH] = string.atof(line[1])
                 linenumber = linenumber + 1
         titdata[residue] = charge
         linenumber = linenumber + 1
         if string.strip(string.lower(
                 lines[linenumber])) == string.lower('End of file'):
             done = 1
     self.titdata = titdata
     return self.titdata