예제 #1
0
    def test_default_settings(self):
        L = PyLammps()

        # verify default settings
        self.assertEqual(L.system.natoms, 0)
        self.assertEqual(L.system.ntypes, 0)
        self.assertEqual(L.system.style, 'none')
        self.assertEqual(L.system.units, 'lj')
        self.assertEqual(L.system.kspace_style, 'none')
        self.assertEqual(L.system.atom_style, 'atomic')
        self.assertEqual(L.system.atom_map, 'none')

        # now explicitly set them and check if nothing changed
        L.units('lj')
        L.boundary("p p p")
        L.lattice("none 1.0")
        L.atom_style("atomic")

        self.assertEqual(L.system.natoms, 0)
        self.assertEqual(L.system.ntypes, 0)
        self.assertEqual(L.system.style, 'none')
        self.assertEqual(L.system.units, 'lj')
        self.assertEqual(L.system.kspace_style, 'none')
        self.assertEqual(L.system.atom_style, 'atomic')
        self.assertEqual(L.system.atom_map, 'none')
예제 #2
0
    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)
예제 #3
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)
예제 #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')
예제 #5
0
    def setUp(self):
        """create 3d rocksalt-like structure"""
        L = PyLammps()
        L.units('real')         # kcal/mol, Angstrom, picoseconds
        L.atom_style('charge')  # atomic + charge

        # lattice for Na+ ions and box
        L.lattice('fcc', 6.0, 'origin', 0.0, 0.0, 0.0)
        L.region('r1', 'block', -3, 3,-3, 3,-3, 3)
        L.create_box(2, 'r1')

        # fill box with Na+ ions according to lattice positions
        L.create_atoms(1, 'box')

        # new lattice for Cl- ions shifted by half box diagonal
        L.lattice('fcc', 6.0, 'origin', 0.5, 0.5, 0.5)
        L.create_atoms(2, 'box')

        L.mass(1, 22.989770)
        L.mass(2, 35.453)
        L.set('type', 1, 'charge',  1.0)
        L.set('type', 2, 'charge', -1.0)

        L.group('na type', 1)
        L.group('cl type', 2)

        L.velocity('all create', 800.0, 12345, 'mom no rot no')
        L.timestep(0.001)
        self.L = L
예제 #6
0
    def test_create_box(self):
        L = PyLammps()
        L.units('real')
        L.lattice('fcc', 3.5)
        L.region("a block", 0, 1, 0, 1, 0, 1)
        L.create_box(1, 'a')

        self.assertEqual(L.system.dimensions, 3)
        self.assertEqual(L.system.orthogonal_box, [3.5, 3.5, 3.5])
        self.assertEqual(L.system.boundaries, 'p,p p,p p,p')
        self.assertEqual(L.system.xlo, 0.0)
        self.assertEqual(L.system.ylo, 0.0)
        self.assertEqual(L.system.zlo, 0.0)
        self.assertEqual(L.system.xhi, 3.5)
        self.assertEqual(L.system.yhi, 3.5)
        self.assertEqual(L.system.zhi, 3.5)
예제 #7
0
indmax = np.where(scatterangle2 == max(X2))
indmax = np.asarray(indmax).item()
cdf2 = np.cumsum(scattercross2[indmin:indmax])

if continueprevsim == False:
    L.boundary("p", "p", "f")  # "f" non-periodic and fixed

    L.region("cluster", "block", (Lsub - dCluster) / 2,
             Lsub - (Lsub - dCluster) / 2, (Lsub - dCluster) / 2,
             Lsub - (Lsub - dCluster) / 2, dsub, dsub + dCluster)
    L.region("subst", "block", 0, Lsub, 0, Lsub, 2, dsub)
    L.region("substinteg", "block", 0, Lsub, 0, Lsub, dsub - 4, dsub)
    L.region("simregion", "block", 0, Lsub, 0, Lsub, 0, dCluster * 3)
    L.region("allintegr", "union", 2, "substinteg", "cluster")

    L.lattice("fcc", latticeconst)

    L.create_box(
        3, "simregion"
    )  # create box containing 3 elements over full simulation region

    #L.mass(1,196.96655) 	# molecular weight in g/mol  Au
    #L.mass(2,58.6934) 		# Ni
    L.mass(3, 12.011)  # C

    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")
예제 #8
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)
예제 #9
0
#!/usr/bin/env python3
from lammps import PyLammps, lammps
import numpy as np
import sys

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")
예제 #10
0
    py_lmp = PyLammps(cmdargs=['-echo', 'both'], comm=mpi_comm)
py_lmp.log('"' + log_path + '"')

rod_params = rods.Rod_params()
if mpi_rank == 0:
    rod_params.from_file(args.cfg_file)
rod_params = mpi_comm.bcast(rod_params, root=0)

# CREATE BASE OBJECTS
model = rods.Rod_model(rod_params)
simulation = rods.Simulation(py_lmp, model, run_args.temp, seed, output_folder)

py_lmp.units("lj")
py_lmp.dimension(3)
py_lmp.boundary("p p p")
py_lmp.lattice("sc", 1 / (run_args.cell_size**3))
py_lmp.region("box", "block", -run_args.num_cells / 2, run_args.num_cells / 2,
              -run_args.num_cells / 2, run_args.num_cells / 2,
              -run_args.num_cells / 2, run_args.num_cells / 2)
simulation.setup("box")
simulation.create_rods(box=None)

# ROD DYNAMICS
py_lmp.fix("thermostat", "all", "langevin", run_args.temp, run_args.temp,
           run_args.damp, seed)  #, "zero yes")

simulation.set_rod_dynamics("nve", opt=["mol", model.rod_states[0]])

py_lmp.neigh_modify("every 1 delay 1")
py_lmp.timestep(run_args.dt)
예제 #11
0
class RealUnitsLatticeBoxTests(unittest.TestCase):
    def setUp(self):
        self.L = PyLammps()
        self.L.units('real')           # default, use reduced units
        self.L.atom_style('atomic')  # default, point particles with mass and type
        self.L.boundary('p p p')     # default, periodic boundaries in 3-d
        self.L.processors('* * *')   # default, automatic domain decomposition
        self.L.newton('on')          # default, use newton's 3rd law for ghost particles

    def assertAlmostEqualList(self, a_list, b_list):
        for a, b in zip(a_list, b_list):
            self.assertAlmostEqual(a, b, places=3)

    def test_real_none_box(self):
        self.L.lattice('none', 1.0)

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

        self.assertEqual(self.L.system.orthogonal_box, [10, 10, 10])
        self.assertEqual(self.L.system.xlo, -5.0)
        self.assertEqual(self.L.system.ylo, -5.0)
        self.assertEqual(self.L.system.zlo, -5.0)
        self.assertEqual(self.L.system.xhi, 5.0)
        self.assertEqual(self.L.system.yhi, 5.0)
        self.assertEqual(self.L.system.zhi, 5.0)

    def test_real_sc_box(self):
        self.L.lattice('sc', 1.0)

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

        self.assertEqual(self.L.system.orthogonal_box, [10, 10, 10])
        self.assertEqual(self.L.system.xlo, -5.0)
        self.assertEqual(self.L.system.ylo, -5.0)
        self.assertEqual(self.L.system.zlo, -5.0)
        self.assertEqual(self.L.system.xhi, 5.0)
        self.assertEqual(self.L.system.yhi, 5.0)
        self.assertEqual(self.L.system.zhi, 5.0)

    def test_real_fcc_box(self):
        self.L.lattice('fcc', 1.0)

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

        self.assertEqual(self.L.system.orthogonal_box, [10, 10, 10])
        self.assertEqual(self.L.system.xlo, -5.0)
        self.assertEqual(self.L.system.ylo, -5.0)
        self.assertEqual(self.L.system.zlo, -5.0)
        self.assertEqual(self.L.system.xhi, 5.0)
        self.assertEqual(self.L.system.yhi, 5.0)
        self.assertEqual(self.L.system.zhi, 5.0)

    def test_real_bcc_box(self):
        self.L.lattice('bcc', 1.0)

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

        self.assertEqual(self.L.system.orthogonal_box, [10, 10, 10])
        self.assertEqual(self.L.system.xlo, -5.0)
        self.assertEqual(self.L.system.ylo, -5.0)
        self.assertEqual(self.L.system.zlo, -5.0)
        self.assertEqual(self.L.system.xhi, 5.0)
        self.assertEqual(self.L.system.yhi, 5.0)
        self.assertEqual(self.L.system.zhi, 5.0)

    def test_real_none_lattice(self):
        self.L.lattice('none', 1.0)

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

        self.assertEqual(self.L.system.orthogonal_box, [10, 10, 10])
        self.assertEqual(self.L.system.xlo, -5.0)
        self.assertEqual(self.L.system.ylo, -5.0)
        self.assertEqual(self.L.system.zlo, -5.0)
        self.assertEqual(self.L.system.xhi, 5.0)
        self.assertEqual(self.L.system.yhi, 5.0)
        self.assertEqual(self.L.system.zhi, 5.0)

    def test_real_sc_lattice(self):
        self.L.lattice('sc', 1.0)

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

        self.assertEqual(self.L.system.orthogonal_box, [10, 10, 10])
        self.assertAlmostEqual(self.L.system.xlo, -5.0)
        self.assertAlmostEqual(self.L.system.ylo, -5.0)
        self.assertAlmostEqual(self.L.system.zlo, -5.0)
        self.assertAlmostEqual(self.L.system.xhi, 5.0)
        self.assertAlmostEqual(self.L.system.yhi, 5.0)
        self.assertAlmostEqual(self.L.system.zhi, 5.0)

    def test_real_fcc_lattice(self):
        self.L.lattice('fcc', 1.0)

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

        lattice_spacing = 1.0

        self.assertAlmostEqualList(self.L.system.orthogonal_box, [10*lattice_spacing, 10*lattice_spacing, 10*lattice_spacing])
        self.assertAlmostEqual(self.L.system.xlo, -5.0 * lattice_spacing, places=3)
        self.assertAlmostEqual(self.L.system.ylo, -5.0 * lattice_spacing, places=3)
        self.assertAlmostEqual(self.L.system.zlo, -5.0 * lattice_spacing, places=3)
        self.assertAlmostEqual(self.L.system.xhi,  5.0 * lattice_spacing, places=3)
        self.assertAlmostEqual(self.L.system.yhi,  5.0 * lattice_spacing, places=3)
        self.assertAlmostEqual(self.L.system.zhi,  5.0 * lattice_spacing, places=3)

    def test_real_bcc_lattice(self):
        self.L.lattice('bcc', 1.0)

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

        lattice_spacing = 1.0

        self.assertAlmostEqualList(self.L.system.orthogonal_box, [10*lattice_spacing, 10*lattice_spacing, 10*lattice_spacing])
        self.assertAlmostEqual(self.L.system.xlo, -5.0 * lattice_spacing, places=3)
        self.assertAlmostEqual(self.L.system.ylo, -5.0 * lattice_spacing, places=3)
        self.assertAlmostEqual(self.L.system.zlo, -5.0 * lattice_spacing, places=3)
        self.assertAlmostEqual(self.L.system.xhi,  5.0 * lattice_spacing, places=3)
        self.assertAlmostEqual(self.L.system.yhi,  5.0 * lattice_spacing, places=3)
        self.assertAlmostEqual(self.L.system.zhi,  5.0 * lattice_spacing, places=3)
예제 #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)