Skip to main content

Python interface for running LAMMPS input scripts

Project description

LAMMPS simulator

A light-weight Python package for launching LAMMPS simulations. Given a LAMMPS input script, the simulation is launched from a specified working directory. The default behavior is to copy the input script and all dependencies to the working directory, making it easy to redo the simulations.

Installation

Install package from source using pip:

$ pip install lammps-simulator

Prerequisites

  1. Python 3.3+ (subprocess.DEVNULL from 3.3 needed)
  2. LAMMPS (Any recent version)

Basic usage

To run a LAMMPS script from the current directory, the script has to be specified and the way of running the simulation has to be defined. The easiest way of doing this is to use the default simulation object, sim:

from lammps_simulator import sim

sim.set_input_script("script.in")
sim.run(num_procs=4, lmp_exec="lmp")

where the LAMMPS input script script.in is launched on 4 CPU processes by calling the LAMMPS executable lmp. This corresponds to running

$ mpirun -n 4 lmp -in script.in

Defining working directory and copy files to it

Associating each simulation with a respective working directory is good practice, as it makes it easy to rerun the simulation. Create a simulator object associated with a directory by:

from lammps_simulator import Simulator

sim = Simulator("simulation", overwrite=False)

The argument overwrite can be set to True if the contents of the simulation should overwrite a potentially existing simulation directory.

Often, the LAMMPS script requires other files, like parameter files, data files or other LAMMPS scripts. The function copy_to_wd can be used to copy any file to the working directory:

sim.copy_to_wd("parameters.vashishta")
sim.copy_to_wd("pos.data")
sim.copy_to_wd("compute_something.in")

or more compact:

sim.copy_to_wd("parameters.vashishta", "pos.data", "compute_something.in")

Assign variables to LAMMPS script

If your LAMMPS script takes command line variables, they can be specified by

sim.set_input_script("script.in", var1=v1, var2=v2, ..., varN=vN)

or

lmp_vars = {'var1': v1, 'var2': v2, ... 'varN': vN}
sim.set_input_script("script.in", **lmp_vars)

Variables might also be lists (index variables in LAMMPS terms):

sim.set_input_script("script.in", var=[1, 2, 3])

For more examples, see the examples pages and the documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lammps_simulator-1.1.1-py2.py3-none-any.whl (21.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file lammps_simulator-1.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: lammps_simulator-1.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.50.2 importlib-metadata/4.11.3 keyring/21.4.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.5

File hashes

Hashes for lammps_simulator-1.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fe275d4364e1209a07fcda532faae4a5181ef1b7dab5346b63b2ac65d77eb1c0
MD5 834506142ae990524667113e44d1fcd4
BLAKE2b-256 8b79984fb61786a9d9784bcfc8ec1c5a4b0b593143c8e68aa368fb9bf7f30bbb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page