Spaces:
Runtime error
Runtime error
adding HF database and parsing entries from it as computedentry, logic for filtering from element list
Browse files
app.py
CHANGED
|
@@ -4,29 +4,40 @@ from pymatgen.analysis.phase_diagram import PhaseDiagram, PDPlotter
|
|
| 4 |
from pymatgen.core.composition import Composition
|
| 5 |
import plotly.graph_objs as go
|
| 6 |
import os
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
def create_phase_diagram(elements, max_e_above_hull, color_scheme, plot_style, functional, finite_temp):
|
| 12 |
# Split elements and remove any whitespace
|
| 13 |
element_list = [el.strip() for el in elements.split('-')]
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
|
| 31 |
# Build the phase diagram
|
| 32 |
try:
|
|
|
|
| 4 |
from pymatgen.core.composition import Composition
|
| 5 |
import plotly.graph_objs as go
|
| 6 |
import os
|
| 7 |
+
from pymatgen.entries.computed_entries import ComputedEntry
|
| 8 |
+
from pymatgen.core import Composition
|
| 9 |
|
| 10 |
+
from datasets import load_dataset
|
| 11 |
+
|
| 12 |
+
# Load only the train split of the dataset
|
| 13 |
+
dataset = load_dataset("LeMaterial/leDataset", split="train")
|
| 14 |
+
|
| 15 |
+
# Convert the train split to a pandas DataFrame
|
| 16 |
+
train_df = dataset.to_pandas()
|
| 17 |
|
| 18 |
|
| 19 |
def create_phase_diagram(elements, max_e_above_hull, color_scheme, plot_style, functional, finite_temp):
|
| 20 |
# Split elements and remove any whitespace
|
| 21 |
element_list = [el.strip() for el in elements.split('-')]
|
| 22 |
|
| 23 |
+
# Fetch all entries from the Materials Project database
|
| 24 |
+
entries = [ComputedEntry(
|
| 25 |
+
Composition(row["chemical_formula_descriptive"]),
|
| 26 |
+
energy = row['energy'],
|
| 27 |
+
correction = row['energy_corrected']-row['energy'],
|
| 28 |
+
entry_id = row['immutable_id']) for n,row in df.iterrows() if len(
|
| 29 |
+
set(row['elements']).intersection(element_list))>0 and set(
|
| 30 |
+
row['elements']).issubset(element_list)]
|
| 31 |
+
# Fetch elemental entries (they are usually GGA calculations)
|
| 32 |
+
elemental_entries = [e for e in entries if e.composition.is_element]
|
| 33 |
|
| 34 |
+
# Filter entries based on functional
|
| 35 |
+
if functional == "GGA":
|
| 36 |
+
entries = [e for e in entries if not e.parameters.get("run_type", "").startswith("GGA+U")]
|
| 37 |
+
elif functional == "GGA+U":
|
| 38 |
+
entries = [e for e in entries if e.parameters.get("run_type", "").startswith("GGA+U")]
|
| 39 |
+
# Add elemental entries to ensure they are included
|
| 40 |
+
entries.extend([e for e in elemental_entries if e not in entries])
|
| 41 |
|
| 42 |
# Build the phase diagram
|
| 43 |
try:
|