pKa/pKa_mutscan.py
def main(options,args):
    """Load the PDB file and the list of mutations"""
    import sys
    pdbfile=args[0]
    target_residues=options.target_groups
    #
    # Load the PDB file
    #
    import Protool
    P=Protool.structureIO()
    P.readpdb(pdbfile)
    residues=P.residues.keys()
    residues.sort()
    if not options.allmutations:
        #
        # Load the mutations
        #
        mutfile=args[1]
        fd=open(mutfile)
        mutlines=fd.readlines()
        fd.close()
    else:
       mutlines=[]
       aas=P.trueaminoacids.keys()
       aas.sort()
       count=1
       for residue in residues:
           for aa in aas:
               if aa==P.resname(residue):
                   continue
               mutlines.append('clone%d,%s:%s:%s' %(count,residue,P.resname(residue),aa))
               count=count+1
       print 'Created %d mutant proteins each containing 1 mutation' %len(mutlines)
    #
    # Make the resultdir
    #
    import os
    resultdir=os.path.join(os.getcwd(),'pKa_mutscan_results')
    if not os.path.isdir(resultdir):
        os.mkdir(resultdir)
    #
    # which target residues
    #
    if target_residues==[] or target_residues==['ALL']:
        target_residues=P.get_titratable_groups()
        import string
        target_residues=string.join(target_residues,',')
    results={}
    import pickle, os
    for mline in mutlines:
        import string
        if mline[0]=='#' or mline[:2]=='//':
            continue
        #
        line=string.strip(mline)
        sp_line=line.split(',')
        variant_name=sp_line[0]
        mutation=sp_line[1]
        print 'Variant: %s, mutations: %s' %(variant_name,mutation)
        if mutation.find('insert')!=-1:
            print 'Skipping insertions'
            continue
        #
        # Define result filename
        #
        resultfile=os.path.join(resultdir,'mutscan_%s.result' %variant_name)
        if os.path.isfile(resultfile):
            fd=open(resultfile)
            results[variant_name]=pickle.load(fd)
            fd.close()
            #print 'Already did',mutation
        else:
            recalc_intpka=1
            defaults=local_defaults(pdbfile,target_residues,recalc_intpka)
            #
            # Set the mutations
            #
            import string
            defaults['mutations'][0]=string.strip(mutation)
            print 'Calculating for',mutation
            import pKa.Design_pKa as Design_pKa
            #
            # Set other parameters
            #
            defaults['ion'][0]=options.ion
            #
            # Calculate the dpKas
            #
            #try:
            solutions=Design_pKa.run_opt(defaults)
            #except Exception,inst:
            #    if str(inst).find('Cannot model mutant')!=-1:
            #        solutions='Cannot model mutant'
            #        raise Exception('Cannot model mutant')
            #    elif str(inst).find('We cannot model insertions')!=-1:
            #        solutions='Skipping insertions'
            #    else:
            #        print inst
            #        raise Exception(str(inst))
            print
            print
            print 'Results are ',solutions
            results[variant_name]=solutions
            #
            # Save this result
            #
            print 'Saving',results[variant_name],'in',resultfile
            import os
            if len(os.path.split(resultfile)[1])>80:
                continue
            
            fd=open(resultfile,'w')
            pickle.dump(results[variant_name],fd)
            print '*********************'
            fd.close()
    #
    # Save all
    #
    name=os.path.join(os.getcwd(),'%s.mutscan.pickle' %pdbfile)
    fd=open(name,'w')
    import pickle
    pickle.dump(results,fd)
    fd.close()
Load the PDB file and the list of mutations
Load the PDB file and the list of mutations
Load the PDB file and the list of mutations
def main(options,args):
    import sys
    pdbfile=args[0]
    target_residues=options.target_groups
     Load the PDB file
    import Protool
    P=Protool.structureIO()
    P.readpdb(pdbfile)
    residues=P.residues.keys()
    residues.sort()
    if not options.allmutations:
         Load the mutations
        mutfile=args[1]
        fd=open(mutfile)
        mutlines=fd.readlines()
        fd.close()
    else:
       mutlines=[]
       aas=P.trueaminoacids.keys()
       aas.sort()
       count=1
       for residue in residues:
           for aa in aas:
               if aa==P.resname(residue):
                   continue
               mutlines.append('clone%d,%s:%s:%s' %(count,residue,P.resname(residue),aa))
               count=count+1
       print 'Created %d mutant proteins each containing 1 mutation' %len(mutlines)
     Make the resultdir
    import os
    resultdir=os.path.join(os.getcwd(),'pKa_mutscan_results')
    if not os.path.isdir(resultdir):
        os.mkdir(resultdir)
     which target residues
    if target_residues==[] or target_residues==['ALL']:
        target_residues=P.get_titratable_groups()
        import string
        target_residues=string.join(target_residues,',')
    results={}
    import pickle, os
    for mline in mutlines:
        import string
        if mline[0]=='' or mline[:2]=='//':
            continue
        line=string.strip(mline)
        sp_line=line.split(',')
        variant_name=sp_line[0]
        mutation=sp_line[1]
        print 'Variant: %s, mutations: %s' %(variant_name,mutation)
        if mutation.find('insert')!=-1:
            print 'Skipping insertions'
            continue
         Define result filename
        resultfile=os.path.join(resultdir,'mutscan_%s.result' %variant_name)
        if os.path.isfile(resultfile):
            fd=open(resultfile)
            results[variant_name]=pickle.load(fd)
            fd.close()
            print 'Already did',mutation
        else:
            recalc_intpka=1
            defaults=local_defaults(pdbfile,target_residues,recalc_intpka)
             Set the mutations
            import string
            defaults['mutations'][0]=string.strip(mutation)
            print 'Calculating for',mutation
            import pKa.Design_pKa as Design_pKa
             Set other parameters
            defaults['ion'][0]=options.ion
             Calculate the dpKas
            try:
            solutions=Design_pKa.run_opt(defaults)
            except Exception,inst:
                if str(inst).find('Cannot model mutant')!=-1:
                    solutions='Cannot model mutant'
                    raise Exception('Cannot model mutant')
                elif str(inst).find('We cannot model insertions')!=-1:
                    solutions='Skipping insertions'
                else:
                    print inst
                    raise Exception(str(inst))
            print
            print
            print 'Results are ',solutions
            results[variant_name]=solutions
             Save this result
            print 'Saving',results[variant_name],'in',resultfile
            import os
            if len(os.path.split(resultfile)[1])>80:
                continue
            fd=open(resultfile,'w')
            pickle.dump(results[variant_name],fd)
            print '*********************'
            fd.close()
     Save all
    name=os.path.join(os.getcwd(),'%s.mutscan.pickle' %pdbfile)
    fd=open(name,'w')
    import pickle
    pickle.dump(results,fd)
    fd.close()
def main ( options , args ) : import sys pdbfile = args [ 0 ] target_residues = options . target_groups import Protool P = Protool . structureIO ( ) P . readpdb ( pdbfile ) residues = P . residues . keys ( ) residues . sort ( ) if not options . allmutations : mutfile = args [ 1 ] fd = open ( mutfile ) mutlines = fd . readlines ( ) fd . close ( ) else : mutlines = [ ] aas = P . trueaminoacids . keys ( ) aas . sort ( ) count = 1 for residue in residues : for aa in aas : if aa == P . resname ( residue ) : continue mutlines . append ( 'clone%d,%s:%s:%s' % ( count , residue , P . resname ( residue ) , aa ) ) count = count + 1 print 'Created %d mutant proteins each containing 1 mutation' % len ( mutlines ) import os resultdir = os . path . join ( os . getcwd ( ) , 'pKa_mutscan_results' ) if not os . path . isdir ( resultdir ) : os . mkdir ( resultdir ) if target_residues == [ ] or target_residues == [ 'ALL' ] : target_residues = P . get_titratable_groups ( ) import string target_residues = string . join ( target_residues , ',' ) results = { } import pickle , os for mline in mutlines : import string if mline [ 0 ] == '#' or mline [ : 2 ] == '//' : continue line = string . strip ( mline ) sp_line = line . split ( ',' ) variant_name = sp_line [ 0 ] mutation = sp_line [ 1 ] print 'Variant: %s, mutations: %s' % ( variant_name , mutation ) if mutation . find ( 'insert' ) != - 1 : print 'Skipping insertions' continue resultfile = os . path . join ( resultdir , 'mutscan_%s.result' % variant_name ) if os . path . isfile ( resultfile ) : fd = open ( resultfile ) results [ variant_name ] = pickle . load ( fd ) fd . close ( ) else : recalc_intpka = 1 defaults = local_defaults ( pdbfile , target_residues , recalc_intpka ) import string defaults [ 'mutations' ] [ 0 ] = string . strip ( mutation ) print 'Calculating for' , mutation import pKa . Design_pKa as Design_pKa defaults [ 'ion' ] [ 0 ] = options . ion solutions = Design_pKa . run_opt ( defaults ) print print print 'Results are ' , solutions results [ variant_name ] = solutions print 'Saving' , results [ variant_name ] , 'in' , resultfile import os if len ( os . path . split ( resultfile ) [ 1 ] ) > 80 : continue fd = open ( resultfile , 'w' ) pickle . dump ( results [ variant_name ] , fd ) print '*********************' fd . close ( ) name = os . path . join ( os . getcwd ( ) , '%s.mutscan.pickle' % pdbfile ) fd = open ( name , 'w' ) import pickle pickle . dump ( results , fd ) fd . close ( )
Load the PDB file and the list of mutations
Load the PDB file and the list of mutations
"""Load the PDB file and the list of mutations""" # # Load the PDB file # # # Load the mutations # # # Make the resultdir # # # which target residues # # # # Define result filename # #print 'Already did',mutation # # Set the mutations # # # Set other parameters # # # Calculate the dpKas # #try: #except Exception,inst: #    if str(inst).find('Cannot model mutant')!=-1: #        solutions='Cannot model mutant' #        raise Exception('Cannot model mutant') #    elif str(inst).find('We cannot model insertions')!=-1: #        solutions='Skipping insertions' #    else: #        print inst #        raise Exception(str(inst)) # # Save this result # # # Save all #
options
args