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
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
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