Example #1
0
def set_parameters(pdbfile=None,
                   design_statement=None,
                   min_dist=None,
                   num_muts=None):
    #
    # Set the parameters that are the same for all permutations
    #
    defaults = Design_pKa.get_defaults()
    #
    # PDB file
    #
    defaults['pdb'][0] = pdbfile
    #
    # pKa calculation parameters
    #
    defaults['pHstart'][0] = 0.1
    defaults['pHstop'][0] = 12.0
    defaults['pHstep'][0] = 0.05
    defaults['pKMCsteps'][0] = 200000
    #
    # Design settings
    #
    # Target
    #
    defaults['pKas'][0] = design_statement
    #
    # Method
    #
    defaults['MC'][0] = 1
    defaults['tabulated'][0] = 1
    defaults['MCsteps'][0] = 0
    defaults['TR'][0] = None
    defaults['MC'][0] = 1
    #
    # Be not-so-noisy
    #
    defaults['silent'][0] = 2
    #
    # Minimum distance between target and mutation
    #
    defaults['min_target_dist'][0] = min_dist
    #
    # Max number of mutations
    #
    defaults['max_mutations'][0] = int(num_muts)
    #
    # Do not save the solutions
    #
    defaults['save_solutions'][0] = None
    return defaults
Example #2
0
def set_parameters(pdbfile=None,design_statement=None,min_dist=None,num_muts=None):
    #
    # Set the parameters that are the same for all permutations
    #
    defaults=Design_pKa.get_defaults()
    #
    # PDB file
    #
    defaults['pdb'][0]=pdbfile
    #
    # pKa calculation parameters
    #
    defaults['pHstart'][0]=0.1
    defaults['pHstop'][0]=12.0
    defaults['pHstep'][0]=0.05
    defaults['pKMCsteps'][0]=200000
    #
    # Design settings
    #
    # Target
    #
    defaults['pKas'][0]=design_statement
    #
    # Method
    #
    defaults['MC'][0]=1
    defaults['tabulated'][0]=1
    defaults['MCsteps'][0]=0
    defaults['TR'][0]=None
    defaults['MC'][0]=1
    #
    # Be not-so-noisy
    #
    defaults['silent'][0]=2
    #
    # Minimum distance between target and mutation
    #
    defaults['min_target_dist'][0]=min_dist
    #
    # Max number of mutations
    #
    defaults['max_mutations'][0]=int(num_muts)
    #
    # Do not save the solutions
    #
    defaults['save_solutions'][0]=None
    return defaults
Example #3
0
def local_defaults(pdbfile,
                   target_residue,
                   target_dpKa,
                   min_dist,
                   pKMCsteps=None):
    #
    # Set the parameters that are the same for all permutations
    #
    defaults = Design_pKa.get_defaults()
    # PDB file
    defaults['pdb'][0] = pdbfile
    #
    # pKa calculation parameters
    #
    defaults['pHstart'][0] = 0.1
    defaults['pHstop'][0] = 12.0
    defaults['pHstep'][0] = 0.05
    defaults['pKMCsteps'][0] = 200000
    if pKMCsteps:
        defaults['pKMCsteps'][0] = pKMCsteps
    #
    # Design settings
    #
    # Target
    #
    target = target_residue + '=' + target_dpKa
    defaults['pKas'][0] = target
    #
    # Method
    #
    defaults['MC'][0] = 1
    defaults['tabulated'][0] = 1
    defaults['MCsteps'][0] = 0
    #
    # Be not-so-noisy
    #
    defaults['silent'][0] = 2
    #
    # Minimum distance between target and mutation
    #
    defaults['min_target_dist'][0] = min_dist
    #
    # Do not save the solutions
    #
    defaults['save_solutions'][0] = None
    return defaults
Example #4
0
def local_defaults(pdbfile,target_residue,target_dpKa,min_dist,pKMCsteps=None):
    #
    # Set the parameters that are the same for all permutations
    #
    defaults=Design_pKa.get_defaults()
    # PDB file
    defaults['pdb'][0]=pdbfile
    #
    # pKa calculation parameters
    #
    defaults['pHstart'][0]=0.1
    defaults['pHstop'][0]=12.0
    defaults['pHstep'][0]=0.05
    defaults['pKMCsteps'][0]=200000
    if pKMCsteps:
        defaults['pKMCsteps'][0]=pKMCsteps
    #
    # Design settings
    #
    # Target
    #
    target=target_residue+'='+target_dpKa
    defaults['pKas'][0]=target
    #
    # Method
    #
    defaults['MC'][0]=1
    defaults['tabulated'][0]=1
    defaults['MCsteps'][0]=0
    #
    # Be not-so-noisy
    #
    defaults['silent'][0]=2
    #
    # Minimum distance between target and mutation
    #
    defaults['min_target_dist'][0]=min_dist
    #
    # Do not save the solutions
    #
    defaults['save_solutions'][0]=None
    return defaults
Example #5
0
def get_this_defaults(pdbfile,target_residue,target_dpKa):
    #
    # Set the parameters that are the same for all permutations
    #
    import Design_pKa

    defaults=Design_pKa.get_defaults()
    # PDB file
    defaults['pdb'][0]=pdbfile
    #
    # pKa calculation parameters
    #
    defaults['pHstart'][0]=0.0
    defaults['pHstop'][0]=14.0
    defaults['pHstep'][0]=0.05
    defaults['MCsteps'][0]=1
    defaults['pKMCsteps'][0]=50000
    #
    # Design settings
    #
    # Target
    #
    target=target_residue+'='+target_dpKa
    defaults['pKas'][0]=target
    #
    # Be not-so-noisy
    #

    defaults['silent'][0]=1

    #
    # Minimum distance between target and mutation
    #
    defaults['min_target_dist'][0]=5.0
    defaults['max_mutations'][0]=20.0
    return defaults
Example #6
0
def get_this_defaults(pdbfile, target_residue, target_dpKa):
    #
    # Set the parameters that are the same for all permutations
    #
    import Design_pKa

    defaults = Design_pKa.get_defaults()
    # PDB file
    defaults['pdb'][0] = pdbfile
    #
    # pKa calculation parameters
    #
    defaults['pHstart'][0] = 0.0
    defaults['pHstop'][0] = 14.0
    defaults['pHstep'][0] = 0.05
    defaults['MCsteps'][0] = 1
    defaults['pKMCsteps'][0] = 50000
    #
    # Design settings
    #
    # Target
    #
    target = target_residue + '=' + target_dpKa
    defaults['pKas'][0] = target
    #
    # Be not-so-noisy
    #

    defaults['silent'][0] = 1

    #
    # Minimum distance between target and mutation
    #
    defaults['min_target_dist'][0] = 5.0
    defaults['max_mutations'][0] = 20.0
    return defaults
Example #7
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
Example #8
0
 def __init__(self,pdbfile,user_params={},reporter_groups=None):
     """Read the pdbfile and the wild type pKa values
     Define the reporter groups"""
     # Topdir
     import os
     self.topdir=os.getcwd()
     #
     # Set the PDB file name
     #
     self.pdbfile=os.path.join(self.topdir,pdbfile)
     import Protool
     self.PI=Protool.structureIO()
     self.PI.readpdb(self.pdbfile)
     #
     # Get the defaults from Design_pKa
     #
     import Design_pKa
     defaults=Design_pKa.get_defaults()
     self.params={}
     for key in defaults.keys():
         self.params[key]=defaults[key][0]
     self.params['pKMCsteps']=20000
     self.params['recalc_intpka']=True
     self.params['recalc_intpka_dist']=20.0
     self.params['save_temp_files']=False
     #
     # Change the values that the user specified
     #
     for u_par in user_params.keys():
         self.params[u_par]=user_params[u_par]
     #
     # Set the pKa calc parms as a subset
     #
     self.pKarun_params={}
     include=['indi','dbcrit','ion','allow_unknown_atoms','unknown_crg','unknown_rad']
     import copy
     for key in include:
         self.pKarun_params[key]=copy.copy(self.params[key])
     #
     # Set the output handler
     #
     self.O=Design_pKa.verbose(self.params['verbose'])
     #
     # Instantiate the pKa_info class and instruct it to save nothing
     #
     import Design_pKa_help
     print 'pKa_info, PDB file',self.pdbfile
     self.pKa_info=Design_pKa_help.pKa_info(pdbfile=self.pdbfile,parent=self,PBEsolver=self.params['PBEsolver'],save_file=False)
     #
     # Set the calculation routine to CPP
     #
     import pKa_MC
     self.pKaCALC=pKa_MC.pKa_calculation_class(pdbfile=self.pdbfile,pKa_info=self.pKa_info,params=self.params,parent=self)
     self.pKaCALC.set_MC_CPP()
     #
     # Re-calculate the wild type pKa values
     #
     print 'Calculating wild type pKa values'
     self.wt_pKas,self.wt_prot_states=self.pKaCALC.calc_wt_pkas()
     #
     # Set the reporter groups
     #
     if reporter_groups:
         self.reporter_groups=reporter_groups
     else:
         self.reporter_groups=self.wt_pKas.keys()
     return
Example #9
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
Example #10
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
Example #11
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
Example #12
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
Example #13
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'
    print
    print 'Usage: Design_dist_nummuts <pdbfile> <database file> <method>'
    print
    #
    # Are we running in parallel?
    #
    import os

    mpi_rank = None
    try:
        import mpi
        mpi_rank = mpi.rank
        mpi_size = mpi.size
        print 'MPI rank', mpi_rank
        print 'MPI size', mpi_size
        if size == 1:
            mpi_rank = None
    except:
        #
        # No MPI
        #
        pass
    #
    # 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 = sys.argv[3]
    #
    # Are we doing this cheap style?
    #
    mcstep_factor = 1.00
    if sys.argv[-1] == 'cheap':
        mcstep_factor = 0.01
    #
    # Set the file name
    #
    filename = os.path.join(
        dir, 'distance_nummuts__' + os.path.split(pdbfile)[1]) + '_' + method
    #
    # Keep the cheap results separated from the real results
    #
    if sys.argv[-1] == 'cheap':
        filename = filename + 'cheap'
    #
    # Print the filename of the dictionary
    #
    print 'Setting dictionary filename to', filename
    DB = dictIO(filename)
    print 'I am running in %s' % os.getcwd()
    #
    # Do we have a completed pKa calc for it?
    #
    import pKaTool.pKaIO
    X = pKaTool.pKaIO.pKaIO(pdbfile)
    if not X.assess_status():
        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
    #
    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
    #
    Design_pKa.delete_old_files(pdbfile, 'N', 'Y')
    #
    # Start looping
    #
    dist_range = range(1, 26)
    num_muts_range = range(1, 21)
    count = 0
    design_low = 2.0
    design_high = 10.0
    #
    # Count the number of designable groups
    #
    design_groups = []
    for group in groups:
        pKaval = wt_pKas[group]['pKa']
        if pKaval > design_low and pKaval < design_high:
            design_groups.append(group)
    tot_count = float(
        len(design_groups) * 2 * len(dist_range) * len(num_muts_range)) / 100.0
    #
    # Set the number of MC steps
    #
    #
    #if len(groups)<60:
    pKMCsteps = 200000
    #else:
    #    #print 'We have %d groups, so increasing pKMCsteps' %(len(groups))
    #    pKMCsteps=200000
    pKMCsteps = int(mcstep_factor * float(pKMCsteps))
    #
    # Start of loop
    #
    groups.sort()
    #
    # Are we running MPI?
    #
    if mpi_rank != None:
        fraction = 1.0 / float(mpi_size)
        print 'I will be doing %.2f %% of the job' % (100.0 * fraction)
        num_groups = len(groups)
        print 'Specifically I will be doing groups', groups[
            int(fraction * mpi_rank *
                num_groups):int(fraction * (mpi_rank + 1) * num_groups)]
        print fraction * mpi_rank * num_groups, 'to', fraction * (
            mpi_rank + 1) * num_groups
        groups = groups[int(fraction * mpi_rank *
                            num_groups):int(fraction * (mpi_rank + 1) *
                                            num_groups)]
        #
        # Sleep to desynchronize processes
        #
        import time
        time.sleep(mpi_rank)
        print mpi_rank, 'done sleeping!'
        import sys
        sys.stdout.flush()
    #
    # Do the calculation
    #
    for group in groups:
        #
        # Loop over all groups
        #
        if not results.has_key(group):
            results[group] = {}
        #
        # Is somebody working on this group?
        #
        #results=DB.update(results)
        if results[group].has_key('locked'):
            if results[group]['locked'] == 1:
                print '%s is locked' % group
                continue
        #
        # Lock group
        #
        results[group]['locked'] = 1

        #
        # Force reinitialisation of instance
        #
        X = None
        #
        # Loop over number of mutations and distance cut-off
        #
        pKaval = wt_pKas[group]['pKa']
        if pKaval > design_low and pKaval < design_high:
            for design in ['+20.0', 'm20.0']:
                if not results[group].has_key(design):
                    results[group][design] = {}
                for min_target_dist in dist_range:
                    for num_muts in num_muts_range:
                        if not results[group][design].has_key(num_muts):
                            results[group][design][num_muts] = {}
                        #
                        # Print what we are doing
                        #
                        print 'Checking: %20s design: %s, dist: %5.1f, nummuts: %3d %%done %5.2f' % (
                            group, design, min_target_dist, num_muts,
                            float(count) / tot_count)
                        count = count + 1
                        #
                        # ..
                        #
                        if not results[group][design][num_muts].has_key(
                                min_target_dist):
                            results[group][design][num_muts][
                                min_target_dist] = {}
                            #
                            # Get the solutions
                            #
                            dpKas, data_added, X = get_solutions_dist_nummuts(
                                pdbfile, group, design, num_muts,
                                min_target_dist, results[group][design]
                                [num_muts][min_target_dist], method, pKMCsteps,
                                X)
                            results[group][design][num_muts][
                                min_target_dist] = dpKas.copy()
                            pass
                    results = DB.update(results)
        else:
            results[group]['pKa out of range'] = 1
        #
        # Unlock group and merge results
        #
        del results[group]['locked']
    results = DB.update(results)
    #
    # All done
    #
    print
    print 'All done - normal exit'
    print
    return
Example #14
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
Example #15
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'
    print
    print 'Usage: Design_dist_nummuts <pdbfile> <database file> <method>'
    print
    #
    # Are we running in parallel?
    #
    import os

    mpi_rank=None
    try:
        import mpi
        mpi_rank=mpi.rank
        mpi_size=mpi.size
        print 'MPI rank',mpi_rank
        print 'MPI size',mpi_size
        if size==1:
            mpi_rank=None
    except:
        #
        # No MPI
        #
        pass
    #
    # 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=sys.argv[3]
    #
    # Are we doing this cheap style?
    #
    mcstep_factor=1.00
    if sys.argv[-1]=='cheap':
        mcstep_factor=0.01
    #
    # Set the file name
    #
    filename=os.path.join(dir,'distance_nummuts__'+os.path.split(pdbfile)[1])+'_'+method
    #
    # Keep the cheap results separated from the real results
    #
    if sys.argv[-1]=='cheap':
        filename=filename+'cheap'
    #
    # Print the filename of the dictionary
    #
    print 'Setting dictionary filename to',filename
    DB=dictIO(filename)
    print 'I am running in %s' %os.getcwd()
    #
    # Do we have a completed pKa calc for it?
    #
    import pKaTool.pKaIO
    X=pKaTool.pKaIO.pKaIO(pdbfile)
    if not X.assess_status():
        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
    #
    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
    #
    Design_pKa.delete_old_files(pdbfile,'N','Y')
    #
    # Start looping
    #
    dist_range=range(1,26)
    num_muts_range=range(1,21)
    count=0
    design_low=2.0
    design_high=10.0
    #
    # Count the number of designable groups
    #
    design_groups=[]
    for group in groups:
        pKaval=wt_pKas[group]['pKa']
        if pKaval>design_low and pKaval<design_high:
            design_groups.append(group)
    tot_count=float(len(design_groups)*2*len(dist_range)*len(num_muts_range))/100.0
    #
    # Set the number of MC steps
    #
    #
    #if len(groups)<60:
    pKMCsteps=200000
    #else:
    #    #print 'We have %d groups, so increasing pKMCsteps' %(len(groups))
    #    pKMCsteps=200000
    pKMCsteps=int(mcstep_factor*float(pKMCsteps))
    #
    # Start of loop
    #
    groups.sort()
    #
    # Are we running MPI?
    #
    if mpi_rank!=None:
        fraction=1.0/float(mpi_size)
        print 'I will be doing %.2f %% of the job' %(100.0*fraction)
        num_groups=len(groups)
        print 'Specifically I will be doing groups',groups[int(fraction*mpi_rank*num_groups):int(fraction*(mpi_rank+1)*num_groups)]
        print fraction*mpi_rank*num_groups,'to',fraction*(mpi_rank+1)*num_groups
        groups=groups[int(fraction*mpi_rank*num_groups):int(fraction*(mpi_rank+1)*num_groups)]
        #
        # Sleep to desynchronize processes
        #
        import time
        time.sleep(mpi_rank)
        print mpi_rank,'done sleeping!'
        import sys
        sys.stdout.flush()
    #
    # Do the calculation
    #
    for group in groups:
        #
        # Loop over all groups
        #
        if not results.has_key(group):
            results[group]={}
        #
        # Is somebody working on this group?
        #
        #results=DB.update(results)
        if results[group].has_key('locked'):
            if results[group]['locked']==1:
                print '%s is locked' %group
                continue
        #
        # Lock group
        #
        results[group]['locked']=1

        #
        # Force reinitialisation of instance
        #
        X=None
        #
        # Loop over number of mutations and distance cut-off
        #
        pKaval=wt_pKas[group]['pKa']
        if pKaval>design_low and pKaval<design_high:
            for design in ['+20.0','m20.0']:
                if not results[group].has_key(design):
                    results[group][design]={}
                for min_target_dist in dist_range:
                    for num_muts in num_muts_range:
                        if not results[group][design].has_key(num_muts):
                            results[group][design][num_muts]={}
                        #
                        # Print what we are doing
                        #
                        print 'Checking: %20s design: %s, dist: %5.1f, nummuts: %3d %%done %5.2f' %(group,design,
                                                                                  min_target_dist,
                                                                                  num_muts,float(count)/tot_count)
                        count=count+1
                        #
                        # ..
                        #
                        if not results[group][design][num_muts].has_key(min_target_dist):
                            results[group][design][num_muts][min_target_dist]={}
                            #
                            # Get the solutions
                            #
                            dpKas,data_added,X=get_solutions_dist_nummuts(pdbfile,
                                                                          group,
                                                                          design,num_muts,
                                                                          min_target_dist,
                                                                          results[group][design][num_muts][min_target_dist],
                                                                          method,pKMCsteps,X)
                            results[group][design][num_muts][min_target_dist]=dpKas.copy()
                            pass
                    results=DB.update(results)
        else:
            results[group]['pKa out of range']=1
        #
        # Unlock group and merge results
        #
        del results[group]['locked']
    results=DB.update(results)
    #
    # All done
    #
    print
    print 'All done - normal exit'
    print
    return
Example #16
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
Example #17
0
def run_sugelm(pdbfile):
    """Run the SugELM command"""
    #
    # Get the name of the PDB file
    #
    import os
    pdb_name = os.path.split(pdbfile)[1]
    pdb_dir = os.path.split(pdbfile)[0]
    topdir = os.getcwd()
    #
    # Check if pKa values were calculated for this file
    #
    import pKaTool.pKaIO
    X = pKaTool.pKaIO.pKaIO(pdbfile)
    if not X.calculation_completed:
        print 'pKa calculation not completed for %s' % pdbfile
        return None
    #
    # Read the pKa values
    #
    pkas = X.readpka()
    target = pkas.keys()[2]
    #
    # Create the SUGELM file
    #
    import Design_pKa
    tparams = Design_pKa.get_defaults()
    params = {}
    for key in tparams.keys():
        params[key] = tparams[key][0]
    #
    # Set the other parameters
    #
    params['pHstart'] = 0.1
    params['pHstop'] = 12.0
    params['pHstep'] = 0.05
    params['pKMCsteps'] = 200000,
    params['pKas'] = target + '=+1.0'
    params['MC'] = 0
    params['TR'] = 0
    params['min_target_dist'] = 1.0
    params['save_solutions'] = None
    params['silent'] = 0
    params['pdb'] = pdbfile
    params['generate_mutations'] = True
    #
    # Log message
    #
    import sys
    print 'Starting pKD mutation preparation'
    sys.stdout.flush()
    try:
        X = Design_pKa.Design_pKa(params)
        X.get_interaction_energies()
        print 'Calculated interaction energies'
    except:
        send_email('*****@*****.**', 'SUGELM failed for ' + pdbfile)
        return None
    #
    # Write a flag file to alert the scheduler
    #
    fd = open(os.path.join(pdb_dir, 'ready'), 'w')
    fd.write('SUGELM is done\n')
    fd.close()
    return 1
Example #18
0
 def __init__(self, pdbfile, user_params={}, reporter_groups=None):
     """Read the pdbfile and the wild type pKa values
     Define the reporter groups"""
     # Topdir
     import os
     self.topdir = os.getcwd()
     #
     # Set the PDB file name
     #
     self.pdbfile = os.path.join(self.topdir, pdbfile)
     import Protool
     self.PI = Protool.structureIO()
     self.PI.readpdb(self.pdbfile)
     #
     # Get the defaults from Design_pKa
     #
     import Design_pKa
     defaults = Design_pKa.get_defaults()
     self.params = {}
     for key in defaults.keys():
         self.params[key] = defaults[key][0]
     self.params['pKMCsteps'] = 20000
     self.params['recalc_intpka'] = True
     self.params['recalc_intpka_dist'] = 20.0
     self.params['save_temp_files'] = False
     #
     # Change the values that the user specified
     #
     for u_par in user_params.keys():
         self.params[u_par] = user_params[u_par]
     #
     # Set the pKa calc parms as a subset
     #
     self.pKarun_params = {}
     include = [
         'indi', 'dbcrit', 'ion', 'allow_unknown_atoms', 'unknown_crg',
         'unknown_rad'
     ]
     import copy
     for key in include:
         self.pKarun_params[key] = copy.copy(self.params[key])
     #
     # Set the output handler
     #
     self.O = Design_pKa.verbose(self.params['verbose'])
     #
     # Instantiate the pKa_info class and instruct it to save nothing
     #
     import Design_pKa_help
     print 'pKa_info, PDB file', self.pdbfile
     self.pKa_info = Design_pKa_help.pKa_info(
         pdbfile=self.pdbfile,
         parent=self,
         PBEsolver=self.params['PBEsolver'],
         save_file=False)
     #
     # Set the calculation routine to CPP
     #
     import pKa_MC
     self.pKaCALC = pKa_MC.pKa_calculation_class(pdbfile=self.pdbfile,
                                                 pKa_info=self.pKa_info,
                                                 params=self.params,
                                                 parent=self)
     self.pKaCALC.set_MC_CPP()
     #
     # Re-calculate the wild type pKa values
     #
     print 'Calculating wild type pKa values'
     self.wt_pKas, self.wt_prot_states = self.pKaCALC.calc_wt_pkas()
     #
     # Set the reporter groups
     #
     if reporter_groups:
         self.reporter_groups = reporter_groups
     else:
         self.reporter_groups = self.wt_pKas.keys()
     return
Example #19
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
def run_sugelm(pdbfile):
    """Run the SugELM command"""
    #
    # Get the name of the PDB file
    #
    import os
    pdb_name=os.path.split(pdbfile)[1]
    pdb_dir=os.path.split(pdbfile)[0]
    topdir=os.getcwd()
    #
    # Check if pKa values were calculated for this file
    #
    import pKaTool.pKaIO
    X=pKaTool.pKaIO.pKaIO(pdbfile)
    if not X.calculation_completed:
        print 'pKa calculation not completed for %s' %pdbfile
        return None
    #
    # Read the pKa values
    #
    pkas=X.readpka()
    target=pkas.keys()[2]
    #
    # Create the SUGELM file
    #
    import Design_pKa
    tparams=Design_pKa.get_defaults()
    params={}
    for key in tparams.keys():
        params[key]=tparams[key][0]
    #
    # Set the other parameters
    #
    params['pHstart']=0.1
    params['pHstop']=12.0
    params['pHstep']=0.05
    params['pKMCsteps']=200000,
    params['pKas']=target+'=+1.0'
    params['MC']=0
    params['TR']=0
    params['min_target_dist']=1.0
    params['save_solutions']=None
    params['silent']=0
    params['pdb']=pdbfile
    params['generate_mutations']=True
    #
    # Log message
    #
    import sys
    print 'Starting pKD mutation preparation'
    sys.stdout.flush()
    try:
        X=Design_pKa.Design_pKa(params)
        X.get_interaction_energies()
        print 'Calculated interaction energies'
    except:
        send_email('*****@*****.**','SUGELM failed for '+pdbfile)
        return None
    #
    # Write a flag file to alert the scheduler
    #
    fd=open(os.path.join(pdb_dir,'ready'),'w')
    fd.write('SUGELM is done\n')
    fd.close()
    return 1