Пример #1
0
def get_solutions(pdbfile,target_residue,target_dpKa,dpKas):
    #
    # Main routine.
    # Get the solutions with MC_tab and then rescore them with a subset of
    # the different methods
    #
    # Get solutions
    #
    import Design_pKa
    defaults=Design_pKa.get_defaults()
    defaults=get_this_defaults(pdbfile,target_residue,target_dpKa)
    # Method
    defaults['MC'][0]=1
    defaults['tabulated'][0]=1
    #
    # Check if we already did this..
    #
    missing=None
    for x in range(1,11):
        if not dpKas.has_key(x):
            missing=1
            print 'Design solutions not calculated'
            break
    #
    # Do it?
    #
    if missing:
        solutions=Design_pKa.run_opt(defaults)
        solution_keys=solutions.keys()
    else:
        solution_keys=dpKas.keys()
    solution_keys.sort()
    #
    # Calculate pKa values using the other methods
    #
    # Define all the other methods that we will use
    #
    # First element is method, second is value of 'tabulated'
    #
    methods=[['TR',None],[None,None],['MC',None],['TR',1],['MC',1]]
    for solution in solution_keys[:10]:
        #
        # Make sure the dictionary is ready
        #
        if not dpKas.has_key(solution):
            dpKas[solution]={}
            dpKas[solution]['mutations']=solutions[solution]['mutations']
            realmut=None
            for mutation in solutions[solution]['mutations']:
                if mutation:
                    realmut=1
            if not realmut:
                continue
        #
        # Now calc dpKas with different methods
        #
        for method,tabulated in methods:
            #
            # Print info
            #
            print
            print 'Calculating dpKa for %s with %s. Tabulated: %s' %(str(dpKas[solution]['mutations']),method,tabulated)
            #
            # Get defaults
            #
            defaults=get_this_defaults(pdbfile,target_residue,target_dpKa)
            if method:
                # Choose method
                defaults[method][0]=1
            #
            # Set tabulated
            #
            defaults['tabulated'][0]=tabulated
            #
            # Set the general parameters
            #
            mutations=dpKas[solution]['mutations']
            import string
            #
            # Remove all None elements from mutations
            #
            filtered_muts=[]
            for mut in mutations:
                if mut:
                    filtered_muts.append(mut)
            #
            # Set the mutations variable in defaults
            #
            defaults['mutations'][0]=string.join(filtered_muts,',')
            # Calculate delta pkas
            defaults['calc_dpka'][0]=1
            #
            # Set a more meaningful method name
            #
            method_name=method
            if not method:
                method_name='phi/ln10'
            #
            # Is this tabulated mode?
            #
            if tabulated:
                method_name=method_name+'_tab'
            #
            # Get the dpKa(s)
            #
            if not dpKas[solution].has_key(method_name):
                tmp=Design_pKa.run_opt(defaults)
                #
                # We should have only one key
                #
                keys=tmp.keys()
                if len(keys)!=1:
                    print keys
                    raise 'Too many keys when calculating dpkas for one solution'
                dpKas[solution][method_name]=tmp[keys[0]]
            
    #
    # Done
    #
    return dpKas
Пример #2
0
def get_solutions(pdbfile, target_residue, target_dpKa, dpKas):
    #
    # Main routine.
    # Get the solutions with MC_tab and then rescore them with a subset of
    # the different methods
    #
    # Get solutions
    #
    import Design_pKa
    defaults = Design_pKa.get_defaults()
    defaults = get_this_defaults(pdbfile, target_residue, target_dpKa)
    # Method
    defaults['MC'][0] = 1
    defaults['tabulated'][0] = 1
    #
    # Check if we already did this..
    #
    missing = None
    for x in range(1, 11):
        if not dpKas.has_key(x):
            missing = 1
            print 'Design solutions not calculated'
            break
    #
    # Do it?
    #
    if missing:
        solutions = Design_pKa.run_opt(defaults)
        solution_keys = solutions.keys()
    else:
        solution_keys = dpKas.keys()
    solution_keys.sort()
    #
    # Calculate pKa values using the other methods
    #
    # Define all the other methods that we will use
    #
    # First element is method, second is value of 'tabulated'
    #
    methods = [['TR', None], [None, None], ['MC', None], ['TR', 1], ['MC', 1]]
    for solution in solution_keys[:10]:
        #
        # Make sure the dictionary is ready
        #
        if not dpKas.has_key(solution):
            dpKas[solution] = {}
            dpKas[solution]['mutations'] = solutions[solution]['mutations']
            realmut = None
            for mutation in solutions[solution]['mutations']:
                if mutation:
                    realmut = 1
            if not realmut:
                continue
        #
        # Now calc dpKas with different methods
        #
        for method, tabulated in methods:
            #
            # Print info
            #
            print
            print 'Calculating dpKa for %s with %s. Tabulated: %s' % (str(
                dpKas[solution]['mutations']), method, tabulated)
            #
            # Get defaults
            #
            defaults = get_this_defaults(pdbfile, target_residue, target_dpKa)
            if method:
                # Choose method
                defaults[method][0] = 1
            #
            # Set tabulated
            #
            defaults['tabulated'][0] = tabulated
            #
            # Set the general parameters
            #
            mutations = dpKas[solution]['mutations']
            import string
            #
            # Remove all None elements from mutations
            #
            filtered_muts = []
            for mut in mutations:
                if mut:
                    filtered_muts.append(mut)
            #
            # Set the mutations variable in defaults
            #
            defaults['mutations'][0] = string.join(filtered_muts, ',')
            # Calculate delta pkas
            defaults['calc_dpka'][0] = 1
            #
            # Set a more meaningful method name
            #
            method_name = method
            if not method:
                method_name = 'phi/ln10'
            #
            # Is this tabulated mode?
            #
            if tabulated:
                method_name = method_name + '_tab'
            #
            # Get the dpKa(s)
            #
            if not dpKas[solution].has_key(method_name):
                tmp = Design_pKa.run_opt(defaults)
                #
                # We should have only one key
                #
                keys = tmp.keys()
                if len(keys) != 1:
                    print keys
                    raise 'Too many keys when calculating dpkas for one solution'
                dpKas[solution][method_name] = tmp[keys[0]]

    #
    # Done
    #
    return dpKas
Пример #3
0
def get_solutions_dist_nummuts(pdbfile=None,
                               target_residue=None,
                               target_dpKa=2.0,
                               num_muts=6,
                               min_target_dist=5.0,
                               dpKas={},
                               method='MC',
                               pKMCsteps=0,
                               X=None):
    #
    # Check if we already did this..
    #
    #
    # Do we have solutions for this problem?
    #
    added_data = None
    missing = None
    if dpKas == {}:
        missing = 1
    #
    # Do it?
    #
    if missing:
        defaults = local_defaults(pdbfile, target_residue, target_dpKa,
                                  float(min_target_dist), pKMCsteps)
        defaults['max_mutations'][0] = int(num_muts)
        print 'Target: %s, dpKa: %s, Number of mutations: %3d, min_dist: %5.3f' % (
            target_residue, target_dpKa, defaults['max_mutations'][0],
            defaults['min_target_dist'][0])
        #
        # Set the method default
        #
        allmethods = ['TR', 'MC']
        for m in allmethods:
            defaults[m][0] = None
        if not method == 'phidiff':
            defaults[method][0] = 1
        #
        # Set the parameters
        #
        if not X:
            params = {}
            for key in defaults.keys():
                params[key] = defaults[key][0]
            X = Design_pKa.Design_pKa(params)
        #
        # Get the solutions and the corresponding dpKas
        #
        solutions, dpKa_dict = Design_pKa.run_opt(defaults, X)
        solution_keys = solutions.keys()
        #

        #
        # If there are no solutions then store that info
        #
        if len(solution_keys) == 0:
            added_data = 1
            dpKas[1] = {'no solutions': 1}
        #
        # Loop over all the solutions and get the dpKas
        #
        for solution in solution_keys:
            #
            # Make sure the dictionary is ready
            #
            if not dpKas.has_key(solution):
                added_data = 1
                dpKas[solution] = {}
            #
            # Check that we have a real mutation (i.e. a non- None) mutation
            #
            dpKas[solution]['mutations'] = solutions[solution]['mutations']
            realmut = None
            for mutation in solutions[solution]['mutations']:
                if mutation:
                    realmut = 1
            if not realmut:
                continue
            #
            # Get the delta pKa value
            #
            key = str(dpKas[solution]['mutations'])
            if dpKa_dict.has_key(key):
                dpKas[solution][method] = dpKa_dict[key]
    #
    # Did we calculate dpKa values?
    #
    for solution in dpKas.keys():
        if not dpKas[solution].has_key('mutations'):
            #
            # If it's not a real solution then don't check it
            #
            continue
        #
        # Now calculate the dpKas with the method we want, it it's needed
        #
        if method == 'phidiff':
            methods = [[None, None]]
        else:
            methods = [[method, None]]
        #
        # Set the method name
        #
        for method, tabulated in methods:
            method_name = method
            if not method:
                method_name = 'phidiff'
            #
            # Is this tabulated mode?
            #
            if tabulated:
                method_name = method_name + '_tab'
            #
            # Did we calculate this dpKa?
            #

            if not dpKas[solution].has_key(
                    method_name) and not dpKas[solution].has_key(method_name +
                                                                 '_tab'):
                #
                # Get defaults
                #
                import Design_accuracy
                defaults = Design_accuracy.get_this_defaults(
                    pdbfile, target_residue, target_dpKa)
                if method:
                    # Choose method
                    defaults[method][0] = 1
                #
                # Set tabulated
                #
                defaults['tabulated'][0] = tabulated
                #
                # Set the general parameters
                #
                mutations = dpKas[solution]['mutations']
                import string
                #
                # Remove all None elements from mutations
                #
                realmut = None
                filtered_muts = []
                for mut in mutations:
                    if mut:
                        filtered_muts.append(mut)
                        realmut = 1
                if not realmut:
                    continue
                #
                # Set the mutations variable in defaults
                #
                defaults['mutations'][0] = string.join(filtered_muts, ',')
                # Calculate delta pkas
                defaults['calc_dpka'][0] = 1
                #
                # Get the dpKa(s)
                #
                print 'Still calculating here'
                tmp = Design_pKa.run_opt(defaults, X)
                #
                # We should have only one key
                #
                keys = tmp.keys()
                if len(keys) != 1:
                    print keys
                    raise 'Too many keys when calculating dpkas for one solution'
                added_data = 1
                dpKas[solution][method_name] = tmp[keys[0]]
    #
    # Done
    #
    return dpKas, added_data, X
Пример #4
0
def get_solutions_dist_nummuts(pdbfile=None,
                               target_residue=None,
                               target_dpKa=2.0,
                               num_muts=6,
                               min_target_dist=5.0,
                               dpKas={},
                               method='MC',
                               pKMCsteps=0,
                               X=None):
    #
    # Check if we already did this..
    #
    #
    # Do we have solutions for this problem?
    #
    added_data=None
    missing=None
    if dpKas=={}:
        missing=1
    #
    # Do it?
    #
    if missing:
        defaults=local_defaults(pdbfile,target_residue,target_dpKa,float(min_target_dist),pKMCsteps)
        defaults['max_mutations'][0]=int(num_muts)
        print 'Target: %s, dpKa: %s, Number of mutations: %3d, min_dist: %5.3f' %(
            target_residue,target_dpKa,defaults['max_mutations'][0],defaults['min_target_dist'][0])
        #
        # Set the method default
        #
        allmethods=['TR','MC']
        for m in allmethods:
            defaults[m][0]=None
        if not method=='phidiff':
            defaults[method][0]=1
        #
        # Set the parameters
        #
        if not X:
            params={}
            for key in defaults.keys():
                params[key]=defaults[key][0]
            X=Design_pKa.Design_pKa(params)
        #
        # Get the solutions and the corresponding dpKas
        #
        solutions,dpKa_dict=Design_pKa.run_opt(defaults,X)
        solution_keys=solutions.keys()
        #

        #
        # If there are no solutions then store that info
        #
        if len(solution_keys)==0:
            added_data=1
            dpKas[1]={'no solutions':1}
        #
        # Loop over all the solutions and get the dpKas        
        #
        for solution in solution_keys:
            #
            # Make sure the dictionary is ready
            #
            if not dpKas.has_key(solution):
                added_data=1
                dpKas[solution]={}
            #
            # Check that we have a real mutation (i.e. a non- None) mutation
            #
            dpKas[solution]['mutations']=solutions[solution]['mutations']
            realmut=None
            for mutation in solutions[solution]['mutations']:
                if mutation:
                    realmut=1
            if not realmut:
                continue
            #
            # Get the delta pKa value
            #
            key=str(dpKas[solution]['mutations'])
            if dpKa_dict.has_key(key):
                dpKas[solution][method]=dpKa_dict[key]
    #
    # Did we calculate dpKa values?
    #
    for solution in dpKas.keys():
        if not dpKas[solution].has_key('mutations'):
            #
            # If it's not a real solution then don't check it
            #
            continue
        #
        # Now calculate the dpKas with the method we want, it it's needed
        #
        if method=='phidiff':
            methods=[[None,None]]
        else:
            methods=[[method,None]]
        #
        # Set the method name
        #
        for method,tabulated in methods:
            method_name=method
            if not method:
                method_name='phidiff'
            #
            # Is this tabulated mode?
            #
            if tabulated:
                method_name=method_name+'_tab'
            #
            # Did we calculate this dpKa?
            #

            if not dpKas[solution].has_key(method_name) and not dpKas[solution].has_key(method_name+'_tab'):
                #
                # Get defaults
                #
                import Design_accuracy
                defaults=Design_accuracy.get_this_defaults(pdbfile,target_residue,target_dpKa)
                if method:
                    # Choose method
                    defaults[method][0]=1
                #
                # Set tabulated
                #
                defaults['tabulated'][0]=tabulated
                #
                # Set the general parameters
                #
                mutations=dpKas[solution]['mutations']
                import string
                #
                # Remove all None elements from mutations
                #
                realmut=None
                filtered_muts=[]
                for mut in mutations:
                    if mut:
                        filtered_muts.append(mut)
                        realmut=1
                if not realmut:
                    continue
                #
                # Set the mutations variable in defaults
                #
                defaults['mutations'][0]=string.join(filtered_muts,',')
                # Calculate delta pkas
                defaults['calc_dpka'][0]=1
                #
                # Get the dpKa(s)
                #
                print 'Still calculating here'
                tmp=Design_pKa.run_opt(defaults,X)
                #
                # We should have only one key
                #
                keys=tmp.keys()
                if len(keys)!=1:
                    print keys
                    raise 'Too many keys when calculating dpkas for one solution'
                added_data=1
                dpKas[solution][method_name]=tmp[keys[0]]
    #
    # Done
    #
    return dpKas,added_data,X
Пример #5
0
def main(pdbfile=None):
    #
    # Calculate the matrix of pKa shifts [number of mutations:min distance from active site]
    #
    # Get the PDB file
    #
    print
    print 'Construct dpKa matrix for a single design criterium'
    print
    print 'Usage: Design_two_targets <pdbfile> <database file> <design statement>'
    print
    #
    # start the run
    #
    import sys, os
    if len(sys.argv) < 4:
        raise 'Incorrect usage'
    if not pdbfile:
        pdbfile = sys.argv[1]
    if len(sys.argv) > 2:
        dir = sys.argv[2]
    else:
        raise 'You have to provide a dir for the output'
    os.chdir(dir)
    #
    # Get the method
    #
    method = 'MC'
    #
    # Which design are we doing?
    #
    design_statement = sys.argv[3]
    #
    # Set the file name
    #
    filename = os.path.join(
        dir, 'designtwo__' +
        os.path.split(pdbfile)[1]) + '_' + method + design_statement
    #
    # Print the filename of the dictionary
    #
    print 'Setting dictionary filename to', filename
    DB = dictIO(filename)
    print 'I am running in %s' % os.getcwd()
    #
    # Get wild type pKa values
    #
    import pKaTool.pKaIO
    X = pKaTool.pKaIO.pKaIO(pdbfile)
    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()
    #
    # See if we have an old database file we should work on
    #
    import os
    if os.path.isfile(filename):
        #
        # Load old file
        #
        results = DB.load()
    else:
        #
        # No, no old restuls
        #
        results = {}
        #
        # Add the PDB file
        #
        fd = open(pdbfile)
        lines = fd.readlines()
        fd.close()
        results['pdbfile'] = lines
        #
        # Add the full wt pKa values
        #
        results['wt_full'] = wt_pKas
        DB.save(results)
    # ---------------------------------------
    #
    # Delete old files
    #
    import Design_pKa
    Design_pKa.delete_old_files(pdbfile, 'N', 'N')
    #
    # Start looping
    #
    dist_range = range(1, 26)
    num_muts_range = range(1, 21)
    count = 0
    #
    # Set the number of MC steps
    #
    pKMCsteps = 200000
    #
    # Start of loop
    #

    #
    # Loop over number of mutations and distance cut-off
    #
    X = None
    if not results.has_key(design_statement):
        results[design_statement] = {}
    for min_target_dist in dist_range:
        for num_muts in num_muts_range:
            #
            # Make sure the dictionary entries are there
            #
            if not results[design_statement].has_key(num_muts):
                results[design_statement][num_muts] = {}
            if not results[design_statement][num_muts].has_key(
                    min_target_dist):
                results[design_statement][num_muts][min_target_dist] = {}
            #
            # Have we done this one yet?
            #
            x = 'Checking dist: %5.2f #muts: %2d....' % (
                float(min_target_dist), num_muts)
            print x,
            if results[design_statement][num_muts][min_target_dist] == {}:
                print 'not done. Designing solutions:'
                #
                # Get the parameters
                #
                defaults = set_parameters(pdbfile=pdbfile,
                                          design_statement=design_statement,
                                          min_dist=min_target_dist,
                                          num_muts=num_muts)
                params = {}
                for key in defaults.keys():
                    params[key] = defaults[key][0]
                #
                # Call the design routine
                #
                if not X:
                    X = Design_pKa.Design_pKa(params)
                solutions, dpKa_dict = Design_pKa.run_opt(defaults, X)
                res = dpKa_dict.keys()
                res.sort()
                #for r in res:
                #    print r,dpKa_dict[r]
                #
                # Store the solutions
                #
                print 'Found these solutions'
                print dpKa_dict.keys()
                if dpKa_dict.keys() == []:
                    results[design_statement][num_muts][min_target_dist] = {
                        method: {
                            'None': 'No solutions'
                        }
                    }
                else:
                    results[design_statement][num_muts][min_target_dist] = {
                        method: dpKa_dict.copy()
                    }
                results = DB.update(results)
            else:
                print 'done.'
    #
    # All done
    #
    print
    print 'All done - normal exit'
    print
    return
Пример #6
0
def main(pdbfile=None):
    #
    # Calculate the matrix of pKa shifts [number of mutations:min distance from active site]
    #
    # Get the PDB file
    #
    print
    print 'Construct dpKa matrix for a single design criterium'
    print
    print 'Usage: Design_two_targets <pdbfile> <database file> <design statement>'
    print
    #
    # start the run
    #
    import sys,os
    if len(sys.argv)<4:
        raise 'Incorrect usage'
    if not pdbfile:
        pdbfile=sys.argv[1]
    if len(sys.argv)>2:
        dir=sys.argv[2]
    else:
        raise 'You have to provide a dir for the output'
    os.chdir(dir)
    #
    # Get the method
    #
    method='MC'
    #
    # Which design are we doing?
    #
    design_statement=sys.argv[3]
    #
    # Set the file name
    #
    filename=os.path.join(dir,'designtwo__'+os.path.split(pdbfile)[1])+'_'+method+design_statement
    #
    # Print the filename of the dictionary
    #
    print 'Setting dictionary filename to',filename
    DB=dictIO(filename)
    print 'I am running in %s' %os.getcwd()
    #
    # Get wild type pKa values
    #
    import pKaTool.pKaIO
    X=pKaTool.pKaIO.pKaIO(pdbfile)
    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()
    #
    # See if we have an old database file we should work on
    #
    import os
    if os.path.isfile(filename):
        #
        # Load old file
        #
        results=DB.load()
    else:
        #
        # No, no old restuls
        #
        results={}
        #
        # Add the PDB file
        #
        fd=open(pdbfile)
        lines=fd.readlines()
        fd.close()
        results['pdbfile']=lines
        #
        # Add the full wt pKa values
        #
        results['wt_full']=wt_pKas
        DB.save(results)
    # ---------------------------------------
    #
    # Delete old files
    #
    import Design_pKa
    Design_pKa.delete_old_files(pdbfile,'N','N')
    #
    # Start looping
    #
    dist_range=range(1,26)
    num_muts_range=range(1,21)
    count=0
    #
    # Set the number of MC steps
    #
    pKMCsteps=200000
    #
    # Start of loop
    #

    #
    # Loop over number of mutations and distance cut-off
    #
    X=None
    if not results.has_key(design_statement):
        results[design_statement]={}
    for min_target_dist in dist_range:
        for num_muts in num_muts_range:
            #
            # Make sure the dictionary entries are there
            #
            if not results[design_statement].has_key(num_muts):
                results[design_statement][num_muts]={}
            if not results[design_statement][num_muts].has_key(min_target_dist):
                results[design_statement][num_muts][min_target_dist]={}
            #
            # Have we done this one yet?
            #
            x='Checking dist: %5.2f #muts: %2d....' %(float(min_target_dist),num_muts)
            print x,
            if results[design_statement][num_muts][min_target_dist]=={}:
                print 'not done. Designing solutions:'
                #
                # Get the parameters
                #
                defaults=set_parameters(pdbfile=pdbfile,
                                        design_statement=design_statement,
                                        min_dist=min_target_dist,
                                        num_muts=num_muts)
                params={}
                for key in defaults.keys():
                    params[key]=defaults[key][0]
                #
                # Call the design routine
                #
                if not X:
                    X=Design_pKa.Design_pKa(params)
                solutions,dpKa_dict=Design_pKa.run_opt(defaults,X)
                res=dpKa_dict.keys()
                res.sort()
                #for r in res:
                #    print r,dpKa_dict[r]
                #
                # Store the solutions
                #
                print 'Found these solutions'
                print dpKa_dict.keys()
                if dpKa_dict.keys()==[]:
                    results[design_statement][num_muts][min_target_dist]={method:{'None':'No solutions'}}
                else:
                    results[design_statement][num_muts][min_target_dist]={method:dpKa_dict.copy()}
                results=DB.update(results)
            else:
                print 'done.'
    #
    # All done
    #
    print
    print 'All done - normal exit'
    print
    return