|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import marimo |
| 4 | + |
| 5 | +__generated_with = "0.14.16" |
| 6 | +app = marimo.App(width="medium") |
| 7 | + |
| 8 | + |
| 9 | +@app.cell |
| 10 | +def _(): |
| 11 | + from ase.build import bulk |
| 12 | + from ase.io import read, write |
| 13 | + import marimo as mo |
| 14 | + from pymatgen.io.ase import AseAtomsAdaptor |
| 15 | + import pymatviz as view |
| 16 | + |
| 17 | + from janus_core.calculations.geom_opt import GeomOpt |
| 18 | + |
| 19 | + return AseAtomsAdaptor, GeomOpt, bulk, mo, read, view, write |
| 20 | + |
| 21 | + |
| 22 | +@app.cell |
| 23 | +def _(bulk, write): |
| 24 | + device = "cpu" |
| 25 | + a = 6.0 |
| 26 | + NaCl = bulk( |
| 27 | + "NaCl", crystalstructure="rocksalt", cubic=True, orthorhombic=True, a=a |
| 28 | + ) * (2, 2, 2) |
| 29 | + NaCl.rattle(stdev=0.1, seed=2042) |
| 30 | + write("NaCl.extxyz", NaCl) |
| 31 | + return (NaCl,) |
| 32 | + |
| 33 | + |
| 34 | +@app.cell |
| 35 | +def _(AseAtomsAdaptor, NaCl, view): |
| 36 | + struct = AseAtomsAdaptor().get_structure(NaCl) |
| 37 | + |
| 38 | + s_widget = view.StructureWidget( |
| 39 | + structure=struct, show_bonds=True, bonding_strategy="nearest_neighbor" |
| 40 | + ) |
| 41 | + s_widget |
| 42 | + return |
| 43 | + |
| 44 | + |
| 45 | +@app.cell |
| 46 | +def _(mo): |
| 47 | + # Create a form with multiple elements |
| 48 | + form = ( |
| 49 | + mo.md(""" |
| 50 | + **Geomtry Optimisation** |
| 51 | +
|
| 52 | + Upload Structure {structure} |
| 53 | +
|
| 54 | + optimize {optimize} |
| 55 | +
|
| 56 | + {fmax} |
| 57 | +
|
| 58 | + ML model :{model} |
| 59 | + """) |
| 60 | + .batch( |
| 61 | + structure=mo.ui.file(label="Structure"), |
| 62 | + fmax=mo.ui.number(label="fmax", value=0.01), |
| 63 | + optimize=mo.ui.radio( |
| 64 | + options={"Just coordinates": 1, "Cell vectors only": 2, "Full": 3}, |
| 65 | + value="Full", # initial value |
| 66 | + label="choose a methood", |
| 67 | + ), |
| 68 | + model=mo.ui.dropdown( |
| 69 | + options={ |
| 70 | + "MACE_MP-small": ("mace_mp", "small"), |
| 71 | + "MACE_MP-medium": ("mace_mp", "medium"), |
| 72 | + }, |
| 73 | + value="MACE_MP-small", |
| 74 | + ), |
| 75 | + ) |
| 76 | + .form( |
| 77 | + show_clear_button=True, |
| 78 | + bordered=True, |
| 79 | + submit_button_disabled=False, |
| 80 | + submit_button_tooltip="start the calculation", |
| 81 | + ) |
| 82 | + ) |
| 83 | + form |
| 84 | + return (form,) |
| 85 | + |
| 86 | + |
| 87 | +@app.cell |
| 88 | +def _(form): |
| 89 | + settings = form.value |
| 90 | + print(settings) |
| 91 | + return (settings,) |
| 92 | + |
| 93 | + |
| 94 | +@app.cell |
| 95 | +def _(GeomOpt, form, mo, read, settings): |
| 96 | + mo.stop(form.value is None, mo.md("Upload a file and submit")) |
| 97 | + |
| 98 | + from io import BytesIO |
| 99 | + |
| 100 | + x = settings["structure"][0] |
| 101 | + m = read(BytesIO(x.contents), format="cif") |
| 102 | + |
| 103 | + model = settings["model"] |
| 104 | + optimized_NaCl = GeomOpt( |
| 105 | + struct=m, |
| 106 | + model=model[1], |
| 107 | + arch=model[0], |
| 108 | + fmax=settings["fmax"], |
| 109 | + optimizer="FIRE", |
| 110 | + write_traj=True, |
| 111 | + ) |
| 112 | + |
| 113 | + optimized_NaCl.run() |
| 114 | + return (m,) |
| 115 | + |
| 116 | + |
| 117 | +@app.cell |
| 118 | +def _(m): |
| 119 | + m |
| 120 | + return |
| 121 | + |
| 122 | + |
| 123 | +if __name__ == "__main__": |
| 124 | + app.run() |
0 commit comments