Spaces:
Running
Running
File size: 8,767 Bytes
b881f30 d9ed521 b881f30 d9ed521 b881f30 af4a473 3eda6d3 606b930 9361457 3b3aaa9 606b930 b881f30 221dfe3 d9ed521 9361457 b9692e2 9361457 8396dce b881f30 221dfe3 5b01054 606b930 b881f30 221dfe3 9361457 221dfe3 b881f30 221dfe3 b881f30 9361457 b881f30 9361457 0d1ce35 3b3aaa9 bcf00b7 d937c80 bcf00b7 d937c80 bcf00b7 d937c80 9361457 d937c80 8396dce d937c80 bcf00b7 d937c80 b881f30 9361457 221dfe3 b881f30 d937c80 bcf00b7 d937c80 b881f30 d937c80 d9ed521 d937c80 9361457 d9ed521 d937c80 d9ed521 d937c80 d9ed521 d937c80 d9ed521 d937c80 221dfe3 d937c80 8396dce d937c80 d9ed521 8396dce d937c80 8396dce d937c80 8396dce d937c80 8396dce d937c80 8396dce d937c80 8396dce d937c80 8396dce d9ed521 d937c80 d9ed521 d937c80 bcf00b7 8396dce d937c80 89bc52a d937c80 52c1bfb d937c80 d9ed521 d937c80 b881f30 d937c80 bcf00b7 d937c80 89bc52a bcf00b7 d937c80 606b930 |
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 |
from pathlib import Path
import numpy as np
import pandas as pd
import plotly.colors as pcolors
import plotly.graph_objects as go
import streamlit as st
from ase.data import chemical_symbols
from plotly.subplots import make_subplots
from scipy.interpolate import CubicSpline
from mlip_arena.models import REGISTRY
st.markdown(
"""
# Homonuclear Diatomics
Homonuclear diatomics are molecules composed of two atoms of the same element.
The potential energy curves of homonuclear diatomics are the most fundamental interactions between atoms in quantum chemistry.
"""
)
st.markdown("### Methods")
container = st.container(border=True)
valid_models = [
model
for model, metadata in REGISTRY.items()
if Path(__file__).stem in metadata.get("gpu-tasks", [])
]
mlip_methods = container.multiselect(
"MLIPs",
valid_models,
["MACE-MP(M)", "CHGNet", "M3GNet", "MatterSim", "SevenNet", "ORBv2", "eqV2(OMat)"],
)
dft_methods = container.multiselect("DFT Methods", ["PBE"], ["PBE"])
st.markdown("### Settings")
vis = st.container(border=True)
energy_plot = vis.checkbox("Show energy curves", value=True)
force_plot = vis.checkbox("Show force curves", value=False)
ncols = vis.select_slider("Number of columns", options=[1, 2, 3, 4], value=2)
# Get all attributes from pcolors.qualitative
all_attributes = dir(pcolors.qualitative)
color_palettes = {
attr: getattr(pcolors.qualitative, attr)
for attr in all_attributes
if isinstance(getattr(pcolors.qualitative, attr), list)
}
color_palettes.pop("__all__", None)
palette_names = list(color_palettes.keys())
palette_colors = list(color_palettes.values())
palette_name = vis.selectbox("Color sequence", options=palette_names, index=22)
color_sequence = color_palettes[palette_name] # type: ignore
if not mlip_methods and not dft_methods:
st.stop()
@st.cache_data
def get_data(mlip_methods, dft_methods):
DATA_DIR = Path("mlip_arena/tasks/diatomics")
dfs = [
pd.read_json(
DATA_DIR / REGISTRY[method]["family"] / "homonuclear-diatomics.json"
)
for method in mlip_methods
]
dfs.extend(
[
pd.read_json(DATA_DIR / "vasp" / "homonuclear-diatomics.json")
# for method in dft_methods
]
)
df = pd.concat(dfs, ignore_index=True)
df.drop_duplicates(inplace=True, subset=["name", "method"])
return df
df = get_data(mlip_methods, dft_methods)
method_color_mapping = {
method: color_sequence[i % len(color_sequence)]
for i, method in enumerate(df["method"].unique())
}
@st.cache_data
def get_plots(df, energy_plot: bool, force_plot: bool, method_color_mapping: dict):
figs = []
for i, symbol in enumerate(chemical_symbols[1:]):
rows = df[df["name"] == symbol + symbol]
if rows.empty:
continue
fig = make_subplots(specs=[[{"secondary_y": True}]])
elo, flo = float("inf"), float("inf")
for j, method in enumerate(rows["method"].unique()):
if method not in mlip_methods and method not in dft_methods:
continue
row = rows[rows["method"] == method].iloc[0]
rs = np.array(row["R"])
es = np.array(row["E"])
fs = np.array(row["F"])
rs = np.array(rs)
ind = np.argsort(rs)
es = np.array(es)
fs = np.array(fs)
rs = rs[ind]
es = es[ind]
fs = fs[ind]
# if method not in ["PBE"]:
es = es - es[-1]
# if method in ["PBE"]:
# xs = np.linspace(rs.min() * 0.99, rs.max() * 1.01, int(5e2))
# else:
xs = rs
if energy_plot:
# if "GPAW" in method:
# cs = CubicSpline(rs, es)
# ys = cs(xs)
# else:
ys = es
elo = min(elo, max(ys.min() * 1.2, -15), -1)
if method in ["PBE"]:
fig.add_trace(
go.Scatter(
x=xs,
y=ys,
mode="markers",
line=dict(
color=method_color_mapping[method],
width=3,
),
name=method,
),
secondary_y=False,
)
# xs = np.linspace(rs.min() * 0.99, rs.max() * 1.01, int(5e2))
# cs = CubicSpline(rs, es)
# ys = cs(xs)
# fig.add_trace(
# go.Scatter(
# x=xs,
# y=ys,
# mode="lines",
# line=dict(
# color=method_color_mapping[method],
# width=3,
# ),
# name=method,
# showlegend=False,
# ),
# secondary_y=False,
# )
else:
fig.add_trace(
go.Scatter(
x=xs,
y=ys,
mode="lines",
line=dict(
color=method_color_mapping[method],
width=3,
),
name=method,
),
secondary_y=False,
)
# if force_plot and method not in ["PBE"]:
if force_plot:
ys = fs
flo = min(flo, max(ys.min() * 1.2, -50))
if method in ["PBE"]:
fig.add_trace(
go.Scatter(
x=xs,
y=ys,
mode="lines+markers",
line=dict(
color=method_color_mapping[method],
width=2,
dash="dashdot",
),
name=method,
showlegend=not energy_plot,
),
secondary_y=True,
)
else:
fig.add_trace(
go.Scatter(
x=xs,
y=ys,
mode="lines",
line=dict(
color=method_color_mapping[method],
width=2,
dash="dashdot",
),
name=method,
showlegend=not energy_plot,
),
secondary_y=True,
)
name = f"{symbol}-{symbol}"
fig.update_layout(
showlegend=True,
legend=dict(
orientation="v",
x=0.95,
xanchor="right",
y=1,
yanchor="top",
bgcolor="rgba(0, 0, 0, 0)",
# traceorder='reversed',
# entrywidth=0.3,
# entrywidthmode='fraction',
),
title_text=f"{name}",
title_x=0.5,
)
# Set x-axis title
fig.update_xaxes(title_text="Distance [Å]")
# Set y-axes titles
if energy_plot:
fig.update_layout(
yaxis=dict(
title=dict(text="Energy [eV]"),
side="left",
range=[elo, 2.0 * (abs(elo))],
)
)
if force_plot:
fig.update_layout(
yaxis2=dict(
title=dict(text="Force [eV/Å]"),
side="right",
range=[flo, 1.0 * abs(flo)],
overlaying="y",
tickmode="sync",
),
)
# cols[i % ncols].plotly_chart(fig, use_container_width=True)
figs.append(fig)
return figs
# fig.write_image(format='svg', file=img_dir / f"{name}.svg")
figs = get_plots(df, energy_plot, force_plot, method_color_mapping)
for i, fig in enumerate(figs):
if i % ncols == 0:
cols = st.columns(ncols)
cols[i % ncols].plotly_chart(fig, use_container_width=True)
|