def rmsd_launcher(input, ref_file): """ Calculate RMSD """ runner = [os.path.join(os.environ['SCHRODINGER'], 'run'), 'rmsd.py'] counter = 0 for file in input: counter += 1 print('%s %s' % (counter, file)) cmd = ["-use_neutral_scaffold", "-c", "rmsd_%s_vs_%s.csv" % (file, os.path.basename(ref_file)), "-m", "-norenumber", "-m", "-verbose", # '-asl', "(chain.name H) AND NOT atom.ele H", os.path.join(INPUT_DIR, '%s_0-out.mae' % file), '%s.mae' % ref_file, '-HOST', "localhost:8"] # job = jc.launch_job(runner + cmd) try: job = jc.launch_job(runner + cmd) job.wait() print(job.getDuration()) print('Finish - %s' % job.Status) except: print('Something is wrong')
def run(self): """ Downloads, calculates, and prepares the pdb, cif, cns, smap, and cmd files to view a pdb structure and electron density maps. """ cmd_file_name = "%s.cmd" % self.jobname if not (self.downloadPDBFile() and self.downloadSFFile()): logger.info("Failed to download the required files.") return inp_file = self.writePrimeXCreateMapInputFile() logger.info("Running PrimeX map generation job...") px_job = jobcontrol.launch_job(["primex", inp_file]) px_job.wait() if not px_job.succeeded(): logger.info("PrimeX map generation failed.") return this_jobbe = jobcontrol.get_backend() launch_dir = os.getcwd() if this_jobbe: # SMAP needs a path for the files, which will the launch # dir when jobcontrol has copied them back. launch_dir = this_jobbe.getJob().Dir # This job only outputs maps. for map_file in px_job.OutputFiles: this_jobbe.addOutputFile(map_file) mae_file_name = "%s.mae" % self.jobname mae_file_path = os.path.join(launch_dir, mae_file_name) smap_file_name = "%s.smap" % self.jobname smap_fh = open(smap_file_name, 'w') smap = """# smap version 1.0 %s primex_%s-out-1.cns:1 primex_%s-out-0.cns:1 #end """ % (mae_file_name, self.jobname, self.jobname) smap_fh.write(smap) smap_fh.close() cmd_fh = open(cmd_file_name, 'w') # smap mechanism seem to need abs paths to trigger extradata. cmd_fh.write('entryimport extradata=true "%s"\n' % mae_file_path) cmd_fh.write('showpanel managesurfaces\n') cmd_fh.write('fit\n') cmd_fh.close() if this_jobbe: this_jobbe.setStructureOutputFile(mae_file_name) this_jobbe.addOutputFile(mae_file_name) this_jobbe.addOutputFile(cmd_file_name) this_jobbe.addOutputFile(smap_file_name) logger.info("Run this command file within Maestro: %s" % cmd_file_name) return
def mini(structures, frozen_atoms=None, fix_torsions=None): """ Takes many structures, minimizes them and returns the minimized structures. It's faster to do multiple structures at once. Arguments --------- structure : list of Schrödinger structure Returns ------- list of Schrödinger structure """ import schrodinger.application.macromodel.utils as mmodutils import schrodinger.job.jobcontrol as jobcontrol from setup_com_from_mae import MyComUtil print(' - ATTEMPTING MINI') sch_writer = sch_struct.StructureWriter('TEMP.mae') sch_writer.extend(structures) sch_writer.close() # Setup the minimization. com_setup = MyComUtil() com_setup.my_mini( mae_file='TEMP.mae', com_file='TEMP.com', out_file='TEMP_OUT.mae', frozen_atoms=frozen_atoms, fix_torsions=fix_torsions) command = ['bmin', '-WAIT', 'TEMP'] # Run the minimization. job = jobcontrol.launch_job(command) job.wait() # Read the minimized structures. sch_reader = sch_struct.StructureReader('TEMP_OUT.mae') new_structures = [] for structure in sch_reader: new_structures.append(structure) sch_reader.close() if len(new_structures) > 0: print(' - MINI SUCCEEDED') structures = [new_structures[0]] else: print(' - MINI FAILED. CONTINUING W/O MINI') if DEBUG: raw_input('Press any button to continue.') # Remove temporary files. os.remove('TEMP.mae') os.remove('TEMP.com') os.remove('TEMP_OUT.mae') os.remove('TEMP.log') return structures
def run_mmgbsa(structures, ligand_asl, njobs=1): """ Run a prime mmgbsa calculations on a series of trajectory frames :param structures: :param ligand_asl: :param njobs: :return: """ logger.info('Launching {} subjobs'.format(njobs)) # Run MMGBSA calculation inp = [] jobs = [] for i, chunk in enumerate(np.array_split(np.arange(len(structures)), njobs)): jobname = 'mmgbsa_input{}'.format(i) infile = 'mmgbsa_input{}.mae'.format(i) for j in chunk: st = structures[j] st.append(infile) inp.append(jobname) args = [ MMGBSA_CMD, infile, ] mmgbsa_options = copy.copy(MMGBSA_OPTIONS) mmgbsa_options['-jobname'] = jobname mmgbsa_options['-ligand'] = ligand_asl for kv in mmgbsa_options.items(): args.extend(kv) logger.info('Running Prime MMGBSA:') logger.info('$SCHRODINGER/' + ' '.join(args)) job = jobcontrol.launch_job(args) jobs.append(job) outfiles = [] for job in jobs: job.wait() if job.succeeded(): outfiles.append(job.getOutputFiles()) else: raise RuntimeError( 'ProteinPreparationWizard failed with {}'.format( job.ExitStatus)) return outfiles
def mini(structures, frozen_atoms=None, fix_torsions=None): """ Takes many structures, minimizes them and returns the minimized structures. It's faster to do multiple structures at once. Arguments --------- structure : list of Schrödinger structure Returns ------- list of Schrödinger structure """ import schrodinger.application.macromodel.utils as mmodutils import schrodinger.job.jobcontrol as jobcontrol from setup_com_from_mae import MyComUtil print(' - ATTEMPTING MINI') sch_writer = sch_struct.StructureWriter('TEMP.mae') sch_writer.extend(structures) sch_writer.close() # Setup the minimization. com_setup = MyComUtil() com_setup.my_mini( mae_file='TEMP.mae', com_file='TEMP.com', out_file='TEMP_OUT.mae', frozen_atoms=frozen_atoms, fix_torsions=fix_torsions) command = ['bmin', '-WAIT', 'TEMP'] # Run the minimization. job = jobcontrol.launch_job(command) job.wait() # Read the minimized structures. sch_reader = sch_struct.StructureReader('TEMP_OUT.mae') new_structures = [] for structure in sch_reader: new_structures.append(structure) sch_reader.close() if len(new_structures) > 0: print(' - MINI SUCCEEDED') structures = [new_structures[0]] else: print(' - MINI FAILED. CONTINUING W/O MINI') if DEBUG: raw_input('Press any button to continue.') # Remove temporary files. os.remove('TEMP.mae') os.remove('TEMP.com') os.remove('TEMP_OUT.mae') os.remove('TEMP.log') return structures
def mcmm(structures, frozen_atoms=None): """ Takes many structures, and does a short MCMM search on them. Arguments --------- structure : list of Schrödinger structure Returns ------- list of Schrödinger structure """ import schrodinger.application.macromodel.utils as mmodutils import schrodinger.job.jobcontrol as jobcontrol from setup_com_from_mae import MyComUtil print(' - ATTEMPTING MCMM') sch_writer = sch_struct.StructureWriter('TEMP.mae') sch_writer.extend(structures) sch_writer.close() com_setup = MyComUtil() com_setup.my_mcmm( mae_file='TEMP.mae', com_file='TEMP.com', out_file='TEMP_OUT.mae', nsteps=50, frozen_atoms=frozen_atoms) command = ['bmin', '-WAIT', 'TEMP'] job = jobcontrol.launch_job(command) job.wait() sch_reader = sch_struct.StructureReader('TEMP_OUT.mae') new_structures = [] for structure in sch_reader: new_structures.append(structure) sch_reader.close() if len(new_structures) > 0: print(' - MCMM SUCCEEDED') structures = [new_structures[0]] else: print(' - MCMM FAILED. CONTINUING W/O MCMM') if DEBUG: raw_input('Press any button to continue.') # Remove temporary files. os.remove('TEMP.mae') os.remove('TEMP.com') os.remove('TEMP_OUT.mae') os.remove('TEMP.log') return structures
def mcmm(structures, frozen_atoms=None): """ Takes many structures, and does a short MCMM search on them. Arguments --------- structure : list of Schrödinger structure Returns ------- list of Schrödinger structure """ import schrodinger.application.macromodel.utils as mmodutils import schrodinger.job.jobcontrol as jobcontrol from setup_com_from_mae import MyComUtil print(' - ATTEMPTING MCMM') sch_writer = sch_struct.StructureWriter('TEMP.mae') sch_writer.extend(structures) sch_writer.close() com_setup = MyComUtil() com_setup.my_mcmm( mae_file='TEMP.mae', com_file='TEMP.com', out_file='TEMP_OUT.mae', nsteps=50, frozen_atoms=frozen_atoms) command = ['bmin', '-WAIT', 'TEMP'] job = jobcontrol.launch_job(command) job.wait() sch_reader = sch_struct.StructureReader('TEMP_OUT.mae') new_structures = [] for structure in sch_reader: new_structures.append(structure) sch_reader.close() if len(new_structures) > 0: print(' - MCMM SUCCEEDED') structures = [new_structures[0]] else: print(' - MCMM FAILED. CONTINUING W/O MCMM') if DEBUG: raw_input('Press any button to continue.') # Remove temporary files. os.remove('TEMP.mae') os.remove('TEMP.com') os.remove('TEMP_OUT.mae') os.remove('TEMP.log') return structures
def launch(cmd): ''' 使用jobcontrol启动一项job并等待结束 Parameters ---------- cmd: 等待执行的命令字符串 ''' cmd_list = cmd.split(' ') # launch_job以列表形式提交参数 job = jc.launch_job(cmd_list) print('JobId: %s' % job.JobId, end='\n') print('Job Name: %s' % job.Name, end='\n') print('Job Status: %s' % job.Status, end='\n') print('Job Running...') job.wait() # 阻塞进程 等待Job结束 print('\nJob %s Complete.\n' % job.Name)
def rmsd_individual(mae_file, ref_file): """ Calculate RMSD """ runner = [os.path.join(os.environ['SCHRODINGER'], 'run'), 'rmsd.py'] cmd = ["-use_neutral_scaffold", "-c", "rmsd_%s_vs_%s.csv" % (mae_file, os.path.basename(ref_file)), "-norenumber", "-m", "-verbose", # '-asl', "(chain.name H) AND NOT atom.ele H", mae_file, ref_file, '-HOST', "localhost:8"] try: job = jc.launch_job(runner + cmd) job.wait() print(job.getDuration()) print('Finish - %s' % job.Status) except: print('Something is wrong')
def homology_multirun(start, end): """ Homology building from separate fasta files in input from start to end file """ fasta_path = os.getcwd() current = os.getcwd() runner = [os.path.join(os.environ['SCHRODINGER'], 'run'), 'homology.py'] counter = 0 inp = [os.path.splitext(f)[0] for f in os.listdir(fasta_path) if os.path.splitext(f)[1] == '.fasta'] out = [f[:-10] for f in os.listdir(fasta_path) if f[-10:] == '_0-out.mae'] input = [f for f in inp if f not in out] # print "run job for %s files" % len(range(start, end)) for file in input[start:end]: counter += 1 os.mkdir('%s' % file) os.chdir('%s' % file) # print('Building %s (%s of %s)' % (file, counter, len(input[start:end]))) cmd = ['-i', os.path.join(fasta_path, '%s.fasta' % file), # input fasta '-n', '1', # Number of templates to use '-r', # Re-align sequences before building the model '-J', '%s' % file, # '-b', 'sort_key=gaps', '-p', 'BUILD_DELETIONS=false', 'BUILD_TRANSITIONS=false', 'KNOWLEDGE_BASED=false' ] try: job = jc.launch_job(runner + cmd) except: pass os.chdir(current) src = os.path.join(current, '%s' % file, '%s_0-out.mae' % file) dst = current try: shutil.copy(src, dst) except: pass
def rmsd_launch(ref_file, start): """ Calculate RMSD ref_file = "path/to/file" no ext! start calls the goal ASL """ mae_path = os.getcwd() runner = [os.path.join(os.environ['SCHRODINGER'], 'run'), 'rmsd.py'] asl_dict = {'loop': "(res.num 99-112) AND NOT atom.ele H", 'rmsd': "not (res.num 26-32,52-57,99-124) AND NOT atom.ele H"} counter = 0 for file in [f[:-10] for f in os.listdir(mae_path) if f[-10:] == '_0-out.mae']: counter += 1 # print('%s %s' % (counter, file)) cmd = ["-use_neutral_scaffold", "-c", "%s_%s.csv" % (start, file), "-norenumber", "-m", "-verbose", '-asl', "%s" % asl_dict[start], '%s.mae' % ref_file, os.path.join(mae_path, '%s_0-out.mae' % file) ] # job = jc.launch_job(runner + cmd) try: job = jc.launch_job(runner + cmd) job.wait() print(job.getDuration()) print('Finish - %s' % job.Status) except: pass
def start(self): """ Runs the enrichment calculation job and populates the text area with the results. """ pdb_code = str(self.ui.pdb_lineedit.text()) if not pdb_code.strip(): self.info("Please enter a four character pdb code.") return script_args = ['run', __file__, pdb_code] fo_fc = self.ui.fo_minus_fc_checkbox.isChecked() two_fo_fc = self.ui.two_fo_minus_fc_checkbox.isChecked() if fo_fc and two_fo_fc: script_args.extend(['-mapcoeff', 'both']) elif two_fo_fc and not fo_fc: script_args.extend(['-mapcoeff', '2FoFc']) elif fo_fc and not two_fo_fc: script_args.extend(['-mapcoeff', 'FoFc']) else: self.info("At least one map coeffient type must be checked.") return if self.ui.omit_ligands_checkbox.isChecked(): script_args.append('-omit_ligands') if self.ui.composite_radiobutton.isChecked(): script_args.extend(['-composite_omit', '5.0']) # Add -HOST, -DISP, -PROJ script_args.extend(self.jobparam.commandLineArgs()) job = jobcontrol.launch_job(script_args) self.monitorJob(job.job_id) return
keys.sort() lines = [] #Different methods availables by ConfGen to generate conformers methods = ['VERY_FAST', 'FAST', 'INTERMEDIATE', 'COMPREHENSIVE', 'FAST_CF', 'PHASE_FAST', 'PHASE_QUALITY'] for method in methods: for hetid in hetids: ligprep = path_to_ligprep + hetid + "_ligprep.mae" CWD = os.getcwd() os.chdir(path_to_ligprep) print hetid #Command to generate conformers by Confgen. Methods: -VERY_FAST; -FAST; -INTERMEDIATE; -COMPREHENSIVE; -FAST_CF; -PHASE_FAST; -PHASE_QUALITY confgen = os.path.join(os.environ['SCHRODINGER'], 'confgen') + " '-" + method + ",-MIN_OUT' " + os.path.basename(ligprep) job = jobcontrol.launch_job(confgen.split()) os.chdir(CWD) #Output of conformers conformers = output_CONFGEN + method +'/' if not os.path.isdir(conformers): os.makedirs(conformers) #Select CPU time from .log files. log = path_to_ligprep + hetid + "_ligprep.log" job.wait() filelog = open(log, 'rb') for line in filelog: lines.append(line) time_line = lines[-2] ctime = time_line.split('u')[0]