Esempio n. 1
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()
Esempio n. 2
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()
Esempio n. 3
0
def test_fr7(spc_water_box):
    """FR7: Python bindings for launching simulations.

    gmx.mdrun uses bindings to C++ API to launch simulations.
    """
    md = gmx.mdrun(spc_water_box)
    md.run()
Esempio n. 4
0
def test_run_trivial_ensemble(spc_water_box, caplog):
    from mpi4py import MPI
    current_rank = MPI.COMM_WORLD.Get_rank()
    with caplog.at_level(logging.DEBUG):
        caplog.handler.setFormatter(formatter)
        with caplog.at_level(logging.WARNING, 'gmxapi'), \
                caplog.at_level(logging.DEBUG, 'gmxapi.mdrun'), \
                caplog.at_level(logging.DEBUG, 'gmxapi.modify_input'), \
                caplog.at_level(logging.DEBUG, 'gmxapi.read_tpr'), \
                caplog.at_level(logging.DEBUG, 'gmxapi.simulation'):

            tpr_filename = spc_water_box
            ensemble_width = 2
            simulation_input = gmx.read_tpr([tpr_filename] * ensemble_width)
            assert simulation_input.output.ensemble_width == ensemble_width
            assert len(simulation_input.output._simulation_input.result()
                       ) == ensemble_width
            md = gmx.mdrun(simulation_input)
            assert md.output.ensemble_width == ensemble_width
            md.run()

            output_directory = md.output._work_dir.result()
            logging.info('output_directory result: {}'.format(
                str(output_directory)))
            assert len(output_directory) == 2

            # Note that the 'cleandir' test fixture will clean up the output directory on
            # other ranks, so only check the current rank. Generally, our behavior
            # is undefined if the client removes the working directory while the job
            # is in progress. We can consider adding some sort of synchronization at
            # the end of the job if running in temporary directories becomes an
            # important use case outside of testing.
            assert output_directory[0] != output_directory[1]
            assert os.path.exists(output_directory[current_rank])
            assert os.path.exists(md.output.trajectory.result()[current_rank])
Esempio n. 5
0
    def single_run(self, name, log = False, template = "", additions = None):
        # 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")
        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")
Esempio n. 6
0
def test_fr7():
    """FR7: Python bindings for launching simulations.

    gmx.mdrun uses bindings to C++ API to launch simulations.
    """
    md = gmx.mdrun(tprfilename)
    md.run()
Esempio n. 7
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)
Esempio n. 8
0
def test_fr15(spc_water_box, caplog):
    """FR15: Simulation input modification.

    * *gmx.modify_input produces new (tpr) simulation input in data flow operation*
      (requires interaction with library development)
    """
    try:
        from mpi4py import MPI
        current_rank = MPI.COMM_WORLD.Get_rank()
        ensemble_size = MPI.COMM_WORLD.Get_size()
    except ImportError:
        current_rank = 0
        ensemble_size = 1

    with caplog.at_level(logging.DEBUG):
        caplog.handler.setFormatter(formatter)
        with caplog.at_level(logging.WARNING, 'gmxapi'), \
                 caplog.at_level(logging.DEBUG, 'gmxapi.mdrun'), \
                 caplog.at_level(logging.DEBUG, 'gmxapi.modify_input'), \
                 caplog.at_level(logging.DEBUG, 'gmxapi.read_tpr'), \
                 caplog.at_level(logging.DEBUG, 'gmxapi.simulation'):

            initial_input = gmx.read_tpr(
                [spc_water_box for _ in range(ensemble_size)])
            parameters = list([{'ld-seed': i} for i in range(ensemble_size)])
            param_sweep = gmx.modify_input(input=initial_input,
                                           parameters=parameters)
            md = gmx.mdrun(param_sweep)
            # TODO: (#3179) Handle ensembles of size 1 more elegantly.
            if md.output.ensemble_width > 1:
                result_list = md.output.parameters['ld-seed'].result()
            else:
                result_list = [md.output.parameters['ld-seed'].result()]
            for expected, actual in zip(parameters, result_list):
                assert expected['ld-seed'] == actual
Esempio n. 9
0
def _(task: scalems.workflow.Task, context: WorkflowManager):
    sublogger = logger.getChild('scalems_helper')
    sublogger.debug('Serialized task record: {}'.format(task.serialize()))
    command = task.type[-1]
    assert command in {'Simulate', 'SimulationInput', 'Executable'}
    # Right now, we should only need to process the 'Simulate' command...
    assert command == 'Simulate'
    # TODO: Typing on the Task data proxy.
    command_message = task.input['message'][command]
    # kwargs = command_message['kwargs']
    input_ref: str = command_message['input']
    logger.debug(f'Decoding reference {input_ref}')
    input_ref: bytes = bytes.fromhex(input_ref)
    task_map = context.task_map
    logger.debug('Items done: {}'.format(
        ', '.join([': '.join([key.hex(), str(value.done())]) for key, value in task_map.items()])
    ))
    # simulator_input_view = context.item(input_ref)

    # TODO: Workaround until we have the framework deliver results.
    # simulator_input: SubprocessResult = simulator_input_view.result()
    # logger.debug(f'Acquired grompp output: {simulator_input}')
    # tprfile = simulator_input.file['-o']
    dependency_dir = pathlib.Path(os.getcwd()).parent / input_ref.hex()
    tprfile = dependency_dir / 'topol.tpr'
    import gmxapi
    md_in = gmxapi.read_tpr(str(tprfile))
    # TODO: Manage or integrate with gmxapi working directories.
    md = gmxapi.mdrun(md_in)
    # TODO: Make sure we mark interrupted simulations as "failed".
    return md.run()
Esempio n. 10
0
def test_run_trivial_ensemble(spc_water_box, caplog):
    from mpi4py import MPI
    current_rank = MPI.COMM_WORLD.Get_rank()
    with caplog.at_level(logging.DEBUG):
        caplog.handler.setFormatter(formatter)
        with caplog.at_level(logging.WARNING, 'gmxapi'), \
                caplog.at_level(logging.DEBUG, 'gmxapi.mdrun'), \
                caplog.at_level(logging.DEBUG, 'gmxapi.modify_input'), \
                caplog.at_level(logging.DEBUG, 'gmxapi.read_tpr'), \
                caplog.at_level(logging.DEBUG, 'gmxapi.simulation'):

            tpr_filename = spc_water_box
            ensemble_width = 2
            simulation_input = gmx.read_tpr([tpr_filename] * ensemble_width)
            assert simulation_input.output.ensemble_width == ensemble_width
            assert len(simulation_input.output._simulation_input.result()
                       ) == ensemble_width
            md = gmx.mdrun(simulation_input)
            assert md.output.ensemble_width == ensemble_width
            md.run()

            output_directory = md.output._work_dir.result()
            logging.info('output_directory result: {}'.format(
                str(output_directory)))
            assert len(output_directory) == 2

            # Note that the 'cleandir' test fixture will clean up the output directory on
            # other ranks, so only check the current rank.
            assert output_directory[0] != output_directory[1]
            assert os.path.exists(output_directory[current_rank])
Esempio n. 11
0
def test_fr7():
    """FR7: Python bindings for launching simulations.

    gmx.mdrun uses bindings to C++ API to launch simulations.
    """
    md = gmx.mdrun(tprfilename)
    md.run()
Esempio n. 12
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)
Esempio n. 13
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)
Esempio n. 14
0
def test_fr23():
    """FR23: Ensemble simulations can themselves use MPI

    *GROMACS simulation can use a set of subcommunicators from the comm owned by the client.*
    (requires interaction with library development)
    """
    from mpi4py import MPI
    comm_world = MPI.COMM_WORLD

    md = gmx.mdrun([tpr_filename for _ in range(2)])

    with gmx.get_context(md, communicator=comm_world) as session:
        session.run()

    md = gmx.mdrun([tpr_filename for _ in range(4)])

    with gmx.get_context(md, communicator=comm_world) as session:
        session.run()
Esempio n. 15
0
def test_run_from_modify_input_op(spc_water_box, caplog):
    with caplog.at_level(logging.DEBUG):

        simulation_input = gmx.read_tpr(spc_water_box)
        modified_input = gmx.modify_input(input=simulation_input,
                                          parameters={'nsteps': 4})
        md = gmx.mdrun(input=modified_input)

        md.run()
Esempio n. 16
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())
Esempio n. 17
0
def test_fr23():
    """FR23: Ensemble simulations can themselves use MPI

    *GROMACS simulation can use a set of subcommunicators from the comm owned by the client.*
    (requires interaction with library development)
    """
    from mpi4py import MPI
    comm_world = MPI.COMM_WORLD

    md = gmx.mdrun([tpr_filename for _ in range(2)])

    with gmx.get_context(md, communicator=comm_world) as session:
        session.run()

    md = gmx.mdrun([tpr_filename for _ in range(4)])


    with gmx.get_context(md, communicator=comm_world) as session:
        session.run()
Esempio n. 18
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
Esempio n. 19
0
 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")
Esempio n. 20
0
def test_fr13():
    """FR13: ``run`` module function simplifies user experience

    * gmx.run finds and runs operations to produce expected output files
    * gmx.run handles ensemble work topologies
    * gmx.run handles multi-process execution
    * gmx.run safety checks to avoid data loss / corruption
    """
    # commandline_operation helper creates a set of operations
    # that includes the discovery and execution of the program
    # named in `executable`.
    md = gmx.mdrun([tprfilename, tprfilename])
    gmx.run()
Esempio n. 21
0
def test_fr13():
    """FR13: ``run`` module function simplifies user experience

    * gmx.run finds and runs operations to produce expected output files
    * gmx.run handles ensemble work topologies
    * gmx.run handles multi-process execution
    * gmx.run safety checks to avoid data loss / corruption
    """
    # commandline_operation helper creates a set of operations
    # that includes the discovery and execution of the program
    # named in `executable`.
    md = gmx.mdrun([tprfilename, tprfilename])
    gmx.run()
Esempio n. 22
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
Esempio n. 23
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
Esempio n. 24
0
def test_fr22():
    """FR22: MPI-based ensemble management from Python

    gmx.context can own an MPI communicator and run ensembles of simulations.
    """
    from mpi4py import MPI
    comm_world = MPI.COMM_WORLD

    group2 = comm_world.Get_group().Incl([0,1])
    ensemble_comm = comm_world.Create_group(group2)

    md = gmx.mdrun([tpr_filename for _ in range(2)])

    with gmx.get_context(md, communicator=ensemble_comm) as session:
        session.run()

    ensemble_comm.Free()
Esempio n. 25
0
def test_fr22():
    """FR22: MPI-based ensemble management from Python

    gmx.context can own an MPI communicator and run ensembles of simulations.
    """
    from mpi4py import MPI
    comm_world = MPI.COMM_WORLD

    group2 = comm_world.Get_group().Incl([0, 1])
    ensemble_comm = comm_world.Create_group(group2)

    md = gmx.mdrun([tpr_filename for _ in range(2)])

    with gmx.get_context(md, communicator=ensemble_comm) as session:
        session.run()

    ensemble_comm.Free()
Esempio n. 26
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')})
Esempio n. 27
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')})
Esempio n. 28
0
def test_fr10():
    """FR10: 10: fused operations for use in looping constructs

    * gmx.subgraph fuses operations
    * gmx.while creates an operation wrapping a dynamic number of iterations of a subgraph
    """
    train = gmx.subgraph(variables={'conformation': initial_input})
    with train:
        myplugin.training_restraint(label='training_potential',
                                    params=my_dict_params)
        modified_input = gmx.modify_input(input=initial_input,
                                          structure=train.conformation)
        md = gmx.mdrun(input=modified_input,
                       potential=train.training_potential)
        # Alternate syntax to facilitate adding multiple potentials:
        # md.interface.potential.add(train.training_potential)
        brer_tools.training_analyzer(
            label='is_converged', params=train.training_potential.output.alpha)
        train.conformation = md.output.conformation

    train_loop = gmx.while_loop(operation=train,
                                condition=gmx.logical_not(train.is_converged))
Esempio n. 29
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
Esempio n. 30
0
def test_fr10():
    """FR10: 10: fused operations for use in looping constructs

    * gmx.subgraph fuses operations
    * gmx.while creates an operation wrapping a dynamic number of iterations of a subgraph
    """
    train = gmx.subgraph(variables={'conformation': initial_input})
    with train:
        myplugin.training_restraint(
            label='training_potential',
            params=my_dict_params)
        modified_input = gmx.modify_input(
            input=initial_input, structure=train.conformation)
        md = gmx.mdrun(input=modified_input, potential=train.training_potential)
        # Alternate syntax to facilitate adding multiple potentials:
        # md.interface.potential.add(train.training_potential)
        brer_tools.training_analyzer(
            label='is_converged',
            params=train.training_potential.output.alpha)
        train.conformation = md.output.conformation

    train_loop = gmx.while_loop(
        operation=train,
        condition=gmx.logical_not(train.is_converged))
Esempio n. 31
0
def test_fr8():
    """FR8: gmx.mdrun understands ensemble work."""
    md = gmx.mdrun([tprfilename, tprfilename])
    md.run()
Esempio n. 32
0
def test_run_from_tpr(spc_water_box):
    assert os.path.exists(spc_water_box)

    md = gmx.mdrun(spc_water_box)
    md.run()
Esempio n. 33
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()
Esempio n. 34
0
def test_fr8(spc_water_box):
    """FR8: gmx.mdrun understands ensemble work."""
    md = gmx.mdrun([spc_water_box, spc_water_box])
    md.run()
Esempio n. 35
0
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()
Esempio n. 36
0
def test_fr8():
    """FR8: gmx.mdrun understands ensemble work."""
    md = gmx.mdrun([tprfilename, tprfilename])
    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