Beispiel #1
0
def main():
    """Calculate the change in chemical shift due to a full charge on each titratable group"""
    import get_dEF, sys
    method = sys.argv[2]
    X = get_dEF.map_struct(sys.argv[1])
    X.build_Hs()
    residues = X.PI.residues.keys()
    residues.sort()
    #
    # Get the titratable groups
    #
    titgroups = X.PI.get_titratable_groups()
    titgroups.sort()
    import pKa.pKD_tools
    for titgroup in titgroups:
        titgroup_type = pKa.pKD_tools.get_titgroup_type_from_titgroup(titgroup)
        charge = X.PI.titgroups[titgroup_type]['charge']
        print 'TITRATABLE GROUP', titgroup
        print 'Residue  CS Nitrogen    CS Hydrogen'
        for residue in residues:
            dCS_N = X.get_dCS(residue + ':N',
                              titgroup,
                              charge=charge,
                              method=method)
            dCS_H = X.get_dCS(residue + ':H',
                              titgroup,
                              charge=charge,
                              method=method)
            print '%8s,    %s,    %s' % (residue, Nonefix(dCS_N),
                                         Nonefix(dCS_H))
Beispiel #2
0
def main(options,args):
    """Calculate the change in chemical shift due to a full charge on each titratable group"""
    import get_dEF
    method=options.method 
    X=get_dEF.map_struct(args[0])
    X.build_Hs()
    residues=X.PI.residues.keys()
    residues.sort()
    #
    # Get the titratable groups
    #
    titgroups=X.PI.get_titratable_groups()
    titgroups.sort()
    import pKa.pKD_tools
    if options.group_by_titgroup:
        for titgroup in titgroups:
            titgroup_type=pKa.pKD_tools.get_titgroup_type_from_titgroup(titgroup)
            charge=X.PI.titgroups[titgroup_type]['charge']
            print 'TITRATABLE GROUP',titgroup
            print 'Residue  CS Nitrogen    CS Hydrogen'
            
            for residue in residues:
                dCS_N=X.get_dCS(residue+':N',titgroup,charge=charge,method=method)
                dCS_H=X.get_dCS(residue+':H',titgroup,charge=charge,method=method)
                print '%8s,    %s,    %s' %(residue,Nonefix(dCS_N),Nonefix(dCS_H))
    else:
        #
        # Group by atom
        #
        for residue in residues:
            for atom in [':N',':H']:
                changes=[]
                for titgroup in titgroups:
                    titgroup_type=pKa.pKD_tools.get_titgroup_type_from_titgroup(titgroup)
                    charge=X.PI.titgroups[titgroup_type]['charge']
                    dCS=X.get_dCS(residue+atom,titgroup,charge=charge,method=method)
                    changes.append([titgroup,dCS])
                #
                if options.sort:
                    def cmpfunc(x,y):
                        if x[1] is None:
                            return 1
                        if y[1] is None:
                            return -1
                        return cmp(abs(y[1]),abs(x[1]))
                    changes.sort(cmpfunc)
                print 'Residue: %s, Atom: %s' %(residue,atom[1])
                for titgroup,dCS in changes[:options.listnumber]:
                    if dCS:
                        if abs(dCS)<options.limit:
                            continue
                        print titgroup,dCS
                print
    return
Beispiel #3
0
def main():
    """Calculate the change in chemical shift due to a full charge on each titratable group"""
    import get_dEF, sys
    method=sys.argv[2] 
    X=get_dEF.map_struct(sys.argv[1])
    X.build_Hs()
    residues=X.PI.residues.keys()
    residues.sort()
    #
    # Get the titratable groups
    #
    titgroups=X.PI.get_titratable_groups()
    titgroups.sort()
    import pKa.pKD_tools
    for titgroup in titgroups:
        titgroup_type=pKa.pKD_tools.get_titgroup_type_from_titgroup(titgroup)
        charge=X.PI.titgroups[titgroup_type]['charge']
        print 'TITRATABLE GROUP',titgroup
        print 'Residue  CS Nitrogen    CS Hydrogen'
        for residue in residues:
            dCS_N=X.get_dCS(residue+':N',titgroup,charge=charge,method=method)
            dCS_H=X.get_dCS(residue+':H',titgroup,charge=charge,method=method)
            print '%8s,    %s,    %s' %(residue,Nonefix(dCS_N),Nonefix(dCS_H))
Beispiel #4
0
	def get_dCS(self):
		"""Calculate the change in chemical shift due to a full charge on each titratable group
		and pickle the dictionary"""
		import cPickle
		import get_dEF
		X=get_dEF.map_struct(self.pdb)
		X.build_Hs()
		residues=X.PI.residues.keys()
		residues.sort()
		#
		# Get the titratable groups
		#
		titgroups=X.PI.get_titratable_groups()
		titgroups.sort()
		print '\nTitratable groups: ',titgroups
		self.residues=residues
		self.titgroups=titgroups
		
		
		directory=self.method+'_potmap/'
		dir_name=os.path.join(os.getcwd(),directory)
		dict_name=dir_name+self.atom+'chemical_shift_'+self.pdb[:-4]+'_'+self.method+'.dat'
		#
		#if dictionary havent been made yet the calculation is run
		#
		if not os.path.isfile(dict_name):
			import pKa.pKD_tools
			#
			#initialize the dictionary which collects all data in one place 
			#
			dict_CS={}
			diel=self.diel_low
			while diel<=self.diel_high:
				dict_CS[diel]={}
				for residue in self.residues:
					dict_CS[diel][residue]={}
				for titgroup in self.titgroups:
					#SHOULD INCLUDE PARALLELISM HERE
					titgroup_type=pKa.pKD_tools.get_titgroup_type_from_titgroup(titgroup)
					charge=X.PI.titgroups[titgroup_type]['charge']
					if self.method=='Coulomb':
						for residue in self.residues:
							dCS=X.get_dCS(residue+':'+self.atom,titgroup, charge=charge, method=self.method, diel=float(diel))
							dict_CS[diel][residue][titgroup]=dCS
					else:
						residue=self.residues[1]
						dCS=X.get_dCS(residue+':'+self.atom,titgroup, charge=charge, method=self.method, diel=float(diel))
						for residue in self.residues:
							dict_CS[diel][residue][titgroup]=dCS[residue]
							
				diel+=self.diel_increment
			fd=open(dict_name,'w')
			cPickle.dump(dict_CS,fd)
			
		else:
			fd=open(dict_name,'r')
			print '\nLoading existing dictionary dict_CS:'
			print dict_name
			dict_CS=cPickle.load(fd)
			
		fd.close()
		self.dict_CS = dict_CS
		print "\nCalculating ghost titrations for dielectric constants in range (%4.2f,%4.2f) with step %4.2f\n" %(self.diel_low,self.diel_high,self.diel_increment)
Beispiel #5
0
def main(options, args):
    """Calculate the change in chemical shift due to a full charge on each titratable group"""
    import get_dEF
    method = options.method
    X = get_dEF.map_struct(args[0])
    X.build_Hs()
    residues = X.PI.residues.keys()
    residues.sort()
    #
    # Get the titratable groups
    #
    titgroups = X.PI.get_titratable_groups()
    titgroups.sort()
    import pKa.pKD_tools
    if options.group_by_titgroup:
        for titgroup in titgroups:
            titgroup_type = pKa.pKD_tools.get_titgroup_type_from_titgroup(
                titgroup)
            charge = X.PI.titgroups[titgroup_type]['charge']
            print 'TITRATABLE GROUP', titgroup
            print 'Residue  CS Nitrogen    CS Hydrogen'

            for residue in residues:
                dCS_N = X.get_dCS(residue + ':N',
                                  titgroup,
                                  charge=charge,
                                  method=method)
                dCS_H = X.get_dCS(residue + ':H',
                                  titgroup,
                                  charge=charge,
                                  method=method)
                print '%8s,    %s,    %s' % (residue, Nonefix(dCS_N),
                                             Nonefix(dCS_H))
    else:
        #
        # Group by atom
        #
        for residue in residues:
            for atom in [':N', ':H']:
                changes = []
                for titgroup in titgroups:
                    titgroup_type = pKa.pKD_tools.get_titgroup_type_from_titgroup(
                        titgroup)
                    charge = X.PI.titgroups[titgroup_type]['charge']
                    dCS = X.get_dCS(residue + atom,
                                    titgroup,
                                    charge=charge,
                                    method=method)
                    changes.append([titgroup, dCS])
                #
                if options.sort:

                    def cmpfunc(x, y):
                        if x[1] is None:
                            return 1
                        if y[1] is None:
                            return -1
                        return cmp(abs(y[1]), abs(x[1]))

                    changes.sort(cmpfunc)
                print 'Residue: %s, Atom: %s' % (residue, atom[1])
                for titgroup, dCS in changes[:options.listnumber]:
                    if dCS:
                        if abs(dCS) < options.limit:
                            continue
                        print titgroup, dCS
                print
    return
Beispiel #6
0
    def energy_analysis(self,exp_ghosts):
        """Calculate energies from ghost titrations"""
        #
        # First instantiate the class for converting between chemical shift and energies
        #
        import get_dEF
        EF=get_dEF.map_struct(self.options.pdbfile)
        #EF.build_Hs()
        #
        # Now load all ghosts and calculate energies
        #
        excludes=self.find_excludes()
        Edict={}
        for titgroup in sorted(exp_ghosts.keys()):
            Edict[titgroup]={}
            for residue in sorted(exp_ghosts[titgroup].keys()):
                if excludes.has_key(titgroup):
                    if residue in excludes[titgroup]:
                        continue
                vals=[]
                D=exp_ghosts[titgroup][residue]
                for nucleus in D.keys():
                    if nucleus=='HA':
                        continue
                    thisval=None
                    if D[nucleus]!='absent':
                        if D[nucleus][0]=='q':
                            thisval=D[nucleus][1:]
                        else:
                            thisval=D[nucleus]
                    else:
                        thisval=0.0
                    #
                    # Deal with range
                    #
                    exp_value,exp_error=self.interpret_ranges(thisval,nucleus)
                    #
                    # convert to kJ/mol
                    #
                    exp_value,angle_degrees=EF.get_energy(exp_value,'%s:%s' %(residue,nucleus),titgroup)
                    if abs(90.0-angle_degrees)>20.0 and abs(270-angle_degrees)>20.0:
                        vals.append([exp_value,exp_error,nucleus])
                Edict[titgroup][residue]=vals[:]
        #
        # Load PDB file 
        #
        import Protool
        PI=Protool.structureIO()
        PI.readpdb(self.options.pdbfile)
        #
        # Read ddGcat values
        #
        fd=open('ddGcat.csv')
        lines=fd.readlines()
        fd.close()
        cat=[]
        for line in lines[1:]:
            sp=line.split(',')
            resnum=int(sp[0])
            mutation=sp[1]
            try:
                ddG=float(sp[2])
            except:
                continue
            cat.append([resnum,mutation,ddG])
        #
        # First hypothesis - We can use the propagation of the electric field from E35 to say something about
        # the effect of the distant mutations - this is a longshot
        if self.options.longshot:
            #
            # Plot everything
            #
            tg=':0035:GLU'
            xs=[]
            ys=[]
            for residue in sorted(Edict[tg].keys()):
                if not PI.residues.has_key(residue):
                    continue
                dist=PI.dist(':0035:CG','%s:N' %residue)
                for exp_value,exp_error,atom in Edict[tg][residue]:
                    xs.append(dist)
                    val=float(exp_value)
                    ys.append(abs(val))
            import pylab
            pylab.plot(xs,ys,'ro',label='Ghosts')
            print 'Average Ghost energy: %5.2f kJ/mol' %(sum(ys)/len(ys))

            #
            # Plot it
            #
            xs=[]
            ys=[]
            for resnum,mutation,ddG in cat:
                import string
                residue=':%s' %(string.zfill(resnum,4))
                md=9999.9
                for atom in PI.residues[residue]:
                    md=min(md,PI.dist(':0035:CG',atom))
                xs.append(md)
                ys.append(abs(ddG))
            pylab.plot(xs,ys,'bo',label='ddGcat')
            print 'Average ddGcat: %5.1f kJ/mol' %(sum(ys)/len(ys))
            pylab.xlabel('Distance from E35CG')
            pylab.ylabel('Energy change (kJ/mol)')
            pylab.legend()
            pylab.title('Correlation between ghosts and change in activity')
            pylab.show()
        #
        # Now for the more reasonable stuff
        #
        if self.options.remotecharge:
            bigx=[]
            bigy=[]
            #
            # Load the complex
            # Find the atoms that are close enough to use for phi sampling
            #
            import Protool
            CPI=Protool.structureIO()
            CPI.readpdb('lysmgm2.pdb')
            TSatoms=[['J:0130:C1',+1.0],[':0035:OE2',-1.0]]
            TSdists={}
            for TSatom,charge in TSatoms:
                TSdists[TSatom]={}
                for residue in CPI.residues.keys():
                    if residue[0]=='J':
                        continue
                    dist=CPI.dist('%s:N' %residue,TSatom)
                    if dist<15.0:
                        TSdists[TSatom][residue]=[dist,charge]
            #
            # Calculate and plot
            #
            import pylab
            print 'Mutation,Ghost,ddGcat'
            muts=[]
            minx=0.0
            maxx=0.0
            count=0
            symbol='o'
            import pylab
            
            for TG in sorted(Edict.keys()):
                count=count+1
                if count>7:
                    symbol='+'
                xs=[]
                ys=[]
                for resnum,mutation,ddG in cat:
                    if int(resnum)==35:
                        continue
                    import string
                    residue=':%s' %(string.zfill(resnum,4))
                    thisTG='%s:%s' %(residue,PI.resname(residue))
                    if thisTG!=TG:
                        continue
                    if Edict.has_key(thisTG):
                        thismut=[]
                        #
                        # Calculate the total energy for this mutant
                        #
                        for TSatom in TSdists.keys():
                            thisTSatom=[]
                            
                            #
                            # Get the sum of distances so we can scale
                            #
                            sumdist=0.0
                            for res in TSdists[TSatom].keys():
                                distance=TSdists[TSatom][res][0]
                                sumdist=sumdist+distance
                            #
                            # Now calculate the field for each observed ghost
                            #
                            for actres in TSdists[TSatom].keys():
                                distance=TSdists[TSatom][actres][0]
                                charge=TSdists[TSatom][actres][1]
                                #print actres,distance,charge
                                if Edict[thisTG].has_key(actres):
                                    for exp_value,exp_error,atom in Edict[thisTG][actres]:
                                        charge=TSdists[TSatom][actres][1]
                                        distance=TSdists[TSatom][actres][0]
                                        thisTSatom.append(charge*distance/sumdist*exp_value)
                            #
                            # Calculate weighted average
                            #
                            exp_value=0.0
                            if len(thisTSatom)>0:
                                exp_value=sum(thisTSatom)
                            #print thisTSatom
                            thismut.append(exp_value)
                    #
                    # Add up the contributions of all the TSatoms
                    #
                    total=0.0
                    for val in thismut:
                        total=total+val
                    xs.append(total)
                    ys.append(ddG)
                    #print '%7s, %5.2f %5.2f' %(mutation,abs(exp_value),abs(ddG))
                                
                    

                minx=min([minx]+xs)
                maxx=max([maxx]+xs)
                if len(xs)>0:
                    bigx=bigx+xs
                    bigy=bigy+ys
                    pylab.plot(xs,ys,symbol,label=TG,linewidth=2,markersize=10,mew=2)
            pylab.xlabel('TS Electrostatic energy (kJ/mol)')
            pylab.ylabel(r'$\Delta\Delta{G}_{cat}$ (kJ/mol)')
            print 'maxx,minx',maxx,minx
            pylab.legend(title='Mutated group',loc=5)
            pylab.plot([minx,maxx],[minx,maxx],'g-',linewidth=2)
            pylab.plot([minx,maxx],[0,0],'b-',linewidth=2)
            pylab.title('Correlation between ghosts and change in activity')
            #
            # do linear least squares fit
            #
            x=numpy.array(bigx)
            A=numpy.vstack([x,numpy.ones(len(x))]).T
            y=numpy.array(bigy)
            solution=numpy.linalg.lstsq(A,y)
            m,c=solution[0]
            print solution[1]
            pylab.plot(x,m*x+c,'r-.',linewidth=1)
            
            #pylab.xlim([-1,4])
            #pylab.ylim([-2,4])
            pylab.savefig('ddGcat.png',dpi=300)
            pylab.show()   
        return