Spaces:
Sleeping
Sleeping
File size: 1,073 Bytes
40fc2b7 |
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 |
import numpy as np
from ase import Atoms
import plotly.graph_objects as go
empty_fig = go.Figure(
data=[
go.Scatter(
x=[],
y=[],
mode="markers",
marker=dict(color="rgba(0,0,0,0)"),
)
],
layout=go.Layout(
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
template="plotly_white",
),
)
def atoms_to_dict(atoms):
"""
Converts an ASE Atoms object to a dictionary for storing.
"""
return {
"symbols": atoms.get_chemical_symbols(),
"positions": atoms.get_positions().tolist(),
"cell": atoms.get_cell().tolist(),
"pbc": atoms.get_pbc().tolist(),
}
def dict_to_atoms(data):
"""
Converts a dictionary back to an ASE Atoms object.
"""
atoms = Atoms(
symbols=data["symbols"],
positions=np.array(data["positions"]),
cell=np.array(data["cell"]),
pbc=np.array(data["pbc"]),
)
return atoms |