def launch(self): """Launches the execution of the Open Babel module.""" # Get local loggers from launchlogger decorator out_log = getattr(self, 'out_log', None) err_log = getattr(self, 'err_log', None) # check input/output paths and parameters self.check_data_params(out_log, err_log) # Check the properties fu.check_properties(self, self.properties) if self.restart: output_file_list = [self.output_path_par, self.output_path_inp, self.output_path_top] if fu.check_complete_files(output_file_list): fu.log('Restart is enabled, this step: %s will the skipped' % self.step, out_log, self.global_log) return 0 # create unique name for temporary folder (created by acpype) self.unique_name = create_unique_name(6) # create command line instruction cmd = self.create_cmd(out_log, err_log) # execute cmd fu.log('Running %s, this execution can take a while' % self.acpype_path, out_log) returncode = cmd_wrapper.CmdWrapper(cmd, out_log, err_log, self.global_log).launch() # move files to output_path and removes temporary folder process_output(self.unique_name, self.basename + "." + self.unique_name + ".acpype", self.remove_tmp, self.basename, get_default_value(self.__class__.__name__), self.output_files, out_log) return returncode
def gmx_check(file_a: str, file_b: str, gmx: str = 'gmx') -> bool: print("Comparing GROMACS files:") print("FILE_A: %s" % str(Path(file_a).resolve())) print("FILE_B: %s" % str(Path(file_b).resolve())) check_result = 'check_result.out' cmd = [gmx, 'check'] if file_a.endswith(".tpr"): cmd.append('-s1') else: cmd.append('-f') cmd.append(file_a) if file_b.endswith(".tpr"): cmd.append('-s2') else: cmd.append('-f2') cmd.append(file_b) cmd.append('> check_result.out') cmd_wrapper.CmdWrapper(cmd).launch() print("Result file: %s" % str(Path(check_result).resolve())) with open(check_result) as check_file: for line_num, line in enumerate(check_file): if not line.startswith('comparing'): print('Discrepance found in line %d: %s' % (line_num, line)) return False return True
def launch(self) -> int: """Execute the :class:`FPocket <fpocket.fpocket.FPocket>` fpocket.fpocket.FPocket object.""" # Get local loggers from launchlogger decorator out_log = getattr(self, 'out_log', None) err_log = getattr(self, 'err_log', None) # check input/output paths and parameters self.check_data_params(out_log, err_log) # Check the properties fu.check_properties(self, self.properties) if self.restart: output_file_list = [self.io_dict["out"]["output_pockets_zip"],self.io_dict["out"]["output_summary"]] if fu.check_complete_files(output_file_list): fu.log('Restart is enabled, this step: %s will the skipped' % self.step, out_log, self.global_log) return 0 # create tmp_folder self.tmp_folder = fu.create_unique_dir() fu.log('Creating %s temporary folder' % self.tmp_folder, out_log) tmp_input = str(PurePath(self.tmp_folder).joinpath('input.pdb')) # copy input_pdb_path to tmp_folder shutil.copy(self.io_dict["in"]["input_pdb_path"], tmp_input) # create cmd cmd = [self.fpocket_path, '-f', tmp_input] # adding extra properties if self.min_radius: cmd.extend(['-m', str(self.min_radius)]) if self.max_radius: cmd.extend(['-M', str(self.max_radius)]) if self.num_spheres: cmd.extend(['-i', str(self.num_spheres)]) fu.log('Executing fpocket', out_log, self.global_log) cmd = fu.create_cmd_line(cmd, out_log=out_log, global_log=self.global_log) returncode = cmd_wrapper.CmdWrapper(cmd, out_log, err_log, self.global_log).launch() process_output_fpocket(self.tmp_folder, self.io_dict["out"]["output_pockets_zip"], self.io_dict["out"]["output_summary"], self.sort_by, self.remove_tmp, out_log, self.__class__.__name__) return returncode
def launch(self): """Launches the execution of the Open Babel module.""" # Get local loggers from launchlogger decorator out_log = getattr(self, 'out_log', None) err_log = getattr(self, 'err_log', None) # Check the properties fu.check_properties(self, self.properties) if self.restart: output_file_list = [self.output_path] if fu.check_complete_files(output_file_list): fu.log('Restart is enabled, this step: %s will the skipped' % self.step, out_log, self.global_log) return 0 # create command line instruction cmd = self.create_cmd(out_log, err_log) returncode = cmd_wrapper.CmdWrapper(cmd, out_log, err_log, self.global_log).launch() return returncode
def launch(self) -> int: """Execute the :class:`ExtractMolecule <utils.extract_molecule.ExtractMolecule>` utils.extract_molecule.ExtractMolecule object.""" self.io_dict['in']['input_structure_path'] = check_input_path(self.io_dict['in']['input_structure_path'], self.out_log, self.__class__.__name__) self.io_dict['out']['output_molecule_path'] = check_output_path(self.io_dict['out']['output_molecule_path'], self.out_log, self.__class__.__name__) # Setup Biobb if self.check_restart(): return 0 self.stage_files() # create temporary folder tmp_folder = fu.create_unique_dir() fu.log('Creating %s temporary folder' % tmp_folder, self.out_log) # create command list file command_list_file = self.create_command_list(tmp_folder + '/extract_prot.lst') # run command line cmd = [self.binary_path, '-i', self.io_dict['in']['input_structure_path'], '-o', self.io_dict['out']['output_molecule_path'], '--force_save', '--non_interactive', 'command_list', '--list', command_list_file] returncode: int = cmd_wrapper.CmdWrapper(cmd, self.out_log, self.err_log, self.global_log).launch() # Run Biobb block self.run_biobb() # Copy files to host self.copy_to_host() # Remove temporal files self.tmp_files.append(self.stage_io_dict.get("unique_dir")) self.remove_tmp_files() return self.return_code
def gmx_rms(file_a: str, file_b: str, file_tpr: str, gmx: str = 'gmx', tolerance: float = 0.5): print("Comparing GROMACS files:") print("FILE_A: %s" % str(Path(file_a).resolve())) print("FILE_B: %s" % str(Path(file_b).resolve())) rmsd_result = 'rmsd.xvg' cmd = [ 'echo', '\"Protein Protein\"', '|', gmx, 'rms', '-s', file_tpr, '-f', file_a, '-f2', file_b, '-xvg', 'none' ] cmd_wrapper.CmdWrapper(cmd).launch() print("Result file: %s" % str(Path(rmsd_result).resolve())) with open(rmsd_result) as check_file: for line in check_file: time_step, rmsd = tuple(line.strip().split()) if float(rmsd) > tolerance: print('RMSD: %s bigger than tolerance %g for time step %s' % (rmsd, tolerance, time_step)) return False return True
def get_gromacs_version(gmx: str = "gmx") -> int: """ Gets the GROMACS installed version and returns it as an int(3) for versions older than 5.1.5 and an int(5) for 20XX versions filling the gaps with '0' digits. Args: gmx (str): ('gmx') Path to the GROMACS binary. Returns: int: GROMACS version. """ unique_dir = fu.create_unique_dir() out_log, err_log = fu.get_logs(path=unique_dir, can_write_console=False) cmd = [gmx, "-version"] try: cmd_wrapper.CmdWrapper(cmd, out_log, err_log).launch() pattern = re.compile(r"GROMACS version:\s+(.+)") with open(Path(unique_dir).joinpath('log.out')) as log_file: for line in log_file: version_str = pattern.match(line.strip()) if version_str: break version = version_str.group(1).replace(".", "").replace("VERSION", "").strip() version = "".join([c for c in version if c.isdigit()]) except: return 0 if version.startswith("2"): while len(version) < 5: version += '0' else: while len(version) < 3: version += '0' fu.rm(unique_dir) return int(version)
def launch(self) -> int: """Launches the execution of the GROMACS solvate module.""" tmp_files = [] # Get local loggers from launchlogger decorator out_log = getattr(self, 'out_log', None) err_log = getattr(self, 'err_log', None) # Check GROMACS version if not self.container_path: if self.gmx_version < 512: raise GromacsVersionError( "Gromacs version should be 5.1.2 or newer %d detected" % self.gmx_version) fu.log( "GROMACS %s %d version detected" % (self.__class__.__name__, self.gmx_version), out_log) # Restart if needed if self.restart: if fu.check_complete_files(self.io_dict["out"].values()): fu.log( 'Restart is enabled, this step: %s will the skipped' % self.step, out_log, self.global_log) return 0 # Unzip topology to topology_out top_file = fu.unzip_top(zip_file=self.input_top_zip_path, out_log=out_log) top_dir = str(Path(top_file).parent) tmp_files.append(top_dir) container_io_dict = fu.copy_to_container(self.container_path, self.container_volume_path, self.io_dict) if self.container_path: shutil.copytree( top_dir, str( Path(container_io_dict.get("unique_dir")).joinpath( Path(top_dir).name))) top_file = str( Path(self.container_volume_path).joinpath( Path(top_dir).name, Path(top_file).name)) cmd = [ self.gmx_path, 'solvate', '-cp', container_io_dict["in"]["input_solute_gro_path"], '-cs', self.input_solvent_gro_path, '-o', container_io_dict["out"]["output_gro_path"], '-p', top_file ] new_env = None if self.gmxlib: new_env = os.environ.copy() new_env['GMXLIB'] = self.gmxlib cmd = fu.create_cmd_line( cmd, container_path=self.container_path, host_volume=container_io_dict.get("unique_dir"), container_volume=self.container_volume_path, container_working_dir=self.container_working_dir, container_user_uid=self.container_user_id, container_shell_path=self.container_shell_path, container_image=self.container_image, out_log=out_log, global_log=self.global_log) returncode = cmd_wrapper.CmdWrapper(cmd, out_log, err_log, self.global_log, new_env).launch() fu.copy_to_host(self.container_path, container_io_dict, self.io_dict) if self.container_path: top_file = str( Path(container_io_dict.get("unique_dir")).joinpath( Path(top_dir).name, Path(top_file).name)) # zip topology fu.log( 'Compressing topology to: %s' % container_io_dict["out"]["output_top_zip_path"], out_log, self.global_log) fu.zip_top(zip_file=self.io_dict["out"]["output_top_zip_path"], top_file=top_file, out_log=out_log) tmp_files.append(container_io_dict.get("unique_dir")) if self.remove_tmp: fu.rm_file_list(tmp_files, out_log=out_log) return returncode
def launch(self) -> int: """Launches the execution of the GROMACS make_ndx module.""" tmp_files = [] # Get local loggers from launchlogger decorator out_log = getattr(self, 'out_log', None) err_log = getattr(self, 'err_log', None) # Check GROMACS version if not self.container_path: if self.gmx_version < 512: raise GromacsVersionError( "Gromacs version should be 5.1.2 or newer %d detected" % self.gmx_version) fu.log( "GROMACS %s %d version detected" % (self.__class__.__name__, self.gmx_version), out_log) # Restart if needed if self.restart: if fu.check_complete_files(self.io_dict["out"].values()): fu.log( 'Restart is enabled, this step: %s will the skipped' % self.step, out_log, self.global_log) return 0 container_io_dict = fu.copy_to_container(self.container_path, self.container_volume_path, self.io_dict) cmd = [ 'echo', '-e', '\'' + self.selection + '\\nq' + '\'', '|', self.gmx_path, 'make_ndx', '-f', container_io_dict["in"]["input_structure_path"], '-o', container_io_dict["out"]["output_ndx_path"] ] if container_io_dict["in"].get("input_ndx_path")\ and Path(container_io_dict["in"].get("input_ndx_path")).exists(): cmd.append('-n') cmd.append(container_io_dict["in"].get("input_ndx_path")) new_env = None if self.gmxlib: new_env = os.environ.copy() new_env['GMXLIB'] = self.gmxlib cmd = fu.create_cmd_line( cmd, container_path=self.container_path, host_volume=container_io_dict.get("unique_dir"), container_volume=self.container_volume_path, container_working_dir=self.container_working_dir, container_user_uid=self.container_user_id, container_shell_path=self.container_shell_path, container_image=self.container_image, out_log=out_log, global_log=self.global_log) returncode = cmd_wrapper.CmdWrapper(cmd, out_log, err_log, self.global_log, new_env).launch() fu.copy_to_host(self.container_path, container_io_dict, self.io_dict) tmp_files.append(container_io_dict.get("unique_dir")) if self.remove_tmp: fu.rm_file_list(tmp_files, out_log=out_log) return returncode
def launch(self) -> int: """Launches the execution of the GROMACS pdb2gmx module.""" tmp_files = [] # Get local loggers from launchlogger decorator out_log = getattr(self, 'out_log', None) err_log = getattr(self, 'err_log', None) # Check GROMACS version if not self.container_path: if self.gmx_version < 512: raise GromacsVersionError( "Gromacs version should be 5.1.2 or newer %d detected" % self.gmx_version) fu.log( "GROMACS %s %d version detected" % (self.__class__.__name__, self.gmx_version), out_log) # Restart if needed if self.restart: if fu.check_complete_files(self.io_dict["out"].values()): fu.log( 'Restart is enabled, this step: %s will the skipped' % self.step, out_log, self.global_log) return 0 container_io_dict = fu.copy_to_container(self.container_path, self.container_volume_path, self.io_dict) output_top_path = fu.create_name(prefix=self.prefix, step=self.step, name=self.output_top_path) output_itp_path = fu.create_name(prefix=self.prefix, step=self.step, name=self.output_itp_path) cmd = [ self.gmx_path, "pdb2gmx", "-f", container_io_dict["in"]["input_pdb_path"], "-o", container_io_dict["out"]["output_gro_path"], "-p", output_top_path, "-water", self.water_type, "-ff", self.force_field, "-i", output_itp_path ] if self.his: cmd.append("-his") cmd = ['echo', self.his, '|'] + cmd if self.ignh: cmd.append("-ignh") new_env = None if self.gmxlib: new_env = os.environ.copy() new_env['GMXLIB'] = self.gmxlib cmd = fu.create_cmd_line( cmd, container_path=self.container_path, host_volume=container_io_dict.get("unique_dir"), container_volume=self.container_volume_path, container_working_dir=self.container_working_dir, container_user_uid=self.container_user_id, container_shell_path=self.container_shell_path, container_image=self.container_image, out_log=out_log, global_log=self.global_log) returncode = cmd_wrapper.CmdWrapper(cmd, out_log, err_log, self.global_log, new_env).launch() fu.copy_to_host(self.container_path, container_io_dict, self.io_dict) if self.container_path: output_top_path = os.path.join(container_io_dict.get("unique_dir"), output_top_path) # zip topology fu.log( 'Compressing topology to: %s' % container_io_dict["out"]["output_top_zip_path"], out_log, self.global_log) fu.zip_top(zip_file=self.io_dict["out"]["output_top_zip_path"], top_file=output_top_path, out_log=out_log) tmp_files.append(self.output_top_path) tmp_files.append(self.output_itp_path) tmp_files.append(container_io_dict.get("unique_dir")) if self.remove_tmp: fu.rm_file_list(tmp_files, out_log=out_log) return returncode
def launch(self): """Launches the execution of the template_container module.""" # Get local loggers from launchlogger decorator out_log = getattr(self, 'out_log', None) err_log = getattr(self, 'err_log', None) # Check the properties fu.check_properties(self, self.properties) # Restart if self.restart: # 4. Include here all output file paths output_file_list = [self.io_dict['out']['output_file_path']] if fu.check_complete_files(output_file_list): fu.log('Restart is enabled, this step: %s will the skipped' % self.step, out_log, self.global_log) return 0 # 5. Copy inputs to container container_io_dict = fu.copy_to_container(self.container_path, self.container_volume_path, self.io_dict) # 6. Prepare the command line parameters as instructions list instructions = ['-j'] if self.boolean_property: instructions.append('-v') fu.log('Appending optional boolean property', out_log, self.global_log) # 7. Build the actual command line as a list of items (elements order will be maintained) cmd = [self.executable_binary_property, ' '.join(instructions), container_io_dict['out']['output_file_path'], container_io_dict['in']['input_file_path1']] fu.log('Creating command line with instructions and required arguments', out_log, self.global_log) # 8. Repeat for optional input files if provided if container_io_dict['in']['input_file_path2']: # Append optional input_file_path2 to cmd cmd.append(container_io_dict['in']['input_file_path2']) fu.log('Appending optional argument to command line', out_log, self.global_log) # 9. Uncomment to check the command line # print(' '.join(cmd)) # 10. Create cmd with specdific syntax according to the required container cmd = fu.create_cmd_line(cmd, container_path=self.container_path, host_volume=container_io_dict.get('unique_dir'), container_volume=self.container_volume_path, container_working_dir=self.container_working_dir, container_user_uid=self.container_user_id, container_image=self.container_image, container_shell_path=self.container_shell_path, out_log=out_log, global_log=self.global_log) # Launch execution returncode = cmd_wrapper.CmdWrapper(cmd, out_log, err_log, self.global_log).launch() # Copy output(s) to output(s) path(s) in case of container execution fu.copy_to_host(self.container_path, container_io_dict, self.io_dict) # Remove temporary file(s) if self.remove_tmp and container_io_dict.get('unique_dir'): fu.rm(container_io_dict.get('unique_dir')) fu.log('Removed: %s' % str(container_io_dict.get('unique_dir')), out_log) return returncode
def launch(self) -> int: """Launches the execution of the GROMACS select module.""" tmp_files = [] # Get local loggers from launchlogger decorator out_log = getattr(self, 'out_log', None) err_log = getattr(self, 'err_log', None) # Check GROMACS version if not self.container_path: if self.gmx_version < 512: raise GromacsVersionError( "Gromacs version should be 5.1.2 or newer %d detected" % self.gmx_version) fu.log( "GROMACS %s %d version detected" % (self.__class__.__name__, self.gmx_version), out_log) # Restart if needed if self.restart: if fu.check_complete_files(self.io_dict["out"].values()): fu.log( 'Restart is enabled, this step: %s will the skipped' % self.step, out_log, self.global_log) return 0 container_io_dict = fu.copy_to_container(self.container_path, self.container_volume_path, self.io_dict) cmd = [ self.gmx_path, 'select', '-s', container_io_dict["in"]["input_structure_path"], '-on', container_io_dict["out"]["output_ndx_path"] ] if container_io_dict["in"].get("input_ndx_path") and pl.Path( container_io_dict["in"].get("input_ndx_path")).exists(): cmd.append('-n') cmd.append(container_io_dict["in"].get("input_ndx_path")) cmd.append('-select') cmd.append("\'" + self.selection + "\'") new_env = None if self.gmxlib: new_env = os.environ.copy() new_env['GMXLIB'] = self.gmxlib if self.container_path: if self.container_path.endswith('singularity'): fu.log('Using Singularity image %s' % self.container_image, out_log, self.global_log) cmd = [ self.container_path, 'exec', '--bind', container_io_dict.get("unique_dir") + ':' + self.container_volume_path, self.container_image, " ".join(cmd) ] elif self.container_path.endswith('docker'): fu.log('Using Docker image %s' % self.container_image, out_log, self.global_log) docker_cmd = [ self.container_path, 'run', ] if self.container_working_dir: docker_cmd.append('-w') docker_cmd.append(self.container_working_dir) if self.container_volume_path: docker_cmd.append('-v') docker_cmd.append( container_io_dict.get("unique_dir") + ':' + self.container_volume_path) if self.container_user_id: docker_cmd.append('--user') docker_cmd.append(self.container_user_id) docker_cmd.append(self.container_image) docker_cmd.append(" ".join(cmd)) cmd = docker_cmd returncode = cmd_wrapper.CmdWrapper(cmd, out_log, err_log, self.global_log, new_env).launch() fu.copy_to_host(self.container_path, container_io_dict, self.io_dict) tmp_files.append(container_io_dict.get("unique_dir")) if self.remove_tmp: fu.rm_file_list(tmp_files, out_log=out_log) return returncode
def launch(self) -> int: """Launches the execution of the GROMACS grompp module. Examples: This is a use example of how to use the Grommpp module from Python >>> from biobb_md.gromacs.grompp import Grompp >>> prop = { 'mdp':{ 'type': 'minimization', 'emtol':'500', 'nsteps':'5000'}} >>> Grompp(input_gro_path='/path/to/myStructure.gro', input_top_zip_path='/path/to/myTopology.zip', output_tpr_path='/path/to/NewCompiledBin.tpr', properties=prop).launch() """ tmp_files = [] mdout = 'mdout.mdp' tmp_files.append(mdout) # Get local loggers from launchlogger decorator out_log = getattr(self, 'out_log', None) err_log = getattr(self, 'err_log', None) # Check GROMACS version if not self.container_path: if self.gmx_version < 512: raise GromacsVersionError( "Gromacs version should be 5.1.2 or newer %d detected" % self.gmx_version) fu.log( "GROMACS %s %d version detected" % (self.__class__.__name__, self.gmx_version), out_log) # Restart if needed if self.restart: if fu.check_complete_files(self.io_dict["out"].values()): fu.log( 'Restart is enabled, this step: %s will the skipped' % self.step, out_log, self.global_log) return 0 # Unzip topology to topology_out top_file = fu.unzip_top(zip_file=self.input_top_zip_path, out_log=out_log) top_dir = str(Path(top_file).parent) tmp_files.append(top_dir) container_io_dict = fu.copy_to_container(self.container_path, self.container_volume_path, self.io_dict) if self.input_mdp_path: self.output_mdp_path = self.input_mdp_path else: mdp_dir = fu.create_unique_dir() tmp_files.append(mdp_dir) self.output_mdp_path = self.create_mdp( path=str(Path(mdp_dir).joinpath(self.output_mdp_path))) md = self.mdp.get('type', 'minimization') if md not in ('index', 'free'): fu.log('Will run a %s md of %s steps' % (md, self.nsteps), out_log, self.global_log) elif md == 'index': fu.log('Will create a TPR to be used as structure file') else: fu.log( 'Will run a %s md of %s' % (md, fu.human_readable_time( int(self.nsteps) * float(self.dt))), out_log, self.global_log) if self.container_path: fu.log('Container execution enabled', out_log) shutil.copy2(self.output_mdp_path, container_io_dict.get("unique_dir")) self.output_mdp_path = str( Path(self.container_volume_path).joinpath( Path(self.output_mdp_path).name)) shutil.copytree( top_dir, str( Path(container_io_dict.get("unique_dir")).joinpath( Path(top_dir).name))) top_file = str( Path(self.container_volume_path).joinpath( Path(top_dir).name, Path(top_file).name)) cmd = [ self.gmx_path, 'grompp', '-f', self.output_mdp_path, '-c', container_io_dict["in"]["input_gro_path"], '-r', container_io_dict["in"]["input_gro_path"], '-p', top_file, '-o', container_io_dict["out"]["output_tpr_path"], '-po', mdout, '-maxwarn', self.maxwarn ] if container_io_dict["in"].get("input_cpt_path") and Path( container_io_dict["in"]["input_cpt_path"]).exists(): cmd.append('-t') if self.container_path: shutil.copy2(container_io_dict["in"]["input_cpt_path"], container_io_dict.get("unique_dir")) cmd.append( str( Path(self.container_volume_path).joinpath( Path(container_io_dict["in"] ["input_cpt_path"]).name))) else: cmd.append(container_io_dict["in"]["input_cpt_path"]) if container_io_dict["in"].get("input_ndx_path") and Path( container_io_dict["in"]["input_ndx_path"]).exists(): cmd.append('-n') if self.container_path: shutil.copy2(container_io_dict["in"]["input_ndx_path"], container_io_dict.get("unique_dir")) cmd.append( Path(self.container_volume_path).joinpath( Path(container_io_dict["in"]["input_ndx_path"]).name)) else: cmd.append(container_io_dict["in"]["input_ndx_path"]) new_env = None if self.gmxlib: new_env = os.environ.copy() new_env['GMXLIB'] = self.gmxlib cmd = fu.create_cmd_line( cmd, container_path=self.container_path, host_volume=container_io_dict.get("unique_dir"), container_volume=self.container_volume_path, container_working_dir=self.container_working_dir, container_user_uid=self.container_user_id, container_shell_path=self.container_shell_path, container_image=self.container_image, out_log=out_log, global_log=self.global_log) returncode = cmd_wrapper.CmdWrapper(cmd, out_log, err_log, self.global_log, new_env).launch() fu.copy_to_host(self.container_path, container_io_dict, self.io_dict) tmp_files.append(container_io_dict.get("unique_dir")) if self.remove_tmp: fu.rm_file_list(tmp_files, out_log=out_log) return returncode
def launch(self) -> int: """Launches the execution of the GROMACS editconf module.""" tmp_files = [] # Get local loggers from launchlogger decorator out_log = getattr(self, 'out_log', None) err_log = getattr(self, 'err_log', None) # Check GROMACS version if not self.container_path: if self.gmx_version < 512: raise GromacsVersionError( "Gromacs version should be 5.1.2 or newer %d detected" % self.gmx_version) fu.log( "GROMACS %s %d version detected" % (self.__class__.__name__, self.gmx_version), out_log) # Restart if needed if self.restart: if fu.check_complete_files(self.io_dict["out"].values()): fu.log( 'Restart is enabled, this step: %s will the skipped' % self.step, out_log, self.global_log) return 0 container_io_dict = fu.copy_to_container(self.container_path, self.container_volume_path, self.io_dict) cmd = [ self.gmx_path, 'editconf', '-f', container_io_dict["in"]["input_gro_path"], '-o', container_io_dict["out"]["output_gro_path"], '-d', str(self.distance_to_molecule), '-bt', self.box_type ] if self.center_molecule: cmd.append('-c') fu.log('Centering molecule in the box.', out_log, self.global_log) fu.log( "Distance of the box to molecule: %6.2f" % self.distance_to_molecule, out_log, self.global_log) fu.log("Box type: %s" % self.box_type, out_log, self.global_log) new_env = None if self.gmxlib: new_env = os.environ.copy() new_env['GMXLIB'] = self.gmxlib cmd = fu.create_cmd_line( cmd, container_path=self.container_path, host_volume=container_io_dict.get("unique_dir"), container_volume=self.container_volume_path, container_working_dir=self.container_working_dir, container_user_uid=self.container_user_id, container_shell_path=self.container_shell_path, container_image=self.container_image, out_log=out_log, global_log=self.global_log) returncode = cmd_wrapper.CmdWrapper(cmd, out_log, err_log, self.global_log, new_env).launch() fu.copy_to_host(self.container_path, container_io_dict, self.io_dict) tmp_files.append(container_io_dict.get("unique_dir")) if self.remove_tmp: fu.rm_file_list(tmp_files, out_log=out_log) return returncode
def launch(self) -> int: """Launches the execution of the GROMACS mdrun module.""" tmp_files = [] # Get local loggers from launchlogger decorator out_log = getattr(self, 'out_log', None) err_log = getattr(self, 'err_log', None) # Check GROMACS version if (not self.mpi_bin) and (not self.container_path): if self.gmx_version < 512: raise GromacsVersionError( "Gromacs version should be 5.1.2 or newer %d detected" % self.gmx_version) fu.log( "GROMACS %s %d version detected" % (self.__class__.__name__, self.gmx_version), out_log) # Restart if needed if self.restart: if fu.check_complete_files(self.io_dict["out"].values()): fu.log( 'Restart is enabled, this step: %s will the skipped' % self.step, out_log, self.global_log) return 0 container_io_dict = fu.copy_to_container(self.container_path, self.container_volume_path, self.io_dict) cmd = [ self.gmx_path, 'mdrun', '-s', container_io_dict["in"]["input_tpr_path"], '-o', container_io_dict["out"]["output_trr_path"], '-c', container_io_dict["out"]["output_gro_path"], '-e', container_io_dict["out"]["output_edr_path"], '-g', container_io_dict["out"]["output_log_path"], '-nt', self.num_threads ] if self.use_gpu: cmd += ["-nb", "gpu", "-pme", "gpu"] if self.mpi_bin: mpi_cmd = [self.mpi_bin] if self.mpi_np: mpi_cmd.append('-np') mpi_cmd.append(str(self.mpi_np)) if self.mpi_hostlist: mpi_cmd.append('-hostfile') mpi_cmd.append(self.mpi_hostlist) cmd = mpi_cmd + cmd if container_io_dict["out"].get("output_xtc_path"): cmd.append('-x') cmd.append(container_io_dict["out"]["output_xtc_path"]) if container_io_dict["out"].get("output_cpt_path"): cmd.append('-cpo') cmd.append(container_io_dict["out"]["output_cpt_path"]) if container_io_dict["out"].get("output_dhdl_path"): cmd.append('-dhdl') cmd.append(container_io_dict["out"]["output_dhdl_path"]) new_env = None if self.gmxlib: new_env = os.environ.copy() new_env['GMXLIB'] = self.gmxlib cmd = fu.create_cmd_line( cmd, container_path=self.container_path, host_volume=container_io_dict.get("unique_dir"), container_volume=self.container_volume_path, container_working_dir=self.container_working_dir, container_user_uid=self.container_user_id, container_shell_path=self.container_shell_path, container_image=self.container_image, out_log=out_log, global_log=self.global_log) returncode = cmd_wrapper.CmdWrapper(cmd, out_log, err_log, self.global_log, new_env).launch() fu.copy_to_host(self.container_path, container_io_dict, self.io_dict) tmp_files.append(container_io_dict.get("unique_dir")) if self.remove_tmp: fu.rm_file_list(tmp_files, out_log=out_log) return returncode
def launch(self): """Launches the execution of the template module.""" # Get local loggers from launchlogger decorator out_log = getattr(self, 'out_log', None) err_log = getattr(self, 'err_log', None) # Check the properties fu.check_properties(self, self.properties) # Restart if self.restart: # 4. Include here all output file paths output_file_list = [self.io_dict['out']['output_file_path']] if fu.check_complete_files(output_file_list): fu.log( 'Restart is enabled, this step: %s will the skipped' % self.step, out_log, self.global_log) return 0 # Creating temporary folder self.tmp_folder = fu.create_unique_dir() fu.log('Creating %s temporary folder' % self.tmp_folder, out_log) # 5. Include here all mandatory input files # Copy input_file_path1 to temporary folder shutil.copy(self.io_dict['in']['input_file_path1'], self.tmp_folder) # 6. Prepare the command line parameters as instructions list instructions = ['-j'] if self.boolean_property: instructions.append('-v') fu.log('Appending optional boolean property', out_log, self.global_log) # 7. Build the actual command line as a list of items (elements order will be maintained) cmd = [ self.executable_binary_property, ' '.join(instructions), self.io_dict['out']['output_file_path'], str( PurePath(self.tmp_folder).joinpath( PurePath(self.io_dict['in']['input_file_path1']).name)) ] fu.log( 'Creating command line with instructions and required arguments', out_log, self.global_log) # 8. Repeat for optional input files if provided if self.io_dict['in']['input_file_path2']: # Copy input_file_path2 to temporary folder shutil.copy(self.io_dict['in']['input_file_path2'], self.tmp_folder) # Append optional input_file_path2 to cmd cmd.append( str( PurePath(self.tmp_folder).joinpath( PurePath( self.io_dict['in']['input_file_path2']).name))) fu.log('Appending optional argument to command line', out_log, self.global_log) # 9. Uncomment to check the command line # print(' '.join(cmd)) # Launch execution returncode = cmd_wrapper.CmdWrapper(cmd, out_log, err_log, self.global_log).launch() # Remove temporary file(s) if self.remove_tmp: fu.rm(self.tmp_folder) fu.log('Removed: %s' % str(self.tmp_folder), out_log) return returncode