def run_epik(input_file_path, output_file_path, max_structures=32, ph=7.4, ph_tolerance=None, min_probability=None, tautomerize=True, extract_range=None): """Run Schrodinger's epik command line utility to enumerate protonation and tautomeric states. Parameters ---------- input_file_path : str Path to input file describing the molecule. output_file_path : str Path to the output file created by epik. max_structures : int, optional Maximum number of generated structures (default is 32). ph : float, optional Target pH for generated states (default is 7.4). ph_tolerance : float, optional Equivalent of -pht option in Epik command (default is None). min_probability: float, optional Minimum probability for the generated states. tautomerize : bool, optional Whether or not tautomerize the input structure (default is True). extract_range : int or list of ints, optional If not None, the function uses the Schrodinger's utility maesubset to extract only a subset of the generated structures. This is the 0-based indices of the structures to extract from the input files. """ # Locate epik executable epik_path = os.path.join(os.environ['SCHRODINGER'], 'epik') # Normalize paths as we'll run in a different working directory input_file_path = os.path.abspath(input_file_path) output_file_path = os.path.abspath(output_file_path) output_dir = os.path.dirname(output_file_path) # Preparing epik command arguments for format() epik_args = dict(ms=max_structures, ph=ph) epik_args['pht'] = '-pht {}'.format(ph_tolerance) if ph_tolerance else '' epik_args['nt'] = '' if tautomerize else '-nt' epik_args['p'] = '-p {}'.format(min_probability) if min_probability else '' # Determine if we need to convert input and/or output file if extract_range is None: epik_output = output_file_path else: epik_output = os.path.splitext(output_file_path)[0] + '-full.mae' # Epik command. We need list in case there's a space in the paths cmd = [epik_path, '-imae', input_file_path, '-omae', epik_output] cmd += '-ms {ms} -ph {ph} {pht} {nt} {p} -pKa_atom -WAIT -NO_JOBCONTROL'.format( **epik_args).split() # We run with output_dir as working directory to save there the log file with utils.temporary_cd(output_dir): run_and_log_error(cmd) # Check if we need to extract a range of structures if extract_range is not None: run_maesubset(epik_output, output_file_path, extract_range) os.remove(epik_output)
def protein_prep(input_file_path, output_file_path, pdbid, pH=7.4, fillsidechains=True, fillloops=True, max_states=32, tolerance=0): # Locate PrepWizard executable prepwiz_path = os.path.join(os.environ['SCHRODINGER'], 'utilities', 'prepwizard') # Normalize paths input_file_path = os.path.abspath(input_file_path) output_file_path = os.path.abspath(output_file_path) output_dir = os.path.join(output_file_path, '%s-fixed' % pdbid) output_file_name = '../%s-fixed.pdb' % pdbid # Check for output file pathway if not os.path.exists(output_dir): os.makedirs(output_dir) # Format arguments for PrepWizard command wiz_args = dict(ms=max_states, ph=pH) wiz_args['fillsidechains'] = '-fillsidechains' if fillsidechains else '' wiz_args['fillloops'] = '-fillloops' if fillloops else '' wiz_args['pht'] = tolerance cmd = [prepwiz_path] cmd += '-captermini -mse -propka_pH {ph} {fillsidechains} {fillloops} -keepfarwat -disulfides -ms {ms} -minimize_adj_h -epik_pH {ph} -epik_pHt {pht} -fix -NOJOBID'.format(**wiz_args).split() cmd.append(input_file_path) cmd.append(output_file_name) with utils.temporary_cd(output_dir): log = schrodinger.run_and_log_error(cmd) write_file('%s.log' % pdbid, log)
def protein_prep(input_file, output_file, cap, pH=7.4, fillsidechains=True, fillloops=True, noepik=False, rehtreat=True, max_states=32, tolerance=0): # Locate PrepWizard executable prepwiz_path = os.path.join(os.environ['SCHRODINGER'], 'utilities', 'prepwizard') # Normalize paths input_file_path = os.path.abspath(input_file) input_file_dir, input_name = os.path.split(input_file_path) output_file_name = os.path.join(input_file_dir, output_file + '-prepped.pdb') working_dir = os.path.join(input_file_dir, '%s-prepped' % input_name) # Check for output file pathway if not os.path.exists(working_dir): os.makedirs(working_dir) # Format arguments for PrepWizard command wiz_args = dict(ms=max_states, ph=pH) wiz_args['fillsidechains'] = '-fillsidechains' if fillsidechains else '' wiz_args['fillloops'] = '-fillloops' if fillloops else '' wiz_args['pht'] = tolerance wiz_args['rehtreat'] = '-rehtreat' if rehtreat else '' wiz_args['water_hbond_cutoff'] = 0 wiz_args['noepik'] = '-noepik' if noepik else '' wiz_args['captermini'] = '-captermini' if cap else '' cmd = [prepwiz_path] cmd += '{captermini} -mse -propka_pH {ph} {fillsidechains} {fillloops} {rehtreat} {noepik} -delwater_hbond_cutoff {water_hbond_cutoff} ' \ '-keepfarwat -disulfides -ms {ms} -minimize_adj_h -epik_pH {ph} -epik_pHt {pht} -fix -NOJOBID'.format(**wiz_args).split() cmd.append(input_file_path) cmd.append(output_file_name) with utils.temporary_cd(working_dir): log = schrodinger.run_and_log_error(cmd) write_file('protein_prep.log', log)
def run_ligprep(input_file_path, output_file_path, max_stereo_isomers=1, ionization_treatment=1): """ Run Schrodinger's ligprep command line utility to clean up a structure. Parameters ---------- input_file_path : str Path to input file describing the molecule. output_file_path : str Path to the output file created by epik. max_stereo_isomers : int, optional Maximum number of generated structures (default is 32). ionization_treatment : int, default 1 0 do not neutralize or ionize, 1 neutralize, 2 neutralize and ionize. """ # Locate executable exe_path = os.path.join(os.environ['SCHRODINGER'], 'ligprep') # Normalize paths as we'll run in a different working directory input_file_path = os.path.abspath(input_file_path) output_file_path = os.path.abspath(output_file_path) output_dir = os.path.dirname(output_file_path) # Preparing epik command arguments for format() prep_args = dict(s=max_stereo_isomers, i=ionization_treatment) prep_output = os.path.splitext(output_file_path)[0] + '.mae' # ligprep command. We need list in case there's a space in the paths cmd = [exe_path, '-imae', input_file_path, '-omae', prep_output] cmd += '-s {s} -i {i} -WAIT'.format( **prep_args).split() # We run with output_dir as working directory to save there the log file with utils.temporary_cd(output_dir): run_and_log_error(cmd)
def run_epik(input_file_path, output_file_path, max_structures=32, ph=7.4, ph_tolerance=None, min_probability=None, tautomerize=True, extract_range=None, max_atoms=150): """Run Schrodinger's epik command line utility to enumerate protonation and tautomeric states. Parameters ---------- input_file_path : str Path to input file describing the molecule. output_file_path : str Path to the output file created by epik. max_structures : int, optional Maximum number of generated structures (default is 32). ph : float, optional Target pH for generated states (default is 7.4). ph_tolerance : float, optional Equivalent of -pht option in Epik command (default is None). min_probability: float, optional Minimum probability for the generated states. tautomerize : bool, optional Whether or not tautomerize the input structure (default is True). extract_range : int or list of ints, optional If not None, the function uses the Schrodinger's utility maesubset to extract only a subset of the generated structures. This is the 0-based indices of the structures to extract from the input files. max_atoms : int, optional Structures containing more than max_atoms atoms will not be adjusted. (default is 150) """ # Locate epik executable epik_path = os.path.join(os.environ['SCHRODINGER'], 'epik') # Normalize paths as we'll run in a different working directory input_file_path = os.path.abspath(input_file_path) output_file_path = os.path.abspath(output_file_path) output_dir = os.path.dirname(output_file_path) # Preparing epik command arguments for format() epik_args = dict(ms=max_structures, ph=ph) epik_args['pht'] = '-pht {}'.format(ph_tolerance) if ph_tolerance else '' epik_args['nt'] = '' if tautomerize else '-nt' epik_args['p'] = '-p {}'.format(min_probability) if min_probability else '' epik_args['ma'] = '-ma {}'.format(max_atoms) # Determine if we need to convert input and/or output file if extract_range is None: epik_output = output_file_path else: epik_output = os.path.splitext(output_file_path)[0] + '-full.mae' # Epik command. We need list in case there's a space in the paths cmd = [epik_path, '-imae', input_file_path, '-omae', epik_output] cmd += '-ms {ms} -ph {ph} {ma} {pht} {nt} {p} -pKa_atom -WAIT -NO_JOBCONTROL'.format( **epik_args).split() # We run with output_dir as working directory to save there the log file with utils.temporary_cd(output_dir): run_and_log_error(cmd) # Check if we need to extract a range of structures if extract_range is not None: run_maesubset(epik_output, output_file_path, extract_range) os.remove(epik_output)
def test_temp_cd_context(): """Test the context temporary_cd().""" with utils.temporary_directory() as tmp_dir: with utils.temporary_cd(tmp_dir): assert os.getcwd() == os.path.realpath(tmp_dir) assert os.getcwd() != os.path.realpath(tmp_dir)