def test_real_units(self):
        L = PyLammps()
        L.units('real') # angstrom, kcal/mol, femtoseconds
        L.atom_style('atomic')
        L.boundary('p p p')

        L.lattice('none', 1.0)

        # create simulation cell
        L.region('r1 block', -15.0, 15.0, -15.0, 15.0, -15.0, 15.0)
        L.create_box(1, 'r1')

        # argon
        L.mass(1, 39.948002)
        L.pair_style('lj/cut', 8.5)
        L.pair_coeff(1, 1, 0.2379, 3.405)

        L.timestep(10.0)

        L.create_atoms(1, 'single', -1.0, 0.0, 0.0)
        L.create_atoms(1, 'single',  1.0, 0.0, 0.0)

        L.velocity('all create', 250.0, 54321, 'mom no rot no')

        L.minimize(1.0e-10, 1.0e-10, 100, 1000)

        L.reset_timestep(0)

        L.thermo(100)
        L.fix('f1 all nve')
        L.run(1000)
Esempio n. 2
0
    def test_melt_using_groups(self):
        """ 3d Lennard-Jones melt with two atom types """
        L = PyLammps()
        L.units('lj')
        L.atom_style('atomic')
        L.lattice('fcc', 0.8442) # NOTE: lattice command is different in LJ units
        L.region('whole block', 0.0, 10.0, 0, 10, 0, 10)
        L.create_box(2, 'whole')
        L.region('upper block', 4.9, 10.1, 'EDGE EDGE EDGE EDGE')
        L.region('lower block', 0.0,  4.9, 'EDGE EDGE EDGE EDGE')

        # fill box with atoms according to lattice positions
        L.create_atoms(1, 'region upper')
        L.create_atoms(2, 'region lower')

        L.mass(1, 1.0)
        L.mass(2, 2.0)

        L.group('gu', 'type', 1)
        L.group('gl', 'type', 2)

        L.velocity('gu', 'create 2.0 12345 mom no rot no')
        L.velocity('gl', 'create 4.0 54321 mom no rot no')


        L.timestep(0.002)
        L.pair_style('lj/cut', 2.5)
        L.pair_coeff('* *', 1.0, 1.0, 2.5)
        L.fix('f1 all nve')

        #L.dump('d1 all image 500 snap-03.*.jpg type type')

        L.thermo(50)
        L.run(500)
    def test_change_potential(self):
        L = PyLammps()
        L.file(IncludeTests.ATOMS_SETUP_FILE)

        # set non-bonded potential
        L.pair_style('lj/cut', 5.0)
        L.pair_coeff(1, 1, 1.0, 1.0)

        # set different non-bonded potential
        L.velocity('all create', 1.0, 54321, 'mom no rot no')

        # import time integration setting from include file
        L.file(IncludeTests.VERLET_CONFIG_FILE)

        L.minimize(1.0e-10, 1.0e-10, 100, 1000)

        L.reset_timestep(0)  # set timestep counter to zero

        L.thermo(10)         # thermo output every 10 steps

        L.run(100, 'post no')

        # continue run with different potential
        L.pair_style('morse', 5.0)
        L.pair_coeff(1, 1, 1.0, 5.0, 1.12)

        L.run(100)
Esempio n. 4
0
    def test_melt(self):
        """ 3d Lennard-Jones melt """
        L = PyLammps()
        L.units('lj')
        L.atom_style('atomic')

        L.lattice('fcc', 0.8442)   # NOTE: lattice command is different in LJ units
                                   #       0.8442 is density fraction
        L.region('r1 block', 0, 10, 0, 10, 0, 10)
        L.create_box(1, 'r1')

        # fill box with atoms according to lattice positions
        L.create_atoms(1, 'box')
        L.mass(1, 1.0)
        L.velocity('all create', 3.0, 87287, 'mom no')

        L.timestep(0.002)

        L.pair_style('lj/cut', 2.5)
        L.pair_coeff(1, 1, 1.0, 1.0, 2.5)
        L.fix('f1 all nve')

        L.dump('d1 all image 500 snap-01.*.jpg type type')

        L.thermo(50)
        L.run(500)

        self.assertTrue(os.path.exists('snap-01.0.jpg'))
        self.assertTrue(os.path.exists('snap-01.500.jpg'))
        os.remove('snap-01.0.jpg')
        os.remove('snap-01.500.jpg')
    def test_morse_potential(self):
        L = PyLammps()
        L.file(IncludeTests.ATOMS_SETUP_FILE)

        # set different non-bonded potential
        L.pair_style('morse', 5.0)
        L.pair_coeff(1, 1, 1.0, 5.0, 1.12)

        L.velocity('all create', 1.0, 54321, 'mom no rot no')

        # import time integration setting from include file
        L.file(IncludeTests.VERLET_CONFIG_FILE)

        L.thermo(10)         # thermo output every 10 steps

        L.run(100)
Esempio n. 6
0
def data(i):
    lmp1 = lammps()
    polymer = PyLammps(ptr=lmp1)
    x = 60
    y = 30
    z = 30
    t = 1
    polymer.units("lj")
    polymer.dimension(3)
    polymer.atom_style("bond")
    polymer.bond_style("harmonic")
    polymer.pair_style("lj/cut", 3)
    polymer.read_data("data.polymer")
    polymer.region("void cylinder x", 15, 15, 2, 29, 31)
    polymer.pair_coeff(1, 2, 2.5, 3)
    polymer.pair_coeff(1, 3, 2.5, 1.12)
    polymer.pair_coeff(2, 3, 2.5, 1.12)
    polymer.velocity("all create", t, 97287)
    polymer.group("polymer type", 1, 2)
    polymer.group("first type", 1)
    polymer.region("box block", 0, x, 0, y, 0, z)
    polymer.region("spherein sphere", 29, 15, 15, 2)
    polymer.region("boxin block", 27, 29, 13, 17, 13, 17)
    polymer.region("hemiin intersect", 2, "boxin spherein")
    x0 = polymer.atoms[0].position[0]
    y0 = polymer.atoms[0].position[1]
    z0 = polymer.atoms[0].position[2]
    r = lambda x0, y0, z0: np.sqrt((x0 - 29)**2 + (y0 - 15)**2 + (z0 - 15)**2)
    fx = lambda x0, y0, z0: 5 * (x0 - 29) / r(x0, y0, z0)
    fy = lambda x0, y0, z0: 5 * (y0 - 15) / r(x0, y0, z0)
    fz = lambda x0, y0, z0: 5 * (z0 - 15) / r(x0, y0, z0)
    polymer.fix(1, "polymer nve")
    polymer.fix(2, "polymer langevin", t, t, 1.5,
                np.random.randint(2, high=200000))
    polymer.fix(3, "polymer spring tether", 10, i, "NULL NULL", 0)
    polymer.timestep(0.01)
    polymer.compute("com polymer com")
    polymer.variable("ftotal equal fcm(polymer,x)")
    polymer.variable("c equal c_com[1]")
    polymer.thermo_style("custom v_ftotal v_c")
    polymer.thermo(1)
    polymer.run(500000)
    l = polymer.runs[0][0][1][20000:] + [i]
    u = [np.mean(polymer.runs[0][0][0][20000:]), i]
    np.savetxt("trial%dmean.txt" % i, u)
    np.savetxt("trial%dall.txt" % i, l)
    return u
    def setUp(self):
        L = PyLammps()
        L.units('lj')
        L.atom_style('atomic')
        L.boundary('p p p')
        L.atom_modify("map array")

        L.region('r1 block', -5.0, 5.0, -5.0, 5.0, -5.0, 5.0)
        L.create_box(1, 'r1')

        L.mass(1, 1.0)

        L.create_atoms(1, 'single', -1.0, 0.0, 0.0)
        L.create_atoms(1, 'single',  1.0, 0.0, 0.0)

        L.pair_style('lj/cut', 5.0)
        L.pair_coeff(1, 1, 1.0, 1.0)

        L.run(0)
        self.L = L
    def test_run_post_no_pre_no(self):
        L = PyLammps()
        L.file(IncludeTests.ATOMS_SETUP_FILE)

        # set non-bonded potential
        L.pair_style('lj/cut', 5.0)
        L.pair_coeff(1, 1, 1.0, 1.0)

        # set different non-bonded potential
        L.velocity('all create', 1.0, 54321, 'mom no rot no')

        # import time integration setting from include file
        L.file(IncludeTests.VERLET_CONFIG_FILE)

        L.minimize(1.0e-10, 1.0e-10, 100, 1000)

        L.reset_timestep(0)  # set timestep counter to zero

        L.thermo(10)         # thermo output every 10 steps

        L.run(100, 'post no') # don't print post run information

        L.run(100, 'pre no')  # don't to pre-run preparation (not needed, if no change)
Esempio n. 9
0
    L.create_atoms(1, "region",
                   "cluster")  # fill cluster region with atoms of type 1
    L.create_atoms(3, "random", nPartsub, 4723738,
                   "subst")  # fill substrate region with atoms of type 3

    L.group("substinteggr", "region", "substinteg")
    L.group("clusterregiongr", "region", "cluster")

    L.group("allintegrategr", "region", "allintegr")

    L.set("region", "cluster", "type/fraction", 2, xNi, 1234)
    L.group("clustergr", "type", 1, 2)

    # mit Zhou-Potential:
    L.pair_style("hybrid", "eam/alloy", "lj/cut", 10.0, "tersoff")
    L.pair_coeff("* * eam/alloy NiAu_Zhou.eam.alloy Au Ni NULL")
    L.pair_coeff(1, 3, "lj/cut", epsAuC, sigAuC, 10.0)
    L.pair_coeff(2, 3, "lj/cut", epsNiC, sigNiC, 10.0)
    L.pair_coeff("* *", "tersoff", "SiC.tersoff", "NULL NULL C")

    # mit Ralf Meyers Potential:
    # L.pair_style("hybrid","eam/fs","lj/cut",10.0,"tersoff")
    # L.pair_coeff("* * eam/fs Ni_Au_SMATB.eam.fs Au Ni NULL")
    # L.pair_coeff(1,3,"lj/cut",epsAuC,sigAuC,10.0)
    # L.pair_coeff(2,3,"lj/cut",epsNiC,sigNiC,10.0)
    # L.pair_coeff("* *","tersoff","SiC.tersoff","NULL NULL C")

    # L.pair_style("hybrid eam lj/cut 10.0 tersoff")
    # L.pair_coeff("* * eam Au_u3.eam")
    # L.pair_coeff(1,2,"lj/cut",epsAuC,sigAuC,10.0)
    # L.pair_coeff("* * tersoff SiC.tersoff NULL C")
Esempio n. 10
0
class PythonPyLammps(unittest.TestCase):
    def setUp(self):
        machine = None
        if 'LAMMPS_MACHINE_NAME' in os.environ:
            machine = os.environ['LAMMPS_MACHINE_NAME']
        self.pylmp = PyLammps(
            name=machine,
            cmdargs=['-nocite', '-log', 'none', '-echo', 'screen'])
        self.pylmp.units("lj")
        self.pylmp.atom_style("atomic")
        self.pylmp.atom_modify("map array")

        if 'LAMMPS_CMAKE_CACHE' in os.environ:
            self.cmake_cache = {}

            with open(os.environ['LAMMPS_CMAKE_CACHE'], 'r') as f:
                for line in f:
                    line = line.strip()
                    if not line or line.startswith('#') or line.startswith(
                            '//'):
                        continue
                    parts = line.split('=')
                    key, value_type = parts[0].split(':')
                    if len(parts) > 1:
                        value = parts[1]
                        if value_type == "BOOL":
                            value = (value.upper() == "ON")
                    else:
                        value = None
                    self.cmake_cache[key] = value

    def tearDown(self):
        self.pylmp.close()
        del self.pylmp

    def test_version(self):
        self.assertGreaterEqual(self.pylmp.version(), 20200824)

    def test_create_atoms(self):
        self.pylmp.region("box block", 0, 2, 0, 2, 0, 2)
        self.pylmp.create_box(1, "box")

        x = [1.0, 1.0, 1.0, 1.0, 1.0, 1.5]

        types = [1, 1]

        self.assertEqual(
            self.pylmp.lmp.create_atoms(2, id=None, type=types, x=x), 2)
        self.assertEqual(self.pylmp.system.natoms, 2)
        self.assertEqual(len(self.pylmp.atoms), 2)
        numpy.testing.assert_array_equal(self.pylmp.atoms[0].position,
                                         tuple(x[0:3]))
        numpy.testing.assert_array_equal(self.pylmp.atoms[1].position,
                                         tuple(x[3:6]))
        self.assertEqual(self.pylmp.last_run, None)

    def test_write_script(self):
        outfile = 'in.test_write_script'
        self.pylmp.write_script(outfile)
        self.assertTrue(os.path.exists(outfile))
        os.remove(outfile)

    def test_runs(self):
        self.pylmp.lattice("fcc", 0.8442),
        self.pylmp.region("box block", 0, 4, 0, 4, 0, 4)
        self.pylmp.create_box(1, "box")
        self.pylmp.create_atoms(1, "box")
        self.pylmp.mass(1, 1.0)
        self.pylmp.velocity("all create", 1.44, 87287, "loop geom")
        self.pylmp.pair_style("lj/cut", 2.5)
        self.pylmp.pair_coeff(1, 1, 1.0, 1.0, 2.5)
        self.pylmp.neighbor(0.3, "bin")
        self.pylmp.neigh_modify("delay 0 every 20 check no")
        self.pylmp.fix("1 all nve")
        self.pylmp.variable("fx atom fx")
        self.pylmp.run(10)

        self.assertEqual(len(self.pylmp.runs), 1)
        self.assertEqual(self.pylmp.last_run, self.pylmp.runs[0])
        self.assertEqual(len(self.pylmp.last_run.thermo.Step), 2)
        self.assertEqual(len(self.pylmp.last_run.thermo.Temp), 2)
        self.assertEqual(len(self.pylmp.last_run.thermo.E_pair), 2)
        self.assertEqual(len(self.pylmp.last_run.thermo.E_mol), 2)
        self.assertEqual(len(self.pylmp.last_run.thermo.TotEng), 2)
        self.assertEqual(len(self.pylmp.last_run.thermo.Press), 2)

    def test_info_queries(self):
        self.pylmp.lattice("fcc", 0.8442),
        self.pylmp.region("box block", 0, 4, 0, 4, 0, 4)
        self.pylmp.create_box(1, "box")
        self.pylmp.variable("a equal 10.0")
        self.pylmp.variable("b string value")
        self.assertEqual(self.pylmp.variables['a'].value, 10.0)
        self.assertEqual(self.pylmp.variables['b'].value, 'value')
        self.assertEqual(len(self.pylmp.variables), 2)
        self.assertEqual(self.pylmp.system.units, 'lj')
        self.assertEqual(self.pylmp.system.atom_style, 'atomic')
        self.assertEqual(self.pylmp.system.ntypes, 1)
        self.assertEqual(self.pylmp.system.natoms, 0)
        self.assertEqual(self.pylmp.communication.comm_style, 'brick')
        self.assertEqual(self.pylmp.communication.comm_layout, 'uniform')
        self.assertEqual(self.pylmp.communication.nprocs, 1)
        self.assertEqual(len(self.pylmp.computes), 3)
        self.assertEqual(self.pylmp.computes[0]['name'], 'thermo_temp')
        self.assertEqual(self.pylmp.computes[0]['style'], 'temp')
        self.assertEqual(self.pylmp.computes[0]['group'], 'all')
        self.assertEqual(self.pylmp.computes[1]['name'], 'thermo_press')
        self.assertEqual(self.pylmp.computes[1]['style'], 'pressure')
        self.assertEqual(self.pylmp.computes[1]['group'], 'all')
        self.assertEqual(self.pylmp.computes[2]['name'], 'thermo_pe')
        self.assertEqual(self.pylmp.computes[2]['style'], 'pe')
        self.assertEqual(self.pylmp.computes[2]['group'], 'all')
        self.assertEqual(len(self.pylmp.dumps), 0)
        self.pylmp.fix('one', 'all', 'nve')
        self.assertEqual(len(self.pylmp.fixes), 1)
        self.assertEqual(self.pylmp.fixes[0]['name'], 'one')
        self.assertEqual(self.pylmp.fixes[0]['style'], 'nve')
        self.assertEqual(self.pylmp.fixes[0]['group'], 'all')
        self.pylmp.group('none', 'empty')
        self.assertEqual(len(self.pylmp.groups), 2)
Esempio n. 11
0
l = lammps()
lmp = PyLammps(ptr=l)


lmp.units("lj")
lmp.atom_style("atomic")
lmp.lattice("fcc", 0.8442)
lmp.region("box", "block", 0, 4, 0, 4, 0, 4)
lmp.create_box(1, "box")
lmp.create_atoms(1, "box")
lmp.mass(1, 1.0)


lmp.velocity("all", "create", 10, 87287)
lmp.pair_style("lj/cut", 2.5)
lmp.pair_coeff(1, 1, 1.0, 1.0, 2.5)
lmp.neighbor(0.3, "bin")
lmp.neigh_modify("delay", 0, "every", 20, "check no")

lmp.fix("1 all nve")
a = l.extract_fix("2",2,2)
print(a.contents)
#nlocal = l.extract_global("nlocal",0) 
#print(nlocal)
#lmp.fix("2 all addforce 1.0 0.0 0.0")

#f = l.extract_atom("f",3)
#a = np.ctypeslib.as_array(f.contents,shape=(natoms, 3))
#print(a)

lmp.dump("id all atom 50 dumpT10.0.lammpstrj")
Esempio n. 12
0
    def test_use_data_file(self):
        L = PyLammps()
        L.units('real') # angstrom, kcal/mol, femtoseconds
        L.atom_style('atomic')
        L.boundary('p p p')

        L.lattice('none', 1.0)

        # create simulation cell
        L.region('r1 block', -15.0, 15.0, -15.0, 15.0, -15.0, 15.0)
        L.create_box(1, 'r1')

        # argon
        L.mass(1, 39.948002)
        L.pair_style('lj/cut', 8.5)
        L.pair_coeff(1, 1, 0.2379, 3.405)

        L.timestep(10.0)

        L.create_atoms(1, 'single', -1.0, 0.0, 0.0)
        L.create_atoms(1, 'single',  1.0, 0.0, 0.0)

        L.velocity('all create', 250.0, 54321, 'mom no rot no')

        L.minimize(1.0e-10, 1.0e-10, 100, 1000)

        L.reset_timestep(0)

        L.thermo(100)
        L.fix('f1 all nve')
        L.run(1000)

        L.write_restart('run.restart')
        L.write_data('run.data')

        L2 = PyLammps()
        L2.units('real')           # angstrom, kcal/mol, femtoseconds
        L2.atom_style('atomic')
        L2.boundary('p p p')

        L2.pair_style('lj/cut', 8.5)
        L2.read_data('run.data')

        L2.timestep(10.0)

        L2.thermo(100)
        L2.fix('f1 all nve')
        L2.run(1000)

        # reset status. forget all settings. delete system
        L2.clear()

        L2.read_restart('run.restart')

        L2.thermo(100)
        L2.fix('f1 all nve')
        L2.run(1000)

        os.remove('run.restart')
        os.remove('run.data')

        self.assertEqual(L.system, L2.system)
Esempio n. 13
0
py_lmp.fix(zwalls_fix, 'all', 'wall/lj126', 'zlo EDGE', 1.0, model.rod_radius,
           model.rod_radius * pow(2, 1. / 6), 'zhi EDGE', 1.0,
           model.rod_radius, model.rod_radius * pow(2, 1. / 6))

for bead_type in membrane.bead_types:
    py_lmp.mass(bead_type, membrane.bead_mass)
py_lmp.angle_coeff(membrane.angle_type, 5.0 * membrane.eps, 180)
py_lmp.bond_coeff(membrane.bond_type, 'fene',
                  30.0 * membrane.eps / membrane.sigma**2,
                  1.5 * membrane.sigma, membrane.eps, membrane.sigma)

lj_factor = pow(2, 1. / 6)
# head-head & head-tail inter-lipid interaction
for bead_type in membrane.bead_types:
    py_lmp.pair_coeff(membrane.head_type, bead_type, membrane.eps,
                      0.95 * membrane.sigma * lj_factor,
                      0.95 * membrane.sigma * lj_factor, 'wca')
# tail-tail inter-lipid interaction
for i in range(len(membrane.tail_types)):
    for j in range(i, len(membrane.tail_types)):
        py_lmp.pair_coeff(membrane.tail_types[i], membrane.tail_types[j],
                          membrane.eps, 1.0 * membrane.sigma * lj_factor,
                          (1.0 * lj_factor + membrane.wc) * membrane.sigma,
                          'wca')

# lipid-protein interaction
sol_lipid_eps = run_args.mem_int_eps
int_factors = (1.0, 0.5, 0.25)
# lipid-protein initial 0 interaction between all
rod_type_range = "{:d}*{:d}".format(simulation.get_min_rod_type(),
                                    simulation.get_max_rod_type())