3.7. Running DeepMD-Kit with Pharmaforge
The goal of this tutorial is to demonstrate the use of the pharmaforge package in conjunction with dftb+ and deepmd-kit to take a query from the database (see the previous example on database querying.
3.7.1. Learning Objectives
Learn hopw to use the pharmaforge package to run a deep potential on queried configurations from the database.
Learn how to use the dftb+ package to run a DFTB calculation on queried configurations from the database using pharmaforge.
Calculate the correction energy using the QDPi1 model.
3.7.2. Required Files
The tutorial python script is located in examples/CalculateMLP
The QDPi1 deepmd-kit model is located at https://gitlab.com/RutgersLBSR/qdpi, and should be downloaded into inputs.
DFTB+ should be installed (https://dftbplus.github.io/).
DFTB+ slater-Koster files must be downloaded somewhere. The path to these files should be pointed to within the run_qdpi1.py script.
3.7.3. Tutorial
First thing, make sure all the required files are in the correct location (See above) and that DFTB+ is installed.
Then, set the skf file locations as follows (or putting them into this location):
from pharmaforge.interfaces import DeepMDInterface
from pharmaforge.interfaces import DFTBInterface
skf_location="./inputs/3ob-3-1"
Now, we will first calculate the deep potential energy using the QDPi1 model, which if you recall is a deepmd-kit \(\Delta MLP\) model. The script to do this is as follows:
print("Test DeepMdKit")
test = DeepMDInterface(model="inputs/qdpi.pb")
test.ObtainDeepData("inputs/saved_model_qdpi1.hdf5")
test_energies, test_forces = test.calculate(limit=2, verbose=True)
print(test_energies)
As with the previous examples, you will see the energies and forces printed out.
Next, we will calculate the DFTB energy using the dftb+ package. The script to do this is as follows:
print("Test DFTB3")
test2 = DFTBInterface(skf_loc=skf_location, default=True)
test2.ObtainDeepData("inputs/saved_model_qdpi1.hdf5")
energies, forces = test2.calculate(limit=2, verbose=True)
print(energies)
Now, for a \(\Delta MLP\) the higher level potential energy is described by the following
So, we can calcualte the correction energy as follows:
for key in energies:
for i, ener in enumerate(energies[key]):
diff_e = test_energies[key][i] + ener
diff_f = test_forces[key][i] + forces[key][i]
print(f"Higher Level Energy for system {key} structure {i}: {diff_e}")
Note that these numbers are very similar to the numbers you found during your data_labeling tutorial!
3.7.4. Full Code
from pharmaforge.interfaces import DeepMDInterface
from pharmaforge.interfaces import DFTBInterface
skf_location="./inputs/3ob-3-1"
print("Test DeepMdKit")
test = DeepMDInterface(model="inputs/qdpi.pb")
test.ObtainDeepData("inputs/saved_model_qdpi1.hdf5")
test_energies, test_forces = test.calculate(limit=2, verbose=True)
print(test_energies)
print("Test DFTB3")
test2 = DFTBInterface(skf_loc=skf_location, default=True)
test2.ObtainDeepData("inputs/saved_model_qdpi1.hdf5")
energies, forces = test2.calculate(limit=2, verbose=True)
print(energies)
for key in energies:
for i, ener in enumerate(energies[key]):
diff_e = test_energies[key][i] + ener
diff_f = test_forces[key][i] + forces[key][i]
print(f"Higher Level Energy for system {key} structure {i}: {diff_e}")