Open In Colab

Nudged Elastic Band

In this tutorial, we will determine the activation energies of Li diffusion along the [010] and [001] directions (referred to as paths b and c respectively) in lithium iron phosphate (LiFePO_4), a cathode material for lithium ion batteries.

DFT references energies are:

  • Barrier heights:

    • path b = 0.27 eV

    • path c = 2.5 eV

(see table 1 in https://doi.org/10.1039/C5TA05062F)

You can toggle the following to investigate different models:

[1]:
model_params = {"arch": "mace_mp", "model": "medium-0b3"}
# model_params = {"arch": "mace_mp", "model": "medium-mpa-0"}
# model_params = {"arch": "mace_mp", "model": "medium-omat-0"}
# model_params = {"arch": "chgnet"}
# model_params = {"arch": "sevennet"}

Set up environment (optional)

These steps are required for Google Colab, but may work on other systems too:

[2]:
# import locale
# locale.getpreferredencoding = lambda: "UTF-8"

# ! pip uninstall torch torchaudio torchvision transformers numpy -y
# ! uv pip install janus-core[all] data-tutorials torch==2.5.1 --system
# get_ipython().kernel.do_shutdown(restart=True)
[3]:
from weas_widget import WeasWidget
from ase.io import read
from data_tutorials.data import get_data

from janus_core.calculations.geom_opt import GeomOpt
from janus_core.calculations.neb import NEB

Use data_tutorials to get the data required for this tutorial:

[4]:
get_data(
    # url="https://raw.githubusercontent.com/stfc/janus-core/main/tests/data/",
    url="https://raw.githubusercontent.com/stfc/janus-tutorials/main/neb/data/",
    filename="LiFePO4_supercell.cif",
    folder="data",
)
try to download LiFePO4_supercell.cif from https://raw.githubusercontent.com/stfc/janus-tutorials/main/neb/data/ and save it in data/LiFePO4_supercell.cif
saved in data/LiFePO4_supercell.cif

Preparing end structures

The initial structure can be downloaded from the Materials Project (mp-19017):

[5]:
LFPO = read("data/LiFePO4_supercell.cif")
v=WeasWidget()
v.from_ase(LFPO)
v.avr.model_style = 1
v.avr.show_hydrogen_bonds = True
v
[5]:

First, we will relax the supercell:

[6]:
GeomOpt(struct=LFPO, **model_params).run()

v1=WeasWidget()
v1.from_ase(LFPO)
v1.avr.model_style = 1
v1.avr.show_hydrogen_bonds = True
v1
/home/runner/work/janus-core/janus-core/.venv/lib/python3.12/site-packages/e3nn/o3/_wigner.py:10: UserWarning: Environment variable TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD detected, since the`weights_only` argument was not explicitly passed to `torch.load`, forcing weights_only=False.
  _Jd, _W3j_flat, _W3j_indices = torch.load(os.path.join(os.path.dirname(__file__), 'constants.pt'))
cuequivariance or cuequivariance_torch is not available. Cuequivariance acceleration will be disabled.
Downloading MACE model from 'https://github.com/ACEsuit/mace-mp/releases/download/mace_mp_0b3/mace-mp-0b3-medium.model'
Cached MACE model to /home/runner/.cache/mace/macemp0b3mediummodel
Using Materials Project MACE for MACECalculator with /home/runner/.cache/mace/macemp0b3mediummodel
Using float64 for MACECalculator, which is slower but more accurate. Recommended for geometry optimization.
Using head default out of ['default']
/home/runner/work/janus-core/janus-core/.venv/lib/python3.12/site-packages/mace/calculators/mace.py:143: UserWarning: Environment variable TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD detected, since the`weights_only` argument was not explicitly passed to `torch.load`, forcing weights_only=False.
  torch.load(f=model_path, map_location=device)
       Step     Time          Energy          fmax
LBFGS:    0 16:53:50     -762.842666        0.654854
LBFGS:    1 16:53:52     -763.038742        0.437508
LBFGS:    2 16:53:54     -763.090096        0.392867
LBFGS:    3 16:53:56     -763.119488        0.374220
LBFGS:    4 16:53:58     -763.172830        0.346620
LBFGS:    5 16:53:59     -763.213488        0.334927
LBFGS:    6 16:54:01     -763.256842        0.327520
LBFGS:    7 16:54:03     -763.297792        0.328964
LBFGS:    8 16:54:05     -763.342419        0.332009
LBFGS:    9 16:54:07     -763.385108        0.328513
LBFGS:   10 16:54:09     -763.427187        0.308144
LBFGS:   11 16:54:11     -763.474267        0.274918
LBFGS:   12 16:54:12     -763.528185        0.234548
LBFGS:   13 16:54:14     -763.579927        0.246328
LBFGS:   14 16:54:16     -763.627605        0.245408
LBFGS:   15 16:54:18     -763.684752        0.231582
LBFGS:   16 16:54:20     -763.766360        0.283626
LBFGS:   17 16:54:22     -763.855346        0.296599
LBFGS:   18 16:54:23     -763.931149        0.188692
LBFGS:   19 16:54:25     -763.965778        0.154808
LBFGS:   20 16:54:27     -763.996599        0.213159
LBFGS:   21 16:54:29     -764.039520        0.255107
LBFGS:   22 16:54:31     -764.108589        0.255570
LBFGS:   23 16:54:33     -764.175608        0.200210
LBFGS:   24 16:54:34     -764.208816        0.096659
[6]:

Next, we will create the start and end structures:

[7]:
# NEB path along b and c directions have the same starting image.
# For start bc remove site 5
LFPO_start_bc = LFPO.copy()
del LFPO_start_bc[5]

# For end b remove site 11
LFPO_end_b = LFPO.copy()
del LFPO_end_b[11]

# For end c remove site 4
LFPO_end_c = LFPO.copy()
del LFPO_end_c[4]

Path b

We can now calculate the barrier height along path b.

This also includes running geometry optimization on the end points of this path.

[8]:
n_images = 7
interpolator="pymatgen" # ASE interpolation performs poorly in this case

neb_b = NEB(
    init_struct=LFPO_start_bc,
    final_struct=LFPO_end_b,
    n_images=n_images,
    interpolator=interpolator,
    minimize=True,
    fmax=0.1,
    **model_params,
)
Using Materials Project MACE for MACECalculator with /home/runner/.cache/mace/macemp0b3mediummodel
Using float64 for MACECalculator, which is slower but more accurate. Recommended for geometry optimization.
Using head default out of ['default']
/home/runner/work/janus-core/janus-core/.venv/lib/python3.12/site-packages/mace/calculators/mace.py:143: UserWarning: Environment variable TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD detected, since the`weights_only` argument was not explicitly passed to `torch.load`, forcing weights_only=False.
  torch.load(f=model_path, map_location=device)
[9]:
results = neb_b.run()
       Step     Time          Energy          fmax
LBFGS:    0 16:54:36     -758.975432        1.930990
LBFGS:    1 16:54:38     -759.140669        0.711957
LBFGS:    2 16:54:40     -759.209571        0.514600
LBFGS:    3 16:54:42     -759.298948        0.404890
LBFGS:    4 16:54:43     -759.316304        0.265548
LBFGS:    5 16:54:45     -759.336518        0.252446
LBFGS:    6 16:54:47     -759.351338        0.330410
LBFGS:    7 16:54:48     -759.368546        0.309163
LBFGS:    8 16:54:50     -759.378014        0.229741
LBFGS:    9 16:54:52     -759.386280        0.221552
LBFGS:   10 16:54:53     -759.395290        0.278156
LBFGS:   11 16:54:55     -759.404981        0.291370
LBFGS:   12 16:54:57     -759.411852        0.192426
LBFGS:   13 16:54:59     -759.415355        0.075502
       Step     Time          Energy          fmax
LBFGS:    0 16:55:00     -758.975436        1.930961
LBFGS:    1 16:55:02     -759.140671        0.711930
LBFGS:    2 16:55:04     -759.209572        0.514582
LBFGS:    3 16:55:05     -759.298949        0.404887
LBFGS:    4 16:55:07     -759.316305        0.265544
LBFGS:    5 16:55:09     -759.336519        0.252446
LBFGS:    6 16:55:11     -759.351338        0.330395
LBFGS:    7 16:55:12     -759.368546        0.309158
LBFGS:    8 16:55:14     -759.378015        0.229745
LBFGS:    9 16:55:16     -759.386281        0.221556
LBFGS:   10 16:55:17     -759.395291        0.278147
LBFGS:   11 16:55:19     -759.404982        0.291359
LBFGS:   12 16:55:21     -759.411852        0.192423
LBFGS:   13 16:55:23     -759.415355        0.075502
                   Step     Time         fmax
NEBOptimizer[ode]:    0 16:55:58       1.5090
NEBOptimizer[ode]:    1 16:56:10       1.1032
NEBOptimizer[ode]:    2 16:56:22       0.9983
NEBOptimizer[ode]:    3 16:56:34       0.8704
NEBOptimizer[ode]:    4 16:56:46       0.8013
NEBOptimizer[ode]:    5 16:56:58       0.7712
NEBOptimizer[ode]:    6 16:57:10       0.7441
NEBOptimizer[ode]:    7 16:57:22       0.6738
NEBOptimizer[ode]:    8 16:57:34       0.4346
NEBOptimizer[ode]:    9 16:57:58       0.4299
NEBOptimizer[ode]:   10 16:58:10       0.4226
NEBOptimizer[ode]:   11 16:58:22       0.3946
NEBOptimizer[ode]:   12 16:58:34       0.2843
NEBOptimizer[ode]:   13 16:58:58       0.2726
NEBOptimizer[ode]:   14 16:59:10       0.2652
NEBOptimizer[ode]:   15 16:59:22       0.2612
NEBOptimizer[ode]:   16 16:59:35       0.2552
NEBOptimizer[ode]:   17 16:59:47       0.2323
NEBOptimizer[ode]:   18 17:00:11       0.2219
NEBOptimizer[ode]:   19 17:00:23       0.2141
NEBOptimizer[ode]:   20 17:00:35       0.2087
NEBOptimizer[ode]:   21 17:00:47       0.2055
NEBOptimizer[ode]:   22 17:00:59       0.2005
NEBOptimizer[ode]:   23 17:01:11       0.1809
NEBOptimizer[ode]:   24 17:01:35       0.1729
NEBOptimizer[ode]:   25 17:01:47       0.1664
NEBOptimizer[ode]:   26 17:01:59       0.1624
NEBOptimizer[ode]:   27 17:02:11       0.1598
NEBOptimizer[ode]:   28 17:02:23       0.1559
NEBOptimizer[ode]:   29 17:02:35       0.1409
NEBOptimizer[ode]:   30 17:02:46       0.2612
NEBOptimizer[ode]:   31 17:03:10       0.0826

The results include the barrier (without any interpolation between highest images) and maximum force at the point in the simulation

[10]:
print(results)
{'barrier': 0.28471736968049277, 'delta_E': -1.6499620869581122e-07, 'max_force': 0.09009922955812238}

We can also plot the band:

[11]:
fig = neb_b.nebtools.plot_band()
v1=WeasWidget()
v1.from_ase(neb_b.nebtools.images)
v1.avr.model_style = 1
v1.avr.show_hydrogen_bonds = True
v1

[11]:
../../_images/tutorials_python_neb_24_1.png

Path c

We can calculate the barrier height along path c similarly

[12]:
n_images = 7
interpolator="pymatgen"

neb_c = NEB(
    init_struct=LFPO_start_bc,
    final_struct=LFPO_end_c,
    n_images=n_images,
    interpolator=interpolator,
    minimize=True,
    fmax=0.1,
    **model_params,
)
Using Materials Project MACE for MACECalculator with /home/runner/.cache/mace/macemp0b3mediummodel
Using float64 for MACECalculator, which is slower but more accurate. Recommended for geometry optimization.
Using head default out of ['default']
/home/runner/work/janus-core/janus-core/.venv/lib/python3.12/site-packages/mace/calculators/mace.py:143: UserWarning: Environment variable TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD detected, since the`weights_only` argument was not explicitly passed to `torch.load`, forcing weights_only=False.
  torch.load(f=model_path, map_location=device)
[13]:
results = neb_c.run()
       Step     Time          Energy          fmax
LBFGS:    0 17:03:16     -759.415355        0.075502
       Step     Time          Energy          fmax
LBFGS:    0 17:03:18     -758.975431        1.930990
LBFGS:    1 17:03:19     -759.140669        0.711958
LBFGS:    2 17:03:21     -759.209571        0.514601
LBFGS:    3 17:03:23     -759.298948        0.404890
LBFGS:    4 17:03:25     -759.316304        0.265548
LBFGS:    5 17:03:26     -759.336518        0.252446
LBFGS:    6 17:03:28     -759.351338        0.330410
LBFGS:    7 17:03:30     -759.368546        0.309163
LBFGS:    8 17:03:31     -759.378014        0.229741
LBFGS:    9 17:03:33     -759.386280        0.221553
LBFGS:   10 17:03:35     -759.395290        0.278156
LBFGS:   11 17:03:36     -759.404981        0.291370
LBFGS:   12 17:03:38     -759.411852        0.192426
LBFGS:   13 17:03:40     -759.415355        0.075502
                   Step     Time         fmax
NEBOptimizer[ode]:    0 17:04:15       2.3204
NEBOptimizer[ode]:    1 17:04:27       1.6499
NEBOptimizer[ode]:    2 17:04:38       0.9977
NEBOptimizer[ode]:    3 17:04:50       0.6537
NEBOptimizer[ode]:    4 17:05:14       0.4186
NEBOptimizer[ode]:    5 17:05:25       0.3969
NEBOptimizer[ode]:    6 17:05:37       0.3176
NEBOptimizer[ode]:    7 17:06:01       0.2998
NEBOptimizer[ode]:    8 17:06:25       0.2690
NEBOptimizer[ode]:    9 17:06:37       0.2608
NEBOptimizer[ode]:   10 17:06:49       0.2293
NEBOptimizer[ode]:   11 17:07:12       0.2186
NEBOptimizer[ode]:   12 17:07:24       0.2622
NEBOptimizer[ode]:   13 17:07:36       0.2009
NEBOptimizer[ode]:   14 17:07:48       0.1946
NEBOptimizer[ode]:   15 17:08:00       0.1883
NEBOptimizer[ode]:   16 17:08:12       0.1653
NEBOptimizer[ode]:   17 17:08:36       0.1600
NEBOptimizer[ode]:   18 17:08:48       0.1538
NEBOptimizer[ode]:   19 17:09:00       0.1475
NEBOptimizer[ode]:   20 17:09:13       0.1379
NEBOptimizer[ode]:   21 17:09:25       0.1346
NEBOptimizer[ode]:   22 17:09:37       0.1288
NEBOptimizer[ode]:   23 17:09:49       0.1263
NEBOptimizer[ode]:   24 17:10:01       0.1169
NEBOptimizer[ode]:   25 17:10:13       0.1806
NEBOptimizer[ode]:   26 17:10:37       0.0821
[14]:
print(results)
{'barrier': 1.7875754406807047, 'delta_E': 4.249613994034007e-09, 'max_force': 0.09762768246406749}
[15]:
fig = neb_c.nebtools.plot_band()
v2=WeasWidget()
v2.from_ase(neb_c.nebtools.images)
v2.avr.model_style = 1
v2.avr.show_hydrogen_bonds = True
v2
[15]:
../../_images/tutorials_python_neb_30_1.png