LAMMPSSimulation¶
-
class
narupatools.lammps.simulation.LAMMPSSimulation(lammps: lammps.PyLammps, universe: Optional[MDAnalysis.core.universe.Universe] = None)¶ Wrapper around a LAMMPS simulation.
Inheritance

Methods
Initialize self.
Define an IMD force for the LAMMPS simulation.
Clear the IMD force on a specific atom.
Run an arbitrary LAMMPS command.
Insert an atom into the simulation.
Create an empty simulation box with the given number of atom types.
Create a new LAMMPS simulation with the given units system.
Create a region in the simulation.
Evaluate an arbitrary expression.
Extract value of a compute.
Runn all commands found in the provided input file.
Load LAMMPS simulation from a file.
Gather a per-atom property from all the processors.
Create a Narupa FrameData of the LAMMPS simulation.
Get the IMD forces on each atom in kilojoules per mole per angstrom.
Run the simulation for a given number of steps.
Set the IMD force on a specific atom.
Set the mass of a specified atom type.
Setup a Langevin thermostat.
-
__init__(lammps: lammps.PyLammps, universe: Optional[MDAnalysis.core.universe.Universe] = None)¶ Initialize self. See help(type(self)) for accurate signature.
-
clear_imd_force(index: int) → None¶ Clear the IMD force on a specific atom.
- Parameters
index – Index of the particle to clear.
-
command(command: str, clear_cache: bool = True) → None¶ Run an arbitrary LAMMPS command.
Running it through this interface means that all previously cached data such as positions etc. are cleared. If you are sure running the command will not affect any data, set clear_cache to False.
- Parameters
command – LAMMPS command to run.
clear_cache – Should all cached information be cleared.
-
create_atom(*, type: int, position: numpy.ndarray[Any, numpy.dtype[numpy.float64]]) → None¶ Insert an atom into the simulation.
- Parameters
type – Type of the atom to insert.
position – Position of the atom in nanometers.
-
create_box(n_types: int, region: Union[narupatools.lammps.region.Region, narupatools.lammps.region.RegionSpecification]) → None¶ Create an empty simulation box with the given number of atom types.
- Parameters
n_types – Number of atom types.
region – Region to define.
- Raises
ValueError – Region does belong to this simulation.
-
classmethod
create_new(units: Literal[lj, real, metal, si, cgs, electron, micro, nano]) → narupatools.lammps.simulation.LAMMPSSimulation¶ Create a new LAMMPS simulation with the given units system.
This automatically runs the ‘atom_modify map yes’ command required to use atom IDs and hence allow certain operations such as setting positions.
- Parameters
units – LAMMPS unit system to use.
- Returns
LAMMPS simulation in provided units.
-
create_region(region: narupatools.lammps.region.RegionSpecification, *, id: Optional[str] = None) → narupatools.lammps.region.Region¶ Create a region in the simulation.
- Parameters
region – Specification to the region.
id – Optional id for the region.
- Returns
Region object.
-
eval(expression: str) → Any¶ Evaluate an arbitrary expression.
- Parameters
expression – Expression to be evaluated using the eval command.
-
extract_compute(key: str, style: narupatools.lammps.constants.VariableStyle, type: Literal[<VariableType.SCALAR: 0>]) → float¶ -
extract_compute(key: str, style: narupatools.lammps.constants.VariableStyle, type: Literal[<VariableType.ARRAY: 2>]) → numpy.ndarray -
extract_compute(key: str, style: narupatools.lammps.constants.VariableStyle, type: Literal[<VariableType.VECTOR: 1>]) → numpy.ndarray Extract value of a compute.
- Parameters
key – ID of the compute.
style – Style of the variable.
type – Type of the variable.
- Raises
ComputeNotFoundError – Key does not match any known computes.
InvalidComputeSpecificationError – Compute exists but doesn’t match style and type provided.
- Returns
Value of the compute.
-
classmethod
from_file(filename: str, data_filename: str) → narupatools.lammps.simulation.LAMMPSSimulation¶ Load LAMMPS simulation from a file.
This automatically runs the ‘atom_modify map yes’ command required to use atom IDs and hence allow certain operations such as setting positions.
- Parameters
filename – Filename of LAMMPS input.
data_filename – Filename of LAMMPS data file, used to generate MDAnalysis universe.
- Returns
LAMMPS simulation based on file.
-
gather_atoms(key: str, type: narupatools.lammps.constants.PropertyType, dimension: int) → numpy.ndarray¶ Gather a per-atom property from all the processors.
- Parameters
key – Id of the property.
type – Type of the variable.
dimension – Dimension of the variable.
- Raises
UnknownAtomPropertyError – Property was not found in the simulation.
- Returns
Value of the atom property.
-
get_frame(*, fields: infinite_sets.infinite_sets.InfiniteSet[str], existing: Optional[narupa.trajectory.frame_data.FrameData] = None) → narupa.trajectory.frame_data.FrameData¶ Create a Narupa FrameData of the LAMMPS simulation.
- Parameters
fields – Fields to populate of the frame data.
existing – Preexisting frame data.
- Returns
FrameData with the appropriate fields.
-
get_imd_forces() → numpy.ndarray¶ Get the IMD forces on each atom in kilojoules per mole per angstrom.
-
run(steps: int = 1) → None¶ Run the simulation for a given number of steps.
- Parameters
steps – Number of steps to run.
-
set_imd_force(index: int, force: numpy.ndarray[Any, numpy.dtype[numpy.float64]]) → None¶ Set the IMD force on a specific atom.
- Parameters
index – Index of the particle to set.
force – IMD force to apply, in kilojoules per mole per nanometer.
-
set_mass(*, type: Union[int, slice], mass: float) → None¶ Set the mass of a specified atom type.
- Parameters
type – Atom type.
mass – Mass in daltons.
-
setup_langevin(*, temperature: float, friction: float, seed: int) → None¶ Setup a Langevin thermostat.
- Parameters
temperature – Temperature in kelvin
friction – Friction of the thermostat in inverse picoseconds.
seed – Seed to use for random number generation.
Attributes
ID of each atom.
Charge of each atom in elementary charges.
List of commands run on the simulation.
Dictionary of computes indexed by their names.
Forces on each atom in kilojoules per mole per nanometer.
Kinetic energy of the system in kilojoules per mole.
List of installed LAMMPS packages.
Masses of each atom in daltons.
Positions of each atom in nanometers.
Potential energy of the system in kilojoules per mole.
Pressure of the system in kilojoules per nanometers cubed.
List of region ids currently in use for the simulation.
Temperature of the system in kelvin.
Timestep of the simulation in picoseconds.
An MDAnalysis Universe containing topology information.
Velocities of each atom in nanometers per picoseconds.
-
atom_ids¶ ID of each atom.
-
charges¶ Charge of each atom in elementary charges.
-
command_history¶ List of commands run on the simulation.
-
computes¶ Dictionary of computes indexed by their names.
-
forces¶ Forces on each atom in kilojoules per mole per nanometer.
-
kinetic_energy¶ Kinetic energy of the system in kilojoules per mole.
-
lammps_packages¶ List of installed LAMMPS packages.
-
masses¶ Masses of each atom in daltons.
-
positions¶ Positions of each atom in nanometers.
-
potential_energy¶ Potential energy of the system in kilojoules per mole.
The potential energy is computed using the ‘thermo_pe’ compute which is added to all LAMMPS simulations automatically. This uses the ‘pe’ compute style which includes contributions from pairs, bonds, angles, dihedrals, impropers, kspace and various fixes.
-
pressure¶ Pressure of the system in kilojoules per nanometers cubed.
-
region_ids¶ List of region ids currently in use for the simulation.
-
temperature¶ Temperature of the system in kelvin.
The temperature is computed using the ‘thermo_temp’ compute which is added to all LAMMPS simulations automatically. This uses the ‘temp’ compute style which uses the equation:
\[KE = \frac{D}{2} N k T\]where \(KE\) is the kinetic energy, \(D\) is the dimension of the system, \(N\) is the number of atoms and \(k\) is the Boltzmann constant.
This removes degrees of freedom due to other fixes that limit molecular motion.
-
timestep¶ Timestep of the simulation in picoseconds.
-
universe¶ An MDAnalysis Universe containing topology information.
-
velocities¶ Velocities of each atom in nanometers per picoseconds.
-