Spaces:
Running
Running
File size: 3,763 Bytes
b881f30 d9ed521 b881f30 d9ed521 b881f30 d9ed521 b881f30 d9ed521 b881f30 d9ed521 89bc52a b881f30 d9ed521 b881f30 d9ed521 b881f30 d9ed521 b881f30 d9ed521 b881f30 d9ed521 b881f30 d9ed521 b881f30 d9ed521 b881f30 d9ed521 b881f30 d9ed521 89bc52a d9ed521 89bc52a d9ed521 89bc52a d9ed521 b881f30 d9ed521 b881f30 d9ed521 89bc52a b881f30 d9ed521 89bc52a b881f30 d9ed521 |
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 |
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
color_sequence = pcolors.qualitative.Plotly
st.markdown("# Homonuclear diatomics")
# button to toggle plots
container = st.container(border=True)
energy_plot = container.checkbox("Show energy curves", value=True)
force_plot = container.checkbox("Show force curves", value=True)
ncols = 2
DATA_DIR = Path("mlip_arena/tasks/diatomics")
mlips = ["MACE-MP", "CHGNet"]
dfs = [pd.read_json(DATA_DIR / mlip.lower() / "homonuclear-diatomics.json") for mlip in mlips]
df = pd.concat(dfs, ignore_index=True)
df.drop_duplicates(inplace=True, subset=["name", "method"])
for i, symbol in enumerate(chemical_symbols[1:]):
if i % ncols == 0:
cols = st.columns(ncols)
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()):
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]
es = es - es[-1]
fs = fs[ind]
xs = np.linspace(rs.min()*0.99, rs.max()*1.01, int(5e2))
if energy_plot:
cs = CubicSpline(rs, es)
ys = cs(xs)
elo = min(elo, ys.min()*1.2, -1)
fig.add_trace(
go.Scatter(
x=xs, y=ys,
mode="lines",
line=dict(
color=color_sequence[j % len(color_sequence)],
width=2,
),
name=method,
),
secondary_y=False,
)
if force_plot:
cs = CubicSpline(rs, fs)
ys = cs(xs)
flo = min(flo, ys.min()*1.2)
fig.add_trace(
go.Scatter(
x=xs, y=ys,
mode="lines",
line=dict(
color=color_sequence[j % len(color_sequence)],
width=1,
dash="dot",
),
name=method,
showlegend=False if energy_plot else True,
),
secondary_y=True,
)
fig.update_layout(
showlegend=True,
title_text=f"{symbol}-{symbol}",
title_x=0.5,
# yaxis_range=[ylo, 2*(abs(ylo))],
)
# Set x-axis title
fig.update_xaxes(title_text="Bond length (Å)")
# Set y-axes titles
if energy_plot:
fig.update_layout(
yaxis=dict(
title=dict(text="Energy [eV]"),
side="left",
range=[elo, 2*(abs(elo))],
)
)
# fig.update_yaxes(title_text="Energy [eV]", secondary_y=False)
if force_plot:
fig.update_layout(
yaxis2=dict(
title=dict(text="Force [eV/Å]"),
side="right",
range=[flo, 2*(abs(flo))],
overlaying="y",
tickmode="sync",
),
)
# fig.update_yaxes(title_text="Force [eV/Å]", secondary_y=True)
# cols[i % ncols].title(f"{row['name']}")
cols[i % ncols].plotly_chart(fig, use_container_width=True, height=250)
|