Added lots of docs, finished CMake script

This commit is contained in:
Andreas Singraber
2021-02-24 17:57:24 +01:00
parent c56f665c5b
commit e713a931d3
12 changed files with 238 additions and 54 deletions

View File

@ -1,25 +1,47 @@
include(FindPackageHandleStandardArgs)
# Check if N2P2_DIR is set manually.
if (DEFINED ENV{N2P2_DIR})
set(N2P2_DIR "${N2P2_DIR}")
# If not, try if directory "lib/nnp/n2p2" exists.
else()
get_filename_component(_fullpath "${LAMMPS_LIB_SOURCE_DIR}/nnp/n2p2" REALPATH)
if (EXISTS ${_fullpath})
set(N2P2_DIR "${_fullpath}")
endif()
endif()
message(STATUS "N2P2_DIR=${N2P2_DIR}")
# Set path to include directory.
find_path(N2P2_INCLUDE_DIR InterfaceLammps.h PATHS "${N2P2_DIR}/include")
# Two libraries need to be linked: libnnp and libnnpif.
find_library(N2P2_LIBNNP NAMES nnp PATHS "${N2P2_DIR}/lib")
find_library(N2P2_LIBNNPIF NAMES nnpif PATHS "${N2P2_DIR}/lib")
# Users could compile n2p2 with extra flags which are then also required for
# pair_nnp.cpp compilation. To forward them to the LAMMPS build process n2p2
# writes a file with cmake commands, e.g.
#
# target_compile_definitions(lammps PRIVATE -DNNP_NO_SF_GROUPS)
#
# to "lib/lammps-extra.cmake" which is then included by USER-NNP.cmake.
find_file(N2P2_CMAKE_EXTRA NAMES lammps-extra.cmake PATHS "${N2P2_DIR}/lib")
find_package_handle_standard_args(N2P2 DEFAULT_MSG N2P2_INCLUDE_DIR N2P2_LIBNNP)
find_package_handle_standard_args(N2P2 DEFAULT_MSG
N2P2_DIR
N2P2_INCLUDE_DIR
N2P2_LIBNNP
N2P2_LIBNNPIF
N2P2_CMAKE_EXTRA)
if(N2P2_FOUND)
set(N2P2_INCLUDE_DIRS ${N2P2_INCLUDE_DIR})
set(N2P2_LIBRARIES ${N2P2_LIBNNPIF} ${N2P2_LIBNNP})
set(N2P2_CMAKE_EXTRAS ${N2P2_CMAKE_EXTRA})
mark_as_advanced(
N2P2_DIR
N2P2_INCLUDE_DIR
N2P2_LIBNNP
N2P2_LIBNNPIF
N2P2_CMAKE_EXTRA
)
endif()

View File

@ -1,3 +1,4 @@
find_package(N2P2 REQUIRED)
target_include_directories(lammps PRIVATE ${N2P2_INCLUDE_DIRS})
target_link_libraries(lammps PRIVATE ${N2P2_LIBRARIES})
include(${N2P2_CMAKE_EXTRAS})

View File

@ -1592,17 +1592,38 @@ on your system.
USER-NNP package
---------------------------------
To build with the USER-NNP package it is required to download and build the
external `n2p2 <https://github.com/CompPhysVienna/n2p2>`__ library ``v2.2.0``
(or higher) before starting the LAMMPS build process. More specifically, only
the *n2p2* core library ``libnnp`` and interface library ``libnnpif`` are
actually needed: when using GCC it should suffice to execute ``make libnnpif``
in the *n2p2* ``src`` directory. For more details please see the `n2p2 build
documentation <https://compphysvienna.github.io/n2p2/topics/build.html>`__. If
*n2p2* is downloaded and compiled in the LAMMPS directory ``lib/nnp/n2p2`` no
special flags need to be set besides the usual package activation. If you prefer
to install *n2p2* somewhere else on your system you must specify the path via
the ``N2P2_DIR`` variable.
.. tabs::
.. tab:: CMake build
There is one additional setting besides ``-D PKG_USER-NNP=yes`` in case
*n2p2* is not installed in the ``lib/nnp/n2p2`` directory:
.. code-block:: bash
ADD STUFF HERE
-D N2P2_DIR=path # path ... n2p2 installation path
.. tab:: Traditional make
ADD STUFF HERE
There is one additional variable that needs to be set besides ``make
yes-user-nnp`` in case *n2p2* is not installed in the ``lib/nnp/n2p2``
directory:
.. code-block:: bash
make N2P2_DIR=path ...
----------

View File

@ -79,7 +79,7 @@ package:
+------------------------------------------------+-----------------------------------------------------------------+-------------------------------------------------------------------------------+------------------------------------------------------+---------+
| :ref:`USER-NETCDF <PKG-USER-NETCDF>` | dump output via NetCDF | :doc:`dump netcdf <dump_netcdf>` | n/a | ext |
+------------------------------------------------+-----------------------------------------------------------------+-------------------------------------------------------------------------------+------------------------------------------------------+---------+
| :ref:`USER-NNP <PKG-USER-NNP>` | High-dimensional neural network potenials | :doc:`pair_style nnp <pair_nnp>` | USER/nnp | ext |
| :ref:`USER-NNP <PKG-USER-NNP>` | High-dimensional neural network potentials | :doc:`pair_style nnp <pair_nnp>` | USER/nnp | ext |
+------------------------------------------------+-----------------------------------------------------------------+-------------------------------------------------------------------------------+------------------------------------------------------+---------+
| :ref:`USER-OMP <PKG-USER-OMP>` | OpenMP-enabled styles | :doc:`Speed omp <Speed_omp>` | `Benchmarks <https://lammps.sandia.gov/bench.html>`_ | no |
+------------------------------------------------+-----------------------------------------------------------------+-------------------------------------------------------------------------------+------------------------------------------------------+---------+

View File

@ -112,7 +112,7 @@ function setup, ``scaling.data`` with symmetry function scaling data and
The keyword *showew* can be used to turn on/off the display of extrapolation
warnings (EWs) which are issued whenever a symmetry function value is out of
bounds defined by minimum/maximum values in "scaling.data". An extrapolation
bounds defined by minimum/maximum values in ``scaling.data``. An extrapolation
warning may look like this:
.. code-block:: LAMMPS
@ -221,14 +221,14 @@ present elements (see above).
.. _Behler_Parrinello_2007:
**(Behler and Parrinello 2007)** Behler, J.; Parrinello, M. Generalized
**(Behler and Parrinello 2007)** `Behler, J.; Parrinello, M. Generalized
Neural-Network Representation of High-Dimensional Potential-Energy Surfaces.
Phys. Rev. Lett. 2007, 98 (14), 146401.
https://doi.org/10.1103/PhysRevLett.98.146401
<https://doi.org/10.1103/PhysRevLett.98.146401>`__
.. _Singraber_et_al_2019:
**(Singraber et al 2019)** Singraber, A.; Behler, J.; Dellago, C. Library-Based
**(Singraber et al 2019)** `Singraber, A.; Behler, J.; Dellago, C. Library-Based
LAMMPS Implementation of High-Dimensional Neural Network Potentials. J. Chem.
Theory Comput. 2019, 15 (3), 18271840.
https://doi.org/10.1021/acs.jctc.8b00770.
Theory Comput. 2019, 15 (3), 1827-1840
<https://doi.org/10.1021/acs.jctc.8b00770>`__

View File

@ -2171,6 +2171,8 @@ Nmin
nmin
Nmols
nn
nnp
NNP
Nocedal
nocite
nocoeff

View File

@ -41,6 +41,8 @@ mscg hooks to the MSCG library, used by fix_mscg command
from Jacob Wagner and Greg Voth group (U Chicago)
netcdf hooks to a NetCDF library installed on your system
from Lars Pastewka (Karlsruhe Institute of Technology)
nnp hooks to n2p2, neural network potential package, used by USER-NNP
from Andreas Singraber
poems POEMS rigid-body integration package, POEMS package
from Rudranarayan Mukherjee (RPI)
python hooks to the system Python library, used by the PYTHON package

View File

@ -1 +1,90 @@
WRITE STUFF HERE
The USER-NNP package requires access to pre-compiled libraries of the n2p2
package (https://github.com/CompPhysVienna/n2p2). More precisely, the n2p2 core
library ("libnnp"), the interface library ("libnnpif"), some headers and extra
build helper files are needed. These files will be created automatically during
the n2p2 build process.
Basic build instructions for n2p2
=================================
The n2p2 software package comes with lots of useful tools for creating and
applying neural network potentials (NNPs). In order to use n2p2 together with
LAMMPS only a portion of the n2p2 code needs to be compiled. As an example,
everything related to NNP training is not required and would only add unwanted
library dependencies. Hence, the build infrastructure of n2p2 is designed to allow
a separate build of the LAMMPS interface.
After downloading n2p2, change to the "src" directory and simply execute
make libnnpif
which should create the following files needed by the USER-NNP package:
* "n2p2/lib/libnnp.a"
* "n2p2/lib/libnnpif.a"
* "n2p2/lib/lammps-extra.cmake"
* "n2p2/lib/Makefile.lammps-extra"
* "n2p2/include/InterfaceLammps.h" and many other header files.
If you prefer dynamically linked libraries use
make MODE=shared libnnpif
instead (by default MODE=static) which will create *.so versions of the
libraries. By default, n2p2 uses the GNU C++ compiler and the corresponding
settings can be found in "n2p2/src/makefile.gnu". Other makefile presets are
also available (e.g. "makefile.intel") and can be activated by supplying the
"COMP" argument:
make COMP=intel libnnpif
Please make sure that your compiler settings for n2p2 and LAMMPS are compatible
(avoid mixing different compilers). For more information about the n2p2 build
process please visit https://compphysvienna.github.io/n2p2/topics/build.html or
ask questions on the Github issue page
(https://github.com/CompPhysVienna/n2p2/issues).
Installation directory of n2p2
==============================
You can install n2p2 either in this folder (1) or somewhere else on your system (2):
(1) If n2p2 is installed here, please make sure that the directory is also named
"n2p2", i.e. within "lib/nnp/n2p2" you can see the n2p2 folder structure, in
particular "lib" and "include":
lib
|
nnp
|
n2p2
|
------------------ ...
| | |
include lib src ...
In this case LAMMPS will automatically find n2p2 during the build process
and you only need to enable the USER-NNP package via CMake (-D
PKG_USER-NNP=yes) or the traditional makefile approach (make yes-user-nnp).
It is also valid to create a link here named "n2p2" which points to the n2p2
installation directory.
(2) If n2p2 is installed somewhere else the path must be given as an additional
setting (variable N2P2_DIR) to the build tool. For example, with CMake use
cmake -D PKG_USER-NNP=yes -D N2P2_DIR=<path-to-n2p2> ../cmake/
and for the traditional makefiles use
make yes-user-nnp
make N2P2_DIR=<path-to-n2p2> mpi
Testing a successful build of LAMMPS with USER-NNP
==================================================
An example is provided in the LAMMPS directory "examples/USER/nnp" which runs
10 timesteps with 360 water molecules. The neural network potential is defined
via files in the "nnp-data" subdirectory. Use the "in.nnp" LAMMPS script file
to run the simulation. You should see a large output of the n2p2 library when
the pair style "nnp" is initialized, followed by the LAMMPS per-timestep
output.

2
src/.gitignore vendored
View File

@ -1079,6 +1079,8 @@
/pair_nm_cut_coul_cut.h
/pair_nm_cut_coul_long.cpp
/pair_nm_cut_coul_long.h
/pair_nnp.cpp
/pair_nnp.h
/pair_oxdna_*.cpp
/pair_oxdna_*.h
/pair_oxdna2_*.cpp

View File

@ -0,0 +1,26 @@
This package implements the "pair_style nnp" command which can be used in a
LAMMPS input script. This pair style allows to use pre-trained high-dimensional
neural network potentials[1] via an interface to the n2p2 library
(https://github.com/CompPhysVienna/n2p2)[2].
Please see the main documentation for the "pair_style nnp" command for further
details on how the pair style is used. An example is provided in the
"examples/USER/nnp" directory of LAMMPS.
The USER-NNP package requires the external library n2p2 which must be
downloaded and compiled before starting the build process of LAMMPS. A rough
guideline on how to build n2p2 is presented in "lib/nnp/README". This package
supports the LAMMPS build process via CMake and traditional makefiles, please
see the LAMMPS manual section on building with external libraries for more
details.
This package was created by Andreas Singraber, please ask questions/report bugs
on the n2p2 Github issues page (https://github.com/CompPhysVienna/n2p2/issues).
[1] Behler, J.; Parrinello, M. Generalized Neural-Network Representation of
High-Dimensional Potential-Energy Surfaces. Phys. Rev. Lett. 2007, 98 (14),
146401. https://doi.org/10.1103/PhysRevLett.98.146401
[2] Singraber, A.; Behler, J.; Dellago, C. Library-Based
LAMMPS Implementation of High-Dimensional Neural Network Potentials. J. Chem.
Theory Comput. 2019, 15 (3), 1827-1840. https://doi.org/10.1021/acs.jctc.8b00770

View File

@ -1,32 +1,35 @@
// n2p2 - A neural network potential package
// Copyright (C) 2018 Andreas Singraber (University of Vienna)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
/* -*- c++ -*- ----------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
This file initially came from n2p2 (https://github.com/CompPhysVienna/n2p2)
Copyright (2018) Andreas Singraber (University of Vienna)
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Andreas Singraber
------------------------------------------------------------------------- */
#include <mpi.h>
#include <string.h>
#include "pair_nnp.h"
#include <mpi.h>
#include "atom.h"
#include "comm.h"
#include "error.h"
#include "memory.h"
#include "neighbor.h"
#include "neigh_list.h"
#include "neigh_request.h"
#include "memory.h"
#include "error.h"
#include "update.h"
#include "utils.h"
#include "InterfaceLammps.h"
#include "InterfaceLammps.h" // n2p2 interface header
using namespace LAMMPS_NS;
@ -89,6 +92,18 @@ void PairNNP::compute(int eflag, int vflag)
void PairNNP::settings(int narg, char **arg)
{
single_enable = 0; // 1 if single() routine exists
single_hessian_enable = 0; // 1 if single_hessian() routine exists
restartinfo = 0; // 1 if pair style writes restart info
respa_enable = 0; // 1 if inner/middle/outer rRESPA routines
one_coeff = 1; // 1 if allows only one coeff * * call
manybody_flag = 1; // 1 if a manybody potential
unit_convert_flag = 0; // value != 0 indicates support for unit conversion.
no_virial_fdotr_compute = 0; // 1 if does not invoke virial_fdotr_compute()
writedata = 0; // 1 if writes coeffs to data file
ghostneigh = 0; // 1 if pair style needs neighbors of ghosts
reinitflag = 0; // 1 if compatible with fix adapt and alike
int iarg = 0;
if (narg == 0) error->all(FLERR,"Illegal pair_style command");
@ -312,7 +327,7 @@ void PairNNP::handleExtrapolationWarnings()
// rank 0.
if(showew > 0) {
// First collect an overview of extrapolation warnings per process.
long* numEWPerProc = nullptr;
long *numEWPerProc = nullptr;
if(comm->me == 0) numEWPerProc = new long[comm->nprocs];
MPI_Gather(&numCurrentEW, 1, MPI_LONG, numEWPerProc, 1, MPI_LONG, 0, world);
@ -323,7 +338,7 @@ void PairNNP::handleExtrapolationWarnings()
MPI_Status ms;
// Get buffer size.
MPI_Recv(&bs, 1, MPI_LONG, i, 0, world, &ms);
char* buf = new char[bs];
char *buf = new char[bs];
// Receive buffer.
MPI_Recv(buf, bs, MPI_BYTE, i, 0, world, &ms);
interface->extractEWBuffer(buf, bs);
@ -336,7 +351,7 @@ void PairNNP::handleExtrapolationWarnings()
// Get desired buffer length for all extrapolation warning entries.
long bs = interface->getEWBufferSize();
// Allocate and fill buffer.
char* buf = new char[bs];
char *buf = new char[bs];
interface->fillEWBuffer(buf, bs);
// Send buffer size and buffer.
MPI_Send(&bs, 1, MPI_LONG, 0, 0, world);

View File

@ -1,18 +1,22 @@
// n2p2 - A neural network potential package
// Copyright (C) 2018 Andreas Singraber (University of Vienna)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
/* -*- c++ -*- ----------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
This file initially came from n2p2 (https://github.com/CompPhysVienna/n2p2)
Copyright (2018) Andreas Singraber (University of Vienna)
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Andreas Singraber
------------------------------------------------------------------------- */
#ifdef PAIR_CLASS
@ -58,9 +62,9 @@ class PairNNP : public Pair {
double cflength;
double cfenergy;
double maxCutoffRadius;
char* directory;
char* emap;
nnp::InterfaceLammps* interface;
char *directory;
char *emap;
nnp::InterfaceLammps *interface;
};
}