Files
lammps/examples/QUANTUM/PySCF
Steve Plimpton 375eb46450 README edits
2023-03-22 09:24:04 -06:00
..
2023-02-03 15:20:18 -07:00
2023-02-03 15:20:18 -07:00
2023-02-09 14:05:47 -07:00
2023-02-09 14:05:47 -07:00
2023-02-09 14:05:47 -07:00
2023-03-22 09:24:04 -06:00

# Test runs with copuling of LAMMPS and PySCF

Step 0: What PySCF currently supports
Step 1: Build LAMMPS
Step 2: Download/build MDI code coupling package
Step 3: Download/build PySCF
Step 4: Perform test runs in any of 3 modes

---------------------------------
---------------------------------

Step 0: What PySCF currently supports

PySCF can be used with fix mdi/qmmm for QM/MM simulations, but not
with fix mdi/qm to perform QM calculations of an entire system.  For
QM/MM it can use the direct mode of fix mdi/qmmm, but not the
potential mode.  PySCF can calculate a QM energy and QM forces on each
atom, but it cannot compute a QM stress tensor.

PySCF does not support MPI parallelism, so run it on a single MPI task.
But it does support multi-threading via OpenMP.  By default it will use
all the threads available on your compute node.  Depending on the size
of the problem and your hardware, it may be faster to run on fewer threads.
Thus for a production run it is a good idea to do some short runs first
with different thread counts to test performance.

For example, these commands will set the OpenMP thread count (to 4)
before performing a run.  Unsetting the environment variable will
revert to the default (use all available threads).

bash:
% export OMP_NUM_THREADS=4
% unset OMP_NUM_THREADS

(t)csh:
% setenv OMP_NUM_THREADS 4
% unsetenv OMP_NUM_THREADS

All the example log files in this directory were run with OMP_NUM_THREADS = 1

---------------------------------
---------------------------------

Step 1: Build LAMMPS

The MDI, molecule, and kspace packages are needed.  Copy the final
LAMMPS executable into the examples/QUANTUM/PySCF directory.

Traditional make:

% cd ~/lammps/lib/mdi
% python Install.py -m mpi
% cd ~/lammps/src
% make yes-mdi yes-molecule yes-kspace
% make -j mpi
% cp lmp_mpi ~/lammps/examples/QUANTUM/PySCF

CMake:

% cd ~/lammps
% mkdir build; cd build
% cmake -DPKG_MDI=yes -DPKG_MOLECULE=yes -DPKG_KSPACE=yes ../cmake
% make -j
% cp lmp ~/lammps/examples/QUANTUM/PySCF/lmp_mpi

---------------------------------
---------------------------------

Step 2: Install MDI code coupling python module

You can install MDI in your Python environment via conda:

% conda install -c conda-forge pymdi=1.4.16

or via pip:

% pip install 'pymdi>=1.4.14'

It is likely fine to leave off the version number, to get the latest
MDI version.  1.4.16 is the version LAMMPS is currently using.

---------------------------------
---------------------------------

Step 3: Download/build PySCF

See https://pyscf.org/install.html for install options.
This describes building PySCF from source code.

(a) clone the PySCF Git repo

% mkdir pyscf; cd pyscf
% git clone https://github.com/pyscf/pyscf.git git

(b) build PySCF

NOTE: you will also need numpy, scipy, h5py in your python

% cd pyscf/git/lib
% mkdir build; cd build
% cmake ..
% make -j

(c) Add a line like this to your ~/.bashrc or ~/.cshrc file so that
Python can find PySCF:

For bash:

% export PYTHONPATH="$PYTHONPATH:/home/sjplimp/pyscf/git"
% hash -r

For (t)csh:

% setenv PYTHONPATH ${PYTHONPATH}:/home/sjplimp/pyscf/git
% rehash

(d) Check import of 4 Python modules which the script that wraps PySCF
will need:

% python
>>> import numpy as np
>>> from mpi4py import MPI
>>> import mdi
>>> import pyscf

---------------------------------
---------------------------------

Step 4: Perform test runs in any of 3 modes

These tests are in lammps/examples/QUANTUM/PySCF

in.water = QMMM of two-water system, 1 QM + 1 MM
in.mixture = QMMM of mixture, QM small molecule in MM water

** run LAMMPS-only versions of mixture problem

lmp_mpi -log log.mixture.mm.1 -in in.mixture.mm

** run LAMMPS and PySCF with TCP/IP, 1 proc each

lmp_mpi -mdi "-name LMP -role DRIVER -method TCP -port 8021" -log log.water.qmmm.tcp.1 -in in.water.qmmm &
python pyscf_mdi.py -mdi "-name PYSCF -role ENGINE -method TCP -port 8021 -hostname localhost"

lmp_mpi -mdi "-name LMP -role DRIVER -method TCP -port 8021" -log log.mixture.qmmm.tcp.1 -in in.mixture.qmmm &
python pyscf_mdi.py -mdi "-name PYSCF -role ENGINE -method TCP -port 8021 -hostname localhost"

** run LAMMPS and PySCF with MPI, 1 proc each

mpirun -np 1 lmp_mpi -mdi "-name LMP -role DRIVER -method MPI" -log log.water.qmmm.mpi.1 -in in.water.qmmm : -np 1 python pyscf_mdi.py -mdi "-name PYSCF -role ENGINE -method MPI" -pbc no

mpirun -np 1 lmp_mpi -mdi "-name LMP -role DRIVER -method MPI" -log log.mixture.qmmm.mpi.1 -in in.mixture.qmmm : -np 1 python pyscf_mdi.py -mdi "-name PYSCF -role ENGINE -method MPI" -pbc no

** run PySCF as plugin MDI engine, 1 proc

lmp_mpi -mdi "-name LMP -role DRIVER -method LINK -plugin_path /home/sjplimp/lammps/git/examples/QUANTUM/PySCF" -log log.water.qmmm.plugin.1 -in in.water.qmmm.plugin

lmp_mpi -mdi "-name LMP -role DRIVER -method LINK -plugin_path /home/sjplimp/lammps/git/examples/QUANTUM/PySCF" -log log.mixture.qmmm.plugin.1 -in in.mixture.qmmm.plugin