MEAMfit2 compilation

Compile MEAMfit2 and add RF-MEAM potential into LAMMPS within WSL2 Ubuntu

Official website: https://www.scd.stfc.ac.uk/Pages/MEAMfit-v2.aspx
Official gitlab: https://gitlab.com/AndyDuff123/meamfit

Steps:

1) Compile MEAMfit2 for optimizing parameters of EAM/RF-MEAM interatomic potentials by fitting on DFT data from CASTEP or VASP.
2) Incorporate RF-MEAM potential into LAMMPS.

Tested PC:
  • Intel(R) Core(TM) i5-14600K 3.50 GHz
  • RTX 2060 SUPER
  • Kingston FURY 32GB KIT DDR5 6000MHz CL32 Renegade
  • WSL2 Ubuntu version: 22.04
 
Prerequisites:

(not all are necessary but might be useful)

sudo apt-get upgrade
sudo apt-get install build-essential cmake cmake-curses-gui libopenmpi-dev openmpi-bin libfftw3-dev libblas-dev liblapack-dev pkg-config ffmpeg python3-dev
sudo apt install python3-pip python3.10-venv python3-venv

Compile OpenMPI: see -> HERE <-

MEAMfit2
git clone https://gitlab.com/AndyDuff123/meamfit.git
cd meamfit

Check available configurations in /meamfit/config/ and decide which compiler you want to use. I will use GNU. In mkconfig file, you will probably need to change the name for python:

cd tools
nano mkconfig

On the first line, change ‚python‘ to ‚python3‘ (!/usr/bin/env python3). Save (control + s), exit nano (control + x).

cd .. 

(to be in parent meamfit folder)

Setting the correct compiler that I want to use for compilation and for running the parallel MEAMfit computions (openMPI) (you likely do not need to write this):

export PATH=/home/lebedmi2/SOFTWARE/openmpi_5/bin:$PATH
export LD_LIBRARY_PATH=/home/lebedmi2/SOFTWARE/openmpi_5/lib:$LD_LIBRARY_PATH

Reduce the number of grid points to create reasonably large EAM potential files:
In ‘/meam/src/plotfunctions.f90’ adjust the number of grid points used to define the embedding function (Nrho) and the pair-potential/electron densities (Nr):

cd src
nano 
plotfunctions.f90

Change:
Nr=100000 => 1000
Nrho=10000000 => 10000
Save and exit nano.

cd ..

Having the meamfit as current directory, write (‚mkconfig gnu‘, but include full path for mkconfig and full path for the selected config):

./tools/mkconfig ./config/gnu
make -j

cd bin
mv MEAMfit.x meamfit
Add path to the meamfit binary to environment variables (add the path to bashrc):
export PATH=/home/lebedmi2/SOFTWARE/meamfit/bin:$PATH

Test:
cd /home/lebedmi2/DATA/MEAMfit2_data/test_vaspruns_bcc (contains .xml outputs from VASP calculations)
mpirun -np 1 meamfit (creates fitdbse - see official documentation)
mpirun -np 1 meamfit (creates settings - see official documentation)

Add some initial value for the cutoff into settings (otherwise an error will appeared):

nano settings

To more suitably select the cutoff up to certain number of nearest neighbours, it can be useful to plot the histogram with the pair distances between different types of atoms:

mpirun -np 1 meamfit -noopt

Visualize the histograms: 

sudo apt-get install gnuplot
gnuplot
Write all the following at once (my vasp files have 4 elements, thus first curve describe counts at given distances between first and first element, second curve is between first and second element, third between first and third, fourth between first and fourth, fifth between second and second, etc.):
plot \
'sepnHistogram.out' using 1:2 title '1-1' with lines, \
'sepnHistogram.out' using 1:3 title '1-2' with lines, \
'sepnHistogram.out' using 1:4 title '1-3' with lines, \
'sepnHistogram.out' using 1:4 title '1-4' with lines, \
'sepnHistogram.out' using 1:5 title '2-2' with lines, \
'sepnHistogram.out' using 1:6 title '2-3' with lines, \
'sepnHistogram.out' using 1:7 title '2-4' with lines, \
'sepnHistogram.out' using 1:8 title '3-3' with lines, \
'sepnHistogram.out' using 1:9 title '3-4' with lines, \
'sepnHistogram.out' using 1:10 title '4-4' with lines

Close gnuplot. Start the fitting:

mpirun -np 8 meamfit

Note: If you want to change the initial values for weights, modify the following line in file /meamfit/src/setupfilenames.f90:         
write(50,'(A50,A3,I1,A18)‘) files(ifile),‘ 1-‚,nconf(ifile),‘   Fr 1 0.1 0.001′
and recompile meamfit.

 
Compile LAMMPS with RF-MEAM
Note: The compilation of LAMMPS with added RF-MEAM source files gives errors for version 24Mar2022 and above.
wget https://download.lammps.org/tars/lammps-17Feb2022.tar.gz 
tar xvzf 
lammps-17Feb2022.tar.gz

cd lammps-17Feb2022/

From /meamfit/lammpsSubs folder, copy the subroutines for rf-meam into /lammps/src directory:

cp /home/lebedmi2/SOFTWARE/meamfit/lammpsSubs/pair_rfmeam.cpp /home/lebedmi2/SOFTWARE/meamfit/lammpsSubs/pair_rfmeam.h /home/lebedmi2/SOFTWARE/LAMMPS/lammps-17Feb2022/srcmkdir build
cd build
sudo cmake -D PKG_GPU=ON -D GPU_API=CUDA -D GPU_PREC=mixed -D GPU_ARCH=sm_75 -D PKG_ORIENT=ON -D PKG_PYTHON=ON -D PKG_OPENMP=ON -D PKG_MEAM=ON -D PKG_MANYBODY=ON -D BUILD_SHARED_LIBS=ON -DBIN2C=/usr/local/cuda-12.3/bin/bin2c -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-12.3 -DCMAKE_LIBRARY_PATH=/usr/local/cuda-12.3/targets/x86_64-linux/lib/stubs ../cmake

(When compiling older versions of LAMMPS on GPU, -DCMAKE_LIBRARY_PATH=/usr/local/cuda-12.3/targets/x86_64-linux/lib/stubs had to be added to solve the error: CMake Error: The following variables are used in this project, but they are set to NOTFOUND
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_CUDA_LIBRARY (ADVANCED))

sudo make -j 10
sudo make install

Add path to lmp binary to bashrc. 

In input script for lammps, define the rf-meam as (see documentation, the atomic numbers must be added for each element):
pair_style rfmeam 
pair_coeff * * ./library.rfmeam.CuSbS Cu Sb S 29 51 16