Esempio n. 1
0
def test_from_dict():
    # Define a new potential, the format is python dictionary or json
    spec = {
        "nonbonded" :  {"Na" : {"q" : 1, "sigma": 0.2, "eps": 0.3, "type": "Na"},
                        "Cl" : {"q" : -1, "sigma": 0.2, "eps": 0.3, "type": "Cl"},
                        "OW" : {"q" : 1, "sigma": 0.2, "eps": 0.3, "type": "O"},
                        "HW1" : {"q" : 1, "sigma": 0.2, "eps": 0.3, "type": "H"},
                        "HW2" : {"q" : 1, "sigma": 0.2, "eps": 0.3, "type": "H"}},

        "bonded" : {'SOL' : { 'particles': ['OW', 'HW1', 'HW2'], 
                              'bonds': [{ 'between': (0, 1), 'r' : 0.2, 'k': 0.1 }, 
                                        { 'between': (0, 1), 'r' : 0.2, 'k': 0.1 }],
                              'angles': [{'between': (1, 0, 2), 'theta' : 90, 'k': 0.1}]
                            },
                    'NA' :  { 'particles' : ['Na'] },
                    'CL' :  { 'particles' : ['Cl'] },
                   }
    }
    
    na = Molecule.from_arrays(type_array=['Na'], molecule_name='NA')
    cl = Molecule.from_arrays(type_array=['Cl'], molecule_name='CL')
    water = Molecule.from_arrays(type_array=['O', 'H', 'H'], 
                                 molecule_name='SOL',
                                 bonds=[[0, 1], [0, 2]])

    s = System([na, na, cl, cl, water, water])
    p = ForceGenerator(spec)
    
    print to_top(s, p)
Esempio n. 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
Esempio n. 3
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
Esempio n. 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)
Esempio n. 5
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)