Skip to content

Commit 89a88ab

Browse files
Fix CLI tutorials for Colab (#492)
1 parent 668bf65 commit 89a88ab

File tree

5 files changed

+82
-71
lines changed

5 files changed

+82
-71
lines changed

docs/source/tutorials/cli/geomopt.ipynb

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838
"source": [
3939
"# import locale\n",
4040
"# locale.getpreferredencoding = lambda: \"UTF-8\"\n",
41-
"# !python3 -m pip install janus-core[all] data-tutorials"
41+
"\n",
42+
"# ! pip uninstall torch torchaudio torchvision numpy -y\n",
43+
"# ! uv pip install janus-core[all] data-tutorials torch==2.5.1 --system\n",
44+
"# get_ipython().kernel.do_shutdown(restart=True)"
4245
]
4346
},
4447
{
@@ -84,10 +87,14 @@
8487
"metadata": {},
8588
"outputs": [],
8689
"source": [
90+
"from pathlib import Path\n",
91+
"\n",
8792
"from ase.build import bulk\n",
8893
"from ase.io import write\n",
8994
"from weas_widget import WeasWidget\n",
9095
"\n",
96+
"Path(\"data\").mkdir(exist_ok=True)\n",
97+
"\n",
9198
"NaCl = bulk(\"NaCl\", \"rocksalt\", a=5.63, cubic=True)\n",
9299
"NaCl[0].position = [1.5, 1.5, 1.5]\n",
93100
"\n",
@@ -375,7 +382,7 @@
375382
"<div class=\"alert alert-block alert-info\">\n",
376383
"<b>Tip:</b> This is equivalent to:\n",
377384
"\n",
378-
"--struct data/NaCl-deformed.xyz --opt-cell-fully --filter-func ExpCellFilter --minimize-kwargs \"{'filter_kwargs': {'constant_volume' : True} --no-tracker\n",
385+
"--struct data/NaCl-deformed.xyz --opt-cell-fully --filter-func ExpCellFilter --minimize-kwargs \"{'filter_kwargs': {'constant_volume' : True}\" --no-tracker\n",
379386
"</div>\n"
380387
]
381388
},
@@ -494,33 +501,14 @@
494501
"tracker: False"
495502
]
496503
},
497-
{
498-
"cell_type": "code",
499-
"execution_count": null,
500-
"metadata": {},
501-
"outputs": [],
502-
"source": [
503-
"%%writefile geomopt_config_sevennet.yml\n",
504-
"\n",
505-
"struct: data/NaCl-deformed.xyz\n",
506-
"arch: sevennet\n",
507-
"opt_cell_fully: True\n",
508-
"minimize_kwargs:\n",
509-
" filter_kwargs:\n",
510-
" constant_volume: True\n",
511-
"pressure: 10\n",
512-
"file_prefix: janus_results/NaCl-sevennet\n",
513-
"tracker: False"
514-
]
515-
},
516504
{
517505
"cell_type": "code",
518506
"execution_count": null,
519507
"metadata": {},
520508
"outputs": [],
521509
"source": [
522510
"! janus geomopt --config geomopt_config_mace.yml\n",
523-
"! janus geomopt --config geomopt_config_sevennet.yml"
511+
"! janus geomopt --config geomopt_config_mace.yml --arch sevennet --file-prefix janus_results/NaCl-sevennet"
524512
]
525513
},
526514
{

docs/source/tutorials/cli/md.ipynb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838
"source": [
3939
"# import locale\n",
4040
"# locale.getpreferredencoding = lambda: \"UTF-8\"\n",
41-
"# !python3 -m pip install janus-core[all] data-tutorials"
41+
"\n",
42+
"# ! pip uninstall torch torchaudio torchvision numpy -y\n",
43+
"# ! uv pip install janus-core[all] data-tutorials torch==2.5.1 --system\n",
44+
"# get_ipython().kernel.do_shutdown(restart=True)"
4245
]
4346
},
4447
{
@@ -121,6 +124,8 @@
121124
"traj_every: 10\n",
122125
"restart_every: 50\n",
123126
"\n",
127+
"tracker: False\n",
128+
"\n",
124129
"# If you have an Nvidia GPU.\n",
125130
"#device: cuda"
126131
]
@@ -373,6 +378,8 @@
373378
" a_kwargs: {'components': ['xy', 'yz', 'zx']}\n",
374379
" points: 250\n",
375380
"\n",
381+
"tracker: False\n",
382+
"\n",
376383
"# If you have an Nvidia GPU.\n",
377384
"#device: cuda"
378385
]
@@ -491,6 +498,8 @@
491498
"stats_every: 10\n",
492499
"traj_every: 10\n",
493500
"\n",
501+
"tracker: False\n",
502+
"\n",
494503
"# If you have an Nvidia GPU.\n",
495504
"#device: cuda"
496505
]
@@ -543,11 +552,6 @@
543552
"\n",
544553
"Experimentally NaCl melts at about 1074 Kelvin at atmospheric pressure."
545554
]
546-
},
547-
{
548-
"cell_type": "markdown",
549-
"metadata": {},
550-
"source": []
551555
}
552556
],
553557
"metadata": {

docs/source/tutorials/cli/neb.ipynb

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@
5858
"source": [
5959
"# import locale\n",
6060
"# locale.getpreferredencoding = lambda: \"UTF-8\"\n",
61-
"# !python3 -m pip install janus-core[all] data-tutorials"
61+
"\n",
62+
"# ! pip uninstall torch torchaudio torchvision numpy -y\n",
63+
"# ! uv pip install janus-core[all] data-tutorials torch==2.5.1 --system\n",
64+
"# get_ipython().kernel.do_shutdown(restart=True)"
6265
]
6366
},
6467
{
@@ -77,7 +80,7 @@
7780
"from data_tutorials.data import get_data\n",
7881
"\n",
7982
"get_data(\n",
80-
" url=\"https://raw.githubusercontent.com/stfc/janus-tutorials/main/data/\",\n",
83+
" url=\"https://raw.githubusercontent.com/stfc/janus-core/main/docs/source/tutorials/data/\",\n",
8184
" filename=[\"ethanol_reactants.extxyz\", \"ethanol_products.extxyz\",\"ethanol_reactants_1water.extxyz\",\"ethanol_products_1water.extxyz\",\"ethanol_reactants_2water.extxyz\",\"ethanol_products_2water.extxyz\"],\n",
8285
" folder=\"data\",\n",
8386
")"
@@ -131,9 +134,10 @@
131134
"minimize: True\n",
132135
"plot_band: True\n",
133136
"write_band: True\n",
134-
"calc-kwargs:\n",
137+
"calc_kwargs:\n",
135138
" dispersion: True\n",
136-
" model: medium-omat-0"
139+
" model: medium-omat-0\n",
140+
"tracker: False"
137141
]
138142
},
139143
{
@@ -302,11 +306,6 @@
302306
"w2"
303307
]
304308
},
305-
{
306-
"cell_type": "markdown",
307-
"metadata": {},
308-
"source": []
309-
},
310309
{
311310
"cell_type": "markdown",
312311
"metadata": {},
@@ -317,16 +316,6 @@
317316
"- analyse the barrier height trend.\n",
318317
"- consider redoing the same exercise with a different potential... remember if you use mace-off dispersion needs to be off.\n"
319318
]
320-
},
321-
{
322-
"cell_type": "markdown",
323-
"metadata": {},
324-
"source": []
325-
},
326-
{
327-
"cell_type": "markdown",
328-
"metadata": {},
329-
"source": []
330319
}
331320
],
332321
"metadata": {

docs/source/tutorials/cli/phonons.ipynb

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
4545
"source": [
4646
"# import locale\n",
4747
"# locale.getpreferredencoding = lambda: \"UTF-8\"\n",
48-
"# !python3 -m pip install janus-core[all] data-tutorials"
48+
"\n",
49+
"# ! pip uninstall torch torchaudio torchvision numpy -y\n",
50+
"# ! uv pip install janus-core[all] data-tutorials torch==2.5.1 --system\n",
51+
"# get_ipython().kernel.do_shutdown(restart=True)"
4952
]
5053
},
5154
{
@@ -153,7 +156,7 @@
153156
"calc-kwargs:\n",
154157
" model: medium-mpa-0\n",
155158
"device: cpu\n",
156-
"\n"
159+
"tracker: False"
157160
]
158161
},
159162
{
@@ -243,7 +246,7 @@
243246
" skin: 0 \n",
244247
" model: medium-mpa-0\n",
245248
"device: cpu\n",
246-
"\n"
249+
"tracker: False"
247250
]
248251
},
249252
{
@@ -316,7 +319,7 @@
316319
" skin: 0 \n",
317320
" model: medium-mpa-0\n",
318321
"device: cpu\n",
319-
"\n"
322+
"tracker: False"
320323
]
321324
},
322325
{
@@ -380,7 +383,7 @@
380383
" skin: 0 \n",
381384
" model: medium-mpa-0\n",
382385
"device: cpu\n",
383-
"\n"
386+
"tracker: False"
384387
]
385388
},
386389
{
@@ -419,7 +422,7 @@
419422
"outputs": [],
420423
"source": [
421424
"get_data(\n",
422-
" url=\"https://raw.githubusercontent.com/stfc/janus-tutorials/main/data/\",\n",
425+
" url=\"https://raw.githubusercontent.com/stfc/janus-core/main/docs/source/tutorials/data/\",\n",
423426
" filename=[\"mof-5.cif\",\"paths.yaml\"],\n",
424427
" folder=\"data\",\n",
425428
")"
@@ -431,7 +434,6 @@
431434
"metadata": {},
432435
"outputs": [],
433436
"source": [
434-
"\n",
435437
"mof5 = read(\"data/mof-5.cif\")\n",
436438
"v=WeasWidget()\n",
437439
"v.from_ase(mof5)\n",
@@ -471,7 +473,7 @@
471473
" skin: 0 \n",
472474
" model: medium-mpa-0\n",
473475
"device: cpu\n",
474-
"\n"
476+
"tracker: False"
475477
]
476478
},
477479
{
@@ -506,7 +508,7 @@
506508
"outputs": [],
507509
"source": [
508510
"from IPython.display import SVG, display\n",
509-
"display(SVG(\"janus_results/mof-5-bs-dos.svg\"))\n"
511+
"display(SVG(\"janus_results/mof-5-bs-dos.svg\"))"
510512
]
511513
},
512514
{
@@ -542,7 +544,7 @@
542544
" skin: 0 \n",
543545
" model: medium-mpa-0\n",
544546
"device: cpu\n",
545-
"\n"
547+
"tracker: False"
546548
]
547549
},
548550
{
@@ -569,7 +571,7 @@
569571
"metadata": {},
570572
"outputs": [],
571573
"source": [
572-
"display(SVG(\"janus_results/mof-5-bs-dos.svg\"))\n"
574+
"display(SVG(\"janus_results/mof-5-bs-dos.svg\"))"
573575
]
574576
},
575577
{
@@ -584,11 +586,6 @@
584586
"\n",
585587
"this is part of this paper if you want to know more: https://arxiv.org/abs/2412.02877"
586588
]
587-
},
588-
{
589-
"cell_type": "markdown",
590-
"metadata": {},
591-
"source": []
592589
}
593590
],
594591
"metadata": {

docs/source/tutorials/cli/singlepoint.ipynb

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@
4747
"source": [
4848
"# import locale\n",
4949
"# locale.getpreferredencoding = lambda: \"UTF-8\"\n",
50-
"# !python3 -m pip install janus-core[all] data-tutorials"
50+
"\n",
51+
"# ! pip uninstall torch torchaudio torchvision numpy -y\n",
52+
"# ! uv pip install janus-core[all] data-tutorials torch==2.5.1 --system\n",
53+
"# get_ipython().kernel.do_shutdown(restart=True)"
5154
]
5255
},
5356
{
@@ -214,11 +217,11 @@
214217
"metadata": {},
215218
"outputs": [],
216219
"source": [
217-
"print(f\"Energy: {results.info[\"mace_mp_energy\"]}\")\n",
220+
"print(f\"Energy: {results.info['mace_mp_energy']}\")\n",
218221
"print()\n",
219-
"print(f\"Stress: {results.info[\"mace_mp_stress\"]}\")\n",
222+
"print(f\"Stress: {results.info['mace_mp_stress']}\")\n",
220223
"print()\n",
221-
"print(f\"Forces: {results.arrays[\"mace_mp_forces\"]}\")"
224+
"print(f\"Forces: {results.arrays['mace_mp_forces']}\")"
222225
]
223226
},
224227
{
@@ -284,6 +287,15 @@
284287
"tracker: False"
285288
]
286289
},
290+
{
291+
"cell_type": "code",
292+
"execution_count": null,
293+
"metadata": {},
294+
"outputs": [],
295+
"source": [
296+
"! cat singlepoint_config_1.yml"
297+
]
298+
},
287299
{
288300
"cell_type": "markdown",
289301
"metadata": {},
@@ -341,7 +353,8 @@
341353
"metadata": {},
342354
"source": [
343355
"<div class=\"alert alert-block alert-info\">\n",
344-
"<b>Note:</b> In the CLI, arguments are separated by \"-\", while in configuration files, they are specified by \"_\"\n",
356+
"<b>Note:</b> In the CLI, multi-word arguments must be separated by \"-\".\n",
357+
"In configuration files, they are preferably separated by \"_\", although \"-\" should be converted automatically.\n",
345358
"</div>"
346359
]
347360
},
@@ -619,7 +632,7 @@
619632
"metadata": {},
620633
"outputs": [],
621634
"source": [
622-
"! janus singlepoint --config singlepoint_config_1.yml --calc-kwargs \"{'dispersion': True}\""
635+
"! janus singlepoint --config singlepoint_config_1.yml --calc-kwargs \"{'dispersion': True}\" --out janus_results/NaCl-dispersion-results.extxyz"
623636
]
624637
},
625638
{
@@ -640,7 +653,24 @@
640653
"struct: data/NaCl.xyz\n",
641654
"tracker: False\n",
642655
"calc_kwargs:\n",
643-
" dispersion: True"
656+
" dispersion: True\n",
657+
"out: janus_results/NaCl-dispersion-results.extxyz"
658+
]
659+
},
660+
{
661+
"cell_type": "code",
662+
"execution_count": null,
663+
"metadata": {},
664+
"outputs": [],
665+
"source": [
666+
"! janus singlepoint --config singlepoint_config_4.yml"
667+
]
668+
},
669+
{
670+
"cell_type": "markdown",
671+
"metadata": {},
672+
"source": [
673+
"Comparing the results before and after the correction:"
644674
]
645675
},
646676
{
@@ -649,7 +679,10 @@
649679
"metadata": {},
650680
"outputs": [],
651681
"source": [
652-
"! janus singlepoint --config singlepoint_config_4.yml --calc-kwargs \"{'dispersion': True}\""
682+
"dispersion_results = read(\"janus_results/NaCl-dispersion-results.extxyz\")\n",
683+
"\n",
684+
"print(f\"Original results: {results.info['mace_mp_energy']}\")\n",
685+
"print(f\"Results with dispersion correction: {dispersion_results.info['mace_mp_energy']}\")"
653686
]
654687
}
655688
],

0 commit comments

Comments
 (0)