Skip to content

Parallel Lammps Python interface - control a mpi4py parallel LAMMPS instance from a serial python process or a Jupyter notebook

License

Notifications You must be signed in to change notification settings

pyiron/pylammpsmpi

Folders and files

NameName
Last commit message
Last commit date
Jun 11, 2023
Jun 7, 2023
Jun 11, 2023
Mar 8, 2020
Jun 5, 2021
Jun 11, 2023
Feb 22, 2023
Aug 20, 2020
Jan 13, 2021
Mar 8, 2020
Jul 7, 2021
Sep 4, 2020
Mar 5, 2020
Mar 8, 2020
Jun 5, 2021
Mar 8, 2020
Jun 11, 2023
Mar 8, 2020

Repository files navigation

PyLammpsMPI

Coverage Status Python package

Install with pip

pip install pylammpsmpi

Example usage

Setting up a simulation

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

Run commands

lmp.command("run 1")
lmp.command(["run 1", "run 1"])

Commands can also be direct

lmp.run(10)
lmp.mass(1, 20)

Extract a global property

lmp.extract_global("boxxhi")
6.718384765530029

Access thermo quantities

lmp.get_thermo("temp")
array(1.12985322)

Thermo quantities can also be accessed directly,

lmp.temp
array(1.12985322)
lmp.press
array(-2.60581752)

Accessing simulation box

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)

Accessing and changing atom properties

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])

Access value of variables

temp = lmp.extract_variable("tt", "all", 0)
temp
0.8846341461467611

Access value of computes

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

Access values from fix

x = lmp.extract_fix("2", 0, 1, 1)
x
-2.605817524153117

Change the simulation box

lmp.reset_box([0.0,0.0,0.0], [8.0,8.0,8.0], 0.0,0.0,0.0)