Example #1
0
    def launch(self):
        """Launches the execution of the GROMACS solvate module.
        """
        out_log, err_log = fu.get_logs(path=self.path, mutation=self.mutation, step=self.step)
        self.output_top_path = fu.add_step_mutation_path_to_name(self.output_top_path, self.step, self.mutation)

        # Unzip topology to topology_out
        fu.unzip_top(zip_file=self.input_top_zip_path, top_file=self.output_top_path)

        gmx = 'gmx' if self.gmx_path is None else self.gmx_path
        cmd = [gmx, 'solvate',
               '-cp', self.input_solute_gro_path,
               '-cs', self.input_solvent_gro_path,
               '-o',  self.output_gro_path,
               '-p',  self.output_top_path]

        if self.mpirun_np is not None:
            cmd.insert(0, str(self.mpirun_np))
            cmd.insert(0, '-np')
        if self.mpirun:
            cmd.insert(0, 'mpirun')
        command = cmd_wrapper.CmdWrapper(cmd, out_log, err_log)
        returncode = command.launch()

        with open(self.output_top_path) as topology_file:
            out_log.info('Last 5 lines of new top file: ')
            lines = topology_file.readlines()
            for index in [-i for i in range(5,0,-1)]:
                out_log.info(lines[index])


        # zip new_topology
        fu.zip_top(self.output_top_path, self.output_top_zip_path, remove_files=True)
        return returncode
Example #2
0
    def launch(self):
        """Launches the execution of the GROMACS genion module.
        """
        if self.global_log is not None:
            if self.concentration:
                self.global_log.info(19 * ' ' + 'To reach up ' +
                                     str(self.concentration) +
                                     ' mol/litre concentration')

        out_log, err_log = fu.get_logs(path=self.path,
                                       mutation=self.mutation,
                                       step=self.step)
        self.output_top_path = fu.add_step_mutation_path_to_name(
            self.output_top_path, self.step, self.mutation)

        # Unzip topology to topology_out
        fu.unzip_top(zip_file=self.input_top_zip_path,
                     top_file=self.output_top_path)
        gmx = 'gmx' if self.gmx_path is None else self.gmx_path
        cmd = [
            gmx, 'genion', '-s', self.input_tpr_path, '-o',
            self.output_gro_path, '-p', self.output_top_path
        ]

        if self.mpirun_np is not None:
            cmd.insert(0, str(self.mpirun_np))
            cmd.insert(0, '-np')
        if self.mpirun:
            cmd.insert(0, 'mpirun')
        if self.neutral:
            cmd.append('-neutral')
        if self.concentration:
            cmd.append('-conc')
            cmd.append(str(self.concentration))

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

        if self.mpirun:
            cmd.append('<<<')
            cmd.append('\"' + self.replaced_group + '\"')
        else:
            cmd.insert(0, '|')
            cmd.insert(0, '\"' + self.replaced_group + '\"')
            cmd.insert(0, 'echo')
        command = cmd_wrapper.CmdWrapper(cmd, out_log, err_log)
        returncode = command.launch()

        # zip new_topology
        fu.zip_top(self.output_top_path,
                   self.output_top_zip_path,
                   remove_files=True)
        return returncode
Example #3
0
    def launch(self):
        """Launches the execution of the GROMACS pdb2gmx module.
        """
        out_log, err_log = fu.get_logs(path=self.path,
                                       mutation=self.mutation,
                                       step=self.step)
        self.output_top_path = fu.add_step_mutation_path_to_name(
            self.output_top_path, self.step, self.mutation)

        gmx = "gmx" if self.gmx_path is None else self.gmx_path
        cmd = [
            gmx, "pdb2gmx", "-f", self.input_structure_pdb_path, "-o",
            self.output_gro_path, "-p", self.output_top_path, "-water",
            self.water_type, "-ff", self.force_field
        ]

        if self.mpirun_np is not None:
            cmd.insert(0, str(self.mpirun_np))
            cmd.insert(0, '-np')
        if self.mpirun:
            cmd.insert(0, 'mpirun')
        if self.output_itp_path is not None:
            self.output_itp_path = self.output_itp_path if self.step is None else self.step + '_' + self.output_itp_path
            self.output_itp_path = self.output_itp_path if self.mutation is None else self.mutation + '_' + self.output_itp_path
            cmd.append("-i")
            cmd.append(self.output_itp_path)
        if self.ignh:
            cmd.append("-ignh")

        command = cmd_wrapper.CmdWrapper(cmd, out_log, err_log)
        returncode = command.launch()

        #Remove comment (first line) from gro file
        with open(self.output_gro_path, 'r') as fin:
            data = fin.read().splitlines(True)
            data[0] = 'Created with pdb2gmx building block\n'
        with open(self.output_gro_path, 'w') as fout:
            fout.writelines(data)

        # zip topology
        fu.zip_top(self.output_top_path,
                   self.output_top_zip_path,
                   remove_files=True)

        return returncode
Example #4
0
    def launch(self):
        """Launches the execution of the GROMACS pdb2gmx module.
        """
        out_log, err_log = fu.get_logs(path=self.path,
                                       mutation=self.mutation,
                                       step=self.step)
        self.output_top_path = fu.add_step_mutation_path_to_name(
            self.output_top_path, self.step, self.mutation)
        self.output_itp_path = fu.add_step_mutation_path_to_name(
            self.output_itp_path, self.step, self.mutation)

        gmx = "gmx" if self.gmx_path is None else self.gmx_path
        cmd = [
            gmx, "genrestr", "-f", self.input_structure_path, "-n",
            self.input_ndx_path, "-o", self.output_itp_path, "-fc",
            self.force_constants
        ]

        if self.mpirun_np is not None:
            cmd.insert(0, str(self.mpirun_np))
            cmd.insert(0, '-np')
        if self.mpirun:
            cmd.insert(0, 'mpirun')

        if self.mpirun:
            cmd.append('<<<')
            cmd.append('\"' + self.restricted_group + '\"')
        else:
            cmd.insert(0, '|')
            cmd.insert(0, '\"' + self.restricted_group + '\"')
            cmd.insert(0, 'echo')

        command = cmd_wrapper.CmdWrapper(cmd, out_log, err_log)
        returncode = command.launch()

        fu.unzip_top(zip_file=self.input_top_zip_path,
                     top_file=self.output_top_path)
        out_log.info('Unzip: ' + self.input_top_zip_path + ' to: ' +
                     self.output_top_path)
        with open(self.output_top_path, 'r') as fin:
            for line in fin:
                if line.startswith('#ifdef POSRES'):
                    itp_name = re.findall('"([^"]*)"', fin.next())[0]
                    out_log.debug('itp_name: ' + itp_name)
                    break

        # with open(self.output_top_path, 'r') as fin:
        #     data = fin.read().splitlines(True)
        #     index = data.index('#ifdef POSRES\n')
        #     data[index+2] = 'system\n'
        #     data.insert(index, '\n')
        #     data.insert(index, '#endif\n')
        #     data.insert(index, '#include "'+self.output_itp_path+'"\n')
        #     data.insert(index, '#ifdef CUSTOM_POSRES\n')
        #     data.insert(index, '; Include Position restraint file\n')
        #     # data.insert(index, '#include "'+self.output_itp_path+'"\n')
        #     # data.insert(index, '; Include genrestr generated itp\n')
        # with open(self.output_top_path, 'w') as fout:
        #     fout.writelines(data)

        with open(self.output_itp_path, 'r') as fin:
            data = fin.read().splitlines(True)
            # data.insert(0, '\n')
            # data.insert(0, 'system    3\n')
            # data.insert(0, ';Name    nrexcl\n')
            # data.insert(0, '[ system ]\n')
        with open(itp_name, 'w') as fout:
            fout.writelines(data)
        os.remove(self.output_itp_path)

        # zip topology
        fu.zip_top(self.output_top_path,
                   self.output_top_zip_path,
                   remove_files=False)
        out_log.info('Zip: ' + self.output_top_path + ' to: ' +
                     self.output_top_zip_path)

        return returncode
    def launch(self):
        """Launch the topology generation.
        """
        out_log, err_log = fu.get_logs(path=self.path,
                                       mutation=self.mutation,
                                       step=self.step)
        self.output_top_path = fu.add_step_mutation_path_to_name(
            self.output_top_path, self.step, self.mutation)

        fu.unzip_top(zip_file=self.input_top_zip_path,
                     top_file=self.output_top_path)
        out_log.info('Unzip: ' + self.input_top_zip_path + ' to: ' +
                     self.output_top_path)

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

        self.ref_rest_chain_triplet_list = [
            tuple(elem.strip(' ()').replace(' ', '').split(','))
            for elem in self.ref_rest_chain_triplet_list.split('),')
        ]
        for reference_group, restrain_group, chain in self.ref_rest_chain_triplet_list:
            out_log.info('Reference group: ' + reference_group)
            out_log.info('Restrain group: ' + restrain_group)
            out_log.info('Chain: ' + chain)
            self.output_itp_path = fu.add_step_mutation_path_to_name(
                restrain_group + '.itp', self.step, self.mutation)

            # Mapping atoms from absolute enumeration to Chain relative enumeration
            out_log.info('reference_group_index: start_closed:' +
                         str(index_dic['[ ' + reference_group + ' ]'][0] + 1) +
                         ' stop_open: ' +
                         str(index_dic['[ ' + reference_group + ' ]'][1]))
            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()
            ]
            out_log.info('restrain_group_index: start_closed:' +
                         str(index_dic['[ ' + restrain_group + ' ]'][0] + 1) +
                         ' stop_open: ' +
                         str(index_dic['[ ' + restrain_group + ' ]'][1]))
            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.output_itp_path, 'w') as f:
                out_log.info('Creating: ' + str(f) +
                             ' and adding the selected atoms force constants')
                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_name in os.listdir('.'):
                if not file_name.startswith(
                        "posre") and not file_name.endswith("_pr.itp"):
                    if fnmatch.fnmatch(file_name, "*_chain_" + chain + ".itp"):
                        with open(file_name, 'a') as f:
                            out_log.info(
                                'Opening: ' + str(f) +
                                ' and adding the ifdef include statement')
                            f.write('\n')
                            f.write('; Include Position restraint file\n')
                            f.write('#ifdef CUSTOM_POSRES\n')
                            f.write('#include "' + self.output_itp_path +
                                    '"\n')
                            f.write('#endif\n')

        # zip topology
        fu.zip_top(self.output_top_path,
                   self.output_top_zip_path,
                   remove_files=True)
        out_log.info('Zip: ' + self.output_top_path + ' to: ' +
                     self.output_top_zip_path)

        return 0