Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 63,225 Bytes
20d2150 4bac676 20d2150 4bac676 20d2150 47585e4 20d2150 6511ca4 20d2150 9dda91a 4162533 acb2b77 d58f33f 980cff6 acb2b77 cf2dead acb2b77 86da990 acb2b77 14a106d acb2b77 4162533 d58f33f 4162533 14a106d 4162533 86da990 4162533 980cff6 4162533 86da990 4162533 d3943ba 4162533 ced9fb3 4162533 ced9fb3 4162533 ced9fb3 4162533 ced9fb3 4162533 ced9fb3 4162533 ced9fb3 4162533 ced9fb3 4162533 ced9fb3 4162533 ced9fb3 86da990 ced9fb3 4162533 ced9fb3 4162533 ced9fb3 4162533 ced9fb3 4162533 ced9fb3 fa3477c ced9fb3 4162533 ced9fb3 4162533 ced9fb3 4162533 ced9fb3 4162533 ced9fb3 538131f e9cc0fb 538131f e9cc0fb 538131f 4162533 4a19067 4162533 86da990 85ef4be 4162533 20d2150 4162533 cf2dead 4162533 20d2150 4162533 14a106d 4bac676 4162533 20d2150 085bc21 acb2b77 20d2150 c080a0f 450850c 20d2150 acb2b77 20d2150 c080a0f 20d2150 cf2dead 77c5b54 acb2b77 20d2150 14a106d 4a19067 cf2dead 4a19067 14a106d 4a19067 14a106d 4a19067 14a106d 20d2150 4a19067 20d2150 8c6ac66 fa3477c 20d2150 4b5186a 20d2150 5881f78 20d2150 ab87ffb 20d2150 4b5186a 20d2150 4b5186a 20d2150 bbb728a 20d2150 bbb728a 20d2150 d56c953 fa3477c d56c953 8903fcc 3872f98 20d2150 12d0e77 db5eef3 20d2150 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 |
"""
Copyright (c) Meta Platforms, Inc. and affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import os
import subprocess
import sys
from pathlib import Path
import gradio as gr
from simulation_scripts import (
run_md_simulation,
run_relaxation_simulation,
validate_ase_atoms_and_login,
)
DEFAULT_MOLECULAR_REPRESENTATIONS = [
{
"model": 0,
"chain": "",
"resname": "",
"style": "sphere",
"color": "Jmol",
"around": 0,
"byres": False,
"scale": 0.3,
},
{
"model": 0,
"chain": "",
"resname": "",
"style": "stick",
"color": "Jmol",
"around": 0,
"byres": False,
"scale": 0.2,
},
]
DEFAULT_MOLECULAR_SETTINGS = {
"backgroundColor": "white",
"orthographic": False,
"disableFog": False,
}
def main():
input_structure = gr.File(
label="ASE-compatible structure",
file_types=[".cif", ".pdb", ".extxyz", ".xyz", ".traj"],
height=150,
value="./examples/metal_cplx.pdb",
)
output_traj = gr.File(
label="Simulation Trajectory (ASE traj file)",
interactive=False,
height=150,
)
input_visualization = Molecule3D(
label="Input Visualization",
reps=DEFAULT_MOLECULAR_REPRESENTATIONS,
config=DEFAULT_MOLECULAR_SETTINGS,
render=False,
inputs=[input_structure],
value=lambda x: x,
interactive=False,
)
md_steps = gr.Slider(minimum=1, maximum=500, value=100, label="MD Steps")
prerelax_steps = gr.Slider(
minimum=0, maximum=100, value=20, label="Pre-Relaxation Steps"
)
temperature_k = gr.Slider(
minimum=0.0,
maximum=1500.0, # Adjusted max value for temperature
value=300.0,
label="Temp [K]",
)
md_timestep = gr.Slider(minimum=0.1, maximum=5.0, value=1.0, label="Timestep [fs]")
md_ensemble = gr.Radio(
label="Thermodynamic Ensemble", choices=["NVE", "NVT"], value="NVE"
)
optimization_steps = gr.Slider(
minimum=1, maximum=500, value=300, step=1, label="Max Steps"
)
fmax = gr.Slider(value=0.05, minimum=0.001, maximum=0.5, label="Opt. Fmax [eV/Å]")
task_name = gr.Radio(
value="OMol", choices=["OMol", "OMC", "OMat", "OC20", "ODAC"], label="Task Name"
)
gr.Markdown("OMol-specific settings for total charge and spin multiplicity")
total_charge = gr.Slider(
value=0, label="Total Charge", minimum=-10, maximum=10, step=1
)
spin_multiplicity = gr.Slider(
value=1, maximum=11, minimum=1, step=1, label="Spin Multiplicity "
)
relax_unit_cell = gr.Checkbox(value=False, label="Relax Unit Cell")
md_button = gr.Button("Run MD Simulation", interactive=True)
optimization_button = gr.Button("Run Optimization", interactive=True)
output_structure = Molecule3D(
label="Simulation Visualization",
reps=DEFAULT_MOLECULAR_REPRESENTATIONS,
config=DEFAULT_MOLECULAR_SETTINGS,
render=False,
elem_classes="structures",
height=500,
inputs=[output_traj],
value=lambda x: x,
interactive=False,
)
explanation = gr.Markdown()
explanation_buffer = gr.Markdown()
output_text = gr.Code(lines=20, max_lines=30, label="Log", interactive=False)
reproduction_script = gr.Code(
interactive=False,
max_lines=30,
language="python",
label="ASE Reproduction Script",
)
with gr.Blocks(theme=gr.themes.Ocean(), title="FAIR Chem UMA Demo") as demo:
with gr.Row():
with gr.Column(scale=2):
with gr.Column(variant="panel"):
gr.Markdown("# Meta's Universal Model for Atoms (UMA) Demo")
with gr.Tab("1. UMA Intro"):
gr.Image(
"figures/uma_overview_figure.svg",
label="UMA Overview",
show_share_button=False,
show_download_button=False,
show_label=False,
show_fullscreen_button=False,
)
gr.Markdown(
"This is the UMA! It is a large mixture-of-linear-experts graph network model trained on billions of atoms across five open-science simulation datasets released by the FAIR Chemistry team over the past 5 years. If you give it an input structure and which task you're interested in modeling in, it will output the energy, forces, and stress which you can use for a molecular simulation! Try one of these examples to see what it can do."
)
with gr.Row():
gr.Examples(
examples=[
[
str(
Path(__file__).parent
/ "./examples/metal_cplx.pdb"
),
100,
20,
1.0,
300.0,
"NVE",
"OMol",
1,
6,
"Congratulations, you just ran your first UMA simulation! This is a molecular dynamics simulation of a transition metal complex that shows the atoms vibrating from thermal motion. Now try running some of the examples in the next tab to more thoroughly explore how UMA can be applied to different domains and types of structures.",
],
[
str(
Path(__file__).parent
/ "./examples/inorganic_crystal.cif"
),
200,
20,
1.0,
300.0,
"NVE",
"OMat",
0,
1,
"Congratulations, you just ran your first UMA simulation! This is a molecular dynamics simulation of an inorganic crystal structure that shows the atoms vibrating from thermal motion. Now try running some of the examples in the next tab to more thoroughly explore how UMA can be applied to different domains and types of structures.",
],
],
example_labels=[
"A transition metal complex",
"An inorganic crystal",
],
inputs=[
input_structure,
md_steps,
prerelax_steps,
md_timestep,
temperature_k,
md_ensemble,
task_name,
total_charge,
spin_multiplicity,
explanation_buffer,
],
outputs=[
output_traj,
output_text,
reproduction_script,
explanation,
],
fn=run_md_simulation,
run_on_click=True,
cache_examples=True,
label="Try an example!",
)
gr.Markdown(
"""
When you've run your first UMA simulation, click on the next tab above to explore the UMA model in more detail and see how it works across many different domains/examples!
"""
)
with gr.Tab("2. Explore UMA's capabilities"):
gr.Markdown(
"""
These next examples are designed to show how the UMA model can be applied to different domains and types of structures, and how different model inputs can impact the results! Each UMA task corresponds to a different domain of chemistry, and a different Density Functional Theory (DFT) code and level of theory that was used for the training data.
As you try each one, look at how the inputs change below, and the simulation outputs change on the right. Feel free to try changing some of the settings below and re-run the simulations to see how the results can vary.
"""
)
with gr.Accordion(
"UMA can handle many different materials/chemical structures!",
open=True,
):
gr.Examples(
examples=[
[
str(
Path(__file__).parent
/ "./examples/metal_cplx.pdb"
),
100,
20,
1.0,
300.0,
"NVE",
"OMol",
1,
6,
"This metal complex showcases the UMA's ability to handle complicated transition metal complexes with ligands, spin, and charge.",
],
[
str(
Path(__file__).parent
/ "./examples/organic_molecular_crystal.cif"
),
200,
20,
1.0,
300.0,
"NVE",
"OMC",
0,
1,
"This organic crystal showcases the UMA's ability to handle organic molecular crystals using the OMC task, using a random packing of a molecule from OE62. You could also try using the OMol or OMat tasks and see how the simulations differ!",
],
[
str(
Path(__file__).parent
/ "./examples/inorganic_crystal.cif"
),
200,
20,
1.0,
300.0,
"NVE",
"OMat",
0,
1,
"This inorganic crystal from the Materials Project showcases the UMA's ability to handle inorganic materials using the OMat task. You should be careful with the output energies since the analysis might require careful application of the Materials Project GGA/GGA+U correction schemes.",
],
[
str(
Path(__file__).parent / "./examples/HEA.cif"
),
200,
20,
1.0,
300.0,
"NVE",
"OMat",
0,
1,
"High-entropy alloys are materials with 4 or more elements, and this example shows the OMat model can also be applied to HEAs. This particular HEA is equimolar Cr/Fe/Ni/Sn, but could exist in other lattice configurations. ",
],
[
str(
Path(__file__).parent
/ "./examples/catalyst.traj"
),
200,
20,
1.0,
300.0,
"NVE",
"OC20",
0,
1,
"This example shows the OC20 model can be applied to small molecules on a catalyst surface, and that OC20 has recently been extended with datasets for multi-adsorbate interactions. Notice some of the adsorbates wrap around the periodic boundary conditions. Some of the adsorbates are weakly bound and desorbing from the surface based on this starting configuration.",
],
[
str(
Path(__file__).parent
/ "./examples/gold_nanoparticle_crystal.cif"
),
200,
20,
1.0,
300.0,
"NVE",
"OMat",
0,
1,
"This example is an experimentally solved crystal structure for a thiolate protected gold nanocluster from an[open-access academic paper](https://pubs.rsc.org/en/content/articlelanding/2016/sc/c5sc02134k) and [available in the COD](https://www.crystallography.net/cod/1540567.html). This is a fun example because it combines small molecules, inorganic materials, and surface chemistry, so it's not so clear which task to use. Try the OMat, OMol, and OC20 tasks to see how the results differ! Further, the experimental paper reported different crystal structures based on the charge and spin multiplicity, so try changing the charge and spin multiplicity to see how the results differ.",
],
[
str(
Path(__file__).parent
/ "./examples/ethylene_carbonate.xyz"
),
500,
20,
1.0,
1000.0,
"NVE",
"OMol",
0,
1,
"Ethylene carbonate is a common electrolyte in batteries, and an important precursor to the solid/electrolyte interface (SEI) formation. This example is the neutral version of ethylene carbonate and it is quite stable even at high temperatures! Try the radical anion version of ethylene carbonate in the next example.",
],
[
str(
Path(__file__).parent
/ "./examples/protein.pdb"
),
200,
20,
1.0,
300.0,
"NVE",
"OMol",
0,
1,
"This is a solvated structure of a small protein fragment using the OMol task. Very little is likely happen in a very short MD simulations. Try increasing the number of MD steps to see how the protein moves. You can also try using the OMat task, but be careful with the results since the OMat task is not trained on solvated systems.",
],
[
str(
Path(__file__).parent
/ "./examples/MOF_CO2.traj"
),
200,
20,
1.0,
300.0,
"NVE",
"ODAC",
0,
1,
"This is a metal organic framework (MOF) structure using the ODac task. You might study structures like if designing MOFs for direct air capture calculations. Look carefully for the red/gray CO2 molecule in the pores of the MOF! You can also try the OMol and OMat tasks to see if the results differ.",
],
],
example_labels=[
"Transition metal complex",
"Organic molecular crystal",
"Inorganic crystal",
"High-entropy alloy",
"Catalyst surface/adsorbate",
"Ligated gold nanoparticle crystal",
"Neutral ethylene carbonate",
"Solvated protein",
"CO2 in a metal organic framework",
],
inputs=[
input_structure,
md_steps,
prerelax_steps,
md_timestep,
temperature_k,
md_ensemble,
task_name,
total_charge,
spin_multiplicity,
explanation_buffer,
],
outputs=[
output_traj,
output_text,
reproduction_script,
explanation,
],
fn=run_md_simulation,
run_on_click=True,
cache_examples=True,
label="Molecular Dynamics Examples",
)
with gr.Accordion(
"UMA with OMol head can handle complex charge and spin multiplicity!",
open=False,
):
gr.Examples(
examples=[
[
str(
Path(__file__).parent
/ "./examples/ethylene_carbonate.xyz"
),
500,
20,
1.0,
1000.0,
"NVE",
"OMol",
0,
1,
"Ethylene carbonate is a common electrolyte in batteries, and an important precursor to the solid/electrolyte interface (SEI) formation. This example is the neutral version of ethylene carbonate and it is quite stable even at high temperatures! Try the radical anion version of ethylene carbonate in the next example.",
],
[
str(
Path(__file__).parent
/ "./examples/ethylene_carbonate.xyz"
),
500,
20,
1.0,
1000.0,
"NVE",
"OMol",
-1,
2,
"With charge of -1 and spin multiplicity of 2, this radical anion version of ethylene carbonate is much less stable than the neutral version and can undergo spontaneous ring-opening at high temperatures, which initiates the formation of a battery's solid/electrolyte interface (SEI). If the simulation doesn't show a ring opening reaction, try clicking the molecular dynamic buttons again to see another short simulation. Only OMol currently supports arbitrary charge/spin multiplicity.",
],
],
example_labels=[
"Neutral ethylene carbonate",
"Radical anion ethylene carbonate",
],
inputs=[
input_structure,
md_steps,
prerelax_steps,
md_timestep,
temperature_k,
md_ensemble,
task_name,
total_charge,
spin_multiplicity,
explanation_buffer,
],
outputs=[
output_traj,
output_text,
reproduction_script,
explanation,
],
fn=run_md_simulation,
run_on_click=True,
cache_examples=True,
label="Molecular Dynamics Examples",
)
gr.Examples(
examples=[
[
str(
Path(__file__).parent
/ "./examples/bis(EDA)Cu.xyz"
),
300,
0.05,
"OMol",
1,
1,
False,
"This is a super fun example of a transition metal complex that changes its geometry based on the assumed charge/spin multiplicity and actually has different local minima. It highlights the ability of the OMol task to handle these additional inputs. In this first example it forms a tetragonal geometry - try clicking on the next example (with charge=+2 and spin multiplicity 2) to see the other local minima!",
],
[
str(
Path(__file__).parent
/ "./examples/bis(EDA)Cu.xyz"
),
300,
0.05,
"OMol",
2,
2,
False,
"This is a super fun example of a transition metal complex that changes its geometry based on the assumed charge/spin multiplicity and actually has different local minima. In contrast to the previous example (charge=+1 and spin multiplicity 1), this one forms a square planar geometry.",
],
],
example_labels=[
"bis(EDA)Cu TM complex with charge=1, spin=1",
"bis(EDA)Cu TM complex with charge=2, spin=2",
],
inputs=[
input_structure,
optimization_steps,
fmax,
task_name,
total_charge,
spin_multiplicity,
relax_unit_cell,
explanation_buffer,
],
outputs=[
output_traj,
output_text,
reproduction_script,
explanation,
],
fn=run_relaxation_simulation,
run_on_click=True,
cache_examples=True,
label="Relaxation examples!",
)
with gr.Accordion(
"UMA can use different output heads for the same structures",
open=False,
):
gr.Examples(
examples=[
[
str(
Path(__file__).parent
/ "./examples/organic_molecular_crystal.cif"
),
200,
20,
1.0,
300.0,
"NVE",
"OMC",
0,
1,
"This organic crystal showcases the UMA's ability to handle organic molecular crystals using the OMC task, using a random packing of a molecule from OE62. You could also try using the OMol or OMat tasks and see how the simulations differ!",
],
[
str(
Path(__file__).parent
/ "./examples/organic_molecular_crystal.cif"
),
200,
20,
1.0,
300.0,
"NVE",
"OMol",
0,
1,
"This organic crystal showcases the UMA's ability to handle organic molecular crystals using the OMol task, using a random packing of a molecule from OE62. You could also try using the OMol or OMat tasks and see how the simulations differ!",
],
[
str(
Path(__file__).parent
/ "./examples/gold_nanoparticle_crystal.cif"
),
200,
20,
1.0,
300.0,
"NVE",
"OMol",
0,
1,
"This example is an experimentally solved crystal structure for a thiolate protected gold nanocluster from an[open-access academic paper](https://pubs.rsc.org/en/content/articlelanding/2016/sc/c5sc02134k) and [available in the COD](https://www.crystallography.net/cod/1540567.html). This is a fun example because it combines small molecules, inorganic materials, and surface chemistry, so it's not so clear which task to use. Try the OMat, OMol, and OC20 tasks to see how the results differ! Further, the experimental paper reported different crystal structures based on the charge and spin multiplicity, so try changing the charge and spin multiplicity to see how the results differ.",
],
[
str(
Path(__file__).parent
/ "./examples/gold_nanoparticle_crystal.cif"
),
200,
20,
1.0,
300.0,
"NVE",
"OMat",
0,
1,
"This example is an experimentally solved crystal structure for a thiolate protected gold nanocluster from an[open-access academic paper](https://pubs.rsc.org/en/content/articlelanding/2016/sc/c5sc02134k) and [available in the COD](https://www.crystallography.net/cod/1540567.html). This is a fun example because it combines small molecules, inorganic materials, and surface chemistry, so it's not so clear which task to use. Try the OMat, OMol, and OC20 tasks to see how the results differ! Further, the experimental paper reported different crystal structures based on the charge and spin multiplicity, so try changing the charge and spin multiplicity to see how the results differ.",
],
[
str(
Path(__file__).parent
/ "./examples/gold_nanoparticle_crystal.cif"
),
200,
20,
1.0,
300.0,
"NVE",
"OC20",
0,
1,
"This example is an experimentally solved crystal structure for a thiolate protected gold nanocluster from an[open-access academic paper](https://pubs.rsc.org/en/content/articlelanding/2016/sc/c5sc02134k) and [available in the COD](https://www.crystallography.net/cod/1540567.html). This is a fun example because it combines small molecules, inorganic materials, and surface chemistry, so it's not so clear which task to use. Try the OMat, OMol, and OC20 tasks to see how the results differ! Further, the experimental paper reported different crystal structures based on the charge and spin multiplicity, so try changing the charge and spin multiplicity to see how the results differ.",
],
[
str(
Path(__file__).parent
/ "./examples/MOF_CO2.traj"
),
200,
20,
1.0,
300.0,
"NVE",
"OMol",
0,
1,
"This is a metal organic framework (MOF) structure using the ODac task. You might study structures like if designing MOFs for direct air capture calculations. Look carefully for the red/gray CO2 molecule in the pores of the MOF! You can also try the OMol and OMat tasks to see if the results differ.",
],
[
str(
Path(__file__).parent
/ "./examples/MOF_CO2.traj"
),
200,
20,
1.0,
300.0,
"NVE",
"ODAC",
0,
1,
"This is a metal organic framework (MOF) structure using the ODac task. You might study structures like if designing MOFs for direct air capture calculations. Look carefully for the red/gray CO2 molecule in the pores of the MOF! You can also try the OMol and OMat tasks to see if the results differ.",
],
[
str(
Path(__file__).parent
/ "./examples/MOF_CO2.traj"
),
200,
20,
1.0,
300.0,
"NVE",
"OMat",
0,
1,
"This is a metal organic framework (MOF) structure using the ODac task. You might study structures like if designing MOFs for direct air capture calculations. Look carefully for the red/gray CO2 molecule in the pores of the MOF! You can also try the OMol and OMat tasks to see if the results differ.",
],
],
example_labels=[
"Organic crystal with OMol task",
"Organic crystal with OMC task",
"Ligated nanoparticle with OMol",
"Ligated nanoparticle with OMat",
"Ligated nanoparticle with OC20",
"CO2 in a MOF with OMol",
"CO2 in a MOF with ODAC",
"CO2 in a MOF with OMat",
],
inputs=[
input_structure,
md_steps,
prerelax_steps,
md_timestep,
temperature_k,
md_ensemble,
task_name,
total_charge,
spin_multiplicity,
explanation_buffer,
],
outputs=[
output_traj,
output_text,
reproduction_script,
explanation,
],
fn=run_md_simulation,
run_on_click=True,
cache_examples=True,
label="Molecular Dynamics Examples",
)
with gr.Accordion(
"UMA can be used for catalyst adsorption energies",
open=False,
):
gr.Markdown("[See the OC20 tutorials for how to use these energies!](https://fair-chem.github.io/catalysts/examples_tutorials/OCP-introduction.html)")
gr.Examples(
examples=[
[
str(
Path(__file__).parent
/ "./examples/pt111_slab.traj"
),
300,
0.05,
"OC20",
0,
1,
False,
"This is a bare Pt111 slab, with 4 layers.",
],
[
str(
Path(__file__).parent
/ "./examples/pt111_O.traj"
),
300,
0.05,
"OC20",
0,
1,
False,
"This is a Pt111 slab with an O adsorbed.",
],
[
str(
Path(__file__).parent
/ "./examples/cu111_slab.traj"
),
300,
0.05,
"OC20",
0,
1,
False,
"This is a bare Cu111 slab, with 4 layers.",
],
[
str(
Path(__file__).parent
/ "./examples/cu111_O.traj"
),
300,
0.05,
"OC20",
0,
1,
False,
"This is a Cu111 slab with an O adsorbed.",
],
],
example_labels=[
"Pt(111) slab",
"Pt(111)+*O adslab",
"Cu(111) slab",
"Cu(111)+*O adslab",
],
inputs=[
input_structure,
optimization_steps,
fmax,
task_name,
total_charge,
spin_multiplicity,
relax_unit_cell,
explanation_buffer,
],
outputs=[
output_traj,
output_text,
reproduction_script,
explanation,
],
fn=run_relaxation_simulation,
run_on_click=True,
cache_examples=True,
label="Catalyst examples!",
)
gr.Markdown(
"""
Once you understand how the UMA model can be applied to different types of molecules and materials, the final tab above will help you try it out with your own structures!
"""
)
with gr.Tab("3. Try UMA on your structures!"):
gr.Markdown(
"""
As the final step of the demo, try running your own structure through the UMA model!
To use a custom input structure with this demo:
1. [Request gated model access.](https://huggingface.co/facebook/UMA) Requests for model access are typically processed within a matter of minutes.
2. Login to Hugging Face using the "Sign in with Hugging Face button" in the inputs section.
3. Then upload a structure file below and click run!
* Note that uploaded structure will be stored by this demo to analyze model usage and identify domains where model accuracy can be improved.
* If you get a redirect error when logging in, please try visiting the direct demo url in a new tab (https://facebook-fairchem-uma-demo.hf.space/) and try again
* Your structure should be in a format supported by ASE 3.25, including .xyz, .extxyz, .cif, .pdb, or ASE .traj.
* Your structure should either have periodic boundary conditions (PBC) all True, or all False. Support for mixed PBC may be added in the future.
"""
)
with gr.Sidebar(open=True):
gr.Markdown("## Learn more about UMA")
with gr.Accordion("What is UMA?", open=False):
gr.Markdown(
"""
* UMA models predict motion and behavior at the atomic scale, ultimately reducing the development cycle in molecular and materials discovery and unlocking new possibilities for innovation and impact.
* UMA models are based on Density Functional Theory (DFT) training datasets. DFT simulations are a commonly used quantum chemistry method to simulate and understand behavior at the atomic scale.
* UMA models are large mixture-of-linear-experts graph networks models trained on billions of atoms across five open-science simulation datasets released by the FAIR Chemistry team over the past 5 years. This demo uses the small UMA model with 146M total parameters, 32 experts, and 6M active parameters at any time to predict across all of these domains.
[Read the UMA paper for details](https://ai.meta.com/research/publications/uma-a-family-of-universal-models-for-atoms/) or [download the UMA model](https://huggingface.co/facebook/UMA) and [FAIR Chemistry repository](https://github.com/facebookresearch/fairchem) to use this yourself!
"""
)
with gr.Accordion("Should I trust UMA?", open=False):
gr.Markdown(
"""
* The UMA model paper contains rigorous accuracy benchmarks on a number of validation sets across chemistry and materials science. As of model release the UMA model was at or near the state-of-the-art for generalization machine learning potentials. [Read the UMA paper for details.](https://ai.meta.com/research/publications/uma-a-family-of-universal-models-for-atoms/)
* Rigorously predicting when AI/ML models will extrapolate (or not) to new domains is an ongoing research area. The best approach is to find or build benchmarks that are similar to the questions you are studying, or be prepared to run some DFT simulations on predictions to validate results on a sample of structures that are relevant to your research problem.
"""
)
with gr.Accordion("Why does this matter?", open=False):
gr.Markdown(
"""
* Many important technological challenges, including developing new molecules to accelerate industrial progress and discovering new materials for energy storage and climate change mitigation, require scientists and engineers to design at the atomic scale.
* Traditional experimental discovery and design processes are extremely time consuming and often take decades from ideation to scaled manufacturing.
* Meta's Fundamental AI Research Lab (FAIR) is drastically accelerating this process by developing accurate and generalizable machine learning models, building on work by academic, industrial, and national lab collaborators.
"""
)
with gr.Accordion("How fast are these simulations?", open=False):
gr.Markdown(
"""
* Each simulation you see would take days or weeks using a traditional quantum chemistry simulation, but UMA can do it in seconds or minutes!
* Examples in the demo are cached ahead of time so they should load right away, but if you run a custom simulation you'll see a progress bar while the simulation runs.'
"""
)
with gr.Accordion("Model Disclaimers", open=False):
gr.Markdown(
"""
* While UMA represents a step forward in terms of having a single model that works across chemistry and materials science, we know the model has limitations and weaknesses and there will be cases where the model fails to produce an accurate simulation.
* Ab-initio calculations are not perfect. You should always consider the limitations of the level of theory, the code, and the pseudopotentials.
"""
)
with gr.Accordion("Open source packages in this demo", open=False):
gr.Markdown(
"""
* The model code is available on github at [FAIR chemistry repo](https://github.com/facebookresearch/fairchem)
* This demo builds on a number of great open source packages like [gradio_molecule3d](https://huggingface.co/spaces/simonduerr/gradio_molecule3d), [3dmol.js](https://3dmol.csb.pitt.edu/), [ASE](https://wiki.fysik.dtu.dk/ase/), and many others!
"""
)
gr.Markdown("## Debugging")
with gr.Accordion("Simulation took >5min", open=False):
gr.Markdown(
"""
* Every calculation uses a pool of GPUs to process simulations for all current users. You can achieve much higher performance with a dedicated GPU and MD-mode enabled.
* Most simulation should finish within a few minutes. Example results are cached, and if you are running a custom simulation you can follow the progress bar
* if you don't see progress or the simulation takes more than ~5min, probably there was an error and please try submitting again.
* If you notice any issues please submit them as issues on the [FAIR Chemistry GitHub](https://github.com/facebookresearch/fairchem).
"""
)
with gr.Accordion("Redirect error on login", open=False):
gr.Markdown(
"""
* If you notice a redirect error when clicking the login to Huggingface button, open a new tab and go to the direct demo url (https://facebook-fairchem-uma-demo.hf.space/) and try again!
"""
)
gr.Markdown("## Simulation inputs")
with gr.Column(variant="panel"):
gr.Markdown("### 1. Input structure (example or upload your own!)")
with gr.Row():
with gr.Column():
input_structure.render()
gr.Markdown("**Validation Errors:**")
structure_validation = gr.Markdown()
login_button = gr.LoginButton(size="large")
with gr.Column(scale=3):
input_visualization.render()
with gr.Column(variant="panel"):
gr.Markdown("### 2. Choose the UMA Model Task")
with gr.Row():
with gr.Column():
task_name.render()
with gr.Row():
total_charge.render()
spin_multiplicity.render()
with gr.Column(scale=2):
with gr.Tabs() as task_name_tabs:
with gr.TabItem("OMol", id=0):
gr.Markdown(
"""
[OMol25](https://arxiv.org/abs/2505.08762) comprises over 100 million calculations covering small molecules, biomolecules, metal complexes, and electrolytes.
**Relevant applications:** Biology, organic chemistry, protein folding, small-molecule pharmaceuticals, organic liquid properties, homogeneous catalysis
**Level of theory:** wB97M-V/def2-TZVPD as implemented in ORCA6, including non-local dispersion. All solvation should be explicit.
**Additional inputs:** total charge and spin multiplicity. If you don't know what these are, you should be very careful if modeling charged or open-shell systems. This can be used to study radical chemistry or understand the impact of magnetic states on the structure of a molecule.
**Caveats:** All training data is aperiodic, so any periodic systems should be treated with some caution. Probably won't work well for inorganic materials.
"""
)
with gr.TabItem("OMC", id=1):
gr.Markdown(
"""
OMC25 comprises ~25 million calculations of organic molecular crystals from random packing of OE62 structures into various 3D unit cells.
**Relevant applications:** Pharmaceutical packaging, bio-inspired materials, organic electronics, organic LEDs
**Level of theory:** PBE+D3 as implemented in VASP.
**Additional inputs:** UMA has not seen varying charge or spin multiplicity for the OMC task, and expects total_charge=0 and spin multiplicity=0 as model inputs.
"""
)
with gr.TabItem("OMat", id=2):
gr.Markdown(
"""
OMat24 comprises >100 million calculations or inorganic materials collected from many open databases like Materials Project and Alexandria, and randomly sampled far from equilibria.
**Relevant applications:** Inorganic materials discovery, solar photovoltaics, advanced alloys, superconductors, electronic materials, optical materials
**Level of theory:** PBE/PBE+U as implemented in VASP using Materials Project suggested settings, except with VASP 54 pseudopotentials. No dispersion.
**Additional inputs:** UMA has not seen varying charge or spin multiplicity for the OMat task, and expects total_charge=0 and spin multiplicity=0 as model inputs.
**Caveats:** Spin polarization effects are included, but you can't select the magnetic state. Further, OMat24 did not fully sample possible spin states in the training data.
"""
)
with gr.TabItem("OC20", id=3):
gr.Markdown(
"""
[OC20](https://pubs.acs.org/doi/abs/10.1021/acscatal.0c04525) comprises >100 million calculations of small molecules adsorbed on catalyst surfaces formed from materials in the Materials Project. It was updated to total energy predictions for the UMA release.
**Relevant applications:** Renewable energy, catalysis, fuel cells, energy conversion, sustainable fertilizer production, chemical refining, plastics synthesis/upcycling
**Level of theory:** RPBE as implemented in VASP, with VASP5.4 pseudopotentials. No dispersion.
**Additional inputs:** UMA has not seen varying charge or spin multiplicity for the OC20 task, and expects total_charge=0 and spin multiplicity=0 as model inputs.
**Caveats:** No oxides or explicit solvents are included in OC20. The model works surprisingly well for transition state searches given the nature of the training data, but you should be careful. RPBE works well for small molecules, but dispersion will be important for larger molecules on surfaces.
"""
)
with gr.TabItem("ODAC", id=4):
gr.Markdown(
"""
[ODAC23](https://pubs.acs.org/doi/full/10.1021/acscentsci.3c01629) comprises >10 million calculations of CO2/H2O molecules adsorbed in Metal Organic Frameworks sampled from various open databases like CoreMOF. It was updated to total energy predictions for the UMA release.
**Relevant applications:** Direct air capture, carbon capture and storage, CO2 conversion, catalysis
**Level of theory:** PBE+D3 as implemented in VASP, with VASP5.4 pseudopotentials.
**Additional inputs:** UMA has not seen varying charge or spin multiplicity for the ODAC task, and expects total_charge=0 and spin multiplicity=0 as model inputs.
**Caveats:** The ODAC23 dataset only contains CO2/H2O water absorption, so anything more than might be inaccurate (e.g. hydrocarbons in MOFs). Further, there is a limited number of bare-MOF structures in the training data, so you should be careful if you are using a new MOF structure.
"""
)
with gr.Column(variant="panel"):
gr.Markdown("### 3. Run Your Simulation")
with gr.Row():
with gr.Column():
gr.Markdown("### Molecular Dynamics")
prerelax_steps.render()
md_steps.render()
temperature_k.render()
md_timestep.render()
md_ensemble.render()
md_button.render()
with gr.Column():
gr.Markdown("### Relaxation")
optimization_steps.render()
fmax.render()
relax_unit_cell.render()
optimization_button.render()
with gr.Column(variant="panel", elem_id="results", min_width=500):
gr.Markdown("## UMA Simulation Results")
with gr.Tab("Visualization"):
output_structure.render()
with gr.Accordion(
"What should I look for in this simulation?", open=True
):
explanation.render()
output_traj.render()
with gr.Tab("Log"):
output_text.render()
with gr.Tab("Script"):
reproduction_script.render()
md_button.click(
run_md_simulation,
inputs=[
input_structure,
md_steps,
prerelax_steps,
md_timestep,
temperature_k,
md_ensemble,
task_name,
total_charge,
spin_multiplicity,
],
outputs=[output_traj, output_text, reproduction_script, explanation],
scroll_to_output=True,
)
optimization_button.click(
run_relaxation_simulation,
inputs=[
input_structure,
optimization_steps,
fmax,
task_name,
total_charge,
spin_multiplicity,
relax_unit_cell,
],
outputs=[output_traj, output_text, reproduction_script, explanation],
scroll_to_output=True,
)
# Change the tab based on the current task name
task_name.input(
lambda x: gr.Tabs(
selected={"OMol": 0, "OMC": 1, "OMat": 2, "OC20": 3, "ODAC": 4}[x]
),
[task_name],
task_name_tabs,
)
# Only show charge/spin inputs for OMol task
task_name.input(
lambda x: (
(gr.Number(visible=True), gr.Number(visible=True))
if x == "OMol"
else (gr.Number(visible=False), gr.Number(visible=False))
),
[task_name],
[total_charge, spin_multiplicity],
)
input_structure.change(
validate_ase_atoms_and_login,
inputs=[input_structure, login_button],
outputs=[optimization_button, md_button, structure_validation],
)
demo.queue(default_concurrency_limit=None)
demo.launch(ssr_mode=False)
if __name__ == "__main__":
os.makedirs("/data/custom_inputs/errors", exist_ok=True)
# On load, build and install the gradio_molecul3d fork
subprocess.call(
["gradio", "cc", "install"], cwd=Path(__file__).parent / "gradio_molecule3d/"
)
subprocess.call(
["gradio", "cc", "build"], cwd=Path(__file__).parent / "gradio_molecule3d/"
)
subprocess.call(
[
sys.executable,
"-m",
"pip",
"install",
Path(__file__).parent
/ "gradio_molecule3d/"
/ "dist/gradio_molecule3d-0.0.7-py3-none-any.whl",
],
cwd=Path(__file__).parent.parent,
)
# Load gradio_molecule3d only once it's built and installed
from gradio_molecule3d import Molecule3D
main()
|