Пример #1
0
 def test_grompp_singulariy(self):
     returncode = grompp(properties=self.properties, **self.paths)
     assert fx.not_empty(self.paths['output_tpr_path'])
     assert gmx_check(self.paths['output_tpr_path'],
                      self.paths['ref_output_tpr_path'],
                      gmx=self.properties.get('gmx_path', 'gmx'))
     assert fx.exe_success(returncode)
Пример #2
0
    def launch(self) -> int:
        """Execute the :class:`GromppMdrun <gromacs.grompp_mdrun.GromppMdrun>` object."""

        fu.log(f'Calling Grompp class', self.out_log, self.global_log)
        grompp_return_code = grompp(input_gro_path=self.input_gro_path,
                                    input_top_zip_path=self.input_top_zip_path,
                                    output_tpr_path=self.output_tpr_path,
                                    input_cpt_path=self.input_cpt_path,
                                    input_ndx_path=self.input_ndx_path,
                                    input_mdp_path=self.input_mdp_path,
                                    properties=self.properties_grompp)
        fu.log(f'Grompp return code: {grompp_return_code}', self.out_log,
               self.global_log)

        if not grompp_return_code:
            fu.log(f'Grompp return code is correct. Calling MDRun class',
                   self.out_log, self.global_log)
            mdrun_return_code = mdrun(input_tpr_path=self.output_tpr_path,
                                      output_trr_path=self.output_trr_path,
                                      output_gro_path=self.output_gro_path,
                                      output_edr_path=self.output_edr_path,
                                      output_log_path=self.output_log_path,
                                      output_xtc_path=self.output_xtc_path,
                                      output_cpt_path=self.output_cpt_path,
                                      output_dhdl_path=self.output_dhdl_path,
                                      properties=self.properties_mdrun)
            fu.log(f'MDRun return code: {mdrun_return_code}', self.out_log,
                   self.global_log)
        else:
            return 1

        return mdrun_return_code
Пример #3
0
    def via_gromacs(cls,
                    parmed_obj,
                    file_name,
                    file_path="./",
                    num_steps=5000 * 500,
                    write_out_freq=5000,
                    num_threads=1,
                    minimisation_mdp=None,
                    equilibration_mdp=None,
                    production_mdp=None,
                    tmp_dir=None,
                    report_equilibration=False,
                    report_production=False,
                    debug=False,
                    stages=["minimisation", "equilibration", "production"],
                    **kwargs):  #TODO infer threads based on system size
        """
        Simulation via GROMACS will be added in the future.

        based on cell size, make recomendation on number of threads to use 
    
        Parameters
        ------------
        parmed_obj : parmed.structure
            Parmed object of the fully parameterised simulated system.
        file_name : str
            No file type postfix is necessary
        file_path : str
            Default to current directory
        platform : str
            The computing architecture to do the calculation, default to CUDA, CPU, OpenCL is also possible.
        num_steps : int
            Number of production simulation to run, default 2,500,000 steps, i.e. 5 ns.
        write_out_freq : int
            Write out every nth frame of simulated trajectory, default to every 5000 frame write out one, i.e. 10 ps per frame.

        Returns
        --------
        path : str
            The absolute path where the trajectory is written to.
        """
        from biobb_md.gromacs.make_ndx import make_ndx, MakeNdx
        # from biobb_md.gromacs.grompp_mdrun import grompp_mdrun
        from biobb_md.gromacs.mdrun import mdrun
        from biobb_md.gromacs.grompp import grompp
        from biobb_common.tools.file_utils import zip_top

        assert tmp_dir is None or os.path.realpath(
            file_path) != os.path.realpath(
                tmp_dir
            ), "Simulation results will not be stored in a temporary directory"

        if debug:
            import shutil
            tmp_dir = "{}/.debug/".format(file_path)
            if os.path.isdir(tmp_dir):
                shutil.rmtree(tmp_dir)
            os.mkdir(tmp_dir)
        elif tmp_dir is None:
            tmp_dir = tempfile.mkdtemp(
                dir=file_path
            )  #FIXME just change this to debug dir in dubug mode
        else:
            try:
                os.mkdir(tmp_dir)
            except:
                raise ValueError(
                    "Cannot create an empty temporary directory for storing intermediate files"
                )

        parmed_obj.residues[0].name = "LIG"
        parmed_obj = parmed.gromacs.gromacstop.GromacsTopologyFile(
        ).from_structure(parmed_obj)

        parmed_obj.defaults.fudgeLJ = 0.5
        parmed_obj.defaults.fudgeQQ = 0.83333
        parmed_obj.defaults.gen_pairs = "yes"

        # Create prop dict and inputs/outputs

        xtc_file = '{}/{}.xtc'.format(file_path, file_name)
        gro_file = "{}/{}.gro".format(file_path, file_name)
        top_file = "{}/{}.top".format(tmp_dir, "topol")
        topzip_file = "{}/{}.zip".format(tmp_dir, "topol")

        # parmed_obj.save("{}/{}.pdb".format(tmp_dir, stage), overwrite=True)
        parmed_obj.save(gro_file, overwrite=True)
        parmed_obj.save(top_file, overwrite=True)

        index_file = "{}/{}.ndx".format(tmp_dir, "index")
        prop = {
            # "can_write_console_log" : False,
            'selection': "! r LIG"
        }

        # Create and launch bb
        # tmp = MakeNdx(input_structure_path = gro_file,
        #         output_ndx_path = index_file,
        #         properties = prop)
        # import logging
        # tmp.out_log = logging.Logger("x")
        # tmp.err_log = logging.Logger("y")
        # tmp.launch()
        # print(getattr(tmp, "out_log"))
        # print(tmp.err_log)
        make_ndx(input_structure_path=gro_file,
                 output_ndx_path=index_file,
                 properties=prop)

        ####################################################

        zip_top(topzip_file, top_file)

        stage = "minimisation"
        if stage in stages:
            mdp_dict = mdp2dict(get_data_filename("{}.mdp".format(stage)))
            if eval("{}_mdp".format(stage)) is not None:
                mdp_dict.update(eval("{}_mdp".format(stage)))
            next_gro_file = "{}/{}.gro".format(tmp_dir, stage)

            # grompp_mdrun(input_gro_path = gro_file,
            #     input_ndx_path = index_file,
            #     input_top_zip_path= topzip_file,
            #     # input_mdp_path = "{}.mdp".format(stage),
            #     output_trr_path = "{}/{}.trr".format(tmp_dir, stage),
            #     output_gro_path = next_gro_file,
            #     output_edr_path = "{}/{}.edr".format(tmp_dir, stage),
            #     output_log_path = "{}/{}.log".format(tmp_dir, stage),
            #     output_xtc_path = "{}/{}.xtc".format(tmp_dir, stage),
            #     num_threads_omp = num_threads,
            #     properties = {
            #         "mdp" : mdp_dict
            #         }
            #     )
            grompp(
                input_gro_path=gro_file,
                input_ndx_path=index_file,
                input_top_zip_path=topzip_file,
                output_tpr_path="{}/{}.tpr".format(tmp_dir, stage),
                # input_mdp_path = "{}.mdp".format(stage),
                properties={"mdp": mdp_dict})
            mdrun(
                input_tpr_path="{}/{}.tpr".format(tmp_dir, stage),
                output_trr_path="{}/{}.trr".format(tmp_dir, stage),
                output_gro_path=next_gro_file,
                output_edr_path="{}/{}.edr".format(tmp_dir, stage),
                output_log_path="{}/{}.log".format(tmp_dir, stage),
                output_cpt_path="{}/{}.cpt".format(tmp_dir, stage),
                output_xtc_path="{}/{}.xtc".format(tmp_dir, stage),
                properties={
                    "num_threads": num_threads,
                    "num_threads_omp": num_threads,
                    "num_threads_omp_pme": num_threads,
                }
                # num_threads_omp = 1 #XXX seems for minimisation speed is very slow when multiple threads are used, especially on cluster. Maybe need better handle
            )
            gro_file = next_gro_file

        ###################################################333

        stage = "equilibration"
        if stage in stages:
            mdp_dict = mdp2dict(get_data_filename("{}.mdp".format(stage)))
            if eval("{}_mdp".format(stage)) is not None:
                mdp_dict.update(eval("{}_mdp".format(stage)))
            next_gro_file = "{}/{}.gro".format(tmp_dir, stage)
            grompp(
                input_gro_path=gro_file,
                input_ndx_path=index_file,
                input_top_zip_path=topzip_file,
                output_tpr_path="{}/{}.tpr".format(tmp_dir, stage),
                # input_mdp_path = "{}.mdp".format(stage),
                properties={"mdp": mdp_dict})
            mdrun(input_tpr_path="{}/{}.tpr".format(tmp_dir, stage),
                  output_trr_path="{}/{}.trr".format(tmp_dir, stage),
                  output_gro_path=next_gro_file,
                  output_edr_path="{}/{}.edr".format(tmp_dir, stage),
                  output_log_path="{}/{}.log".format(tmp_dir, stage),
                  output_cpt_path="{}/{}.cpt".format(tmp_dir, stage),
                  output_xtc_path="{}/{}.xtc".format(tmp_dir, stage),
                  properties={
                      "num_threads": num_threads,
                      "num_threads_omp": num_threads,
                      "num_threads_omp_pme": num_threads,
                  })
            gro_file = next_gro_file

        ######################################################3

        stage = "production"
        if stage in stages:
            mdp_dict = mdp2dict(get_data_filename("{}.mdp".format(stage)))
            if eval("{}_mdp".format(stage)) is not None:
                mdp_dict.update(eval("{}_mdp".format(stage)))
            next_gro_file = "{}/{}.gro".format(tmp_dir, stage)
            grompp(
                input_gro_path=gro_file,
                input_ndx_path=index_file,
                input_top_zip_path=topzip_file,
                output_tpr_path="{}/{}.tpr".format(tmp_dir, stage),
                # input_mdp_path = "{}.mdp".format(stage),
                properties={"mdp": mdp_dict})
            mdrun(input_tpr_path="{}/{}.tpr".format(tmp_dir, stage),
                  output_trr_path="{}/{}.trr".format(tmp_dir, stage),
                  output_gro_path=next_gro_file,
                  output_edr_path="{}/{}.edr".format(tmp_dir, stage),
                  output_log_path="{}/{}.log".format(tmp_dir, stage),
                  output_cpt_path="{}/{}.cpt".format(tmp_dir, stage),
                  output_xtc_path=xtc_file,
                  properties={
                      "num_threads": num_threads,
                      "num_threads_omp": num_threads,
                      "num_threads_omp_pme": num_threads,
                  })
            # gro_file = next_gro_file

        ######################################################3

        if debug is not True and tmp_dir is not None:
            import shutil
            shutil.rmtree(tmp_dir)
        return os.path.abspath(xtc_file)