|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": { |
| 6 | + "colab_type": "text", |
| 7 | + "id": "view-in-github" |
| 8 | + }, |
| 9 | + "source": [ |
| 10 | + "[](https://colab.research.google.com/github/stfc/janus-core/blob/main/docs/source/tutorials/cli/neb.ipynb)" |
| 11 | + ] |
| 12 | + }, |
| 13 | + { |
| 14 | + "cell_type": "markdown", |
| 15 | + "metadata": {}, |
| 16 | + "source": [ |
| 17 | + "# Command-line interface (CLI) with nudge elastic bands" |
| 18 | + ] |
| 19 | + }, |
| 20 | + { |
| 21 | + "cell_type": "markdown", |
| 22 | + "metadata": { |
| 23 | + "id": "4vcbRxmIhHLL" |
| 24 | + }, |
| 25 | + "source": [ |
| 26 | + "`janus-core` contains various machine learnt interatomic potentials (MLIPs), including MACE based models (MACE-MP, MACE-OFF), CHGNet, SevenNet and more, full list on https://github.com/stfc/janus-core.\n", |
| 27 | + "\n", |
| 28 | + "Other will be added as their utility is proven beyond a specific material." |
| 29 | + ] |
| 30 | + }, |
| 31 | + { |
| 32 | + "cell_type": "markdown", |
| 33 | + "metadata": {}, |
| 34 | + "source": [ |
| 35 | + "## Aim\n", |
| 36 | + "\n", |
| 37 | + "We showcase the use of NEB with janus and MLIPs by stuing Ethanol oxidation reactions catalyzed by water molecules, the full study was carried out in this paper Chemical Physics Letters 363 (2002) 80–86\n", |
| 38 | + "\n", |
| 39 | + "https://doi.org/10.1016/S0009-2614(02)01142-9" |
| 40 | + ] |
| 41 | + }, |
| 42 | + { |
| 43 | + "cell_type": "markdown", |
| 44 | + "metadata": {}, |
| 45 | + "source": [ |
| 46 | + "## Set up environment (optional)\n", |
| 47 | + "\n", |
| 48 | + "These steps are required for Google Colab, but may work on other systems too:" |
| 49 | + ] |
| 50 | + }, |
| 51 | + { |
| 52 | + "cell_type": "code", |
| 53 | + "execution_count": null, |
| 54 | + "metadata": { |
| 55 | + "id": "TF-EiWxyuMc7" |
| 56 | + }, |
| 57 | + "outputs": [], |
| 58 | + "source": [ |
| 59 | + "# import locale\n", |
| 60 | + "# locale.getpreferredencoding = lambda: \"UTF-8\"\n", |
| 61 | + "# !python3 -m pip install janus-core[all] data-tutorials" |
| 62 | + ] |
| 63 | + }, |
| 64 | + { |
| 65 | + "cell_type": "markdown", |
| 66 | + "metadata": {}, |
| 67 | + "source": [ |
| 68 | + "Use `data_tutorials` to get the data required for this tutorial:" |
| 69 | + ] |
| 70 | + }, |
| 71 | + { |
| 72 | + "cell_type": "code", |
| 73 | + "execution_count": null, |
| 74 | + "metadata": {}, |
| 75 | + "outputs": [], |
| 76 | + "source": [ |
| 77 | + "from data_tutorials.data import get_data\n", |
| 78 | + "\n", |
| 79 | + "get_data(\n", |
| 80 | + " url=\"https://raw.githubusercontent.com/stfc/janus-tutorials/main/data/\",\n", |
| 81 | + " filename=[\"ethanol_reactants.extxyz\", \"ethanol_products.extxyz\",\"ethanol_reactants_1water.extxyz\",\"ethanol_products_1water.extxyz\",\"ethanol_reactants_2water.extxyz\",\"ethanol_products_2water.extxyz\"],\n", |
| 82 | + " folder=\"data\",\n", |
| 83 | + ")" |
| 84 | + ] |
| 85 | + }, |
| 86 | + { |
| 87 | + "cell_type": "markdown", |
| 88 | + "metadata": {}, |
| 89 | + "source": [ |
| 90 | + "## Command-line help and options" |
| 91 | + ] |
| 92 | + }, |
| 93 | + { |
| 94 | + "cell_type": "markdown", |
| 95 | + "metadata": {}, |
| 96 | + "source": [ |
| 97 | + "Once `janus-core` is installed, the `janus` CLI command should be available:" |
| 98 | + ] |
| 99 | + }, |
| 100 | + { |
| 101 | + "cell_type": "code", |
| 102 | + "execution_count": null, |
| 103 | + "metadata": {}, |
| 104 | + "outputs": [], |
| 105 | + "source": [ |
| 106 | + "! janus neb --help" |
| 107 | + ] |
| 108 | + }, |
| 109 | + { |
| 110 | + "cell_type": "markdown", |
| 111 | + "metadata": {}, |
| 112 | + "source": [ |
| 113 | + "## run a simple Nudge Elastic Bands\n", |
| 114 | + "\n", |
| 115 | + "### 0 water molecules case" |
| 116 | + ] |
| 117 | + }, |
| 118 | + { |
| 119 | + "cell_type": "code", |
| 120 | + "execution_count": null, |
| 121 | + "metadata": {}, |
| 122 | + "outputs": [], |
| 123 | + "source": [ |
| 124 | + "%%writefile neb.yml\n", |
| 125 | + "\n", |
| 126 | + "init_struct: data/ethanol_reactants.extxyz\n", |
| 127 | + "final_struct: data/ethanol_products.extxyz\n", |
| 128 | + "n_images: 11\n", |
| 129 | + "device: cpu\n", |
| 130 | + "arch: mace_mp\n", |
| 131 | + "minimize: True\n", |
| 132 | + "plot_band: True\n", |
| 133 | + "write_band: True\n", |
| 134 | + "calc-kwargs:\n", |
| 135 | + " dispersion: True\n", |
| 136 | + " model: medium-omat-0" |
| 137 | + ] |
| 138 | + }, |
| 139 | + { |
| 140 | + "cell_type": "markdown", |
| 141 | + "metadata": {}, |
| 142 | + "source": [ |
| 143 | + "visualise the inputs" |
| 144 | + ] |
| 145 | + }, |
| 146 | + { |
| 147 | + "cell_type": "code", |
| 148 | + "execution_count": null, |
| 149 | + "metadata": {}, |
| 150 | + "outputs": [], |
| 151 | + "source": [ |
| 152 | + "from ase.io import read\n", |
| 153 | + "from weas_widget import WeasWidget\n", |
| 154 | + "\n", |
| 155 | + "r = read(\"data/ethanol_reactants.extxyz\")\n", |
| 156 | + "p = read(\"data/ethanol_products.extxyz\")\n", |
| 157 | + "\n", |
| 158 | + "v=WeasWidget()\n", |
| 159 | + "v.from_ase([r,p])\n", |
| 160 | + "v.avr.model_style = 1\n", |
| 161 | + "v.avr.show_hydrogen_bonds = True\n", |
| 162 | + "v\n" |
| 163 | + ] |
| 164 | + }, |
| 165 | + { |
| 166 | + "cell_type": "code", |
| 167 | + "execution_count": null, |
| 168 | + "metadata": {}, |
| 169 | + "outputs": [], |
| 170 | + "source": [ |
| 171 | + "!janus neb --config neb.yml" |
| 172 | + ] |
| 173 | + }, |
| 174 | + { |
| 175 | + "cell_type": "code", |
| 176 | + "execution_count": null, |
| 177 | + "metadata": {}, |
| 178 | + "outputs": [], |
| 179 | + "source": [ |
| 180 | + "!ls janus_results/" |
| 181 | + ] |
| 182 | + }, |
| 183 | + { |
| 184 | + "cell_type": "code", |
| 185 | + "execution_count": null, |
| 186 | + "metadata": {}, |
| 187 | + "outputs": [], |
| 188 | + "source": [ |
| 189 | + "from IPython.display import SVG, display\n", |
| 190 | + "display(SVG(\"janus_results/ethanol_reactants-neb-plot.svg\"))" |
| 191 | + ] |
| 192 | + }, |
| 193 | + { |
| 194 | + "cell_type": "code", |
| 195 | + "execution_count": null, |
| 196 | + "metadata": {}, |
| 197 | + "outputs": [], |
| 198 | + "source": [ |
| 199 | + "nebp = read(\"janus_results/ethanol_reactants-neb-band.extxyz\", index=\":\")\n", |
| 200 | + "\n", |
| 201 | + "w=WeasWidget()\n", |
| 202 | + "w.from_ase(nebp)\n", |
| 203 | + "w.avr.model_style = 1\n", |
| 204 | + "w.avr.show_hydrogen_bonds = True\n", |
| 205 | + "w" |
| 206 | + ] |
| 207 | + }, |
| 208 | + { |
| 209 | + "cell_type": "markdown", |
| 210 | + "metadata": {}, |
| 211 | + "source": [ |
| 212 | + "is the barrier realistic? compare with the numbers from the paper.\n", |
| 213 | + "\n", |
| 214 | + "### 1 water molecule\n", |
| 215 | + "\n", |
| 216 | + "we can use the previous config and just overwrite the init and final structures" |
| 217 | + ] |
| 218 | + }, |
| 219 | + { |
| 220 | + "cell_type": "code", |
| 221 | + "execution_count": null, |
| 222 | + "metadata": {}, |
| 223 | + "outputs": [], |
| 224 | + "source": [ |
| 225 | + "! janus neb --config neb.yml --init-struct data/ethanol_reactants_1water.extxyz --final-struct data/ethanol_products_1water.extxyz" |
| 226 | + ] |
| 227 | + }, |
| 228 | + { |
| 229 | + "cell_type": "code", |
| 230 | + "execution_count": null, |
| 231 | + "metadata": {}, |
| 232 | + "outputs": [], |
| 233 | + "source": [ |
| 234 | + "!ls janus_results/" |
| 235 | + ] |
| 236 | + }, |
| 237 | + { |
| 238 | + "cell_type": "code", |
| 239 | + "execution_count": null, |
| 240 | + "metadata": {}, |
| 241 | + "outputs": [], |
| 242 | + "source": [ |
| 243 | + "display(SVG(\"janus_results/ethanol_reactants_1water-neb-plot.svg\"))" |
| 244 | + ] |
| 245 | + }, |
| 246 | + { |
| 247 | + "cell_type": "code", |
| 248 | + "execution_count": null, |
| 249 | + "metadata": {}, |
| 250 | + "outputs": [], |
| 251 | + "source": [ |
| 252 | + "from ase.io import read\n", |
| 253 | + "from weas_widget import WeasWidget\n", |
| 254 | + "nebp = read(\"janus_results/ethanol_reactants_1water-neb-band.extxyz\", index=\":\")\n", |
| 255 | + "\n", |
| 256 | + "w1=WeasWidget()\n", |
| 257 | + "w1.from_ase(nebp)\n", |
| 258 | + "w1.avr.model_style = 1\n", |
| 259 | + "w1.avr.show_hydrogen_bonds = True\n", |
| 260 | + "w1" |
| 261 | + ] |
| 262 | + }, |
| 263 | + { |
| 264 | + "cell_type": "markdown", |
| 265 | + "metadata": {}, |
| 266 | + "source": [ |
| 267 | + "### 2 water molecules" |
| 268 | + ] |
| 269 | + }, |
| 270 | + { |
| 271 | + "cell_type": "code", |
| 272 | + "execution_count": null, |
| 273 | + "metadata": {}, |
| 274 | + "outputs": [], |
| 275 | + "source": [ |
| 276 | + "! janus neb --config neb.yml --init-struct data/ethanol_reactants_2water.extxyz --final-struct data/ethanol_products_2water.extxyz" |
| 277 | + ] |
| 278 | + }, |
| 279 | + { |
| 280 | + "cell_type": "code", |
| 281 | + "execution_count": null, |
| 282 | + "metadata": {}, |
| 283 | + "outputs": [], |
| 284 | + "source": [ |
| 285 | + "display(SVG(\"janus_results/ethanol_reactants_2water-neb-plot.svg\"))" |
| 286 | + ] |
| 287 | + }, |
| 288 | + { |
| 289 | + "cell_type": "code", |
| 290 | + "execution_count": null, |
| 291 | + "metadata": {}, |
| 292 | + "outputs": [], |
| 293 | + "source": [ |
| 294 | + "from ase.io import read\n", |
| 295 | + "from weas_widget import WeasWidget\n", |
| 296 | + "nebp = read(\"janus_results/ethanol_reactants_2water-neb-band.extxyz\", index=\":\")\n", |
| 297 | + "\n", |
| 298 | + "w2=WeasWidget()\n", |
| 299 | + "w2.from_ase(nebp)\n", |
| 300 | + "w2.avr.model_style = 1\n", |
| 301 | + "w2.avr.show_hydrogen_bonds = True\n", |
| 302 | + "w2" |
| 303 | + ] |
| 304 | + }, |
| 305 | + { |
| 306 | + "cell_type": "markdown", |
| 307 | + "metadata": {}, |
| 308 | + "source": [] |
| 309 | + }, |
| 310 | + { |
| 311 | + "cell_type": "markdown", |
| 312 | + "metadata": {}, |
| 313 | + "source": [ |
| 314 | + "### extra bits\n", |
| 315 | + "\n", |
| 316 | + "\n", |
| 317 | + "- analyse the barrier height trend.\n", |
| 318 | + "- consider redoing the same exercise with a different potential... remember if you use mace-off dispersion needs to be off.\n" |
| 319 | + ] |
| 320 | + }, |
| 321 | + { |
| 322 | + "cell_type": "markdown", |
| 323 | + "metadata": {}, |
| 324 | + "source": [] |
| 325 | + }, |
| 326 | + { |
| 327 | + "cell_type": "markdown", |
| 328 | + "metadata": {}, |
| 329 | + "source": [] |
| 330 | + } |
| 331 | + ], |
| 332 | + "metadata": { |
| 333 | + "accelerator": "GPU", |
| 334 | + "colab": { |
| 335 | + "authorship_tag": "ABX9TyNvtIsPHVgkt0NvUv51T6ZG", |
| 336 | + "gpuType": "T4", |
| 337 | + "include_colab_link": true, |
| 338 | + "private_outputs": true, |
| 339 | + "provenance": [] |
| 340 | + }, |
| 341 | + "kernelspec": { |
| 342 | + "display_name": "Python 3", |
| 343 | + "language": "python", |
| 344 | + "name": "python3" |
| 345 | + }, |
| 346 | + "language_info": { |
| 347 | + "codemirror_mode": { |
| 348 | + "name": "ipython", |
| 349 | + "version": 3 |
| 350 | + }, |
| 351 | + "file_extension": ".py", |
| 352 | + "mimetype": "text/x-python", |
| 353 | + "name": "python", |
| 354 | + "nbconvert_exporter": "python", |
| 355 | + "pygments_lexer": "ipython3", |
| 356 | + "version": "3.12.0" |
| 357 | + } |
| 358 | + }, |
| 359 | + "nbformat": 4, |
| 360 | + "nbformat_minor": 4 |
| 361 | +} |
0 commit comments