Exemplo n.º 1
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)

        # Restart if needed
        if self.restart:
            output_file_list = [self.io_dict['out'].get("output_top_zip_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

        # Unzip topology
        top_file = fu.unzip_top(
            zip_file=self.io_dict['in'].get("input_top_zip_path"),
            out_log=out_log)
        top_dir = str(Path(top_file).parent)
        tmp_files.append(top_dir)
        itp_name = str(Path(self.io_dict['in'].get("input_itp_path")).name)

        with open(top_file) as top_f:
            top_lines = top_f.readlines()
            top_f.close()
        fu.rm(top_file)

        forcefield_pattern = r'#include.*forcefield.itp\"'
        for index, line in enumerate(top_lines):
            if re.search(forcefield_pattern, line):
                break
        top_lines.insert(index + 1, '\n')
        top_lines.insert(index + 2, '; Including ligand ITP\n')
        top_lines.insert(index + 3, '#include "' + itp_name + '"\n')
        top_lines.insert(index + 4, '\n')
        if self.io_dict['in'].get("input_posres_itp_path"):
            top_lines.insert(index + 5, '; Ligand position restraints' + '\n')
            top_lines.insert(index + 6, '#ifdef ' + self.posres_name + '\n')
            top_lines.insert(
                index + 7, '#include "' + str(
                    Path(self.io_dict['in'].get("input_posres_itp_path")).name)
                + '"\n')
            top_lines.insert(index + 8, '#endif' + '\n')
            top_lines.insert(index + 9, '\n')

        inside_moleculetype_section = False
        with open(self.io_dict['in'].get("input_itp_path")) as itp_file:
            moleculetype_pattern = r'\[ moleculetype \]'
            for line in itp_file:
                if re.search(moleculetype_pattern, line):
                    inside_moleculetype_section = True
                    continue
                if inside_moleculetype_section and not line.startswith(';'):
                    moleculetype = line.strip().split()[0].strip()
                    break

        molecules_pattern = r'\[ molecules \]'
        inside_molecules_section = False
        index_molecule = None
        molecule_string = moleculetype + (20 -
                                          len(moleculetype)) * ' ' + '1' + '\n'
        for index, line in enumerate(top_lines):
            if re.search(molecules_pattern, line):
                inside_molecules_section = True
                continue
            if inside_molecules_section and not line.startswith(
                    ';') and line.upper().startswith('PROTEIN'):
                index_molecule = index

        if index_molecule:
            top_lines.insert(index_molecule + 1, molecule_string)
        else:
            top_lines.append(molecule_string)

        new_top = fu.create_name(path=top_dir,
                                 prefix=self.prefix,
                                 step=self.step,
                                 name='ligand.top')

        with open(new_top, 'w') as new_top_f:
            new_top_f.write("".join(top_lines))

        shutil.copy2(self.io_dict['in'].get("input_itp_path"), top_dir)
        if self.io_dict['in'].get("input_posres_itp_path"):
            shutil.copy2(self.io_dict['in'].get("input_posres_itp_path"),
                         top_dir)

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

        if self.remove_tmp:
            fu.rm_file_list(tmp_files, out_log=out_log)

        return 0
Exemplo n.º 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
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
0
    def launch(self) -> int:
        """Launch the topology generation."""
        tmp_files = []

        # Get local loggers from launchlogger decorator
        out_log = getattr(self, 'out_log', None)
        err_log = getattr(self, 'err_log', None)

        # Restart if needed
        if self.restart:
            output_file_list = [self.io_dict['out'].get("output_top_zip_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

        top_file = fu.unzip_top(zip_file=self.io_dict['in'].get("input_top_zip_path"), out_log=out_log)

        # Create index list of index file :)
        index_dic = {}
        lines = open(self.io_dict['in'].get("input_ndx_path")).read().splitlines()
        for index, line in enumerate(lines):
            if line.startswith('['):
                index_dic[line] = index,
                label = line
                if index > 0:
                    index_dic[label] = index_dic[label][0], index
        index_dic[label] = index_dic[label][0], index
        fu.log('Index_dic: '+str(index_dic), out_log, self.global_log)

        self.ref_rest_chain_triplet_list = [tuple(elem.strip(' ()').replace(' ', '').split(',')) for elem in self.ref_rest_chain_triplet_list.split('),')]
        fu.log('ref_rest_chain_triplet_list: ' + str(self.ref_rest_chain_triplet_list), out_log, self.global_log)
        for reference_group, restrain_group, chain in self.ref_rest_chain_triplet_list:
            fu.log('Reference group: '+reference_group, out_log, self.global_log)
            fu.log('Restrain group: '+restrain_group, out_log, self.global_log)
            fu.log('Chain: '+chain, out_log, self.global_log)
            self.io_dict['out']["output_itp_path"] = fu.create_name(path=str(Path(top_file).parent), prefix=self.prefix, step=self.step, name=restrain_group+'.itp')

            # Mapping atoms from absolute enumeration to Chain relative enumeration
            fu.log('reference_group_index: start_closed:'+str(index_dic['[ '+reference_group+' ]'][0]+1)+' stop_open: '+str(index_dic['[ '+reference_group+' ]'][1]), out_log, self.global_log)
            reference_group_list = [int(elem) for line in lines[index_dic['[ '+reference_group+' ]'][0]+1: index_dic['[ '+reference_group+' ]'][1]] for elem in line.split()]
            fu.log('restrain_group_index: start_closed:'+str(index_dic['[ '+restrain_group+' ]'][0]+1)+' stop_open: '+str(index_dic['[ '+restrain_group+' ]'][1]), out_log, self.global_log)
            restrain_group_list = [int(elem) for line in lines[index_dic['[ '+restrain_group+' ]'][0]+1: index_dic['[ '+restrain_group+' ]'][1]] for elem in line.split()]
            selected_list = [reference_group_list.index(atom)+1 for atom in restrain_group_list]
            # Creating new ITP with restrictions
            with open(self.io_dict['out'].get("output_itp_path"), 'w') as f:
                fu.log('Creating: '+str(f)+' and adding the selected atoms force constants', out_log, self.global_log)
                f.write('[ position_restraints ]\n')
                f.write('; atom  type      fx      fy      fz\n')
                for atom in selected_list:
                    f.write(str(atom)+'     1  '+self.force_constants+'\n')

            # Including new ITP in the corresponding ITP-chain file
            for file_dir in Path(top_file).parent.iterdir():
                if not file_dir.name.startswith("posre") and not file_dir.name.endswith("_pr.itp"):
                    if fnmatch.fnmatch(str(file_dir), "*_chain_"+chain+".itp"):
                        with open(str(file_dir), 'a') as f:
                            fu.log('Opening: '+str(f)+' and adding the ifdef include statement', out_log, self.global_log)
                            f.write('\n')
                            f.write('; Include Position restraint file\n')
                            f.write('#ifdef CUSTOM_POSRES\n')
                            f.write('#include "'+str(Path(self.io_dict['out'].get("output_itp_path")).name)+'"\n')
                            f.write('#endif\n')

        # zip topology
        fu.zip_top(zip_file=self.io_dict['out'].get("output_top_zip_path"), top_file=top_file, out_log=out_log)

        if self.remove_tmp:
            fu.rm_file_list(tmp_files, out_log=out_log)

        return 0
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
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
Exemplo n.º 9
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