Пример #1
0
    def launch(self) -> int:
        """Execute the :class:`Gmxselect <gromacs.gmxselect.Gmxselect>` object."""

        # Setup Biobb
        if self.check_restart(): return 0
        self.stage_files()

        self.cmd = [
            self.gmx_path, 'select', '-s',
            self.stage_io_dict["in"]["input_structure_path"], '-on',
            self.stage_io_dict["out"]["output_ndx_path"]
        ]

        if self.stage_io_dict["in"].get("input_ndx_path") and Path(
                self.stage_io_dict["in"].get("input_ndx_path")).exists():
            self.cmd.append('-n')
            self.cmd.append(self.stage_io_dict["in"].get("input_ndx_path"))

        self.cmd.append('-select')
        self.cmd.append("\'" + self.selection + "\'")

        if self.gmx_lib:
            self.environment = os.environ.copy()
            self.environment['GMXLIB'] = self.gmx_lib

        # 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), self.out_log)

        # Run Biobb block
        self.run_biobb()

        # Copy files to host
        self.copy_to_host()

        if self.io_dict["in"].get("input_ndx_path"):
            if self.append:
                fu.log(
                    f"Appending {self.io_dict['in'].get('input_ndx_path')} to {self.io_dict['out']['output_ndx_path']}",
                    self.out_log, self.global_log)
                with open(self.io_dict["out"]["output_ndx_path"],
                          'a') as out_ndx_file:
                    out_ndx_file.write('\n')
                    with open(self.io_dict["in"].get(
                            "input_ndx_path")) as in_ndx_file:
                        for line in in_ndx_file:
                            out_ndx_file.write(line)

        # Remove temporal files
        self.tmp_files.append(self.stage_io_dict.get("unique_dir"))
        self.remove_tmp_files()

        return self.return_code
Пример #2
0
    def launch(self) -> int:
        """Execute the :class:`Solvate <gromacs.solvate.Solvate>` object."""

        # Setup Biobb
        if self.check_restart(): return 0
        self.stage_files()

        # Unzip topology to topology_out
        top_file = fu.unzip_top(zip_file=self.input_top_zip_path, out_log=self.out_log)
        top_dir = str(Path(top_file).parent)

        if self.container_path:
            shutil.copytree(top_dir, str(Path(self.stage_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))

        self.cmd = [self.gmx_path, 'solvate',
                    '-cp', self.stage_io_dict["in"]["input_solute_gro_path"],
                    '-cs', self.stage_io_dict["in"]["input_solvent_gro_path"],
                    '-o', self.stage_io_dict["out"]["output_gro_path"],
                    '-p', top_file]

        if self.shell:
            self.cmd.append("-shell")
            self.cmd.append(str(self.shell))

        if self.gmx_lib:
            self.environment = os.environ.copy()
            self.environment['GMXLIB'] = self.gmx_lib

        # 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), self.out_log)

        # Run Biobb block
        self.run_biobb()

        # Copy files to host
        self.copy_to_host()

        if self.container_path:
            top_file = str(Path(self.stage_io_dict.get("unique_dir")).joinpath(Path(top_dir).name, Path(top_file).name))

        # zip topology
        fu.log('Compressing topology to: %s' % self.stage_io_dict["out"]["output_top_zip_path"], self.out_log,
               self.global_log)
        fu.zip_top(zip_file=self.io_dict["out"]["output_top_zip_path"], top_file=top_file, out_log=self.out_log)

        # Remove temporal files
        self.tmp_files.extend([self.stage_io_dict.get("unique_dir"), top_dir])
        self.remove_tmp_files()

        return self.return_code
Пример #3
0
    def launch(self) -> int:
        """Execute the :class:`Editconf <gromacs.editconf.Editconf>` object."""

        # Setup Biobb
        if self.check_restart(): return 0
        self.stage_files()

        # Create command line
        self.cmd = [
            self.gmx_path, 'editconf', '-f',
            self.stage_io_dict["in"]["input_gro_path"], '-o',
            self.stage_io_dict["out"]["output_gro_path"], '-d',
            str(self.distance_to_molecule), '-bt', self.box_type
        ]

        if self.center_molecule:
            self.cmd.append('-c')
            fu.log('Centering molecule in the box.', self.out_log,
                   self.global_log)

        fu.log(
            "Distance of the box to molecule: %6.2f" %
            self.distance_to_molecule, self.out_log, self.global_log)
        fu.log("Box type: %s" % self.box_type, self.out_log, self.global_log)

        if self.gmx_lib:
            self.environment = os.environ.copy()
            self.environment['GMXLIB'] = self.gmx_lib

        # 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), self.out_log)

        # 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
Пример #4
0
    def launch(self) -> int:
        """Execute the :class:`MakeNdx <gromacs.make_ndx.MakeNdx>` object."""

        # Setup Biobb
        if self.check_restart(): return 0
        self.stage_files()

        # Create command line
        self.cmd = [
            'echo', '-e', '\'' + self.selection + '\\nq' + '\'', '|',
            self.gmx_path, 'make_ndx', '-f',
            self.stage_io_dict["in"]["input_structure_path"], '-o',
            self.stage_io_dict["out"]["output_ndx_path"]
        ]

        if self.stage_io_dict["in"].get("input_ndx_path")\
                and Path(self.stage_io_dict["in"].get("input_ndx_path")).exists():
            self.cmd.append('-n')
            self.cmd.append(self.stage_io_dict["in"].get("input_ndx_path"))

        if self.gmx_lib:
            self.environment = os.environ.copy()
            self.environment['GMXLIB'] = self.gmx_lib

        # 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), self.out_log)

        # create_cmd_line and execute_command
        self.run_biobb()

        # Retrieve results
        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
Пример #5
0
    def launch(self) -> int:
        """Execute the :class:`Grompp <gromacs.grompp.Grompp>` object."""

        # Setup Biobb
        if self.check_restart(): return 0
        self.stage_files()

        self.cmd = ['echo', '\"'+self.restrained_group+'\"', '|',
                    self.gmx_path, "genrestr",
                    "-f", self.stage_io_dict["in"]["input_structure_path"],
                    "-o", self.stage_io_dict["out"]["output_itp_path"],
                    "-fc", self.force_constants]

        if self.stage_io_dict["in"].get("input_ndx_path"):
            self.cmd.append('-n')
            self.cmd.append(self.stage_io_dict["in"]["input_ndx_path"])

        if self.gmx_lib:
            self.environment = os.environ.copy()
            self.environment['GMXLIB'] = self.gmx_lib

        # 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), self.out_log)

        # 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
Пример #6
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
Пример #7
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
Пример #8
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
Пример #9
0
    def launch(self) -> int:
        """Execute the :class:`Grompp <gromacs.grompp.Grompp>` object."""

        # Setup Biobb
        if self.check_restart(): return 0
        self.stage_files()

        # Unzip topology to topology_out
        top_file = fu.unzip_top(zip_file=self.input_top_zip_path,
                                out_log=self.out_log)
        top_dir = str(Path(top_file).parent)

        # Create MDP file
        mdp_dir = fu.create_unique_dir()
        self.output_mdp_path = create_mdp(
            output_mdp_path=str(Path(mdp_dir).joinpath(self.output_mdp_path)),
            input_mdp_path=self.io_dict["in"]["input_mdp_path"],
            preset_dict=mdp_preset(self.simulation_type),
            mdp_properties_dict=self.mdp)

        # Copy extra files to container: MDP file and topology folder
        if self.container_path:
            fu.log('Container execution enabled', self.out_log)

            shutil.copy2(self.output_mdp_path,
                         self.stage_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(self.stage_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))

        self.cmd = [
            self.gmx_path, 'grompp', '-f', self.output_mdp_path, '-c',
            self.stage_io_dict["in"]["input_gro_path"], '-r',
            self.stage_io_dict["in"]["input_gro_path"], '-p', top_file, '-o',
            self.stage_io_dict["out"]["output_tpr_path"], '-po', 'mdout.mdp',
            '-maxwarn', self.maxwarn
        ]

        if self.stage_io_dict["in"].get("input_cpt_path") and Path(
                self.stage_io_dict["in"]["input_cpt_path"]).exists():
            self.cmd.append('-t')
            if self.container_path:
                shutil.copy2(self.stage_io_dict["in"]["input_cpt_path"],
                             self.stage_io_dict.get("unique_dir"))
                self.cmd.append(
                    str(
                        Path(self.container_volume_path).joinpath(
                            Path(self.stage_io_dict["in"]
                                 ["input_cpt_path"]).name)))
            else:
                self.cmd.append(self.stage_io_dict["in"]["input_cpt_path"])
        if self.stage_io_dict["in"].get("input_ndx_path") and Path(
                self.stage_io_dict["in"]["input_ndx_path"]).exists():
            self.cmd.append('-n')
            if self.container_path:
                shutil.copy2(self.stage_io_dict["in"]["input_ndx_path"],
                             self.stage_io_dict.get("unique_dir"))
                self.cmd.append(
                    Path(self.container_volume_path).joinpath(
                        Path(self.stage_io_dict["in"]["input_ndx_path"]).name))
            else:
                self.cmd.append(self.stage_io_dict["in"]["input_ndx_path"])

        if self.gmx_lib:
            self.environment = os.environ.copy()
            self.environment['GMXLIB'] = self.gmx_lib

        # 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), self.out_log)

        # Run Biobb block
        self.run_biobb()

        # Copy files to host
        self.copy_to_host()

        # Remove temporal files
        self.tmp_files.extend([
            self.stage_io_dict.get("unique_dir"), top_dir, mdp_dir, 'mdout.mdp'
        ])
        self.remove_tmp_files()

        return self.return_code
Пример #10
0
    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
Пример #11
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
Пример #12
0
    def launch(self) -> int:
        """Execute the :class:`Mdrun <gromacs.mdrun.Mdrun>` object."""

        # Setup Biobb
        if self.check_restart(): return 0
        self.stage_files()

        self.cmd = [self.gmx_path, 'mdrun',
                    '-s', self.stage_io_dict["in"]["input_tpr_path"],
                    '-o', self.stage_io_dict["out"]["output_trr_path"],
                    '-c', self.stage_io_dict["out"]["output_gro_path"],
                    '-e', self.stage_io_dict["out"]["output_edr_path"],
                    '-g', self.stage_io_dict["out"]["output_log_path"]]

        if self.stage_io_dict["in"].get("input_cpt_path"):
            self.cmd.append('-cpi')
            self.cmd.append(self.stage_io_dict["in"]["input_cpt_path"])
        if self.stage_io_dict["out"].get("output_xtc_path"):
            self.cmd.append('-x')
            self.cmd.append(self.stage_io_dict["out"]["output_xtc_path"])
        if self.stage_io_dict["out"].get("output_cpt_path"):
            self.cmd.append('-cpo')
            self.cmd.append(self.stage_io_dict["out"]["output_cpt_path"])
            if self.checkpoint_time:
                self.cmd.append('-cpt')
                self.cmd.append(str(self.checkpoint_time))
        if self.stage_io_dict["out"].get("output_dhdl_path"):
            self.cmd.append('-dhdl')
            self.cmd.append(self.stage_io_dict["out"]["output_dhdl_path"])

        # general mpi properties
        if self.mpi_bin:
            mpi_cmd = [self.mpi_bin]
            if self.mpi_np:
                mpi_cmd.append('-n')
                mpi_cmd.append(str(self.mpi_np))
            if self.mpi_flags:
                mpi_cmd.extend(self.mpi_flags)
            self.cmd = mpi_cmd + self.cmd

        # gromacs cpu mpi/openmp properties
        if self.num_threads:
            fu.log(f'User added number of gmx threads: {self.num_threads}', self.out_log)
            self.cmd.append('-nt')
            self.cmd.append(self.num_threads)
        if self.num_threads_mpi:
            fu.log(f'User added number of gmx mpi threads: {self.num_threads_mpi}', self.out_log)
            self.cmd.append('-ntmpi')
            self.cmd.append(self.num_threads_mpi)
        if self.num_threads_omp:
            fu.log(f'User added number of gmx omp threads: {self.num_threads_omp}', self.out_log)
            self.cmd.append('-ntomp')
            self.cmd.append(self.num_threads_omp)
        if self.num_threads_omp_pme:
            fu.log(f'User added number of gmx omp_pme threads: {self.num_threads_omp_pme}', self.out_log)
            self.cmd.append('-ntomp_pme')
            self.cmd.append(self.num_threads_omp_pme)
        # GMX gpu properties
        if self.use_gpu: 
            fu.log('Adding GPU specific settings adds: -nb gpu -pme gpu', self.out_log)
            self.cmd += ["-nb", "gpu", "-pme", "gpu"]
        if self.gpu_id:
            fu.log(f'List of unique GPU device IDs available to use: {self.gpu_id}', self.out_log)
            self.cmd.append('-gpu_id')
            self.cmd.append(self.gpu_id)
        if self.gpu_tasks:
            fu.log(f'List of GPU device IDs, mapping each PP task on each node to a device: {self.gpu_tasks}', self.out_log)
            self.cmd.append('-gputasks')
            self.cmd.append(self.gpu_tasks)
        # Not documented and not listed option, only for devs
        if self.dev:
            fu.log(f'Adding development options: {self.dev}', self.out_log)
            self.cmd += self.dev.split()

        if self.gmx_lib:
            self.environment = os.environ.copy()
            self.environment['GMXLIB'] = self.gmx_lib

        # 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), self.out_log)

        # 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
Пример #13
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
Пример #14
0
    def launch(self) -> int:
        """Execute the :class:`Pdb2gmx <gromacs.pdb2gmx.Pdb2gmx>` object."""

        # Setup Biobb
        if self.check_restart(): return 0
        self.stage_files()

        internal_top_name = fu.create_name(prefix=self.prefix,
                                           step=self.step,
                                           name=self.internal_top_name)
        internal_itp_name = fu.create_name(prefix=self.prefix,
                                           step=self.step,
                                           name=self.internal_itp_name)

        # Create command line
        self.cmd = [
            self.gmx_path, "pdb2gmx", "-f",
            self.stage_io_dict["in"]["input_pdb_path"], "-o",
            self.stage_io_dict["out"]["output_gro_path"], "-p",
            internal_top_name, "-water", self.water_type, "-ff",
            self.force_field, "-i", internal_itp_name
        ]

        if self.his:
            self.cmd.append("-his")
            self.cmd = ['echo', self.his, '|'] + self.cmd
        if self.ignh:
            self.cmd.append("-ignh")
        if self.merge:
            self.cmd.append("-merge")
            self.cmd.append("all")

        if self.gmx_lib:
            self.environment = os.environ.copy()
            self.environment['GMXLIB'] = self.gmx_lib

        # 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), self.out_log)

        # Run Biobb block
        self.run_biobb()

        # Copy files to host
        self.copy_to_host()

        if self.container_path:
            internal_top_name = os.path.join(
                self.stage_io_dict.get("unique_dir"), internal_top_name)

        # zip topology
        fu.log(
            'Compressing topology to: %s' %
            self.io_dict["out"]["output_top_zip_path"], self.out_log,
            self.global_log)
        fu.zip_top(zip_file=self.io_dict["out"]["output_top_zip_path"],
                   top_file=internal_top_name,
                   out_log=self.out_log)

        # Remove temporal files
        self.tmp_files.extend([
            self.internal_top_name, self.internal_itp_name,
            self.stage_io_dict.get("unique_dir")
        ])
        self.remove_tmp_files()

        return self.return_code
Пример #15
0
    def launch(self) -> int:
        """Execute the :class:`Genion <gromacs.genion.Genion>` object."""

        # Setup Biobb
        if self.check_restart(): return 0
        self.stage_files()

        # Unzip topology to topology_out
        top_file = fu.unzip_top(zip_file=self.input_top_zip_path,
                                out_log=self.out_log)
        top_dir = str(Path(top_file).parent)

        if self.container_path:
            shutil.copytree(
                top_dir,
                Path(self.stage_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))

        self.cmd = [
            'echo', '\"' + self.replaced_group + '\"', '|', self.gmx_path,
            'genion', '-s', self.stage_io_dict["in"]["input_tpr_path"], '-o',
            self.stage_io_dict["out"]["output_gro_path"], '-p', top_file
        ]

        if self.stage_io_dict["in"].get("input_ndx_path") and Path(
                self.stage_io_dict["in"].get("input_ndx_path")).exists():
            self.cmd.append('-n')
            self.cmd.append(self.stage_io_dict["in"].get("input_ndx_path"))

        if self.neutral:
            self.cmd.append('-neutral')

        if self.concentration:
            self.cmd.append('-conc')
            self.cmd.append(str(self.concentration))
            fu.log(
                'To reach up %g mol/litre concentration' % self.concentration,
                self.out_log, self.global_log)

        if self.seed is not None:
            self.cmd.append('-seed')
            self.cmd.append(str(self.seed))

        if self.gmx_lib:
            self.environment = os.environ.copy()
            self.environment['GMXLIB'] = self.gmx_lib

        # 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), self.out_log)

        # Run Biobb block
        self.run_biobb()

        # Copy files to host
        self.copy_to_host()

        if self.container_path:
            top_file = str(
                Path(self.stage_io_dict.get("unique_dir")).joinpath(
                    Path(top_dir).name,
                    Path(top_file).name))

        # zip topology
        fu.log(
            'Compressing topology to: %s' %
            self.stage_io_dict["out"]["output_top_zip_path"], self.out_log,
            self.global_log)
        fu.zip_top(zip_file=self.io_dict["out"]["output_top_zip_path"],
                   top_file=top_file,
                   out_log=self.out_log)

        # Remove temporal files
        self.tmp_files.extend([self.stage_io_dict.get("unique_dir"), top_dir])
        self.remove_tmp_files()

        return self.return_code
Пример #16
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