Skip to content

Commit

Permalink
Merge pull request lammps#4401 from mala-project/mala
Browse files Browse the repository at this point in the history
Kokkos versions of bispectrum and Gaussian descriptors on grid
  • Loading branch information
akohlmey authored Jan 23, 2025
2 parents e548c65 + 048b96a commit 0dfd5d8
Show file tree
Hide file tree
Showing 36 changed files with 3,434 additions and 56 deletions.
5 changes: 3 additions & 2 deletions doc/src/Commands_compute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ KOKKOS, o = OPENMP, t = OPT.
* :doc:`fep/ta <compute_fep_ta>`
* :doc:`force/tally <compute_tally>`
* :doc:`fragment/atom <compute_cluster_atom>`
* :doc:`gaussian/grid/local (k) <compute_gaussian_grid_local>`
* :doc:`global/atom <compute_global_atom>`
* :doc:`group/group <compute_group_group>`
* :doc:`gyration <compute_gyration>`
Expand Down Expand Up @@ -140,8 +141,8 @@ KOKKOS, o = OPENMP, t = OPT.
* :doc:`smd/vol <compute_smd_vol>`
* :doc:`snap <compute_sna_atom>`
* :doc:`sna/atom <compute_sna_atom>`
* :doc:`sna/grid <compute_sna_atom>`
* :doc:`sna/grid/local <compute_sna_atom>`
* :doc:`sna/grid (k) <compute_sna_atom>`
* :doc:`sna/grid/local (k) <compute_sna_atom>`
* :doc:`snad/atom <compute_sna_atom>`
* :doc:`snav/atom <compute_sna_atom>`
* :doc:`sph/e/atom <compute_sph_e_atom>`
Expand Down
1 change: 1 addition & 0 deletions doc/src/compute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ The individual style names on the :doc:`Commands compute <Commands_compute>` pag
* :doc:`fep/ta <compute_fep_ta>` - compute free energies for a test area perturbation
* :doc:`force/tally <compute_tally>` - force between two groups of atoms via the tally callback mechanism
* :doc:`fragment/atom <compute_cluster_atom>` - fragment ID for each atom
* :doc:`gaussian/grid/local <compute_gaussian_grid_local>` - local array of Gaussian atomic contributions on a regular grid
* :doc:`global/atom <compute_global_atom>` - assign global values to each atom from arrays of global values
* :doc:`group/group <compute_group_group>` - energy/force between two groups of atoms
* :doc:`gyration <compute_gyration>` - radius of gyration of group of atoms
Expand Down
97 changes: 97 additions & 0 deletions doc/src/compute_gaussian_grid_local.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
.. index:: compute gaussian/grid/local
.. index:: compute gaussian/grid/local/kk

compute gaussian/grid/local command
===================================

Accelerator Variants: *gaussian/grid/local/kk*

Syntax
""""""

.. code-block:: LAMMPS
compute ID group-ID gaussian/grid/local grid nx ny nz rcutfac R_1 R_2 ... sigma_1 sigma_2
* ID, group-ID are documented in :doc:`compute <compute>` command
* gaussian/grid/local = style name of this compute command
* *grid* values = nx, ny, nz, number of grid points in x, y, and z directions (positive integer)
* *rcutfac* = scale factor applied to all cutoff radii (positive real)
* *R_1, R_2,...* = list of cutoff radii, one for each type (distance units)
* *sigma_1, sigma_2,...* = Gaussian widths, one for each type (distance units)

Examples
""""""""

.. code-block:: LAMMPS
compute mygrid all gaussian/grid/local grid 40 40 40 4.0 0.5 0.5 0.4 0.4
Description
"""""""""""

Define a computation that calculates a Gaussian representation of the ionic
structure. This representation is used for the efficient evaluation
of quantities related to the structure factor in a grid-based workflow,
such as the ML-DFT workflow MALA :ref:`(Ellis) <Ellis2021b>`, for which it was originally
implemented. Usage of the workflow is described in a separate publication :ref:`(Fiedler) <Fiedler2023>`.

For each LAMMPS type, a separate sum of Gaussians is calculated, using
a separate Gaussian broadening per type. The computation
is always performed on the numerical grid, no atom-based version of this
compute exists. The Gaussian representation can only be executed in a local
fashion, thus the output array only contains rows for grid points
that are local to the processor subdomain. The layout of the grid is the same
as for the see :doc:`sna/grid/local <compute_sna_atom>` command.

Namely, the array contains one row for each of the
local grid points, looping over the global index *ix* fastest,
then *iy*, and *iz* slowest. Each row of the array contains
the global indexes *ix*, *iy*, and *iz* first, followed by the *x*, *y*,
and *z* coordinates of the grid point, followed by the values of the Gaussians
(one floating point number per type per grid point).

----------


.. include:: accel_styles.rst



----------

Output info
"""""""""""

Compute *gaussian/grid/local* evaluates a local array.
The array contains one row for each of the
local grid points, looping over the global index *ix* fastest,
then *iy*, and *iz* slowest. The array contains math :math:`ntypes+6` columns,
where *ntypes* is the number of LAMMPS types. The first three columns are
the global indexes *ix*, *iy*, and *iz*, followed by the *x*, *y*,
and *z* coordinates of the grid point, followed by the *ntypes* columns
containing the values of the Gaussians for each type.

Restrictions
""""""""""""

These computes are part of the ML-SNAP package. They are only enabled
if LAMMPS was built with that package. See the :doc:`Build package
<Build_package>` page for more info.

Related commands
""""""""""""""""

:doc:`compute sna/grid/local <compute_sna_atom>`

----------

.. _Ellis2021b:

**(Ellis)** Ellis, Fiedler, Popoola, Modine, Stephens, Thompson, Cangi, Rajamanickam, `Phys. Rev. B, 104, 035120, (2021) <https://doi.org/10.1103/PhysRevB.104.035120>`_

.. _Fiedler2023:

**(Fiedler)** Fiedler, Modine, Schmerler, Vogel, Popoola, Thompson, Rajamanickam, and Cangi,
`npj Comp. Mater., 9, 115 (2023) <https://doi.org/10.1038/s41524-023-01070-z>`_

36 changes: 25 additions & 11 deletions doc/src/compute_sna_atom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
.. index:: compute snav/atom
.. index:: compute snap
.. index:: compute sna/grid
.. index:: compute sna/grid/kk
.. index:: compute sna/grid/local
.. index:: compute sna/grid/local/kk

compute sna/atom command
========================
Expand All @@ -20,9 +22,14 @@ compute snap command
compute sna/grid command
========================

compute sna/grid/kk command
===========================

compute sna/grid/local command
==============================

Accelerator Variants: *sna/grid/local/kk*

Syntax
""""""

Expand All @@ -33,17 +40,17 @@ Syntax
compute ID group-ID snav/atom rcutfac rfac0 twojmax R_1 R_2 ... w_1 w_2 ... keyword values ...
compute ID group-ID snap rcutfac rfac0 twojmax R_1 R_2 ... w_1 w_2 ... keyword values ...
compute ID group-ID snap rcutfac rfac0 twojmax R_1 R_2 ... w_1 w_2 ... keyword values ...
compute ID group-ID sna/grid nx ny nz rcutfac rfac0 twojmax R_1 R_2 ... w_1 w_2 ... keyword values ...
compute ID group-ID sna/grid/local nx ny nz rcutfac rfac0 twojmax R_1 R_2 ... w_1 w_2 ... keyword values ...
compute ID group-ID sna/grid grid nx ny nz rcutfac rfac0 twojmax R_1 R_2 ... w_1 w_2 ... keyword values ...
compute ID group-ID sna/grid/local grid nx ny nz rcutfac rfac0 twojmax R_1 R_2 ... w_1 w_2 ... keyword values ...
* ID, group-ID are documented in :doc:`compute <compute>` command
* sna/atom = style name of this compute command
* rcutfac = scale factor applied to all cutoff radii (positive real)
* rfac0 = parameter in distance to angle conversion (0 < rcutfac < 1)
* twojmax = band limit for bispectrum components (non-negative integer)
* R_1, R_2,... = list of cutoff radii, one for each type (distance units)
* w_1, w_2,... = list of neighbor weights, one for each type
* nx, ny, nz = number of grid points in x, y, and z directions (positive integer)
* *rcutfac* = scale factor applied to all cutoff radii (positive real)
* *rfac0* = parameter in distance to angle conversion (0 < rcutfac < 1)
* *twojmax* = band limit for bispectrum components (non-negative integer)
* *R_1, R_2,...* = list of cutoff radii, one for each type (distance units)
* *w_1, w_2,...* = list of neighbor weights, one for each type
* *grid* values = nx, ny, nz, number of grid points in x, y, and z directions (positive integer)
* zero or more keyword/value pairs may be appended
* keyword = *rmin0* or *switchflag* or *bzeroflag* or *quadraticflag* or *chem* or *bnormflag* or *wselfallflag* or *bikflag* or *switchinnerflag* or *sinner* or *dinner* or *dgradflag* or *nnn* or *wmode* or *delta*

Expand Down Expand Up @@ -103,7 +110,7 @@ Examples
compute snap all snap 1.4 0.95 6 2.0 1.0
compute snap all snap 1.0 0.99363 6 3.81 3.83 1.0 0.93 chem 2 0 1
compute snap all snap 1.0 0.99363 6 3.81 3.83 1.0 0.93 switchinnerflag 1 sinner 1.35 1.6 dinner 0.25 0.3
compute bgrid all sna/grid/local 200 200 200 1.4 0.95 6 2.0 1.0
compute bgrid all sna/grid/local grid 200 200 200 1.4 0.95 6 2.0 1.0
compute bnnn all sna/atom 9.0 0.99363 8 0.5 1.0 rmin0 0.0 nnn 24 wmode 1 delta 0.2
Description
Expand Down Expand Up @@ -252,7 +259,8 @@ for finite-temperature Kohn-Sham density functional theory (:ref:`Ellis
et al. <Ellis2021>`) Neighbor atoms not in the group do not contribute
to the bispectrum components of the grid points. The distance cutoff
:math:`R_{ii'}` assumes that *i* has the same type as the neighbor atom
*i'*.
*i'*. Both computes can be hardware accelerated with Kokkos by using the
*sna/grid/kk* and *sna/grid/local/kk* commands, respectively.

Compute *sna/grid* calculates a global array containing bispectrum
components for a regular grid of points.
Expand Down Expand Up @@ -463,6 +471,12 @@ fluctuations in the resulting local atomic environment fingerprint. The
detailed formalism is given in the paper by Lafourcade et
al. :ref:`(Lafourcade) <Lafourcade2023_2>`.

----------


.. include:: accel_styles.rst


----------

Output info
Expand Down Expand Up @@ -654,7 +668,7 @@ of Angular Momentum, World Scientific, Singapore (1987).

.. _Ellis2021:

**(Ellis)** Ellis, Fiedler, Popoola, Modine, Stephens, Thompson, Cangi, Rajamanickam, Phys Rev B, 104, 035120, (2021)
**(Ellis)** Ellis, Fiedler, Popoola, Modine, Stephens, Thompson, Cangi, Rajamanickam, `Phys. Rev. B, 104, 035120, (2021) <https://doi.org/10.1103/PhysRevB.104.035120>`_

.. _Lafourcade2023_2:

Expand Down
2 changes: 2 additions & 0 deletions doc/utils/sphinx-config/false_positives.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3380,6 +3380,7 @@ Schilfgarde
Schimansky
Schiotz
Schlitter
Schmerler
Schmid
Schnieders
Schoen
Expand Down Expand Up @@ -4042,6 +4043,7 @@ VMDARCH
VMDHOME
vn
Voigt
Vogel
volfactor
Volkov
Volpe
Expand Down
6 changes: 6 additions & 0 deletions examples/snap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@ in.snap.Mo_Chen # SNAP linear Mo potential
in.snap.compute # SNAP compute for training a linear model
in.snap.compute.quadratic # SNAP compute for training a quadratic model
in.snap.scale.Ni_Zuo_JCPA2020 # SNAP linear Ni potential with thermodynamic integration (fix adapt scale)
in.C_SNAP # SNAP carbon potential

compute_snap_dgrad.py # SNAP compute with dgradflag (dBi/dRj) for training a non-linear model

in.snap.grid # SNAP descriptors on a grid
in.snap.grid.triclinic # SNAP descriptors on a grid, triclinic
in.gaussian.grid # Gaussian descriptors on a grid

68 changes: 68 additions & 0 deletions examples/snap/in.gaussian.grid
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Demonstrate calculation of Gaussian descriptors on a grid
# for a cell with two atoms of type 1 and type 2.
# The output in dump.glocal shows that for grid points
# sitting on an atom of type 1 or 2:
# val1 = 1.0/(0.1355*sqrt(2.0*pi))**3 = 25.5219
# val2 = 1.0/(0.2 *sqrt(2.0*pi))**3 = 7.93670
# These values are extracted to the log file
#

variable nrep index 1
variable a index 3.316
variable ngrid index 2

units metal
atom_modify map hash

# generate the box and atom positions using a BCC lattice

variable nx equal ${nrep}
variable ny equal ${nrep}
variable nz equal ${nrep}

boundary p p p

lattice custom $a &
a1 1 0 0 &
a2 0 1 0 &
a3 0 0 1 &
basis 0 0 0 &
basis 0.5 0.5 0.5 &

region box block 0 ${nx} 0 ${ny} 0 ${nz}
create_box 2 box
create_atoms 1 box basis 1 1 basis 2 2

mass * 180.88

# define atom compute and grid compute

variable rcutfac equal 4.67637
variable radelem1 equal 0.5
variable radelem2 equal 0.5
variable sigmaelem1 equal 0.1355
variable sigmaelem2 equal 0.2
variable gaussian_options string &
"${rcutfac} ${radelem1} ${radelem2} ${sigmaelem1} ${sigmaelem2}"

# build zero potential to force ghost atom creation

pair_style zero ${rcutfac}
pair_coeff * *

# define atom and grid computes

compute mygridlocal all gaussian/grid/local grid ${ngrid} ${ngrid} ${ngrid} &
${gaussian_options}

# define output

dump 1 all local 1000 dump.glocal c_mygridlocal[*]
dump 2 all custom 1000 dump.gatom id x y z
compute val1 all reduce max c_mygridlocal[7] inputs local
compute val2 all reduce max c_mygridlocal[8] inputs local
thermo_style custom step c_val1 c_val2

# run

run 0
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ lattice custom $a &
basis 0.0 0.0 0.5 &
spacing 1 1 1

box tilt large
region box prism 0 ${nx} 0 ${ny} 0 ${nz} ${ny} ${nz} ${nz}
create_box 1 box
create_atoms 1 box
Expand Down
Loading

0 comments on commit 0dfd5d8

Please sign in to comment.