pip install pylammpsmpi
from pylammpsmpi import LammpsLibrary
Set up a job which runs on 2 cores
lmp = LammpsLibrary(cores=2)
Read an input file
lmp.file("tests/in.simple")
Check version of lammps
lmp.version
20190807
Check number of atoms
lmp.natoms
256
lmp.command("run 1")
lmp.command(["run 1", "run 1"])
Commands can also be direct
lmp.run(10)
lmp.mass(1, 20)
lmp.extract_global("boxxhi")
6.718384765530029
lmp.get_thermo("temp")
array(1.12985322)
Thermo quantities can also be accessed directly,
lmp.temp
array(1.12985322)
lmp.press
array(-2.60581752)
lmp.extract_box()
([0.0, 0.0, 0.0],
[6.718384765530029, 6.718384765530029, 6.718384765530029],
0.0,
0.0,
0.0,
[1, 1, 1],
0)
Get individual atom properties, for example force on each atoms
ff = lmp.gather_atoms("f")
print(type(ff))
print(len(ff))
<class 'numpy.ndarray'>
256
Get atom properties by their ids
ids = lmp.gather_atoms("id")
ff = lmp.gather_atoms("f", ids=ids[:10])
len(ff)
10
Change atom properties
ff = ff*0.5
lmp.scatter_atoms("f", ff, ids=ids[:10])
temp = lmp.extract_variable("tt", "all", 0)
temp
0.8846341461467611
ke = lmp.extract_compute("ke", 1, 1)
len(ke)
256
v = lmp.extract_compute("v", 1, 2, width=3)
v.shape
(256, 3)
lmp.extract_compute("1", 0, 0)
0.8846341461467611
msd = lmp.extract_compute("msd", 0, 1, length=4)
msd[0]
0.005507481618069701
x = lmp.extract_fix("2", 0, 1, 1)
x
-2.605817524153117
lmp.reset_box([0.0,0.0,0.0], [8.0,8.0,8.0], 0.0,0.0,0.0)