예제 #1
0
    def md(self,
           workdir,
           gro_file,
           top_file,
           ndx_file,
           in_protocol,
           out_prefix=False,
           restriction_gro=False,
           gromacs_run="gmx mdrun",
           gromacs_grompp="gmx grompp"):
        """This starts an initial run for a simulation "step". very crude and
        easy ;) :param workdir: absolute path to folder with step prefix as last
        part ("absolutePath/prefix") :param gromacs_run: contains the string,
        executing the gromacs command: "gmx mdrun" "gmx_mpi mdrun" ... :param
        gro_file:absolute path to .gro file input (build input or previous
        simulation step) :param top_file: absolute path to .top file input
        (build input folder) :param ndx_file: absolute path to .ndx file input
        (build input folder) :return: stepcounter (updates the gro_file for next
        step)

        Args:
            workdir:
            gro_file:
            top_file:
            ndx_file:
            in_protocol:
            out_prefix:
            restriction_gro:
            gromacs_run:
            gromacs_grompp:
        """
        if (out_prefix):
            step_name = out_prefix
        else:
            step_name = os.path.splitext(
                os.path.basename(in_protocol))[0]  # prefix of the step
        if (not restriction_gro):
            restriction_gro = gro_file
        output = workdir + "/" + step_name

        # Formulate commands
        grompp_command = gromacs_grompp + " -f " + output + ".mdp -c " + gro_file + " -p " + top_file + " -n " + ndx_file + " -r " + restriction_gro + " -o " + output + ".tpr 1> " + output + "_grompp.log 2>" + output + "_grompp.err\n"
        mdrun_command = gromacs_run + " -s " + output + ".tpr -deffnm " + output + " 1> " + output + "_mdrun.log 2>" + output + "_mdrun.err\n"
        try:
            # execute commands:
            print("\tCopy_protocol: " + step_name)
            bash.copy_file(in_protocol, output + ".mdp")

            print("\tgrompp command: " + step_name)
            bash.execute("cd " + workdir + "\n" + grompp_command)

            print("\trun_sim: " + step_name)
            bash.execute("cd " + workdir + "\n" + mdrun_command)
        except Exception as err:
            raise bash.increment_error_level("simple sim failed!\n", err)
        return output
예제 #2
0
    def grompp(self,
               workdir,
               gro_file,
               top_file,
               ndx_file,
               in_protocol,
               gromacs_grompp="grompp_mpi",
               out_prefix=False):
        """This starts grompp to build a tpr file. :param workdir: absolute path
        to folder with step prefix as last part ("absolutePath/prefix") :param
        gro_file:absolute path to .gro file input (build input or previous
        simulation step) :param top_file: absolute path to .top file input
        (build input folder) :param ndx_file: absolute path to .ndx file input
        (build input folder) :return: stepcounter (updates the gro_file for next
        step)

        Args:
            workdir:
            gro_file:
            top_file:
            ndx_file:
            in_protocol:
            gromacs_grompp:
            out_prefix:
        """
        if (out_prefix):
            step_name = out_prefix
        else:
            step_name = os.path.splitext(
                os.path.basename(in_protocol))[0]  # prefix of the step
        output = workdir + "/" + step_name

        # Formulate commands
        grompp_command = gromacs_grompp + " -f " + output + ".mdp -c " + gro_file + " -p " + top_file + " -n " + ndx_file + " -o " + output + ".tpr 1> " + output + "_grompp.log 2>" + output + "_grompp.err\n"
        try:
            # execute commands:
            print("\tCopy_protocol: " + step_name)
            bash.copy_file(in_protocol, output + ".mdp")

            print("\tgrompp command: " + step_name)
            bash.execute("cd " + workdir + "\n" + grompp_command)

        except Exception as err:
            raise bash.increment_error_level("grompp failed!\n", err)

        return output
예제 #3
0
    def mdrun(self,
              workdir,
              tpr_file,
              out_prefix=False,
              gromacs="gmx ",
              additional_options: str = " "):
        """This starts an initial run for a simulation "step". very crude and
        easy ;) :param workdir: absolute path to folder with step prefix as last
        part ("absolutePath/prefix") :param gromacs_run: contains the string,
        executing the gromacs command: "gmx mdrun" "gmx_mpi mdrun" ... :param
        gro_file:absolute path to .gro file input (build input or previous
        simulation step) :param top_file: absolute path to .top file input
        (build input folder) :param ndx_file: absolute path to .ndx file input
        (build input folder) :return: stepcounter (updates the gro_file for next
        step)

        Args:
            workdir:
            tpr_file:
            out_prefix:
            gromacs:
            additional_options (str):
        """
        if (out_prefix):
            step_name = out_prefix
        else:
            step_name = os.path.splitext(
                os.path.basename(tpr_file))[0]  # prefix of the step
        output = workdir + "/" + step_name

        # Formulate commands
        mdrun_command = gromacs + " mdrun -s " + tpr_file + " -deffnm " + output + " " + additional_options + " 1> " + output + "_mdrun.log 2>" + output + "_mdrun.err"
        try:
            # execute commands:
            print("\tCopy_protocol: " + step_name)
            if (not os.path.exists(output + ".tpr")):
                bash.copy_file(tpr_file, output + ".tpr")

            print("\trun_sim: " + step_name)
            bash.execute("cd " + workdir + " && " + mdrun_command)
        except Exception as err:
            raise bash.increment_error_level("mdrun failed!\n", err)
        return output