Integrate Lammps with MLIPs

Hey guys,

I’m writing my bachelors thesis about integrating multiple machine-learning interatomic potentials into Lammps.

I’ve checked the ML-IAP package, but they seem to only allow the custom definition of a pairwise potential. All python SOTA machine learning models take in the entire atomic graph and outputs all the forces at once.

What is my best angle here? Should I write my own package? Have I overlooked something?

I have looked thoroughly through all packages but haven’t found an example that seems to match.

Thanks in advance for the helpful answers!

I think you should take a step back and learn a bit about how LAMMPS is parallelized using domain decomposition and how it is linear scaling with system size through using neighbor lists.

Understanding that should make you realize that feeding the entire system data is impractical and conflicting with achieving any level of efficient parallel performance.

I am not at all an expert of machine learning potentials, but I thought the “unified” flag for pair style mliap should allow you to load python objects for machine learning potentials. I know from user posts here in the forum that the MACE package can be used like this: MACE in LAMMPS with ML-IAP — mace 0.3.13 documentation

Hey that looks very helpful!
Thanks so much and have a good day

In LAMMPS, “pair” styles like ML-IAP are actually not limited to only pairwise interactions. Many of the ML-XXX packages in LAMMPS are abusing this and implement 3-,4-,5-bodies interactions and more as a “pair” style. ML-PACE implements ACE which can go to arbitrarily high body order, ML-QUIP provides an interface to GAP which is 3 bodies, ML-SNAP is a version of the bispectrum which is 4-bodies, etc.


For integrating multiple MLIPs with LAMMPS, you might also be interested in our project, metatomic!

It has similar goals to ML-IAP in unified model, with the two main differences being (a) that we don’t need to have a Python interpreter around to execute user-defined models — we currently rely on TorchScript for this instead; and (b) that the interface is not specific to LAMMPS and can also be used with other simulation engines.

The interface to LAMMPS currently lives in a fork, but we hope to be able to merge with mainstream LAMMPS one day!

This is like exactly what I needed, what the hell? xD
Let me see if I can get it to run Jax models…
Thank you for the work and recommendation, very helpful!

As I mentioned, metatomic is currently built on top of TorchScript, so you will not be able to use it with JAX. This is something we’d like to add soon though, and we are figuring out what’s the best path forward here. Feel free to send me an email if you want to discuss it in more details, although the timeline for our implementation might not match with a Bachelor thesis.

1 Like
1 Like

As @Luthaf said this is not correct. ML-IAP supports many-body potentials, not just pairwise.

1 Like

So I’ve installed the “LAMMPS 64-bit 22Jul2025 with Python” version of Lammp for Windows.

When I run

C:\Users\strun\AppData\Local\LAMMPS 64-bit 22Jul2025 with Python\Examples\mliap>python mliap_pytorch_ACE.py

I’m seeing this stupid error:

Traceback (most recent call last):
  File "C:\Users\strun\AppData\Local\LAMMPS 64-bit 22Jul2025 with Python\Python\lammps\mliap\loader.py", line 65, in activate_mliappy
    loader = DynamicLoader(module_name,library,api_version)
  File "C:\Users\strun\AppData\Local\LAMMPS 64-bit 22Jul2025 with Python\Python\lammps\mliap\loader.py", line 34, in __init__
    initfunc = getattr(library,attr)
  File "C:\Python313\Lib\ctypes\__init__.py", line 403, in __getattr__
    func = self.__getitem__(name)
  File "C:\Python313\Lib\ctypes\__init__.py", line 408, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'PyInit_mliap_model_python_couple' not found

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\strun\AppData\Local\LAMMPS 64-bit 22Jul2025 with Python\Examples\mliap\mliap_pytorch_ACE.py", line 73, in <module>
    lammps.mliap.activate_mliappy(lmp)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
  File "C:\Users\strun\AppData\Local\LAMMPS 64-bit 22Jul2025 with Python\Python\lammps\mliap\loader.py", line 73, in activate_mliappy
    raise ImportError("Could not load ML-IAP python coupling module.") from ee
ImportError: Could not load ML-IAP python coupling module.
Total wall time: 0:00:00

When I run lmp -h I am seeing:

Installed packages:

AMOEBA ASPHERE ATC AWPMD BOCS BODY BPM BROWNIAN CG-DNA CG-SPICA CLASS2 COLLOID
COLVARS COMPRESS CORESHELL DIELECTRIC DIFFRACTION DIPOLE DPD-BASIC DPD-MESO
DPD-REACT DPD-SMOOTH DRUDE EFF ELECTRODE EXTRA-COMMAND EXTRA-COMPUTE
EXTRA-DUMP EXTRA-FIX EXTRA-MOLECULE EXTRA-PAIR FEP GPU GRANULAR INTERLAYER
KOKKOS KSPACE LEPTON MACHDYN MANIFOLD MANYBODY MC MDI MEAM MESONT MGPT MISC
**ML-HDNNP ML-IAP ML-POD ML-RANN ML-SNAP ML-UF3** MOFFF MOLECULE MOLFILE OPENMP
OPT ORIENT PERI PHONON PLUGIN POEMS PTM PYTHON QEQ QTB REACTION REAXFF REPLICA
RHEO RIGID SHOCK SMTBQ SPH SPIN SRD TALLY UEF VORONOI YAFF

where lmp outputs C:\Users\strun\AppData\Local\LAMMPS 64-bit 22Jul2025 with Python\bin\lmp.exe

I’ve also tried various complete restarts.

I know it’s missing this, but I don’t know how I can compile and provide that to it.

I’ve tried setting system and user environment variables.
I’ve been trying to build lammps on Windows and Linux with the ML-IAP package installed but that is apparently too hard for me after trying for ~5 hours?
I’ve tried using different python versions (3.10, 3.12, 3.13) to run the example script, but the issue persists.

Can anyone help me?
I wouldn’t ask if I hadn’t thoroughly failed.
Big thanks in advance.

To get help here, you will need to ask specific questions, “help me” won’t do.

What you are asking here is more like somebody tutoring you. Since people here volunteer their time, nobody will have time for that. Please note, that to get the kind of help you are currently asking for, you will be best off to find somebody local. You won’t need necessarily somebody with experience in compiling and installing LAMMPS, but somebody with general experience in that area and that should be quite easier than finding somebody with specific LAMMPS experience. LAMMPS has a decent documentation, so anybody with some experience in compiling and installing scientific software should be able to handle it.

Beyond that, for any details about the mliappy unified model setup, you probably need to contact the folks at Los Alamos that contributed it.

LAMMPS is very much a community project, so there is not a single person that knows “everything”.

1 Like