-
Notifications
You must be signed in to change notification settings - Fork 648
[Q&A] Hybrid DeepMD–Classical Force Field NVT Simulation in CP2K #5505
Question
Is it possible to perform an NVT simulation in CP2K for a hybrid metallic–organic system, where a DeepMD potential is used for the inorganic component and a classical force field is applied to the organic component?
DeePMD-kit Version
DeePMD-kit v3.1.3
Backend and its version
TensorFlow 2.19.1
Python Version, CUDA Version, GCC Version, LAMMPS Version, etc
Python 3.12.13
CUDA toolkit (nvcc) 12.0.140
CUDA 12.8
CP2K 2024.3
Details
No response
Reproducible Example, Input Files, and Commands
No response
Further Information, Files, and Links
No response
All reactions
Replies: 6 comments 6 replies
Hi @drpriyadey,
Yes, this is completely possible in CP2K, but it requires configuring the simulation engine under a Mixed Force-Field (QM/MM style) framework. Instead of treating DeePMD as a global potential, you partition the system so that CP2K evaluates the organic component using its internal classical MM mechanics, while routing the inorganic/metallic atomic coordinates to DeePMD-kit via an external calculator hook.
Here is how to map this out in your CP2K input script (.inp):
- Define the Mixed Force Evaluation Structure
You must instruct CP2K to initialize a MIXED force environment. This tells the core coordinator to combine different calculation blocks for the total energy and forces:
Fortran
&FORCE_EVAL
METHOD Mixed
&MIXED
MIXING_TYPE Linear
&LINEAR
# Combines forces additively across the defined subsystems
V_NAME Force_Metal, Force_Organic
WEIGHT 1.0, 1.0
&END LINEAR
&END MIXED
&END FORCE_EVAL
- Bind the Inorganic Metallic Subsystem to DeePMD-kit
Create your first distinct FORCE_EVAL block tracking your inorganic component. You will use EXTERNAL_POTENTIAL to pass your exported TensorFlow graph (.pb file) to the DeepMD C++ API interface embedded in your CP2K build:
Fortran
&FORCE_EVAL
METHOD FIST
SUBsys_NAME Force_Metal
&MM
&FORCEFIELD
&EXTERNAL_POTENTIAL
FUNCTION_TYPE DEEPMD
MODEL_FILE_NAME ./graph.pb
# Explicitly list the atom types assigned to the Deep Potential
ATOM_MAP_NAME Mo, S
&END EXTERNAL_POTENTIAL
&END FORCEFIELD
&END MM
&SUBSYS
# Include coordinate definitions tracking only the inorganic subset
&CELL
ABC 25.0 25.0 25.0
&END CELL
&TOPOLOGY
COORD_FILE_NAME metal_slice.xyz
COORDINATE XYZ
&END TOPOLOGY
&END SUBSYS
&END FORCE_EVAL
- Bind the Organic Subsystem to your Classical Force Field
Create your second FORCE_EVAL block using standard FIST mechanics to evaluate your classical force parameters (e.g., AMBER, CHARMM, or OPLS-AA) for the organic component:
Fortran
&FORCE_EVAL
METHOD FIST
SUBsys_NAME Force_Organic
&MM
&FORCEFIELD
PARM_FILE_NAME organic_forcefield.parm
PARMTYPE AMBER
&END FORCEFIELD
&POISSON
&EWALD
EWALD_TYPE SPME
&END EWALD
&POISSON
&END MM
&SUBSYS
&CELL
ABC 25.0 25.0 25.0
&END CELL
&TOPOLOGY
COORD_FILE_NAME organic_slice.xyz
COORDINATE XYZ
&END TOPOLOGY
&END SUBSYS
&END FORCE_EVAL
- Configure the NVT Ensemble Integration Loop
Finally, your main MOTION block handles the execution matrix. For a hybrid system, a stochastic velocity rescaling thermostat (CSVR) is highly recommended to prevent temperature spikes or artificial energy transfer across the hybrid boundary:
Fortran
&MOTION
&MD
ENSEMBLE NVT
STEPS 50000
TIMESTEP [fs] 0.5
TEMPERATURE [K] 300.0
&THERMOSTAT
TYPE CSVR
&CSVR
TIMECON [fs] 10.0
&END CSVR
&END THERMOSTAT
&MD
&END MOTION
Ensure that your CP2K executable was compiled with the flags matching your libdeepmd_c.so library linking, or you will throw an unrecognized keyword error when initializing the DEEPMD block type.
All reactions
Thank you so much @Tobi-Adesoye san. I will try the procedure.
All reactions
All reactions
Dear @Tobi-Adesoye ,
When i am running the above script with the suitable structure and parameter files, i am getting the "unknown keyword" error from cp2k for some of the lines. Is there anything I am missing? Thank you for your help.
All reactions
Dear @Tobi-Adesoye
After i am trying to correct the input file, I have the following error:
DBCSR| CPU Multiplication driver XSMM (U)
DBCSR| Multrec recursion limit 512 (U)
DBCSR| Multiplication stack size 1000 (D)
DBCSR| Maximum elements for images UNLIMITED (U)
DBCSR| Multiplicative factor virtual images 1 (U)
DBCSR| Use multiplication densification T (D)
DBCSR| Multiplication size stacks 3 (U)
DBCSR| Use memory pool for CPU allocation F (U)
DBCSR| Number of 3D layers SINGLE (U)
DBCSR| Use MPI memory allocation F (U)
DBCSR| Use RMA algorithm F (U)
DBCSR| Use Communication thread T (U)
DBCSR| Communication thread load 87 (D)
DBCSR| MPI: My process id 0
DBCSR| MPI: Number of processes 1
DBCSR| OMP: Current number of threads 1
DBCSR| OMP: Max number of threads 1
DBCSR| Split modifier for TAS multiplication algorithm 1.0E+00 (U)
**** **** ****** ** PROGRAM STARTED AT 2026年06月22日 18:05:18.760
***** ** *** *** ** PROGRAM STARTED ON priya-dey
** **** ****** PROGRAM STARTED BY priya-dey
***** ** ** ** ** PROGRAM PROCESS ID 88936
**** ** ******* ** PROGRAM STARTED IN /home/priya-dey/Project-ML/bt3
CP2K| version string: CP2K version 2024.3
CP2K| source code revision number: git:6712648
CP2K| cp2kflags: omp libint fftw3 libxc libgrpp pexsi elpa parallel scalapack m
CP2K| pi_f08 cosma quip deepmd xsmm plumed2 spglib sirius libvori li
CP2K| ibbqb libtorch libvdwxc hdf5
CP2K| is freely available from https://www.cp2k.org/
CP2K| Program compiled at Tue Apr 7 01:57:03 AM JST 2026
CP2K| Program compiled on priya-dey
CP2K| Program compiled for local
CP2K| Data directory path /home/priya-dey/cp2k/data
CP2K| Input file name tobi.inp
- ___ *
- / \ *
- [ABORT] *
- ___/ CPASSERT failed *
- | *
- O/| *
- /| | *
- / \ force_env_types.F:730 *
===== Routine Calling Stack =====
1 CP2K
All reactions
All reactions
Dear @Tobi-Adesoye
The input is following:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!instruct CP2K to initialize a MIXED force environment
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
&FORCE_EVAL
METHOD Mixed
&MIXED
MIXING_TYPE LINEAR_COMBINATION
&LINEAR
!# Combines forces additively across the defined subsystems
LAMBDA 0.5
&END LINEAR
&END MIXED
&END FORCE_EVAL
!!Bind the Inorganic Metallic Subsystem to DeePMD-kit
&FORCE_EVAL
METHOD FIST
&MM
&FORCEFIELD
&NONBONDED
&DEEPMD
ATOMS C CU N S
ATOMS_DEEPMD_TYPE 0 1 2 3
POT_FILE_NAME graph.pb
&END DEEPMD
&END NONBONDED
&END FORCEFIELD
&END MM
&SUBSYS
&CELL
A 18.8886360910 0 0
B 0 19.7198589339 0
C 0 0 55.0091418766
PERIODIC XY
&END CELL
&TOPOLOGY
COORD_FILE_NAME structure_new.xyz
COORD_FILE_FORMAT XYZ
&END TOPOLOGY
&KIND C
ELEMENT C
&END KIND
&KIND Cu
ELEMENT Cu
&END KIND
&KIND N
ELEMENT N
&END KIND
&KIND S
ELEMENT S
&END KIND
&END SUBSYS
&END FORCE_EVAL
#Bind the Organic Subsystem to your Classical Force Field
&FORCE_EVAL
METHOD FIST
#SUBsys_NAME Force_Organic
&MM
&FORCEFIELD
PARM_FILE_NAME y6.prmtop
PARMTYPE AMBER
&END FORCEFIELD
&POISSON
&EWALD
EWALD_TYPE SPME
&END EWALD
&END POISSON
&END MM
&SUBSYS
&CELL
ABC 25.0 25.0 25.0
&END CELL
&TOPOLOGY
COORD_FILE_NAME y6_core.xyz
COORD_FILE_FORMAT XYZ
&END TOPOLOGY
&END SUBSYS
&END FORCE_EVAL
#Configure the NVT Ensemble Integration Loop
&MOTION
&MD
ENSEMBLE NVT
STEPS 50000
TIMESTEP [fs] 0.5
TEMPERATURE [K] 300.0
&THERMOSTAT
TYPE CSVR
&CSVR
TIMECON 1000.0
&END CSVR
&END THERMOSTAT
&END MD
&END MOTION
All reactions
Dear @Tobi-Adesoye ,
Can you help me understand, what do you mean by "the required coupling
mechanism is explicitly supported by your CP2K version and build
configuration"?
All reactions
All reactions
Dear @Tobi-Adesoye
Thank you for replying. I am using the following version of software:
- CP2K version 2024.3
- DeePMD-kit v3.1.3
the compiler flag:
2026年06月24日 14:58:04.983380: I tensorflow/core/util/port.cc:111] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable TF_ENABLE_ONEDNN_OPTS=0.
2026年06月24日 14:58:05.001677: E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:9342] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
2026年06月24日 14:58:05.001701: E tensorflow/compiler/xla/stream_executor/cuda/cuda_fft.cc:609] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
2026年06月24日 14:58:05.001729: E tensorflow/compiler/xla/stream_executor/cuda/cuda_blas.cc:1518] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
DeePMD-kit: Successfully load libcudart.so.11.0
CP2K version 2024.3
Source code revision git:6712648
cp2kflags: omp libint fftw3 libxc libgrpp pexsi elpa parallel scalapack mpi_f08 cosma quip deepmd xsmm plumed2 spglib sirius libvori libbqb libtorch libvdwxc hdf5
compiler: GCC version 13.3.0
All reactions
All reactions
Dear @Tobi-Adesoye,
Thank you so much for the explanation. Can you recommend any tutorial or article for using the external coupling (ASE / Python driver / LAMMPS + DeePMD plugin).
Also, can you explain more about re-training a unified deepmd pot that absorbs the classical effect.