Skip to content

Commit 9a388fc

Browse files
authored
Add NEB CLI tutorial (#482)
* add neb cli tutorial
1 parent 6660868 commit 9a388fc

File tree

7 files changed

+445
-0
lines changed

7 files changed

+445
-0
lines changed
Lines changed: 361 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,361 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"colab_type": "text",
7+
"id": "view-in-github"
8+
},
9+
"source": [
10+
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](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+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
9
2+
Properties=species:S:1:pos:R:3:mace_mp_forces:R:3:forces:R:3 Ethanol=T initial_spacegroup units="_JSON {\"energy\": \"eV\", \"forces\": \"ev/Ang\", \"stress\": \"ev/Ang^3\"}" final_spacegroup model_path=../ml/models/mace-omat-0-medium.model arch=mace_mp mace_mp_energy=-44.96710136891945 system_name=ethanol_reactants energy=-44.96710136891945 pbc="F F F"
3+
H 2.21252233 -0.24833443 0.74736958 0.00006429 0.00001342 -0.00010172 0.00006429 0.00001342 -0.00010172
4+
C 1.60736052 0.14373518 -0.08545979 -0.00010665 -0.00020321 0.00002484 -0.00010665 -0.00020321 0.00002484
5+
H 1.78463902 1.23000029 -0.13164203 0.00007171 0.00009147 -0.00003627 0.00007171 0.00009147 -0.00003627
6+
H 1.86174463 -0.34391689 -1.02943516 0.00012753 0.00007105 0.00010169 0.00012753 0.00007105 0.00010169
7+
C 0.14958063 -0.07874383 0.25000376 -0.00013935 0.00016028 0.00006731 -0.00013935 0.00016028 0.00006731
8+
H -2.57133357 0.04440644 1.78179096 -0.00009307 0.00022931 0.00037864 -0.00009307 0.00022931 0.00037864
9+
H -0.14604684 0.40316655 1.20433475 0.00000365 -0.00010029 -0.00008260 0.00000365 -0.00010029 -0.00008260
10+
O -0.63929762 -0.70586982 -0.42066807 -0.00001297 -0.00002976 0.00000850 -0.00001297 -0.00002976 0.00000850
11+
H -2.33056910 -0.26604350 1.14200600 0.00008485 -0.00023228 -0.00036041 0.00008485 -0.00023228 -0.00036041
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
12
2+
XYZ file generated by Avogadro.
3+
C -2.38024 0.55852 0.26888
4+
C -1.68958 -0.72815 0.66580
5+
H -1.34230 0.84971 0.22717
6+
O -3.07569 1.00826 -0.57726
7+
H -3.57080 0.31220 2.17960
8+
H -0.92672 -1.15690 0.02361
9+
H -1.13392 -0.42099 1.54581
10+
H -2.45593 -1.05063 1.34149
11+
H -4.45258 1.07363 -0.01683
12+
O -4.93716 0.96200 0.82966
13+
H -5.11712 1.81389 1.18201
14+
H -4.01580 0.66329 1.68800

0 commit comments

Comments
 (0)