Setup for M3GNet versatile force field¶
Setting Python¶
This page outlines the necessary configuration steps for using the M3GNet versatile force field (original version, MatGL version) + Simple DFT-D3 correction in LAMMPS.
The original M3GNet was released as a standalone package. However, its successor is now part of the Materials Graph Library (MatGL). In LAMMPS modified by AdvanceSoft, the use of the pretrained model MP-2021.2.8-EFS
from the original version will select the original M3GNet. For all other cases, the MatGL version of M3GNet is selected for execution.
Install the software on the machine that will be used for the calculation (e.g. if you will plan to submit the job to a calculation server, the installation should be done on that server).
Preparing conda environment
Conda is utilized as the Python environment. If you are not already using conda, it is recommended to install Miniconda, which provides the minimum necessary recommended.
Download the Python 3.9 installer from the Miniconda page and proceed with its installation.
If you are using Windows and install Miniconda without altering the
PATH
variable, you should launch Anaconda Prompt from the Start menu and use it for subsequent procedure.If you need to use a proxy for internet connection, make sure to adjust the environment variable settings accordingly.
set HTTP_PROXY=http://host:port set HTTPS_PROXY=http://host:port
export HTTP_PROXY=http://user:pass@host:port export HTTPS_PROXY=http://user:pass@host:port
(Optional) Configuration to use GPU
The MatGL version of M3GNet, which utilize PyTorch, can be accelerated by employing the GPU version of PyTorch.
If NVIDIA driver is not already installed on your system, ensure you install it beforehand.
First, install the GPU version of PyTorch. For those with the latest version of CUDA, consult the Get Started section. If you have an older version of CUDA, refer to the Previous Versions section and execute the pip installation command that matches your CUDA version.
Next, install the GPU version of the Deep Graph Library (DGL). Refer to Get Started and execute the pip installation command appropriate for your CUDA version.
After completing the installation, you can verify whether the GPU is available or not by checking in the Python interactive environment.
python >>> import torch >>> print(torch.cuda.is_available()) # Check GPU availability True >>> exit() # Exit Python environment
Installation
Install the m3gnet and packages necessary for DFT-D3 correction.
pip install m3gnet matgl conda install simple-dftd3 dftd3-python -c conda-forge
Configuring NanoLabo¶
To run locally (on the machine running NanoLabo)
Set the path for the Python executable in
from the located in the upper left corner of the screen(or button in the Force Field setting screen).On Windows, the Python executable is located at the
conda installation destination\python.exe
. For Linux or mac OS, it is located in theconda installation destination/bin/python
.To run remotely (on calculation server etc.)
If Conda is installed in either
~/anaconda3
or~/miniconda3
, theLD_LIBRARY_PATH
is automatically updated, so no additional configuration is required in this case.If Conda is installed in a different location, click the icon located in the upper left corner, open
, and then add theLD_LIBRARY_PATH
to your job script.export LD_LIBRARY_PATH=(conda installation destination)/lib:$LD_LIBRARY_PATH
Troubleshooting¶
The following error may occur during runtime.
ValueError: Model does not existsThis message suggests that the required pretrained model data for execution is missing. Since the m3gnet package does not come with the model data, it attempts to download it during the initial run. However, if there is a problem with the internet connection, the download cannot proceed.
Alternatively, you can download the model data manually. Obtain the files from the MP-2021.2.8-EFS folder in the m3gnet repository and save them to the following location
(conda installation path)/lib/site-packages/m3gnet/models/MP-2021.2.8-EFS
.In the MatGL version of M3GNet, you may encounter the following error for the same reason.
ValueError: No valid model found in pre-trained_models at https://github.com/materialsvirtuallab/matgl/raw/main/pretrained_models/.In the case of the MatGL version, there is a folder for each model name in the matgl repository. Download the file for the model you wish to use and save it in
(home directory)/.cache/matgl/(model name)
.
On Windows, you may encounter the following error during runtime.
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.In this case, rename
(conda installation path)\Library\bin\libiomp5md.dll
tolibiomp5md.dll_
for example.
The following error may occur during runtime when DFT-D3 is enabled.
version `GOMP_5.0' not foundIf you encounter this issue, set the following environment variable.
export LD_PRELOAD=(conda installation destination)/lib/libgomp.so
We are aware that an error occurs with PyTorch version 1.13.1 and earlier versions:
IndexError: tensors used as indices must be long, byte or bool tensorsIf you encounter this issue, check your current version of PyTorch and ensure to install PyTorch version 2.0 or later.
# Check the installed version pip list # Uninstall PyTorch pip uninstall torch torchvision torchaudio # Display installable PyTorch versions pip install torch== # Install specifying PyTorch 2 or later pip install 'torch>=2' torchvision torchaudio
Using LAMMPS directly¶
This guidance is for running LAMMPS in a standalone mode, not through NanoLabo.
Utilize the executable file lammps_m3gnet
included in NanoLabo Tool. Please note that MPI parallel execution is not supported.
Setting Environment Variables¶
Since Python dynamic libraries are used at runtime, set the environment variable LD_LIBRARY_PATH
on Linux/macOS, or the environment variable PATH
on Windows (if not set during installation).
On Linux, OpenMPI dynamic libraries are required, so add their path to LD_LIBRARY_PATH
as well.
$ export LD_LIBRARY_PATH=(conda installation destination)/lib:(NanoLabo Tool installation destination)/exec.LINUX/mpi/lib:$LD_LIBRARY_PATH
> set PATH=(conda installation destination)/envs/ocp-models;%PATH%
Additionally, on Linux, you should set the environment variable OPAL_PREFIX
.
$ export OPAL_PREFIX=/opt/AdvanceSoft/NanoLabo/exec.LINUX/mpi
Since LAMMPS accesses m3gnet_driver.py
or matgl_driver.py
during operation, add the m3gnet
folder from the NanoLabo Tool installation location to Python’ module search path. This can be achieved, for example, by adding it to the PYTHONPATH
environment variable.
$ export PYTHONPATH=(NanoLabo Tool installation destination)/m3gnet:$PYTHONPATH
Setting Input File¶
In the LAMMPS input file, set the pair_style
as follows.
pair_style m3gnet
pair_coeff * * <model> <element1 element2 ...>
pair_style m3gnet/d3
pair_coeff * * <model> <element1 element2 ...>
Parameter
model
Specify the graph neural network model to be usedspecify MP-2021.2.8-EFS to use the original M3GNet + bundled pretrained modelspecify M3GNet-MP-2021.2.8-PES or M3GNet-MP-2021.2.8-DIRECT-PES to use the MatGL version M3GNet + bundled pretrained modelspecify the folder path to use the MatGL version M3GNet + model stored in that folderelement
list the element names in the same order as the atom types used in LAMMPS
Hint
The following error may appear at runtime.
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
In this case, ensure that the environment variable PYTHONHOME
is set correctly.
set PYTHONHOME=(conda installation destination)