Beispiel #1
0
    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
Beispiel #2
0
    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
Beispiel #3
0
    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
Beispiel #4
0
    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
Beispiel #5
0
    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
Beispiel #6
0
    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
Beispiel #7
0
    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
Beispiel #8
0
    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