Running machine-learned force fields in LAMMPS: Difference between revisions
No edit summary |
No edit summary |
||
Line 3: | Line 3: | ||
== LAMMPS input scripts == | == LAMMPS input scripts == | ||
LAMMPS comes with its own powerful script language which allows the user to specify all relevant MD simulation parameters in a single file. Please consult the [https://docs.lammps.org/Commands_input.html LAMMPS documentation] for details. Within the LAMMPS script language the commands <code>pair_style</code> and <code>pair_coeff</code> are responsible for selecting a force field. The patch | LAMMPS comes with its own powerful script language which allows the user to specify all relevant MD simulation parameters in a single file. Please consult the [https://docs.lammps.org/Commands_input.html LAMMPS documentation] for details. Within the LAMMPS script language the commands <code>pair_style</code> and <code>pair_coeff</code> are responsible for selecting a force field. The patch VASPml provides introduces a new <code>pair_style</code> called <code>vasp</code>. The <code>pair_style vasp</code> command does not have any additional arguments, all configurable settings are given as arguments to the <code>pair_coeff</code> command in this format: | ||
<pre>pair_style vasp | <pre>pair_style vasp | ||
Line 48: | Line 48: | ||
== MD run in example directory == | == MD run in example directory == | ||
An example LAMMPS MD simulation of Cesium Lead Bromide can be found in the following directory relative to the | An example LAMMPS MD simulation of Cesium Lead Bromide can be found in the following directory relative to the VASPml base directory: | ||
<pre>examples/lammps/CsPbBr3</pre> | <pre>examples/lammps/CsPbBr3</pre> | ||
Line 57: | Line 57: | ||
= Quick How-To for experienced {{VASP}}/LAMMPS users = | = Quick How-To for experienced {{VASP}}/LAMMPS users = | ||
{{NB|warning|Connect this section to actual installation instructions||ToDo:}} | |||
# Just like in {{VASP}} pick a template from the <code>arch</code> directory and copy it to the base directory, e.g. | # Just like in {{VASP}} pick a template from the <code>arch</code> directory and copy it to the base directory, e.g. |
Revision as of 09:36, 18 October 2024
ToDo: Write introduction to LAMMPS! |
LAMMPS input scripts
LAMMPS comes with its own powerful script language which allows the user to specify all relevant MD simulation parameters in a single file. Please consult the LAMMPS documentation for details. Within the LAMMPS script language the commands pair_style
and pair_coeff
are responsible for selecting a force field. The patch VASPml provides introduces a new pair_style
called vasp
. The pair_style vasp
command does not have any additional arguments, all configurable settings are given as arguments to the pair_coeff
command in this format:
pair_style vasp pair_coeff * * file types
The pair_coeff
command must be followed by * *
, then followed by the name of the VASP force field file, typically ML_FF
. Finally, there comes a mapping from LAMMPS atom types to VASP force fiel types, e.g., H O Na Cl
means that LAMMPS types 1
, 2
, 3
and 4
are mapped to VASP types H
, O
, Na
and Cl
, respectively. A valid example may look like this:
pair_style vasp pair_coeff * * ML_FF Pb Br Cs
This will map the LAMMPS atom types 1
, 2
and 3
in the input data file to the types Pb
, Br
and Cs
for which a pre-trained machine-learned force field should be present in the ML_FF
file in the execution directory. A summary of the type mapping is provided in the screen output and the log.lammps
file, e.g. for the example above it looks like this:
LAMMPS pair_coeff VASP | VASP force field types names subtypes | types names subtypes ----------------------------------------- | ------------------------------------- 1 <---> Pb <---> 0 | 0 <---> Pb <---> 0 2 <---> Br <---> 1 | 1 <---> Br <---> 1 3 <---> Cs <---> 2 | 2 <---> Cs <---> 2
On the left side we find the mapping, the right side gives an overview of types present in the force field file. In this example, there is a one-to-one mapping, hence, the table looks pretty obvious and contains somewhat redundant information. However, it is also possible to leave out a mapping from specified LAMMPS types by supplying NULL
instead of a valid VASP type name. This can be helpful when multiple force fields should be combined, see pair_style hybrid
. Furthermore, multiple LAMMPS types may be mapped to the same VASP types. Finally, the force field file may contain types which are not used in the current MD simulation. Therefore, a more complicated example may look like this:
pair_coeff * * vasp ML_FF NULL Cs NULL Br Pb Br
and the corresponding table could contain this information:
LAMMPS pair_coeff VASP | VASP force field types names subtypes | types names subtypes ----------------------------------------- | ------------------------------------- 1 <---> unmapped! <---> unmapped! | 0 <---> Ca <---> unused! 2 <---> Cs <---> 2 | 1 <---> Pb <---> 0 3 <---> unmapped! <---> unmapped! | 2 <---> O <---> unused! 4 <---> Br <---> 1 | 3 <---> Br <---> 1 5 <---> Pb <---> 0 | 4 <---> Cs <---> 2 6 <---> Br <---> 1 |
It is important to always ensure that the type mapping is correctly set up because mixed-up types may not immediately result in errors. An MD simulation may still run and only post-processing may ultimately reveal inconsistencies which can be tedious to trace back to type-mapping mistakes.
The pair_style vasp
expects input coordinates to be in the units of Ångström and returns energies and forces with the energy unit of eV. Hence, it is only compatible with the LAMMPS setting units metal
in the input script, otherwise an error will occur.
LAMMPS input data file
Where VASP uses POSCAR files to define the input structure (lattice and ion positions) LAMMPS uses its own file format to start MD simulations from. For simple cubic or orthorhombic systems the files can be manually converted with little effort. However, this becomes more cumbersome with triclinic simulation cells because LAMMPS originally only supported restricted triclinic boxes. Here, the first lattice vector is restricted to lie along the x-axis of the Cartesian coordinate system and the second vector must lie in the xy-plane. The third lattice vector can be arbitrary as long as it points out of the xy-plane and the three vectors form a right-hand system. Note that any set of lattice vectors can be transformed (rotated and/or mirrored) to fulfill these conditions without changing the physical situation. These restrictions do not apply to VASP POSCAR files and therefore general triclinic lattices need to be transformed to create a valid LAMMPS input file. This task can be performed by the Python script poscar2lammps_data.py
which is located in the res
directory relative to the base folder. It takes two command-line arguments:
poscar2lammps_data.py <in> <out>
where <in>
is the POSCAR input file and out
is the resulting LAMMPS data file in restricted triclinic form. If <out>
is omitted, the output file is written to lammps.data
.
Please be aware that this script is not heavily tested and its results should be checked for consistency. Also, recent versions of LAMMPS (e.g. patch_17Apr2024
) do support general triclinic lattices for convenience, see remarks here.
MD run in example directory
An example LAMMPS MD simulation of Cesium Lead Bromide can be found in the following directory relative to the VASPml base directory:
examples/lammps/CsPbBr3
To execute, first compile the patched LAMMPS executable change into the directory above and run a parallel MD simulation with this command:
mpirun -np 4 ../../../bin/lmp_mpi -in in.lmp
Here, lmp_mpi
is the patched LAMMPS executable and -in in.lmp
is one of its command line arguments specifying that the LAMMPS commands should be read from a script file called in.lmp
. This file is present in the example directory and contains an already advanced MD setup for a simulation of 100 time steps sampling the NpT ensemble. in.lmp
also specifies that the output trajectory should be written to out.dump
and global thermodynamic properties (e.g. potential energy, pressure,…) are written to out.prop
. The example LAMMPS script file can be easily altered to sample also NVE or NVT ensembles. Many other simulation parameters can also be modified by changing the variable values at the beginning of the file. Please have a look at the comments in in.lmp
and visit the LAMMPS documentation for more information.
Quick How-To for experienced VASP/LAMMPS users
ToDo: Connect this section to actual installation instructions |
- Just like in VASP pick a template from the
arch
directory and copy it to the base directory, e.g.
cp arch/makefile.include.gnu makefile.include
- Modify the build settings in
makefile.include
according to your system. - Compile a patched version of LAMMPS with support for VASP machine-learned force fields:
make lammps -j
- Switch to the
examples/lammps/CsPbBr3
directory and try to run the example MD simulation, e.g. with
mpirun -np 4 ../../../bin/lmp_mpi -in in.lmp
- Inspect the LAMMPS input script
in.lmp
and modify to your needs.