Updating nn example and mliap .rst

This commit is contained in:
Pedro Antonio Santos Flórez
2021-03-03 13:36:00 -03:00
parent 59eaa46f8d
commit 38d076e22e
4 changed files with 139 additions and 3 deletions

View File

@ -16,7 +16,7 @@ Syntax
.. parsed-literal:: .. parsed-literal::
*model* values = style filename *model* values = style filename
style = *linear* or *quadratic* or *mliappy* style = *linear* or *quadratic* or *nn* or *mliappy*
filename = name of file containing model definitions filename = name of file containing model definitions
*descriptor* values = style filename *descriptor* values = style filename
style = *sna* style = *sna*
@ -45,7 +45,7 @@ pair style currently supports just one descriptor style, but it is
is straightforward to add new descriptor styles. is straightforward to add new descriptor styles.
The SNAP descriptor style *sna* is the same as that used by :doc:`pair_style snap <pair_snap>`, The SNAP descriptor style *sna* is the same as that used by :doc:`pair_style snap <pair_snap>`,
including the linear, quadratic, and chem variants. including the linear, quadratic, and chem variants.
The available models are *linear*, *quadratic*, and *mliappy*. The available models are *linear*, *quadratic*, *nn*, and *mliappy*.
The *mliappy* style can be used to couple python models, The *mliappy* style can be used to couple python models,
e.g. PyTorch neural network energy models, and requires building e.g. PyTorch neural network energy models, and requires building
LAMMPS with the PYTHON package (see below). LAMMPS with the PYTHON package (see below).
@ -77,13 +77,32 @@ line must contain two integers:
* nelems = Number of elements * nelems = Number of elements
* nparams = Number of parameters * nparams = Number of parameters
This is followed by one block for each of the *nelem* elements. When the *model* keyword is *linear* or *quadratic*,
this is followed by one block for each of the *nelem* elements.
Each block consists of *nparams* parameters, one per line. Each block consists of *nparams* parameters, one per line.
Note that this format is similar, but not identical to that used Note that this format is similar, but not identical to that used
for the :doc:`pair_style snap <pair_snap>` coefficient file. for the :doc:`pair_style snap <pair_snap>` coefficient file.
Specifically, the line containing the element weight and radius is omitted, Specifically, the line containing the element weight and radius is omitted,
since these are handled by the *descriptor*. since these are handled by the *descriptor*.
When the *model* keyword is *nn* (neural networks), the model file can contain
blank and comment lines (start with #) anywhere. The second non-blank non-comment
line must contain the string NET, followed by two integers:
* ndescriptors = Number of descriptors
* nlayers = Number of layers (including the hidden layers and the output layer)
and followed by a sequence of a string and an integer for each layer:
* Activation function (linear, sigmoid, tanh or relu)
* nnodes = Number of nodes
This is followed by one block for each of the *nelem* elements. Each block consists
of *scale0* minimum values, *scale1* (maximum - minimum) values,
in order to normalize the descriptors, followed by *nparams* parameters,
including *bias* and *weights* of the model, starting with the first node of the first layer
and so on, max. 30 parameters per line.
Notes on mliappy models: Notes on mliappy models:
When the *model* keyword is *mliappy*, the filename should end in '.pt', When the *model* keyword is *mliappy*, the filename should end in '.pt',
'.pth' for pytorch models, or be a pickle file. To load a model from '.pth' for pytorch models, or be a pickle file. To load a model from

View File

@ -0,0 +1,41 @@
# DATE: 2021-03-03 UNITS: metal CONTRIBUTOR: Pedro Antonio Santos Florez pedroantoniosantosf@gmail.com CITATION: none
# Neural networks weights generated in PyXtal_FF
# total_species nparams
1 71
# NET ndescriptors nlayers activation_func for layer 1, number of nodes for layer 1, ..., ..., ....,
NET 30 3 tanh 2 tanh 2 linear 1
# Scale0
98.5564567301067 0.1817576370006 -5.0513436999162 0.0453581866073 -4.4382278670569
-2.6985391112026 -4.9445068940273 7.8840372041149 -12.8729456412560 -2.9748781222888
-1.7702149043285 -4.6911979511282 -1.8167140506334 67.7067032503211 -12.5675074252146
-10.3889411514447 -2.6194029974308 1.8750503488944 -5.0934919399232 4.2037760919263
20.6488797181668 -8.2381178902428 -3.1311436510232 -1.1570117080256 2.1652328079269
0.0854872341687 73.5970916724043 -5.3230176040510 -5.3409170596296 -6.4491186818574
# Scale1
783.0204659783215 33.6453931227955 7.9068346594951 32.2509031640463 5.6624925894670
5.6511565657016 8.2175114613285 108.9434600935519 16.3162547782998 6.4485086884047
9.5767453287024 24.1576638495153 25.1723098340896 202.6741688060115 26.3843102888906
19.7937707236334 13.9016635198379 14.1399097533048 72.7078614093291 39.8358080634714
370.1745750951991 21.6864533954642 14.6554778261065 18.6456437491491 43.2946309680355
68.9168418942695 481.9819429675007 14.5585849595560 61.9026061535013 112.5968384702330
# Coefficients
-0.2503221860648 0.4607794046378 0.4080552184108 0.0043328332206 0.2778722163950
-0.0050555739235 0.0406748042003 -0.1188215011883 0.4669700426246 0.4050949681583
0.3004118858813 -0.3937378155782 0.5165632847373 0.1381866719908 -0.3996533578004
0.1330571447244 0.1124773980921 0.1548275555377 -0.6221152970188 -0.7813275942231
-0.4320969824072 0.2045533448767 -0.1687644566507 -0.0424066840175 -0.1981208883936
-0.3406471991751 0.1272788573915 -0.1236220514264 0.6482374783971 -0.0590428211363
0.1326060235944 0.1890472518561 -0.5428894028577 0.0229420637813 0.0750842032804
-0.2443049940974 0.5265826743321 -0.1802773940492 0.0309737044359 -0.4987806786020
-0.6233577810656 -0.9910225261357 0.3430680860751 0.2918559145139 0.0666915892882
-0.2558026088950 0.0417769401952 -0.2582828540822 -0.3685977011673 0.4793473883461
1.0290706767456 0.0400544448686 -0.1474888333296 0.2403156153173 0.1050109023846
0.1413378531949 0.0907250056918 -0.1185878739508 0.1471942864979 -0.2829701766758
0.1137318187684 0.0476123438306 0.8040349098084 -0.5432518550512 0.2312003570779
0.6886872913686 -0.1247049894693 0.6848986783339 -2.6353147047309 -0.7173579584864
-1.0543148168289

View File

@ -0,0 +1,21 @@
# DATE: 2021-03-03 UNITS: metal CONTRIBUTOR: Pedro Antonio Santos Florez pedroantoniosantosf@gmail.com CITATION: none
# LAMMPS SNAP parameters for Cu
# required
rcutfac 5.0
twojmax 6
# elements
nelems 1
elems Cu
radelems 0.5
welems 1.0
# optional
rfac0 0.99363
rmin0 0
bzeroflag 0
switchflag 1

View File

@ -0,0 +1,55 @@
# Demonstrate MLIAP interface to SNAP nn Cu potential
# Initialize simulation
variable nsteps index 100
variable nrep equal 4
variable a equal 3.621262
units metal
# 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 fcc $a
region box block 0 ${nx} 0 ${ny} 0 ${nz}
create_box 1 box
create_atoms 1 box
mass 1 63.546
# choose potential
pair_style mliap model nn Cu_nn.mliap.model descriptor sna Cu_snap.mliap.descriptor
pair_coeff * * Cu Cu
# Setup output
compute eatom all pe/atom
compute energy all reduce sum c_eatom
compute satom all stress/atom NULL
compute str all reduce sum c_satom[1] c_satom[2] c_satom[3]
variable press equal (c_str[1]+c_str[2]+c_str[3])/(3*vol)
thermo_style custom step temp epair c_energy etotal press v_press
thermo 10
thermo_modify norm yes
# Set up NVE run
timestep 0.5e-3
neighbor 1.0 bin
neigh_modify once no every 1 delay 0 check yes
# Run MD
velocity all create 300.0 4928459 loop geom
fix 1 all nve
run ${nsteps}