Beispiel #1
0
 def calculate_desolvation(self, filename=None, updater=None):
     """Calculate the desolvation energies for all titratable groups"""
     if not getattr(self, 'atom_close', None):
         self.get_atoms_around()
     #
     #
     titgrps = self.titratable_groups
     residues = titgrps.keys()
     residues.sort()
     self.desolv = {}
     for residue in residues:
         if updater:
             updater('Calculating for %s' % residue)
         for group in titgrps[residue]:
             name1 = self.get_titgroup_name(residue, group)
             #
             # Calculate the desolvation
             #
             self.desolv[name1] = 12.5 * math.pow(self.atom_close[name1],
                                                  1.7)
     #
     # Write the file
     #
     if filename:
         import pKaIO
         X = pKaIO.pKaIO()
         X.desolv = self.desolv
         X.write_desolv(filename + '.DESOLV.DAT')
     return self.desolv
Beispiel #2
0
 def calculate_desolvation(self,filename=None,updater=None):
     """Calculate the desolvation energies for all titratable groups"""
     if not getattr(self,'atom_close',None):
         self.get_atoms_around()
     #
     #
     titgrps=self.titratable_groups
     residues=titgrps.keys()
     residues.sort()
     self.desolv={}
     for residue in residues:
         if updater:
             updater('Calculating for %s' %residue)
         for group in titgrps[residue]:
             name1=self.get_titgroup_name(residue,group)
             #
             # Calculate the desolvation
             #
             self.desolv[name1]=12.5*math.pow(self.atom_close[name1],1.7)
     #
     # Write the file
     #
     if filename:
         import pKaIO
         X=pKaIO.pKaIO()
         X.desolv=self.desolv
         X.write_desolv(filename+'.DESOLV.DAT')
     return self.desolv
def _get_CCPS_population(options,args):
    """recalculate titration curves and get the pH-dependent population of select protonation states"""
    import pKaIO
    pdbfile=args[0]
    MCsteps=options.MCsteps
    pHstep=options.pHstep
    pHstart=options.pHstart
    pHend=options.pHstop
    IO=pKaIO.pKaIO(pdbfile)
    import pKa.pKa_MC 
    print 'Recalculating wild type titration curves'
    pKa_params={'pHstart':pHstart,'pHstop':pHend,'pHstep':pHstep,'pKMCsteps':MCsteps,'verbose':1}
    pKaCALC=pKa.pKa_MC.pKa_calculation_class(pdbfile,pKa_info=None,params=pKa_params)
    pKaCALC.set_MC_CPP()
    #
    #
    #
    groups=pKaCALC.MC.desolv.keys()
    groups.sort()
    if options.list_groups:
        print 'The PDB file contains these titratable groups:\n',groups
        return
    #
    # Set the protonation state
    #
    CCPS={}
    for spec in options.ccps:
        split=spec.split('=')
        group=split[0]
        charge=abs(int(split[1]))
        if CCPS.has_key(group):
            raise Exception('You cannot specify two protonation states for a single group: %s' %group)
        if not group in groups:
            raise Exception('Unknown group: %s' %group)
        CCPS[group]=charge
    #
    # Construct monitor_states        
    #
    monitor_states=[]
    for group in groups:
        if CCPS.has_key(group):
            monitor_states.append(CCPS[group])
        else:
            monitor_states.append(-99)
    #
    # Calculate the pKa values
    #
    print 'pHrange: step: %.2f start: %.2f, end: %.2f. MCsteps: %e ' %(pHstep,pHstart,pHend,MCsteps)
    wtpkas,titration_curves=pKaCALC.MC.calc_pKas(MCsteps,pHstep,pHstart,pHend,0,
        monitor_states=monitor_states)
    pHs=pKaCALC.MC.pH[:]
    CCPS=pKaCALC.MC.CCPS_pop[:]
    if options.show_plot:
        import matplotlib.pyplot as plt
        plt.plot(pHs,CCPS,'ro-',linewidth=2.0)
        plt.show()
    return pHs,CCPS
Beispiel #4
0
    def load_matrix(self):
        """Load a matrix file"""
        import tkFileDialog, os
        filename=tkFileDialog.askopenfilename(defaultextension='.MATRIX.DAT',
                                              initialdir=os.getcwd(),
                                              parent=self.Dcontrol,
                                              filetypes=[("pKa MATRIX file","*.MATRIX.DAT"),
                                                         ("All files","*.*")])
        if filename:
            import pKaIO
            self.M=pKaIO.pKaIO()
            self.pkamatrix=self.M.read_matrix(filename)

            for res1 in self.pkamatrix.keys():
                for res2 in self.pkamatrix.keys():
                    print res1,res2,self.pkamatrix[res1][res2][0]-self.pkamatrix[res1][res2][1]-self.pkamatrix[res1][res2][2]+self.pkamatrix[res1][res2][3]
            
        return
Beispiel #5
0
    def load_matrix(self):
        """Load a matrix file"""
        import tkFileDialog, os

        filename = tkFileDialog.askopenfilename(
            defaultextension=".MATRIX.DAT",
            initialdir=os.getcwd(),
            parent=self.Dcontrol,
            filetypes=[("pKa MATRIX file", "*.MATRIX.DAT"), ("All files", "*.*")],
        )
        if filename:
            import pKaIO

            self.M = pKaIO.pKaIO()
            self.pkamatrix = self.M.read_matrix(filename)

            for res1 in self.pkamatrix.keys():
                for res2 in self.pkamatrix.keys():
                    print res1, res2, self.pkamatrix[res1][res2][0] - self.pkamatrix[res1][res2][1] - self.pkamatrix[
                        res1
                    ][res2][2] + self.pkamatrix[res1][res2][3]

        return
Beispiel #6
0
def _get_CCPS_population(options, args):
    """recalculate titration curves and get the pH-dependent population of select protonation states"""
    import pKaIO
    pdbfile = args[0]
    MCsteps = options.MCsteps
    pHstep = options.pHstep
    pHstart = options.pHstart
    pHend = options.pHstop
    IO = pKaIO.pKaIO(pdbfile)
    import pKa.pKa_MC
    print 'Recalculating wild type titration curves'
    pKa_params = {
        'pHstart': pHstart,
        'pHstop': pHend,
        'pHstep': pHstep,
        'pKMCsteps': MCsteps,
        'verbose': 1
    }
    pKaCALC = pKa.pKa_MC.pKa_calculation_class(pdbfile,
                                               pKa_info=None,
                                               params=pKa_params)
    pKaCALC.set_MC_CPP()
    #
    #
    #
    groups = pKaCALC.MC.desolv.keys()
    groups.sort()
    if options.list_groups:
        print 'The PDB file contains these titratable groups:\n', groups
        return
    #
    # Set the protonation state
    #
    CCPS = {}
    for spec in options.ccps:
        split = spec.split('=')
        group = split[0]
        charge = abs(int(split[1]))
        if CCPS.has_key(group):
            raise Exception(
                'You cannot specify two protonation states for a single group: %s'
                % group)
        if not group in groups:
            raise Exception('Unknown group: %s' % group)
        CCPS[group] = charge
    #
    # Construct monitor_states
    #
    monitor_states = []
    for group in groups:
        if CCPS.has_key(group):
            monitor_states.append(CCPS[group])
        else:
            monitor_states.append(-99)
    #
    # Calculate the pKa values
    #
    print 'pHrange: step: %.2f start: %.2f, end: %.2f. MCsteps: %e ' % (
        pHstep, pHstart, pHend, MCsteps)
    wtpkas, titration_curves = pKaCALC.MC.calc_pKas(
        MCsteps, pHstep, pHstart, pHend, 0, monitor_states=monitor_states)
    pHs = pKaCALC.MC.pH[:]
    CCPS = pKaCALC.MC.CCPS_pop[:]
    if options.show_plot:
        import matplotlib.pyplot as plt
        plt.plot(pHs, CCPS, 'ro-', linewidth=2.0)
        plt.show()
    return pHs, CCPS
Beispiel #7
0
    def calculate_background(self, filename=None, updater=None):
        """Calculate the background interaction energy"""
        if not getattr(self, 'atom_close', None):
            self.get_atoms_around()
        #
        # Calc the background ene
        #
        titgrps = self.titratable_groups
        residues = titgrps.keys()
        residues.sort()
        self.background = {}
        count = 0
        for residue in residues:
            if updater:
                updater('Calculating for %s' % residue)
            for group in titgrps[residue]:
                name1 = self.get_titgroup_name(residue, group)
                #
                # Calculate the background interaction energy
                #
                # First approximation: we count potential hydrogen bonds
                #
                hbonds = 0
                tot_bonds = 0
                #
                # Get the sign right
                #
                counted = {}
                sign = group['charge']
                for atom in self.close_atoms_list[name1]:

                    for atom2 in group['atoms']:
                        #
                        # First for full-strength hydrogen bonds
                        #
                        hb = self.is_hydrogen_bond(atom, residue + ':' + atom2,
                                                   2.2, 3.5)

                        if hb == 1:
                            if not counted.has_key(atom):
                                #print 'Accepting from',atom,residue+':'+atom2
                                hbonds = hbonds - 1 * sign
                        elif hb == 2:
                            if not counted.has_key(atom):
                                #print 'Donating to',atom,residue+':'+atom2
                                hbonds = hbonds + 1 * sign
                        #
                        if hb:
                            tot_bonds = tot_bonds + 1
                            #counted[atom]=1
                        #
                        # Then for weaker - purely electrostatic interactions
                        # These are only counted half
                        #
                        hb = self.is_hydrogen_bond(atom, residue + ':' + atom2,
                                                   3.5, 7.0)
                        weak_hb = 0.3
                        if hb == 1:
                            if not counted.has_key(atom):
                                #print 'Accepting from',atom,residue+':'+atom2
                                hbonds = hbonds - weak_hb * sign
                        elif hb == 2:
                            if not counted.has_key(atom):
                                #print 'Donating to',atom,residue+':'+atom2
                                hbonds = hbonds + weak_hb * sign
                        #
                        if hb:
                            tot_bonds = tot_bonds + weak_hb
                            #counted[atom]=1

                #
                #
                #print 'Hbonds: %3d, tot_bonds: %3d' %(hbonds,tot_bonds)
                self.background[name1] = 0.69 * hbonds * math.pow(
                    self.atom_close[name1], 1)
        #
        # Write the file
        #
        if filename:
            import pKaIO
            X = pKaIO.pKaIO()
            X.backgr = self.background
            X.write_backgr(filename + '.BACKGR.DAT')
        return self.background
Beispiel #8
0
    def calculate_matrix(self, filename=None, eps=8, exdi=80, updater=None):
        """
        # This function calculates a simplified version of the charge-charge interaction
        # energy matrix
        #
        #
        # Calculate the factor that converts formal charges and distances in A into kT energies
        # eps is the dielectric constant
        """
        factor = (1.0 /
                  (4.0 * pi * e0)) * (e * e / A) * 1.0 / eps * 1.0 / (k * T)
        #
        # Get the fast scaled accessibility
        #
        acc = self.get_atoms_around(updater=updater)
        #
        # And now we calculate the matrix
        #
        import string
        if not getattr(self, 'titratable_groups', None):
            self.get_titratable_groups()
        self.matrix = {}
        self.distmatrix = {}
        titgrps = self.titratable_groups
        residues = titgrps.keys()
        residues.sort()
        #
        # Get the total number of calcs
        #
        ncalcs = len(residues) * len(residues)
        count = 0
        for residue in residues:
            for group in titgrps[residue]:
                name1 = self.get_titgroup_name(residue, group)
                if not self.matrix.has_key(name1):
                    self.matrix[name1] = {}
                if not self.distmatrix.has_key(name1):
                    self.distmatrix[name1] = {}
                #
                # Calculate distance from center of atoms
                #
                x = 0.0
                y = 0.0
                z = 0.0
                for atom in group['atoms']:
                    x = x + self.atoms[residue + ':' + atom]['X'] / float(
                        len(group['atoms']))
                    y = y + self.atoms[residue + ':' + atom]['Y'] / float(
                        len(group['atoms']))
                    z = z + self.atoms[residue + ':' + atom]['Z'] / float(
                        len(group['atoms']))
                #
                # Now for the second residue
                #
                for residue2 in titgrps.keys():
                    for group2 in titgrps[residue2]:
                        if not updater is None:
                            updater('%d of %d (%4.1f%% completed)' %
                                    (count, ncalcs,
                                     float(count) / float(ncalcs) * 100.0))
                        count = count + 1
                        name2 = self.get_titgroup_name(residue2, group2)
                        if self.matrix[name1].has_key(name2):
                            continue
                        #
                        # Get center of atoms for this res
                        #
                        x2 = 0.0
                        y2 = 0.0
                        z2 = 0.0
                        for atom in group2['atoms']:
                            x2 = x2 + self.atoms[residue2 + ':' +
                                                 atom]['X'] / float(
                                                     len(group2['atoms']))
                            y2 = y2 + self.atoms[residue2 + ':' +
                                                 atom]['Y'] / float(
                                                     len(group2['atoms']))
                            z2 = z2 + self.atoms[residue2 + ':' +
                                                 atom]['Z'] / float(
                                                     len(group2['atoms']))
                        #
                        # Get the distance
                        #
                        v1 = numpy.array([x, y, z])
                        v2 = numpy.array([x2, y2, z2])
                        import geometry
                        dist = geometry.length(v1 - v2)

                        if dist != 0:
                            crg1 = group['charge']
                            crg2 = group2['charge']
                            ene = factor * float(crg1 * crg2) / (math.pow(
                                dist, 1.5))
                            #
                            # Get the influence of the acc
                            #
                            acc_frac = math.sqrt(acc[name1] * acc[name2])
                            acc_frac = math.pow(acc_frac, 2.0)
                            ene = ene * 1.99 * acc_frac + (
                                1.0 -
                                acc_frac) * float(eps) / float(exdi) * ene
                        else:
                            ene = 0.0
                        #if ene:
                        #    print '%20s - %20s: %7.3f' %(name1,name2,ene)
                        self.matrix[name1][name2] = [ene, 0.0, 0.0, 0.0]
                        self.distmatrix[name1][name2] = dist
                        if not self.matrix.has_key(name2):
                            self.matrix[name2] = {}
                            self.matrix[name2] = {}
                        self.matrix[name2][name1] = [ene, 0.0, 0.0, 0.0]
                        self.distmatrix[name2][name1] = dist
        #
        # Write the matrix file
        #
        if filename:
            import pKaIO
            X = pKaIO.pKaIO()
            X.matrix = self.matrix
            X.write_matrix(filename + '.MATRIX.DAT')
        return self.matrix
Beispiel #9
0
 def calculate_background(self,filename=None,updater=None):
     """Calculate the background interaction energy"""
     if not getattr(self,'atom_close',None):
         self.get_atoms_around()
     #
     # Calc the background ene
     #
     titgrps=self.titratable_groups
     residues=titgrps.keys()
     residues.sort()
     self.background={}
     count=0
     for residue in residues:
         if updater:
             updater('Calculating for %s' %residue)
         for group in titgrps[residue]:
             name1=self.get_titgroup_name(residue,group)
             #
             # Calculate the background interaction energy
             #
             # First approximation: we count potential hydrogen bonds
             #
             hbonds=0
             tot_bonds=0
             #
             # Get the sign right
             #
             counted={}
             sign=group['charge']
             for atom in self.close_atoms_list[name1]:
                 
                     for atom2 in group['atoms']:
                         #
                         # First for full-strength hydrogen bonds
                         #
                         hb=self.is_hydrogen_bond(atom,residue+':'+atom2,2.2,3.5)
                         
                         if hb==1:
                             if not counted.has_key(atom):
                                 #print 'Accepting from',atom,residue+':'+atom2
                                 hbonds=hbonds-1*sign
                         elif hb==2:
                             if not counted.has_key(atom):
                                 #print 'Donating to',atom,residue+':'+atom2
                                 hbonds=hbonds+1*sign
                         #
                         if hb:
                             tot_bonds=tot_bonds+1
                             #counted[atom]=1
                         #
                         # Then for weaker - purely electrostatic interactions
                         # These are only counted half
                         #
                         hb=self.is_hydrogen_bond(atom,residue+':'+atom2,3.5,7.0)
                         weak_hb=0.3
                         if hb==1:
                             if not counted.has_key(atom):
                                 #print 'Accepting from',atom,residue+':'+atom2
                                 hbonds=hbonds-weak_hb*sign
                         elif hb==2:
                             if not counted.has_key(atom):
                                 #print 'Donating to',atom,residue+':'+atom2
                                 hbonds=hbonds+weak_hb*sign
                         #
                         if hb:
                             tot_bonds=tot_bonds+weak_hb
                             #counted[atom]=1
             
             #
             #
             #print 'Hbonds: %3d, tot_bonds: %3d' %(hbonds,tot_bonds)
             self.background[name1]=0.69*hbonds*math.pow(self.atom_close[name1],1)
     #
     # Write the file
     #
     if filename:
         import pKaIO
         X=pKaIO.pKaIO()
         X.backgr=self.background
         X.write_backgr(filename+'.BACKGR.DAT')
     return self.background
Beispiel #10
0
    def calculate_matrix(self,filename=None,eps=8,exdi=80,updater=None):
        """
        # This function calculates a simplified version of the charge-charge interaction
        # energy matrix
        #
        #
        # Calculate the factor that converts formal charges and distances in A into kT energies
        # eps is the dielectric constant
        """
        factor=(1.0/(4.0*pi*e0))*(e*e/A)*1.0/eps*1.0/(k*T)
        #
        # Get the fast scaled accessibility
        #
        acc=self.get_atoms_around(updater=updater)
        #
        # And now we calculate the matrix
        #
        import string
        if not getattr(self,'titratable_groups',None):
            self.get_titratable_groups()
        self.matrix={}
        self.distmatrix={}
        titgrps=self.titratable_groups
        residues=titgrps.keys()
        residues.sort()
        #
        # Get the total number of calcs
        #
        ncalcs=len(residues)*len(residues)
        count=0
        for residue in residues:
            for group in titgrps[residue]:
                name1=self.get_titgroup_name(residue,group) 
                if not self.matrix.has_key(name1):
                    self.matrix[name1]={}
                if not self.distmatrix.has_key(name1):
                    self.distmatrix[name1]={}
                #
                # Calculate distance from center of atoms
                #
                x=0.0
                y=0.0
                z=0.0
                for atom in group['atoms']:
                    x=x+self.atoms[residue+':'+atom]['X']/float(len(group['atoms']))
                    y=y+self.atoms[residue+':'+atom]['Y']/float(len(group['atoms']))
                    z=z+self.atoms[residue+':'+atom]['Z']/float(len(group['atoms']))
                #
                # Now for the second residue
                #
                for residue2 in titgrps.keys():
                    for group2 in titgrps[residue2]:
                        if not updater is None:
                            updater('%d of %d (%4.1f%% completed)' %(count,ncalcs,float(count)/float(ncalcs)*100.0))
                        count=count+1
                        name2=self.get_titgroup_name(residue2,group2)
                        if self.matrix[name1].has_key(name2):
                            continue
                        #
                        # Get center of atoms for this res
                        #
                        x2=0.0
                        y2=0.0
                        z2=0.0
                        for atom in group2['atoms']:
                            x2=x2+self.atoms[residue2+':'+atom]['X']/float(len(group2['atoms']))
                            y2=y2+self.atoms[residue2+':'+atom]['Y']/float(len(group2['atoms']))
                            z2=z2+self.atoms[residue2+':'+atom]['Z']/float(len(group2['atoms']))
                        #
                        # Get the distance
                        #
                        v1=numpy.array([x,y,z])
                        v2=numpy.array([x2,y2,z2])
                        import geometry
                        dist=geometry.length(v1-v2)
 
                        if dist!=0:
                            crg1=group['charge']
                            crg2=group2['charge']
                            ene=factor*float(crg1*crg2)/(math.pow(dist,1.5))
                            #
                            # Get the influence of the acc
                            #
                            acc_frac=math.sqrt(acc[name1]*acc[name2])
                            acc_frac=math.pow(acc_frac,2.0)
                            ene=ene*1.99*acc_frac+(1.0-acc_frac)*float(eps)/float(exdi)*ene
                        else:
                            ene=0.0
                        #if ene:
                        #    print '%20s - %20s: %7.3f' %(name1,name2,ene)
                        self.matrix[name1][name2]=[ene,0.0,0.0,0.0]
                        self.distmatrix[name1][name2]=dist 
                        if not self.matrix.has_key(name2):
                            self.matrix[name2]={}
                            self.matrix[name2]={}
                        self.matrix[name2][name1]=[ene,0.0,0.0,0.0]
                        self.distmatrix[name2][name1]=dist
        #
        # Write the matrix file
        #
        if filename:
            import pKaIO
            X=pKaIO.pKaIO()
            X.matrix=self.matrix
            X.write_matrix(filename+'.MATRIX.DAT')
        return self.matrix