Home / Tutorials

Tutorials

Build a training set, fit 1-RDM and 2-RDM models, then drive AIMD with the ASE calculator. Click a notebook to read it in the browser, or download the .ipynb from that page and run it locally after you install QMLearn. Talks from the QMLearn YouTube playlist are at the bottom of this page.

HDF5 databases used in the papers are not shipped with the notebooks. Generate them with the training-set notebook, or point the AIMD scripts at your own .hdf5 files.

Training

1-RDM / 2-RDM learning and training

The first notebook builds a QMLearn database: displaced geometries, a PySCF engine, and stored potentials plus RDMs. The second notebook is the unified training workflow used for the 2-RDM paper: it fits γ, δγ, Γ, Γc, and Δ models, scans KRR hyperparameters, and plots potential-energy curves against CASCI/FCI references.

Beginners Notebook Description
👉 create_training Sample geometries, run PySCF, and write an HDF5 training database.
👉 rdm_training Unified 1-RDM and 2-RDM fitting (γ, δγ, Γ, Γc, Δ), hyperparameter search, and PEC plots.

The unified trainer lives as Unify_Training_Webpage.ipynb in the examples bundle; the copy above is the website tutorial.

Dynamics

1-RDM / 2-RDM AIMD

These notebooks attach QMLCalculator to ASE and run NVE velocity-Verlet dynamics for water at 300 K (0.5 fs timestep). Production runs in the examples used 20 000 steps; the notebooks default to a short trajectory so they are interactive. Swap in your trained HDF5 path before running.

Beginners Notebook Description
👉 aimd_1rdm 1-RDM AIMD: learn δγ, then energy and forces from the predicted γ (method='gamma').
aimd_2rdm_gamma2c 2-RDM AIMD from the correlated 2-RDM Γc (method='gamma2').
aimd_2rdm_cumulant 2-RDM AIMD from δγ plus the cumulant Δ (method='gamma2cum').
Calculator

Minimal 2-RDM (Γc) calculator

Load a trained Γc model and attach it as an ASE calculator. The same pattern works for gamma and gamma2cum by changing the target, method, and kernel-ridge key.

from sklearn.kernel_ridge import KernelRidge
from qmlearn.io.model import db2qmmodel
from qmlearn.api.api4ase import QMLCalculator
from ase.build import molecule

models = {'gamma2c': KernelRidge(alpha=0.0, kernel='rbf')}
qmmodel = db2qmmodel('train.hdf5', mmodels=models,
                     target='gamma2c', method='gamma2c',
                     purify_gamma=True)

atoms = molecule('H2O')
atoms.calc = QMLCalculator(qmmodel=qmmodel, method='gamma2',
                           properties=('energy',))
print(atoms.get_potential_energy())
Examples

Production scripts

The notebooks above are the tutorial versions. The original water AIMD scripts (20 000 steps) and SLURM jobfiles are in notebooks/examples/.

On HPC, wrap the AIMD Python with your site’s job script. Keep OMP_NUM_THREADS=1 unless you have measured a benefit from threaded BLAS inside PySCF.

Talks

Video tutorials

QMLearn YouTube playlist ↗

Bhaskar Rana: Learning the Electronic Structure of Excited States via the 1-RDM Rutgers Theory Symposium · September 7, 2025
Jessica Martinez: Machine Learning the 2-RDM Rutgers Theory Symposium · September 7, 2025
Michele Pavanello: Learning functional theories of the 1- and 2-electron reduced density matrices IPAM · April 1, 2025

For the Python API behind these notebooks, see The code. For the scientific background, see the papers.