Beispiel #1
0
def do_dir(path,detailed=None):
    #
    # Load experimental pKa values
    #
    expdata='/u1/jnielsen/work/pka/exppka/lysozyme.PKA.DAT'
    experimental=pKa.pKaIO()
    experimental.readpka(expdata)
    A=pKa.pKanalyse()
    #
    # Find all directories with pKa calculations and loop over them
    #
    list=ostools.find('*.PKA.DAT',path)
    topdir=os.getcwd()
    print
    print '================================================'
    print 'Evaluating ',len(list),' calculations in: %s' %os.path.split(path)[1]
    #
    # Reset counters
    #
    correct=0
    wrong=0
    rmsds=[]
    E35sum=[]
    D52sum=[]
    for file in list:
        dir,pkafile=os.path.split(file)
        pos=string.find(dir,path)
        os.chdir(dir)
        if pos!=1:
            dir=dir[pos+len(path):]
        calculated=pKa.pKaIO()
        calculated.readpka(pkafile)
        rmsd=A.rmsd_between_sets(experimental.pka,calculated.pka)
        if detailed:
            print 'Dir: %6s rmsd: %5.2f ' %(dir,rmsd)
            #
            # Get stats on D52 and E35
            #
            residues=['0035GLU','0052ASP']
            print '          Residue  Exp. Calc. diff'
            for residue in residues:
                print ' %15s %5.2f %5.2f %5.2f' %(residue,experimental.pka[residue]['pKa'], calculated.pka[residue]['pKa'],experimental.pka[residue]['pKa']-calculated.pka[residue]['pKa'])
            if calculated.pka['0035GLU']['pKa']-calculated.pka['0052ASP']['pKa']>=1.5 and calculated.pka['0035GLU']['pKa']>5.0:
                print 'GLU35!'
            elif -calculated.pka['0035GLU']['pKa']+calculated.pka['0052ASP']['pKa']>=1.5 and calculated.pka['0052ASP']['pKa']>5.0:
                print 'ASP52!'
            else:
                print 'None'
            print
        #
        # Did we get the h-donor right?
        #
        if calculated.pka.has_key('0035GLU'):
            E35=calculated.pka['0035GLU']['pKa']
            E35sum.append(E35)
        if calculated.pka.has_key('0052ASP'):
            D52=calculated.pka['0052ASP']['pKa']
            D52sum.append(D52)
        if calculated.pka.has_key('0035GLU') and calculated.pka.has_key('0052ASP'):
            if E35>5.0 and E35-D52>=1.5:
                correct=correct+1
            if D52>5.0 and D52-E35>=1.5:
                wrong=wrong+1
        rmsds.append(rmsd)
    #
    # --------------------------------------------------------
    #
    # Print the summary
    #
    print 'Number of dirs',len(rmsds)
    if len(rmsds)>0:
        sum=0.0
        for rmsd in rmsds:
            sum=sum+rmsd
        Esum=0.0
        for p in E35sum:
            Esum=Esum+p
        Dsum=0.0
        for p in D52sum:
            Dsum=Dsum+p
        D52mean=Dsum/float(len(D52sum))
        E35mean=Esum/float(len(E35sum))
        avgdevE=0.0
        avgdevD=0.0
        for p in E35sum:
            avgdevE=avgdevE+abs(p-E35mean)
        for p in D52sum:
            avgdevD=avgdevD+abs(p-D52mean)
        avgdevE=avgdevE/float(len(E35sum))
        avgdevD=avgdevD/float(len(D52sum))
        print 'Average rmsd: %5.2f' %(sum/float(len(rmsds)))
        print 'Average pKa E35: %5.2f' %(Esum/float(len(E35sum)))
        print 'Average pKa D52: %5.2f' %(Dsum/float(len(D52sum)))
        print 'Avg. deviation from mean (E35): %7.3f' %avgdevE
        print 'Avg. deviation from mean (D52): %7.3f' %avgdevD
        print 'Correct:',correct
        print 'Wrong:',wrong

        #
        # Average the titration curves
        #
        list=ostools.find('*.TITCURV.DAT',path)
        avg_charge_pKa(list)
        os.chdir(topdir)
    return
Beispiel #2
0
def avg_charge_pKa(files):
    #
    # Calculate the average titration curve and the average pKa for the dirs
    #
    import sys, os, string
    #dirs=sys.argv[1:]
    top=os.getcwd()
    pkadict={}
    titdict={}
    ok=0
    wrong=0
    for file in files:
        if os.path.isfile(file):
            #print 'Processing file:',file
            import pKa
            if os.path.isfile(file):
                X=pKa.pKaIO()
                tit=X.readtitcurv(file)
                titdict[file]={}
                if tit.has_key('0035GLU') and tit.has_key('0052ASP'):
                    titdict[file]={'35':tit['0035GLU'],'52':tit['0052ASP']}
                    
            else:
                print 'pKa calculations not finished for: %s' %dir
    #
    # Calculate averages
    #
    sumtit={}
    #
    # Zero dictionaries
    #
    for outkey in titdict.keys():
        for key in titdict[outkey].keys():
            sumtit[key]={}
    #
    # Sum all
    #
    pkacount=0
    for dir in titdict.keys():
        for key in titdict[dir].keys():
            for ph in titdict[dir][key].keys():
                if sumtit[key].has_key(ph):
                    sumtit[key][ph]=sumtit[key][ph]+titdict[dir][key][ph]
                else:
                    sumtit[key][ph]=titdict[dir][key][ph]
    #
    # Get average 
    #
    for key in sumtit.keys():
        for ph in sumtit[key].keys():
            sumtit[key][ph]=float(sumtit[key][ph])/float(len(titdict.keys()))
    #
    # Print the results
    #
    residues=sumtit.keys()
    residues.sort()
    pka=0.0
    print 'pKa value from average titration curve'
    for key in residues:
        phvals=sumtit[key].keys()
        phvals.sort()
        for ph in phvals:
            if sumtit[key][ph]<=-0.5:
                pka=ph
                break
        print "Residue: %s, pKa value: %5.2f" %(key,pka)
    return
Beispiel #3
0
def main():
    #
    # Get the PDB file
    #
    import sys,os
    pdbfile=sys.argv[1]
    suffix=sys.argv[2]
    if os.environ['USER']=='nielsen':
        filename=os.path.join('/enzyme/nielsen/work/pKa_design/accuracy','accuracy_'+os.path.split(pdbfile)[1])
    elif os.environ['USER']=='btconnolly':
        filename=os.path.join('/enzyme/btconnolly/pKa_design',suffix+'accuracy_'+os.path.split(pdbfile)[1])
    #filename=os.path.join(os.getcwd(),'accuracy_'+os.path.split(pdbfile)[1])
    print 'Setting dictionary filename to',filename
    #
    # Make sure that we delete all info from previous runs
    #
    wtpKafile=pdbfile+'_wt_pKavals'
    if os.path.isfile(wtpKafile):
        os.unlink(wtpKafile)
    #
    # Do we have a completed pKa calc for it?
    #
    import pKa
    X=pKa.pKaIO(pdbfile)
    X.usenewnames()
    if not X.assess_status():
        import os
        print 'You have to run a pKa calculation first'
        raise Exception()
    #
    # OK, got the pKa calc. Read results
    #
    wt_pKas=X.readpka()
    groups=wt_pKas.keys()
    groups.sort()
    #
    # Design target: for all groups with pKa value between 2 and 10: +2 and -2
    #
    DB=dictIO(filename)
    import os
    if os.path.isfile(filename):
        #
        # Load old file
        #
        accuracy=DB.load()
    else:
        #
        # No, no old restuls
        #
        accuracy={}
        #
        # Add the PDB file
        #
        fd=open(pdbfile)
        lines=fd.readlines()
        fd.close()
        accuracy['pdbfile']=lines
        #
        # Add the full wt pKa values
        #
        accuracy['wt_full']=wt_pKas
        DB.save(accuracy)
    # ---------------------------------------
    #
    # Delete old files
    #
    import Design_pKa
    Design_pKa.delete_old_files(pdbfile,'N','N')
    #
    # Start looping
    #
    groups.sort()
    for group in groups:
        #if not group==':0129:LEU:CTERM':
        #    continue
        if not accuracy.has_key(group):
            accuracy[group]={}
        #
        # Is somebody working on this group?
        #
        accuracy=DB.update(accuracy)
        if accuracy[group].has_key('locked'):
            if accuracy[group]['locked']==1:
                continue
        #
        # Lock group
        #
        accuracy[group]['locked']=1
        #
        # Save the dictionary
        #
        accuracy=DB.update(accuracy)
        #
        # OK, now we can calculate in peace
        #
        pKaval=wt_pKas[group]['pKa']
        if pKaval>2.0 and pKaval<10.0:
            #
            # First design pKa +2.0
            #
            design='+2.0'
            if not accuracy[group].has_key(design):
                accuracy[group][design]={}
            print 'Designing and evalulating: %s' %(group+design)
            dpKas=get_solutions(pdbfile,group,design,accuracy[group][design])
            accuracy[group][design]=dpKas.copy()
            #
            # Then do pKa -2.0
            #
            design='m2.0'
            if not accuracy[group].has_key(design):
                accuracy[group][design]={}
            print 'Designing and evalulating: %s' %(group+design)
            dpKas=get_solutions(pdbfile,group,design,accuracy[group][design])
            accuracy[group][design]=dpKas.copy()
        else:
            accuracy[group]['pKa out of range']=1
        #
        # Unlock group and merge results
        #
        accuracy[group]['locked']=None
        accuracy=DB.update(accuracy)
    #
    # All done
    #
    return
Beispiel #4
0
def main():
    #
    # Get the PDB file
    #
    import sys, os
    pdbfile = sys.argv[1]
    suffix = sys.argv[2]
    if os.environ['USER'] == 'nielsen':
        filename = os.path.join('/enzyme/nielsen/work/pKa_design/accuracy',
                                'accuracy_' + os.path.split(pdbfile)[1])
    elif os.environ['USER'] == 'btconnolly':
        filename = os.path.join(
            '/enzyme/btconnolly/pKa_design',
            suffix + 'accuracy_' + os.path.split(pdbfile)[1])
    #filename=os.path.join(os.getcwd(),'accuracy_'+os.path.split(pdbfile)[1])
    print 'Setting dictionary filename to', filename
    #
    # Make sure that we delete all info from previous runs
    #
    wtpKafile = pdbfile + '_wt_pKavals'
    if os.path.isfile(wtpKafile):
        os.unlink(wtpKafile)
    #
    # Do we have a completed pKa calc for it?
    #
    import pKa
    X = pKa.pKaIO(pdbfile)
    X.usenewnames()
    if not X.assess_status():
        import os
        print 'You have to run a pKa calculation first'
        raise Exception()
    #
    # OK, got the pKa calc. Read results
    #
    wt_pKas = X.readpka()
    groups = wt_pKas.keys()
    groups.sort()
    #
    # Design target: for all groups with pKa value between 2 and 10: +2 and -2
    #
    DB = dictIO(filename)
    import os
    if os.path.isfile(filename):
        #
        # Load old file
        #
        accuracy = DB.load()
    else:
        #
        # No, no old restuls
        #
        accuracy = {}
        #
        # Add the PDB file
        #
        fd = open(pdbfile)
        lines = fd.readlines()
        fd.close()
        accuracy['pdbfile'] = lines
        #
        # Add the full wt pKa values
        #
        accuracy['wt_full'] = wt_pKas
        DB.save(accuracy)
    # ---------------------------------------
    #
    # Delete old files
    #
    import Design_pKa
    Design_pKa.delete_old_files(pdbfile, 'N', 'N')
    #
    # Start looping
    #
    groups.sort()
    for group in groups:
        #if not group==':0129:LEU:CTERM':
        #    continue
        if not accuracy.has_key(group):
            accuracy[group] = {}
        #
        # Is somebody working on this group?
        #
        accuracy = DB.update(accuracy)
        if accuracy[group].has_key('locked'):
            if accuracy[group]['locked'] == 1:
                continue
        #
        # Lock group
        #
        accuracy[group]['locked'] = 1
        #
        # Save the dictionary
        #
        accuracy = DB.update(accuracy)
        #
        # OK, now we can calculate in peace
        #
        pKaval = wt_pKas[group]['pKa']
        if pKaval > 2.0 and pKaval < 10.0:
            #
            # First design pKa +2.0
            #
            design = '+2.0'
            if not accuracy[group].has_key(design):
                accuracy[group][design] = {}
            print 'Designing and evalulating: %s' % (group + design)
            dpKas = get_solutions(pdbfile, group, design,
                                  accuracy[group][design])
            accuracy[group][design] = dpKas.copy()
            #
            # Then do pKa -2.0
            #
            design = 'm2.0'
            if not accuracy[group].has_key(design):
                accuracy[group][design] = {}
            print 'Designing and evalulating: %s' % (group + design)
            dpKas = get_solutions(pdbfile, group, design,
                                  accuracy[group][design])
            accuracy[group][design] = dpKas.copy()
        else:
            accuracy[group]['pKa out of range'] = 1
        #
        # Unlock group and merge results
        #
        accuracy[group]['locked'] = None
        accuracy = DB.update(accuracy)
    #
    # All done
    #
    return
Beispiel #5
0
def avg_charge_pKa(files):
    #
    # Calculate the average titration curve and the average pKa for the dirs
    #
    import sys, os, string
    #dirs=sys.argv[1:]
    top = os.getcwd()
    pkadict = {}
    titdict = {}
    ok = 0
    wrong = 0
    for file in files:
        if os.path.isfile(file):
            #print 'Processing file:',file
            import pKa
            if os.path.isfile(file):
                X = pKa.pKaIO()
                tit = X.readtitcurv(file)
                titdict[file] = {}
                if tit.has_key('0035GLU') and tit.has_key('0052ASP'):
                    titdict[file] = {
                        '35': tit['0035GLU'],
                        '52': tit['0052ASP']
                    }

            else:
                print 'pKa calculations not finished for: %s' % dir
    #
    # Calculate averages
    #
    sumtit = {}
    #
    # Zero dictionaries
    #
    for outkey in titdict.keys():
        for key in titdict[outkey].keys():
            sumtit[key] = {}
    #
    # Sum all
    #
    pkacount = 0
    for dir in titdict.keys():
        for key in titdict[dir].keys():
            for ph in titdict[dir][key].keys():
                if sumtit[key].has_key(ph):
                    sumtit[key][ph] = sumtit[key][ph] + titdict[dir][key][ph]
                else:
                    sumtit[key][ph] = titdict[dir][key][ph]
    #
    # Get average
    #
    for key in sumtit.keys():
        for ph in sumtit[key].keys():
            sumtit[key][ph] = float(sumtit[key][ph]) / float(
                len(titdict.keys()))
    #
    # Print the results
    #
    residues = sumtit.keys()
    residues.sort()
    pka = 0.0
    print 'pKa value from average titration curve'
    for key in residues:
        phvals = sumtit[key].keys()
        phvals.sort()
        for ph in phvals:
            if sumtit[key][ph] <= -0.5:
                pka = ph
                break
        print "Residue: %s, pKa value: %5.2f" % (key, pka)
    return
Beispiel #6
0
def do_dir(path, detailed=None):
    #
    # Load experimental pKa values
    #
    expdata = '/u1/jnielsen/work/pka/exppka/lysozyme.PKA.DAT'
    experimental = pKa.pKaIO()
    experimental.readpka(expdata)
    A = pKa.pKanalyse()
    #
    # Find all directories with pKa calculations and loop over them
    #
    list = ostools.find('*.PKA.DAT', path)
    topdir = os.getcwd()
    print
    print '================================================'
    print 'Evaluating ', len(
        list), ' calculations in: %s' % os.path.split(path)[1]
    #
    # Reset counters
    #
    correct = 0
    wrong = 0
    rmsds = []
    E35sum = []
    D52sum = []
    for file in list:
        dir, pkafile = os.path.split(file)
        pos = string.find(dir, path)
        os.chdir(dir)
        if pos != 1:
            dir = dir[pos + len(path):]
        calculated = pKa.pKaIO()
        calculated.readpka(pkafile)
        rmsd = A.rmsd_between_sets(experimental.pka, calculated.pka)
        if detailed:
            print 'Dir: %6s rmsd: %5.2f ' % (dir, rmsd)
            #
            # Get stats on D52 and E35
            #
            residues = ['0035GLU', '0052ASP']
            print '          Residue  Exp. Calc. diff'
            for residue in residues:
                print ' %15s %5.2f %5.2f %5.2f' % (
                    residue, experimental.pka[residue]['pKa'],
                    calculated.pka[residue]['pKa'],
                    experimental.pka[residue]['pKa'] -
                    calculated.pka[residue]['pKa'])
            if calculated.pka['0035GLU']['pKa'] - calculated.pka['0052ASP'][
                    'pKa'] >= 1.5 and calculated.pka['0035GLU']['pKa'] > 5.0:
                print 'GLU35!'
            elif -calculated.pka['0035GLU']['pKa'] + calculated.pka['0052ASP'][
                    'pKa'] >= 1.5 and calculated.pka['0052ASP']['pKa'] > 5.0:
                print 'ASP52!'
            else:
                print 'None'
            print
        #
        # Did we get the h-donor right?
        #
        if calculated.pka.has_key('0035GLU'):
            E35 = calculated.pka['0035GLU']['pKa']
            E35sum.append(E35)
        if calculated.pka.has_key('0052ASP'):
            D52 = calculated.pka['0052ASP']['pKa']
            D52sum.append(D52)
        if calculated.pka.has_key('0035GLU') and calculated.pka.has_key(
                '0052ASP'):
            if E35 > 5.0 and E35 - D52 >= 1.5:
                correct = correct + 1
            if D52 > 5.0 and D52 - E35 >= 1.5:
                wrong = wrong + 1
        rmsds.append(rmsd)
    #
    # --------------------------------------------------------
    #
    # Print the summary
    #
    print 'Number of dirs', len(rmsds)
    if len(rmsds) > 0:
        sum = 0.0
        for rmsd in rmsds:
            sum = sum + rmsd
        Esum = 0.0
        for p in E35sum:
            Esum = Esum + p
        Dsum = 0.0
        for p in D52sum:
            Dsum = Dsum + p
        D52mean = Dsum / float(len(D52sum))
        E35mean = Esum / float(len(E35sum))
        avgdevE = 0.0
        avgdevD = 0.0
        for p in E35sum:
            avgdevE = avgdevE + abs(p - E35mean)
        for p in D52sum:
            avgdevD = avgdevD + abs(p - D52mean)
        avgdevE = avgdevE / float(len(E35sum))
        avgdevD = avgdevD / float(len(D52sum))
        print 'Average rmsd: %5.2f' % (sum / float(len(rmsds)))
        print 'Average pKa E35: %5.2f' % (Esum / float(len(E35sum)))
        print 'Average pKa D52: %5.2f' % (Dsum / float(len(D52sum)))
        print 'Avg. deviation from mean (E35): %7.3f' % avgdevE
        print 'Avg. deviation from mean (D52): %7.3f' % avgdevD
        print 'Correct:', correct
        print 'Wrong:', wrong

        #
        # Average the titration curves
        #
        list = ostools.find('*.TITCURV.DAT', path)
        avg_charge_pKa(list)
        os.chdir(topdir)
    return