def check_structure_and_run_ndx_pc( ensemble, output_structure_path, input_structure_path, output_ndx_path, properties_makendx, input_gro_path, input_top_zip_path, output_tpr_path, properties_grompp, output_trr_path, output_gro_path, output_edr_path, output_xtc_path, output_log_path, properties_mdrun, **kwargs): try: dummy = bool(os.path.getsize(output_structure_path)) if not dummy: #if ensemble == "stateA": from shutil import copyfile copyfile(input_gro_path, output_gro_path) fu.write_failed_output(output_ndx_path) fu.write_failed_output(output_tpr_path) fu.write_failed_output(output_trr_path) fu.write_failed_output(output_edr_path) fu.write_failed_output(output_xtc_path) fu.write_failed_output(output_log_path) else: # step4_gmx_makendx make_ndx_pc(input_structure_path=input_structure_path, output_ndx_path=output_ndx_path, properties=properties_makendx) # step5_gmx_grompp grompp_ndx_pc(input_gro_path=input_gro_path, input_top_zip_path=input_top_zip_path, output_tpr_path=output_tpr_path, input_ndx_path=output_ndx_path, properties=properties_grompp) # step6_gmx_mdrun mdrun_pc(input_tpr_path=output_tpr_path, output_trr_path=output_trr_path, output_gro_path=output_gro_path, output_edr_path=output_edr_path, output_xtc_path=output_xtc_path, output_log_path=output_log_path, properties=properties_mdrun) except Exception as e: raise Exception( "Error ocurred while checking the file containing dummy atoms")
def main(config, system=None): start_time = time.time() conf = settings.ConfReader(config, system) global_log, _ = fu.get_logs(path=conf.get_working_dir_path(), light_format=True) global_prop = conf.get_prop_dic() global_paths = conf.get_paths_dic() for structure in conf.properties['input_structures'].split(','): prefix_str = os.path.basename(structure) prefix_str = prefix_str.replace('.', '_') mut_prop = conf.get_prop_dic(prefix=prefix_str) mut_paths = conf.get_paths_dic(prefix=prefix_str) global_log.info("Starting setup process for PDB: " + prefix_str) mut_paths['step1_pdb2gmx']['input_pdb_path'] = structure global_log.info("step1_pdb2gmx: Generate the topology") pdb2gmx_pc(**mut_paths["step1_pdb2gmx"], properties=mut_prop["step1_pdb2gmx"]) global_log.info("step2_editconf: Create the solvent box") editconf_pc(**mut_paths["step2_editconf"], properties=mut_prop["step2_editconf"]) global_log.info( "step3_solvate: Fill the solvent box with water molecules") solvate_pc(**mut_paths["step3_solvate"], properties=mut_prop["step3_solvate"]) global_log.info("step4_grompp_genion: Preprocess ion generation") grompp_pc(**mut_paths["step4_grompp_genion"], properties=mut_prop["step4_grompp_genion"]) global_log.info("step5_genion: Ion generation") genion_pc(**mut_paths["step5_genion"], properties=mut_prop["step5_genion"]) global_log.info("step6_grompp_min: Preprocess energy minimization") grompp_pc(**mut_paths["step6_grompp_min"], properties=mut_prop["step6_grompp_min"]) global_log.info("step7_mdrun_min: Execute energy minimization") mdrun_pc(**mut_paths["step7_mdrun_min"], properties=mut_prop["step7_mdrun_min"]) global_log.info("step8_make_ndx: Generate GROMACS index file") make_ndx_pc(**mut_paths["step8_make_ndx"], properties=mut_prop["step8_make_ndx"]) global_log.info( "step9_grompp_nvt: Preprocess system temperature equilibration") grompp_ndx_pc(**mut_paths["step9_grompp_nvt"], properties=mut_prop["step9_grompp_nvt"]) global_log.info( "step10_mdrun_nvt: Execute system temperature equilibration") mdrun_pc(**mut_paths["step10_mdrun_nvt"], properties=mut_prop["step10_mdrun_nvt"]) global_log.info( "step11_grompp_npt: Preprocess system pressure equilibration") grompp_ndx_pc(**mut_paths["step11_grompp_npt"], properties=mut_prop["step11_grompp_npt"]) global_log.info( "step12_mdrun_npt: Execute system pressure equilibration") mdrun_pc(**mut_paths["step12_mdrun_npt"], properties=mut_prop["step12_mdrun_npt"]) global_log.info("step13_grompp_md: Preprocess free dynamics") grompp_ndx_pc(**mut_paths["step13_grompp_md"], properties=mut_prop["step13_grompp_md"]) global_log.info( "step14_mdrun_md: Execute free molecular dynamics simulation") mdrun_pc(**mut_paths["step14_mdrun_md"], properties=mut_prop["step14_mdrun_md"]) elapsed_time = time.time() - start_time global_log.info('') global_log.info('') global_log.info('Execution successful: ') global_log.info(' Workflow_path: %s' % conf.get_working_dir_path()) global_log.info(' Config File: %s' % config) if system: global_log.info(' System: %s' % system) global_log.info('') global_log.info('Elapsed time: %.1f minutes' % (elapsed_time / 60)) global_log.info('')
def main(config, system=None): start_time = time.time() conf = settings.ConfReader(config, system) global_log, _ = fu.get_logs(path=conf.get_working_dir_path(), light_format=True) global_prop = conf.get_prop_dic() global_paths = conf.get_paths_dic() dhdl_paths_listA = [] dhdl_paths_listB = [] for ensemble, mutation in conf.properties['mutations'].items(): ensemble_prop = conf.get_prop_dic(prefix=ensemble) ensemble_paths = conf.get_paths_dic(prefix=ensemble) # step0_image global_log.info( ensemble + " Step 0: gmx image: Imaging trajectories to remove PBC issues") ensemble_paths['step0_image']['input_traj_path'] = conf.properties[ 'input_trajs'][ensemble]['input_traj_path'] ensemble_paths['step0_image']['input_top_path'] = conf.properties[ 'input_trajs'][ensemble]['input_tpr_path'] gmx_image_pc(**ensemble_paths["step0_image"], properties=ensemble_prop["step0_image"]) # step1_trjconv global_log.info( ensemble + " Step 1: gmx trjconv: Extract snapshots from equilibrium trajectories" ) ensemble_paths['step1_trjconv_' + ensemble]['input_top_path'] = conf.properties[ 'input_trajs'][ensemble]['input_tpr_path'] gmx_trjconv_str_ens_pc(**ensemble_paths['step1_trjconv_' + ensemble], properties=ensemble_prop['step1_trjconv_' + ensemble]) for ensemble, mutation in conf.properties['mutations'].items(): ensemble_prop = conf.get_prop_dic(prefix=ensemble) ensemble_paths = conf.get_paths_dic(prefix=ensemble) compss_wait_on_file(ensemble_paths['step1_trjconv_' + ensemble]["output_str_ens_path"]) with zipfile.ZipFile( ensemble_paths['step1_trjconv_' + ensemble]["output_str_ens_path"]) as zip_f: unique_dir = os.path.abspath( fu.create_unique_dir( prefix=ensemble_prop['step1_trjconv_' + ensemble]['working_dir_path'] + '/' + ensemble + '/')) zip_f.extractall(unique_dir) state_pdb_list = [ os.path.join(unique_dir, name) for name in zip_f.namelist() ] for pdb_path in state_pdb_list: pdb_name = os.path.splitext(os.path.basename(pdb_path))[0] prop = conf.get_prop_dic(prefix=os.path.join(ensemble, pdb_name)) paths = conf.get_paths_dic(prefix=os.path.join(ensemble, pdb_name)) # Fixing terminal residues newpdb2 = pdb_path + ".term.gro" #cmd2 = "sed 's/600ASN /600NASN/g' " + pdb_path + "| sed 's/ 1SER / 1NSER /g' | sed 's/597ASP /597CASP/g' | sed 's/793PRO /793CPRO/g' | sed 's/HIS /HIE /g' > " + newpdb2 cmd2 = "sed 's/600ASN /600NASN/g' " + pdb_path + "| sed 's/ 1SER / 1NSER /g' | sed 's/597ASP /597CASP/g' | sed 's/793PRO /793CPRO/g' > " + newpdb2 subprocess.call(cmd2, shell=True) paths['step1_pmx_mutate']['input_structure_path'] = newpdb2 # step1_pmx_mutate global_log.info(ensemble + " " + pdb_name + " Step 1: pmx mutate: Generate Hybrid Structure") prop['step1_pmx_mutate']['mutation_list'] = mutation mutate_pc(**paths["step1_pmx_mutate"], properties=prop["step1_pmx_mutate"]) # step1.1_check_dummies global_log.info(ensemble + " " + pdb_name + " Step 1.1 Check for dummy atoms") extract_atoms_pc(**paths['step1.1_check_dummies'], properties=prop['step1.1_check_dummies']) compss_wait_on_file( paths['step1.1_check_dummies']['output_structure_path']) try: dummy = bool( os.path.getsize(paths['step1.1_check_dummies'] ['output_structure_path'])) except: global_log.info( "Error ocurred while checking the file containing dummy atoms" ) global_log.info(sys.exc_info()[0]) # step1.2_remove_ligand #global_log.info(ensemble + " " + pdb_name + " Step 1.2 Remove ligand") #remove_ligand_pc(**paths['step1.2_remove_ligand'], properties=prop['step1.2_remove_ligand']) # step2_gmx_pdb2gmx global_log.info(ensemble + " " + pdb_name + " Step 2: gmx pdb2gmx: Generate Topology") pdb2gmx_pc(**paths["step2_gmx_pdb2gmx"], properties=prop["step2_gmx_pdb2gmx"]) # step2.1_sort_gro #global_log.info(ensemble + " " + pdb_name + " Step 2.1 Sort gro residues") #sort_gro_residues_pc(**paths['step2.1_sort_gro'], properties=prop['step2.1_sort_gro']) # step2.2_lig_gmx_appendLigand #global_log.info(ensemble + " " + pdb_name +" Step 2.2_lig: gmx appendLigand: Append a ligand to a GROMACS topology") #append_ligand_pc(**paths["step2.2_lig_gmx_appendLigand"], properties=prop["step2.2_lig_gmx_appendLigand"]) # step3_pmx_gentop global_log.info(ensemble + " " + pdb_name + " Step 3: pmx gentop: Generate Hybrid Topology") gentop_pc(**paths["step3_pmx_gentop"], properties=prop["step3_pmx_gentop"]) if not dummy: paths['step7_gmx_grompp']['input_gro_path'] = paths[ 'step2_gmx_pdb2gmx']['output_gro_path'] else: # step4_gmx_makendx global_log.info( ensemble + " " + pdb_name + " Step 4 (Dummies): gmx make_ndx: Generate Gromacs Index file to select atoms to freeze" ) make_ndx_pc(**paths["step4_gmx_makendx"], properties=prop["step4_gmx_makendx"]) # step5_gmx_grompp global_log.info( ensemble + " " + pdb_name + " Step 5 (Dummies): gmx grompp: Creating portable binary run file for energy minimization" ) grompp_ndx_pc(**paths["step5_gmx_grompp"], properties=prop["step5_gmx_grompp"]) # step6_gmx_mdrun global_log.info( ensemble + " " + pdb_name + " Step 6 (Dummies): gmx mdrun: Running energy minimization" ) mdrun_pc(**paths["step6_gmx_mdrun"], properties=prop["step6_gmx_mdrun"]) # step7_gmx_grompp global_log.info( ensemble + " " + pdb_name + " Step 7: gmx grompp: Creating portable binary run file for system equilibration" ) grompp_pc(**paths["step7_gmx_grompp"], properties=prop["step7_gmx_grompp"]) # step8_gmx_mdrun global_log.info(ensemble + " " + pdb_name + " Step 8: gmx mdrun: Running system equilibration") mdrun_pc(**paths["step8_gmx_mdrun"], properties=prop["step8_gmx_mdrun"]) # step9_gmx_grompp global_log.info( ensemble + " " + pdb_name + " Step 9: Creating portable binary run file for thermodynamic integration (ti)" ) grompp_pc(**paths["step9_gmx_grompp"], properties=prop["step9_gmx_grompp"]) # step10_gmx_mdrun global_log.info( ensemble + " " + pdb_name + " Step 10: gmx mdrun: Running thermodynamic integration") mdrun_dhdl_pc(**paths["step10_gmx_mdrun"], properties=prop["step10_gmx_mdrun"]) if ensemble == "stateA": dhdl_paths_listA.append( paths["step10_gmx_mdrun"]["output_dhdl_path"]) elif ensemble == "stateB": dhdl_paths_listB.append( paths["step10_gmx_mdrun"]["output_dhdl_path"]) # Creating zip file containing all the dhdl files dhdlA_path = os.path.join( global_prop["step11_pmx_analyse"]['working_dir_path'], 'dhdlA.zip') dhdlB_path = os.path.join( global_prop["step11_pmx_analyse"]['working_dir_path'], 'dhdlB.zip') for dhdl_file in dhdl_paths_listA: compss_wait_on_file(dhdl_file) for dhdl_file in dhdl_paths_listB: compss_wait_on_file(dhdl_file) fu.zip_list(dhdlA_path, dhdl_paths_listA) fu.zip_list(dhdlB_path, dhdl_paths_listB) # step11_pmx_analyse global_log.info( ensemble + " Step 11: pmx analyse: Calculate free energies from fast growth thermodynamic integration simulations" ) global_paths["step11_pmx_analyse"]["input_a_xvg_zip_path"] = dhdlA_path global_paths["step11_pmx_analyse"]["input_b_xvg_zip_path"] = dhdlB_path analyse_pc(**global_paths["step11_pmx_analyse"], properties=global_prop["step11_pmx_analyse"]) elapsed_time = time.time() - start_time global_log.info('') global_log.info('') global_log.info('Execution successful: ') global_log.info(' Workflow_path: %s' % conf.get_working_dir_path()) global_log.info(' Config File: %s' % config) if system: global_log.info(' System: %s' % system) global_log.info('') global_log.info('Elapsed time: %.1f minutes' % (elapsed_time / 60)) global_log.info('')
def main(config, imaged_traj_available): start_time = time.time() conf = settings.ConfReader(config) global_log, _ = fu.get_logs(path=conf.get_working_dir_path(), light_format=True) global_prop = conf.get_prop_dic() global_paths = conf.get_paths_dic() dhdl_paths_listA = [] dhdl_paths_listB = [] for ensemble, mutation in conf.properties['mutations'].items(): ensemble_prop = conf.get_prop_dic(prefix=ensemble) ensemble_paths = conf.get_paths_dic(prefix=ensemble) if not imaged_traj_available: # step0_image There isn't an imaged trajectory global_log.info( ensemble + " Step 0: gmx image: Imaging trajectories to remove PBC issues" ) ensemble_paths['step0_image']['input_top_path'] = conf.properties[ 'input_trajs'][ensemble]['input_tpr_path'] ensemble_paths['step0_image']['input_traj_path'] = conf.properties[ 'input_trajs'][ensemble]['input_traj_path'] gmx_image_pc(**ensemble_paths["step0_image"], properties=ensemble_prop["step0_image"]) else: # An imaged trajectory is available ensemble_paths['step1_trjconv_' + ensemble]['input_traj_path'] = conf.properties[ 'input_trajs'][ensemble]['input_traj_path'] # step1_trjconv global_log.info( ensemble + " Step 1: gmx trjconv: Extract snapshots from equilibrium trajectories" ) ensemble_paths['step1_trjconv_' + ensemble]['input_top_path'] = conf.properties[ 'input_trajs'][ensemble]['input_tpr_path'] gmx_trjconv_str_ens_pc(**ensemble_paths['step1_trjconv_' + ensemble], properties=ensemble_prop['step1_trjconv_' + ensemble]) for ensemble, mutation in conf.properties['mutations'].items(): ensemble_prop = conf.get_prop_dic(prefix=ensemble) ensemble_paths = conf.get_paths_dic(prefix=ensemble) compss_wait_on_file(ensemble_paths['step1_trjconv_' + ensemble]["output_str_ens_path"]) with zipfile.ZipFile( ensemble_paths['step1_trjconv_' + ensemble]["output_str_ens_path"]) as zip_f: unique_dir = os.path.abspath( fu.create_unique_dir( prefix=ensemble_prop['step1_trjconv_' + ensemble]['working_dir_path'] + '/' + ensemble + '/')) zip_f.extractall(unique_dir) state_pdb_list = [ os.path.join(unique_dir, name) for name in zip_f.namelist() ] for pdb_path in state_pdb_list: pdb_name = os.path.splitext(os.path.basename(pdb_path))[0] prop = conf.get_prop_dic(prefix=os.path.join(ensemble, pdb_name)) paths = conf.get_paths_dic(prefix=os.path.join(ensemble, pdb_name)) # step2_pmx_mutate global_log.info(ensemble + " " + pdb_name + " Step 2: pmx mutate: Generate Hybrid Structure") paths['step2_pmx_mutate']['input_structure_path'] = pdb_path prop['step2_pmx_mutate']['mutation_list'] = mutation mutate_pc(**paths["step2_pmx_mutate"], properties=prop["step2_pmx_mutate"]) # step3_check_dummies global_log.info(ensemble + " " + pdb_name + " Step 3 Check for dummy atoms") extract_atoms_pc(**paths['step3_check_dummies'], properties=prop['step3_check_dummies']) compss_wait_on_file( paths['step3_check_dummies']['output_structure_path']) try: dummy = bool( os.path.getsize( paths['step3_check_dummies']['output_structure_path'])) except: global_log.info( "Error ocurred while checking the file containing dummy atoms" ) global_log.info(sys.exc_info()[0]) # step4_gmx_pdb2gmx global_log.info(ensemble + " " + pdb_name + " Step 4: gmx pdb2gmx: Generate Topology") pdb2gmx_pc(**paths["step4_gmx_pdb2gmx"], properties=prop["step4_gmx_pdb2gmx"]) # step5_pmx_gentop global_log.info(ensemble + " " + pdb_name + " Step 5: pmx gentop: Generate Hybrid Topology") gentop_pc(**paths["step5_pmx_gentop"], properties=prop["step5_pmx_gentop"]) if not dummy: paths['step9_gmx_grompp']['input_gro_path'] = paths[ 'step4_gmx_pdb2gmx']['output_gro_path'] else: # step6_gmx_makendx global_log.info( ensemble + " " + pdb_name + " Step 6: (Dummies): gmx make_ndx: Generate Gromacs Index file to select atoms to freeze" ) make_ndx_pc(**paths["step6_gmx_makendx"], properties=prop["step6_gmx_makendx"]) # step7_gmx_grompp global_log.info( ensemble + " " + pdb_name + " Step 7: (Dummies): gmx grompp: Creating portable binary run file for energy minimization" ) grompp_ndx_pc(**paths["step7_gmx_grompp"], properties=prop["step7_gmx_grompp"]) # step8_gmx_mdrun global_log.info( ensemble + " " + pdb_name + " Step 8: (Dummies): gmx mdrun: Running energy minimization" ) mdrun_pc(**paths["step8_gmx_mdrun"], properties=prop["step8_gmx_mdrun"]) # step9_gmx_grompp global_log.info( ensemble + " " + pdb_name + " Step 9: gmx grompp: Creating portable binary run file for system equilibration" ) grompp_pc(**paths["step9_gmx_grompp"], properties=prop["step9_gmx_grompp"]) # step10_gmx_mdrun global_log.info( ensemble + " " + pdb_name + " Step 10: gmx mdrun: Running system equilibration") mdrun_pc(**paths["step10_gmx_mdrun"], properties=prop["step10_gmx_mdrun"]) # step11_gmx_grompp global_log.info( ensemble + " " + pdb_name + " Step 11: Creating portable binary run file for thermodynamic integration (ti)" ) grompp_pc(**paths["step11_gmx_grompp"], properties=prop["step11_gmx_grompp"]) # step12_gmx_mdrun global_log.info( ensemble + " " + pdb_name + " Step 12: gmx mdrun: Running thermodynamic integration") mdrun_dhdl_pc(**paths["step12_gmx_mdrun"], properties=prop["step12_gmx_mdrun"]) if ensemble == "stateA": dhdl_paths_listA.append( paths["step12_gmx_mdrun"]["output_dhdl_path"]) elif ensemble == "stateB": dhdl_paths_listB.append( paths["step12_gmx_mdrun"]["output_dhdl_path"]) # Creating zip file containing all the dhdl files dhdlA_path = os.path.join( global_prop["step13_pmx_analyse"]['working_dir_path'], 'dhdlA.zip') dhdlB_path = os.path.join( global_prop["step13_pmx_analyse"]['working_dir_path'], 'dhdlB.zip') for dhdl_file in dhdl_paths_listA: compss_wait_on_file(dhdl_file) for dhdl_file in dhdl_paths_listB: compss_wait_on_file(dhdl_file) fu.zip_list(dhdlA_path, dhdl_paths_listA) fu.zip_list(dhdlB_path, dhdl_paths_listB) # step13_pmx_analyse global_log.info( ensemble + " Step 13: pmx analyse: Calculate free energies from fast growth thermodynamic integration simulations" ) global_paths["step13_pmx_analyse"]["input_a_xvg_zip_path"] = dhdlA_path global_paths["step13_pmx_analyse"]["input_b_xvg_zip_path"] = dhdlB_path analyse_pc(**global_paths["step13_pmx_analyse"], properties=global_prop["step13_pmx_analyse"]) elapsed_time = time.time() - start_time global_log.info('') global_log.info('') global_log.info('Execution successful: ') global_log.info(' Workflow_path: %s' % conf.get_working_dir_path()) global_log.info(' Config File: %s' % config) global_log.info('') global_log.info('Elapsed time: %.1f minutes' % (elapsed_time / 60)) global_log.info('')