Example #1
0
def make_gromacs(simulation, directory, clean=False):
    """Create gromacs directory structure"""
    if clean is False and os.path.exists(directory):
        raise ValueError(
            'Cannot override {}, use option clean=True'.format(directory))
    else:
        shutil.rmtree(directory, ignore_errors=True)
        os.mkdir(directory)

    # Check custom simulation potential

    if simulation.potential.intermolecular.type == 'custom':

        for pair in simulation.potential.intermolecular.special_pairs:
            table = to_table(
                simulation.potential.intermolecular.pair_interaction(*pair),
                simulation.cutoff)
            fname1 = os.path.join(directory,
                                  'table_{}_{}.xvg'.format(pair[0], pair[1]))
            fname2 = os.path.join(directory,
                                  'table_{}_{}.xvg'.format(pair[1], pair[0]))

            with open(fname1, 'w') as fd:
                fd.write(table)

            with open(fname2, 'w') as fd:
                fd.write(table)

        ndx = {'System': np.arange(simulation.system.n_atoms, dtype='int')}
        for particle in simulation.potential.intermolecular.particles:
            idx = simulation.system.where(
                atom_name=particle)['atom'].nonzero()[0]
            ndx[particle] = idx

        with open(os.path.join(directory, 'index.ndx'), 'w') as fd:
            fd.write(to_ndx(ndx))

    # Parameter file
    mdpfile = to_mdp(simulation)
    with open(os.path.join(directory, 'grompp.mdp'), 'w') as fd:
        fd.write(mdpfile)

    # Topology file
    topfile = to_top(simulation.system, simulation.potential)
    with open(os.path.join(directory, 'topol.top'), 'w') as fd:
        fd.write(topfile)

    # Simulation file
    datafile(os.path.join(directory, 'conf.gro'),
             'w').write('system', simulation.system)

    return directory
Example #2
0
def make_gromacs(simulation, directory, clean=False):
    """Create gromacs directory structure"""
    if clean is False and os.path.exists(directory):
        raise ValueError("Cannot override {}, use option clean=True".format(directory))
    else:
        shutil.rmtree(directory, ignore_errors=True)
        os.mkdir(directory)

    # Check custom simulation potential

    if simulation.potential.intermolecular.type == "custom":

        for pair in simulation.potential.intermolecular.special_pairs:
            table = to_table(simulation.potential.intermolecular.pair_interaction(*pair), simulation.cutoff)
            fname1 = os.path.join(directory, "table_{}_{}.xvg".format(pair[0], pair[1]))
            fname2 = os.path.join(directory, "table_{}_{}.xvg".format(pair[1], pair[0]))

            with open(fname1, "w") as fd:
                fd.write(table)

            with open(fname2, "w") as fd:
                fd.write(table)

        ndx = {"System": np.arange(simulation.system.n_atoms, dtype="int")}
        for particle in simulation.potential.intermolecular.particles:
            idx = simulation.system.where(atom_name=particle)["atom"].nonzero()[0]
            ndx[particle] = idx

        with open(os.path.join(directory, "index.ndx"), "w") as fd:
            fd.write(to_ndx(ndx))

    # Parameter file
    mdpfile = to_mdp(simulation)
    with open(os.path.join(directory, "grompp.mdp"), "w") as fd:
        fd.write(mdpfile)

    # Topology file
    topfile = to_top(simulation.system, simulation.potential)
    with open(os.path.join(directory, "topol.top"), "w") as fd:
        fd.write(topfile)

    # Simulation file
    datafile(os.path.join(directory, "conf.gro"), "w").write("system", simulation.system)

    return directory
Example #3
0
def run_gromacs(simulation, directory, clean=False):
    if clean is False and os.path.exists(directory):
        raise ValueError(
            'Cannot override {}, use option clean=True'.format(directory))
    else:
        shutil.rmtree(directory, ignore_errors=True)
        os.mkdir(directory)

    # Parameter file
    mdpfile = to_mdp(simulation)
    with open(os.path.join(directory, 'grompp.mdp'), 'w') as fd:
        fd.write(mdpfile)

    # Topology file
    topfile = to_top(simulation.system, simulation.potential)
    with open(os.path.join(directory, 'topol.top'), 'w') as fd:
        fd.write(topfile)

    # Simulation file
    datafile(os.path.join(directory, 'conf.gro'),
             'w').write('system', simulation.system)

    process = subprocess.Popen(
        'cd {} && grompp_d && exec mdrun_d -v'.format(directory),
        shell=True,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        universal_newlines=True)

    output_box = Textarea()
    output_box.height = '200px'
    output_box.font_family = 'monospace'
    output_box.color = '#AAAAAA'
    output_box.background_color = 'black'
    output_box.width = '800px'
    display(output_box)

    def output_function(text, output_box=output_box):
        output_box.value += text.decode('utf8')
        output_box.scroll_to_bottom()

    return AsyncCalculation(process, simulation, directory, output_function)
Example #4
0
def run_gromacs(simulation, directory, clean=False):
    if clean is False and os.path.exists(directory):
        raise ValueError("Cannot override {}, use option clean=True".format(directory))
    else:
        shutil.rmtree(directory, ignore_errors=True)
        os.mkdir(directory)

    # Parameter file
    mdpfile = to_mdp(simulation)
    with open(os.path.join(directory, "grompp.mdp"), "w") as fd:
        fd.write(mdpfile)

    # Topology file
    topfile = to_top(simulation.system, simulation.potential)
    with open(os.path.join(directory, "topol.top"), "w") as fd:
        fd.write(topfile)

    # Simulation file
    datafile(os.path.join(directory, "conf.gro"), "w").write("system", simulation.system)

    process = subprocess.Popen(
        "cd {} && grompp_d && exec mdrun_d -v".format(directory),
        shell=True,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        universal_newlines=True,
    )

    output_box = Textarea()
    output_box.height = "200px"
    output_box.font_family = "monospace"
    output_box.color = "#AAAAAA"
    output_box.background_color = "black"
    output_box.width = "800px"
    display(output_box)

    def output_function(text, output_box=output_box):
        output_box.value += text.decode("utf8")
        output_box.scroll_to_bottom()

    return AsyncCalculation(process, simulation, directory, output_function)