Spaces:
Running
Running
incorporate our data and our fields
Browse files
app.py
CHANGED
|
@@ -6,9 +6,41 @@ from crystal_toolkit.settings import SETTINGS
|
|
| 6 |
import dash
|
| 7 |
from dash import html, dcc
|
| 8 |
from dash.dependencies import Input, Output, State
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
# Initialize the Dash app
|
| 14 |
app = dash.Dash(__name__, assets_folder=SETTINGS.ASSETS_PATH)
|
|
@@ -51,12 +83,15 @@ layout = html.Div([
|
|
| 51 |
|
| 52 |
# Function to search for materials
|
| 53 |
def search_materials(query):
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
)
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
| 60 |
return options
|
| 61 |
|
| 62 |
|
|
@@ -86,26 +121,23 @@ def update_material_dropdown(n_clicks, query):
|
|
| 86 |
def display_material(n_clicks, material_id):
|
| 87 |
if n_clicks is None or not material_id:
|
| 88 |
return '', ''
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
# Create the StructureMoleculeComponent
|
| 94 |
-
structure_component = ctc.StructureMoleculeComponent(
|
| 95 |
|
| 96 |
# Extract key properties
|
| 97 |
properties = {
|
| 98 |
-
"Material ID":
|
| 99 |
-
"Formula":
|
| 100 |
-
"Energy
|
| 101 |
-
"
|
| 102 |
-
"
|
| 103 |
-
"Formation Energy (eV/atom)": summary.formation_energy_per_atom,
|
| 104 |
-
"Magnetic Ordering": summary.ordering,
|
| 105 |
-
"Total Magnetization (μB/f.u.)": summary.total_magnetization,
|
| 106 |
-
"Is Stable": summary.is_stable,
|
| 107 |
-
"Crystal System": summary.symmetry.crystal_system,
|
| 108 |
-
"Density (g/cm³)": summary.density,
|
| 109 |
}
|
| 110 |
|
| 111 |
# Format properties as an HTML table
|
|
|
|
| 6 |
import dash
|
| 7 |
from dash import html, dcc
|
| 8 |
from dash.dependencies import Input, Output, State
|
| 9 |
+
from pymatgen.core import Structure
|
| 10 |
+
|
| 11 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 12 |
+
|
| 13 |
+
# Load only the train split of the dataset
|
| 14 |
+
dataset = load_dataset(
|
| 15 |
+
"LeMaterial/leDataset",
|
| 16 |
+
token=HF_TOKEN,
|
| 17 |
+
split="train",
|
| 18 |
+
columns=[
|
| 19 |
+
"lattice_vectors",
|
| 20 |
+
"species_at_sites",
|
| 21 |
+
"cartesian_site_positions",
|
| 22 |
+
"energy",
|
| 23 |
+
"energy_corrected",
|
| 24 |
+
"immutable_id",
|
| 25 |
+
"elements",
|
| 26 |
+
"functional",
|
| 27 |
+
"stress_tensor",
|
| 28 |
+
"magnetic_moments",
|
| 29 |
+
"forces",
|
| 30 |
+
"band_gap_direct",
|
| 31 |
+
"band_gap_indirect",
|
| 32 |
+
"dos_ef",
|
| 33 |
+
"charges",
|
| 34 |
+
"functional",
|
| 35 |
+
"chemical_formula_reduced",
|
| 36 |
+
"chemical_formula_descriptive",
|
| 37 |
+
"total_magnetization"
|
| 38 |
+
],
|
| 39 |
+
)
|
| 40 |
|
| 41 |
+
# Convert the train split to a pandas DataFrame
|
| 42 |
+
train_df = dataset.to_pandas()
|
| 43 |
+
del dataset
|
| 44 |
|
| 45 |
# Initialize the Dash app
|
| 46 |
app = dash.Dash(__name__, assets_folder=SETTINGS.ASSETS_PATH)
|
|
|
|
| 83 |
|
| 84 |
# Function to search for materials
|
| 85 |
def search_materials(query):
|
| 86 |
+
element_list = [el.strip() for el in query.split("-")]
|
| 87 |
+
isubset = lambda x: set(x).issubset(element_list)
|
| 88 |
+
isintersection = lambda x: len(set(x).intersection(element_list)) > 0
|
| 89 |
+
entries_df = train_df[
|
| 90 |
+
[isintersection(l) and isubset(l) for l in train_df.elements.values.tolist()]
|
| 91 |
+
]
|
| 92 |
+
|
| 93 |
+
options = [{'label': f"{res.chemical_formula_reduced} ({res.immutable_id}) Calculated with {res.functional}", 'value': n} for n,res in entries_df.iterrows()]
|
| 94 |
+
del entries_df
|
| 95 |
return options
|
| 96 |
|
| 97 |
|
|
|
|
| 121 |
def display_material(n_clicks, material_id):
|
| 122 |
if n_clicks is None or not material_id:
|
| 123 |
return '', ''
|
| 124 |
+
row = train_df.iloc[material_id]
|
| 125 |
+
|
| 126 |
+
structure = Structure([x for y in row['lattice_vectors'] for x in y],
|
| 127 |
+
row['species_at_sites'],
|
| 128 |
+
row['cartesian_site_positions'],
|
| 129 |
+
coords_are_cartesian= True)
|
| 130 |
|
| 131 |
# Create the StructureMoleculeComponent
|
| 132 |
+
structure_component = ctc.StructureMoleculeComponent(structure)
|
| 133 |
|
| 134 |
# Extract key properties
|
| 135 |
properties = {
|
| 136 |
+
"Material ID": row.immutable_id,
|
| 137 |
+
"Formula": row.chemical_formula_descriptive,
|
| 138 |
+
"Energy per atom (eV/atom)": row.energy/len(row.species_at_sites),
|
| 139 |
+
"Band Gap (eV)": row.band_gap_direct or row.band_gap_indirect,
|
| 140 |
+
"Total Magnetization (μB/f.u.)": row.total_magnetization,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
}
|
| 142 |
|
| 143 |
# Format properties as an HTML table
|