Thank you for your question.
Using M3GNet requires the installation of pytorch into QuantumATK first. There are two possibilities how to do that in QuantumATK.
Option 1: Installing pytorch in a python virtual environment (venv, see also https://docs.python.org/3/library/venv.html (https://docs.python.org/3/library/venv.html) ):
This is the safe way as it keeps pytorch separated from the QuantumATK installation.
Create a folder with enough space for the venv (we call it $MY_ENV_DIR).
Set up the venv using the python executable in the QuantumATK package:
"$QATK_DIR/atkpython/bin/python" -m venv --system-site-packages "$MY_ENV_DIR"
Activate the venv:
source "$MY_ENV_DIR/bin/activate"
Installing pytorch 2.1
python -m pip install torch==2.1.1 --index-url https://download.pytorch.org/whl/cu118
All simulations need to be run in the activated venv.
The differences to running a simulation via atkpython is:
1. Use the python executable instead of atkpython.
2. Add the line at the top of the python script you want to run.
Then M3GNet can be imported and set up like a normal calculator in QuantumATK:
from tremolox.neighborlistcalculator.M3GNetCalculator import TremoloXM3GNetDirectPESCalculator
calculator = TremoloXM3GNetDirectPESCalculator(device='cpu')
Option 2: Installing pytorch directly into the QuantumATK installation.
Although we have not encountered any compatibility issue between pytorch and the external modules in quantumatk, there is still a small risk that this can cause problems. Therefore we recommend making a separate installation of QuantumATK for this. The advantage is that the usage is more straightforward.
Install pytorch using pip:
"$QATK_DIR/atkpython/bin/python -m pip install torch==2.1.1 --index-url https://download.pytorch.org/whl/cu118
In this case scripts can directly be run via atkpython, as one is used to.
M3GNet can be imported and set up like a normal calculator in QuantumATK:
from tremolox.neighborlistcalculator.M3GNetCalculator import TremoloXM3GNetDirectPESCalculator
calculator = TremoloXM3GNetDirectPESCalculator(device='cpu')
To use GPU acceleration one can set
Note, these instructions are for Linux systems.
For Windows the steps are identical but some of the directories have to be adapted slightly, e.g. replacing bin/ with Scripts/
In case you encounter problems with disc space during installation of pytorch, we recommend to set the environment variables XDG_CACHE_HOME (for the pip cache) and TMPDIR to directories where enough disc space is available.
Hope this helps.
Dear Asif,
The M3GNet calculator does currently not support parallelization over multiple cores via MPI. Instead you could use OMP threading to parallelize over the cores.
In the job manager you can do it as shown in the attached screenshot (assuming you are running on 8 cores).
From the terminal, one would do it like this:
# Define the number of threads to use
export OMP_NUM_THREADS=8
export MKL_NUM_THREADS=8
mpiexec -n 1 atkpython my_script.py
To include vdW interactions, it is posssible to combine the M3GNet calculator with a D3-dispersion correction (in analogy to what one would in a DFT calculation for such a system). The calculator would look like this:
calculator_m3gnet = TremoloXM3GNetDirectPESCalculator(device='cpu')
calculator_d3 = TremoloXCalculator(parameters=DispersionD3Z(xc='PBE'))
calculator = CombinedCalculator([calculator_m3gnet,calculator_d3])