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).

  1. 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 PATHvariable, 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.

    Example: Windows, without authentication
    set HTTP_PROXY=http://host:port
    set HTTPS_PROXY=http://host:port
    Example: Linux, with authentication
    export HTTP_PROXY=http://user:pass@host:port
    export HTTPS_PROXY=http://user:pass@host:port
  2. (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.

    >>> import torch
    >>> print(torch.cuda.is_available())   # Check GPU availability
    >>> exit()                             # Exit Python environment
  3. 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 Properties ‣ Python from the mainmenuicon located in the upper left corner of the screen(or gearicon 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 the conda installation destination/bin/python .

  • To run remotely (on calculation server etc.)

    If Conda is installed in either ~/anaconda3 or ~/miniconda3, the LD_LIBRARY_PATHis automatically updated, so no additional configuration is required in this case.

    If Conda is installed in a different location, click the icon mainmenuicon located in the upper left corner, open Network ‣ SSH server, and then add the LD_LIBRARY_PATH to your job script.

    export LD_LIBRARY_PATH=(conda installation destination)/lib:$LD_LIBRARY_PATH


  • The following error may occur during runtime.

ValueError: Model does not exists

This 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

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 to libiomp5md.dll_ for example.

  • The following error may occur during runtime when DFT-D3 is enabled.

version `GOMP_5.0' not found

If you encounter this issue, set the following environment variable.

export LD_PRELOAD=(conda installation destination)/lib/
  • 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 tensors

If 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.

On Linux/macOS, it is necessary to set the environment variable LD_LIBRARY_PATH . This ensure that the program can access the Python dynamic library when executed.

$ export LD_LIBRARY_PATH=(conda installation destination)/lib:$LD_LIBRARY_PATH

Additionally, on Linux, you should set the environment variable OPAL_PREFIX .

if installed in the default location
$ export OPAL_PREFIX=/opt/AdvanceSoft/NanoLabo/exec.LINUX/mpi

Since LAMMPS accesses or 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 PYTHONPATHenvironment variable.

Linux example
$ export PYTHONPATH=(NanoLabo Tool installation destination)/m3gnet:$PYTHONPATH

In the LAMMPS input file, set the pair_style as follows.

pair_style m3gnet
pair_coeff * * <model> <element1 element2 ...>
M3GNet + DFT-D3 correction
pair_style m3gnet/d3
pair_coeff * * <model> <element1 element2 ...>



Specify the graph neural network model to be used
specify MP-2021.2.8-EFS to use the original M3GNet + bundled pretrained model
specify M3GNet-MP-2021.2.8-PES or M3GNet-MP-2021.2.8-DIRECT-PES to use the MatGL version M3GNet + bundled pretrained model
specify the folder path to use the MatGL version M3GNet + model stored in that folder


list the element names in the same order as the atom types used in LAMMPS


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.

Windows example
set PYTHONHOME=(conda installation destination)