Exemple #1
0
def test_fr9():
    """FR9: *gmx.mdrun supports interface for binding MD plugins*

    (requires interaction with library development)
    """
    import sample_restraint

    starting_structure = 'input_conf.gro'
    topology_file = 'input.top'
    run_parameters = 'params.mdp'

    initial_tpr = gmx.commandline_operation(
        'gmx',
        'grompp',
        input={
            '-f': run_parameters,
            '-c': starting_structure,
            '-p': topology_file
        },
        output={'-o': gmx.OutputFile('.tpr')})

    simulation_input = gmx.read_tpr(initial_tpr.output.file['-o'])

    # Prepare a simple harmonic restraint between atoms 1 and 4
    restraint_params = {'sites': [1, 4],
                        'R0': 2.0,
                        'k': 10000.0}

    restraint = sample_restraint.harmonic_restraint(input=restraint_params)

    md = gmx.mdrun(input=simulation_input, potential=sample_restraint)
Exemple #2
0
def test_run_from_read_tpr_op(spc_water_box, caplog):
    with caplog.at_level(logging.DEBUG):
        caplog.handler.setFormatter(formatter)
        with caplog.at_level(logging.DEBUG, 'gmxapi'):
            simulation_input = gmx.read_tpr(spc_water_box)
            md = gmx.mdrun(input=simulation_input)

            md.run()
            if rank_number == 0:
                assert os.path.exists(md.output.trajectory.result())
Exemple #3
0
def test_read_tpr(spc_water_box):
    tpr_filename = spc_water_box
    tpr_source = gmxapi.read_tpr(tpr_filename)
    assert 'parameters' in tpr_source.output
    assert hasattr(tpr_source.output, 'parameters')
    parameters = tpr_source.output.parameters.result()
    assert 'nsteps' in parameters
    assert 'foo' not in parameters
    assert parameters['nsteps'] == 2
    assert tpr_source.output.parameters['nsteps'].result() == 2
Exemple #4
0
def test_fr11():
    """FR11: Python access to TPR file contents.

    * gmx.read_tpr utility provides access to TPR file contents
    * gmx.read_tpr operation produces output consumable by gmx.mdrun
    * gmx.mdrun produces gromacs.read_tpr node for tpr filename kwargs
    """
    simulation_input = gmx.read_tpr(initial_tpr)
    nsteps = simulation_input.params('nsteps')
    md = gmx.mdrun(simulation_input)
    assert md.output.trajectory.step.result() == nsteps
 def single_run(self, prep, name, log=True):
     mdrun = gmx.read_tpr(prep.output.file["-o"])
     md = gmx.mdrun(mdrun)
     md.run()
     path = md.output.trajectory.result()
     path = path[:path.rfind("/") + 1]
     self.configuration_file = path + "confout.gro"
     if log:
         self.history.append(path)
     self.latest_path = path
     shutil.move(name + ".mdp", path + name + ".mdp")
     shutil.move(name + ".tpr", path + name + ".tpr")
Exemple #6
0
def make_input(simulation_parameters=['md.mdp'],
               topology=['md.top'],
               conformation=['md.gro'],
               wrapper_name='gmx'):
    preprocess = scalems.executable(
        (wrapper_name, 'grompp'),
        inputs={
            '-f': simulation_parameters,
            '-p': topology,
            '-c': conformation
        },
        outputs={'-o': scalems.OutputFile(suffix='.tpr')})

    return gmxapi.read_tpr(preprocess.output.files['-o'])
Exemple #7
0
def test_fr16():
    """FR16: Create simulation input from simulation output.

    *gmx.make_input handles state from checkpoints*
    (requires interaction with library development)
    """
    initial_input = gmx.read_tpr(tpr_filename)
    md = gmx.mdrun(initial_input)
    stage2_input = gmx.make_input(topology=initial_input,
                                  conformation=md.output,
                                  parameters=stage2_params,
                                  simulation_state=md.output)
    md = gmx.mdrun(stage2_input)
    md.run()
Exemple #8
0
def test_fr16():
    """FR16: Create simulation input from simulation output.

    *gmx.make_input handles state from checkpoints*
    (requires interaction with library development)
    """
    initial_input = gmx.read_tpr(tpr_filename)
    md = gmx.mdrun(initial_input)
    stage2_input = gmx.make_input(topology=initial_input,
                                  conformation=md.output,
                                  parameters=stage2_params,
                                  simulation_state=md.output)
    md = gmx.mdrun(stage2_input)
    md.run()
Exemple #9
0
def test_fr15():
    """FR15: Simulation input modification.

    * *gmx.modify_input produces new (tpr) simulation input in data flow operation*
      (requires interaction with library development)
    * gmx.make_input dispatches appropriate preprocessing for file or in-memory simulation input.
    """
    initial_input = gmx.read_tpr([tpr_filename for _ in range(10)])
    tau_t = list([i / 10. for i in range(10)])
    param_sweep = gmx.modify_input(input=initial_input,
                                   parameters={'tau_t': tau_t})
    md = gmx.mdrun(param_sweep)
    for tau_expected, tau_actual in zip(tau_t,
                                        md.output.params['tau_t'].extract()):
        assert tau_expected == tau_actual
Exemple #10
0
def test_fr12():
    """FR12: Simulation checkpoint handling

    * gmx.mdrun is properly restartable

    This should be invisible to the user, and requires introspection and testing infrastructure to properly test (TBD).
    """
    from gmxapi import testsupport

    simulation_input = gmx.read_tpr(initial_tpr)
    md = gmx.mdrun(simulation_input, label='md')
    interrupting_context = testsupport.interrupted_md(md)
    with interrupting_context as session:
        first_half_md = session.md.run()
    md = gmx.mdrun(first_half_md, context=testsupport.inspect)
    testsupport.verify_restart(md)
Exemple #11
0
def test_fr12():
    """FR12: Simulation checkpoint handling

    * gmx.mdrun is properly restartable

    This should be invisible to the user, and requires introspection and testing infrastructure to properly test (TBD).
    """
    from gmxapi import testsupport

    simulation_input = gmx.read_tpr(initial_tpr)
    md = gmx.mdrun(simulation_input, label='md')
    interrupting_context = testsupport.interrupted_md(md)
    with interrupting_context as session:
        first_half_md = session.md.run()
    md = gmx.mdrun(first_half_md, context=testsupport.inspect)
    testsupport.verify_restart(md)
Exemple #12
0
def test_fr15():
    """FR15: Simulation input modification.

    * *gmx.modify_input produces new (tpr) simulation input in data flow operation*
      (requires interaction with library development)
    * gmx.make_input dispatches appropriate preprocessing for file or in-memory simulation input.
    """
    initial_input = gmx.read_tpr([tpr_filename for _ in range(10)])
    tau_t = list([i/10. for i in range(10)])
    param_sweep = gmx.modify_input(input=initial_input,
                                   parameters={
                                       'tau_t': tau_t
                                   }
                                   )
    md = gmx.mdrun(param_sweep)
    for tau_expected, tau_actual in zip(tau_t, md.output.params['tau_t'].extract()):
        assert tau_expected == tau_actual
Exemple #13
0
def test_fr4():
    """FR4: Dimensionality and typing of named data causes generation of correct work topologies."""
    N = 10
    simulation_input = gmx.read_tpr(initial_tpr)

    # Array inputs imply array outputs.
    input_array = gmx.modify_input(
        simulation_input, params={'tau-t': [t / 10.0 for t in range(N)]})

    md = gmx.mdrun(input_array)  # An array of simulations

    rmsf = gmx.commandline_operation(
        'gmx',
        'rmsf',
        input={
            '-f': md.output.trajectory,
            '-s': initial_tpr
        },
        output={'-o': gmx.FileName(suffix='.xvg')})
Exemple #14
0
def test_fr4():
    """FR4: Dimensionality and typing of named data causes generation of correct work topologies."""
    N = 10
    simulation_input = gmx.read_tpr(initial_tpr)

    # Array inputs imply array outputs.
    input_array = gmx.modify_input(
        simulation_input, params={'tau-t': [t / 10.0 for t in range(N)]})

    md = gmx.mdrun(input_array)  # An array of simulations

    rmsf = gmx.commandline_operation(
        'gmx',
        'rmsf',
        input={
            '-f': md.output.trajectory,
            '-s': initial_tpr
        },
        output={'-o': gmx.FileName(suffix='.xvg')})
Exemple #15
0
    def single_run(self,
                   name,
                   log = False,
                   template = "",
                   additions = None,
                   restrained = False):
        # Preperes a run and runs it.
        mdp_create(file_name = name + ".mdp",
                   new_parameters = self.mdp_settings[name],
                   old_file = template)
        executable = "gmx"
        arguments = ["grompp"]
        input_files = {"-f": name + ".mdp",
                       "-c": self.configuration_file,
                       "-p": "topol.top"}
        output_files = {"-o" : name + ".tpr"}
        #print(name, "", executable, arguments, input_files, output_files,"","",sep="\n")
        if additions:
            if "in" in additions:
                append_dict(input_files, additions["in"])
            if "out" in additions:
                append_dict(output_files, additions["out"])
        #print(name, "", executable, arguments, input_files, output_files,"","",sep="\n")
        #print("input files:\n"+str(input_files))
        #input()
        prep =  gmx.commandline_operation(executable = executable,
                                          arguments = arguments,
                                          input_files = input_files,
                                          output_files = output_files)
        prep.run()
        print("prep "+ name + ":\n", prep.output.erroroutput.result())

        mdrun = gmx.read_tpr(prep.output.file["-o"])
        md = gmx.mdrun(mdrun)
        md.run()
        path = md.output.trajectory.result()
        path = path[:path.rfind("/") + 1]
        self.configuration_file = path + "confout.gro"
        if log:
            self.history.append(self.configuration_file)
        self.latest_path = path
        shutil.move(name + ".mdp", path + name + ".mdp")
        shutil.move(name + ".tpr", path + name + ".tpr")
Exemple #16
0
 def single_run(self, prep, name, log_run=True):
     # Runs a prepared MD run
     new_path = self.main_path + name + "/"
     try:
         os.listdir(new_path)
         self.configuration_file = new_path + "confout.gro"
         self.latest_path = new_path
         return
     except FileNotFoundError:
         pass
     mdrun = gmx.read_tpr(prep.output.file["-o"])
     md = gmx.mdrun(mdrun)
     md.run()
     path = md.output.trajectory.result()
     #print(path + (2 * "\n") + "result path")
     path = path[:path.rfind("/") + 1]
     try:
         os.mkdir(new_path)
     except FileNotFoundError as e:
         print(str(e) + (5 * "\n"))
         raise DebugException("Super directory non existant")
     """except FileExistsError as e:
         print(str(e)+ 5*"\n")            
         raise DebugException("MD run with duplicate directory")"""
     self.configuration_file = new_path + "confout.gro"
     if log_run:
         self.history.append(new_path)
     self.latest_path = new_path
     shutil.move(path + "confout.gro", self.configuration_file)
     try:
         shutil.move(path + "traj_comp.xtc", new_path + "traj_comp.xtc")
     except FileNotFoundError:
         log(name + ":\nNo traj.xtc found in: " + path + "\nfor: " +
             new_path)
     shutil.move(name + ".mdp", new_path + name + ".mdp")
     shutil.move(name + ".tpr", new_path + name + ".tpr")
     #input("Pause")
     return path
Exemple #17
0
def test_run_from_read_tpr_op(spc_water_box):
    simulation_input = gmx.read_tpr(spc_water_box)
    md = gmx.mdrun(input=simulation_input)

    md.run()
import gmxapi as gmx
# import numpy as np

## create tpr file:
## gmx grompp -f md.mdp -c conf.gro -p topol.top -o topol.tpr -maxwarn 3

## numpy  and networkx needed for initial testrun

trial_input = gmx.read_tpr("topol.tpr")
md = gmx.mdrun(trial_input)
md.run()
def main():
    print('''Welcome to an automated run of the Gromacs Lysozyme tutorial, this program
should work on most systems containable within the same simulation box.
Some files are necessary for running the program:

 - a *.pdb file describing a protein.
 - an "ions.mdp" file for the ion placement configurations
 - an "minim.mdp" file for energy minimization configurations
 - "nvt.mdp" AND "npt.mdp" files for equilibration"
 - "md.mdp" for the md run configurations.\n\n
 ''')
    try:
        #file_name = select_file("Please type the .pdb files name: ")
        file_name = "1aki.pdb"
        clean_name = clean_h2o(file_name, False)
        out_name = "processed_" + ".".join(file_name.split(".")[:-1]) + ".gro"
        box_name = "newbox_" +  ".".join(file_name.split(".")[:-1]) + ".gro"
        solv_name = "solv_" +  ".".join(file_name.split(".")[:-1]) + ".gro"
        is_name = "ion_" + solv_name

        """ Haven't been able to get this to work lately, meant to delete old backups
            might also unintentionally delete valuable work so not very safe. """
        sp.run(["rm", "\#*"])

        # First command line instruction
        pdb2gmx=gmx.commandline_operation(executable = "gmx",
                                          arguments = ["pdb2gmx", "-water", "spce",
                                                       "-ff", "oplsaa"],
                                          input_files =  {"-f": clean_name},
                                          output_files = {"-o" : out_name})
        pdb2gmx.run()
        print("pdb2gmx",pdb2gmx.output.erroroutput.result())
        file_name = "conf.gro"
        box = gmx.commandline_operation(executable ="gmx",
                                        arguments = [ "editconf","-c", "-d", "1.0", "-bt", "cubic"],
                                        input_files = {"-f": pdb2gmx.output.file["-o"]},
                                        output_files= {"-o": box_name})
        box.run()
        print("box",box.output.erroroutput.result())

        """ Until I get a grip on what I'm doing wrong with commandline_operation """
        solvate = gmx.commandline_operation(executable = "gmx",
                                            arguments = ["solvate"],
                                            input_files = {"-cp": box.output.file["-o"],
                                                           "-p": "topol.top"},
                                            output_files = {"-o": solv_name})

        solvate.run()
        print("solvate",solvate.output.erroroutput.result())

        #ion_name = select_file("Please type the name of you ion .mdp files name")
        ion_name = "ions.mdp"
        ion_top =  ".".join(ion_name.split(".")[:-1]) + ".tpr"
        pname = "NA" #get_pname()
        nname = "CL" #get_nname()
        tpr_assemble = gmx.commandline_operation(executable = "gmx",
                                                 arguments = ["grompp"],
                                                 input_files = {"-f": ion_name,
                                                                "-c": solvate.output.file["-o"],
                                                                "-p": "topol.top"},
                                                 output_files = {"-o": ion_top})
        tpr_assemble.run()
        print("tpr_assemble",tpr_assemble.output.erroroutput.result())


        #sp.run(["gmx", "genion", "-s", ion_top, "-o", is_name, "-p","topol.top",\
        #        "-pname", pname, "-nname", nname, "-neutral"], input="SOL", text=True)



        genion = gmx.commandline_operation(executable = "gmx",
                                           arguments =  ["genion", "-pname", pname, "-nname", nname, "-neutral"],
                                           input_files = {"-s": tpr_assemble.output.file["-o"],
                                                          "-p": "topol.top"},
                                           output_files = {"-o": is_name},
                                           stdin = "SOL")

        genion.run()
        print("genion", genion.output.erroroutput.result())
        # Energy minimization
        emtprprep = gmx.commandline_operation(executable = "gmx",
                                              arguments = ["grompp"],
                                              input_files = {"-f": "minim.mdp",
                                                             "-c": genion.output.file["-o"],
                                                             "-p": "topol.top"},
                                              output_files = {"-o": "em.tpr"})
        emtprprep.run()
        print ("emtprprep", emtprprep.output.erroroutput.result())
        #sp.run(["gmx", "grompp", "-f", "minim.mdp", "-c", is_name, "-p", "topol.top",\
        #        "-o", "em.tpr"])
        emtpr = gmx.read_tpr(emtprprep.output.file["-o"])
        em =  gmx.mdrun(emtpr)
        em.run()


        #sp.run(["gmx", "mdrun", "-deffnm", "em"])
        emgro=em.output.trajectory.result()
        emgro=emgro[:emgro.rfind('/') + 1] + "confout.gro"

        # Equilibration
        eq1tpr =  gmx.commandline_operation(executable = "gmx",
                                            arguments = ["grompp"],
                                            input_files = {"-f": "nvt.mdp",
                                                           "-c": emgro,
                                                           "-r": emgro,
                                                           "-p": "topol.top"},
                                            output_files = {"-o": "nvt.tpr"})
        eq1tpr.run()
        print ("eq1tpr", eq1tpr.output.erroroutput.result())
        eq1tp = gmx.read_tpr(eq1tpr.output.file["-o"])
        eq1=gmx.mdrun(eq1tp)
        eq1.run()
        #sp.run(["gmx", "grompp", "-f", "nvt.mdp", "-c", "em.gro", "-r", "em.gro", "-p",\
        #        "topol.top", "-o",  "nvt.tpr"])
        #sp.run(["gmx", "mdrun", "-deffnm", "nvt"])
        eq1gro=eq1.output.trajectory.result()
        eq1gro=eq1gro[:eq1gro.rfind('/') + 1] + "confout.gro"
        

        
        # Equilibration 2
        eq2tpr =  gmx.commandline_operation(executable = "gmx",
                                            arguments = ["grompp"],
                                            input_files = {"-f": "npt.mdp",
                                                           "-c": eq1gro,
                                                           "-r": eq1gro,
                                                           "-p": "topol.top"},
                                            output_files = {"-o": "npt.tpr"})
        eq2tpr.run()
        print ("eq2tpr", eq2tpr.output.erroroutput.result())
        eq2tp = gmx.read_tpr(eq2tpr.output.file["-o"])
        eq2 = gmx.mdrun(eq2tp)
        eq2.run()
        eq2out = eq2.output.trajectory.result()
        eq2out = eq2out[:eq2out.rfind('/') + 1] 





        mdtpr = gmx.commandline_operation(executable = "gmx",
                                          arguments = ["grompp"],
                                          input_files = {"-f": "md.mdp",
                                                         "-c": eq2out + "confout.gro",
                                                         "-t": eq2out + "state.cpt",
                                                         "-p": "topol.top"},
                                          output_files = {"-o": "md_0_1.tpr"})
        mdtpr.run()

        mdtp = gmx.read_tpr(mdtpr.output.file["-o"])
        md = gmx.mdrun(mdtp)
        md.run()

        print("Finished")
                                                         

        # RUN
        """sp.run(["gmx", "grompp", "-f", "md.mdp", "-c", "npt.gro", "-t", "npt.cpt", "-p", \
                "topol.top", "-o", "md_0_1.tpr"])
        sp.run(["gmx", "mdrun", "-deffnm", "md_0_1"])"""
    except stop:
        print ("*** Exiting program per users wishes ***")
        return