msiron commited on
Commit
70b543a
·
1 Parent(s): 1a9eacc

adding HF database and parsing entries from it as computedentry, logic for filtering from element list

Browse files
Files changed (1) hide show
  1. app.py +26 -15
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
- MATERIALS_PROJECT_API_KEY = os.getenv('MATERIALS_PROJECT_API_KEY')
 
 
 
 
 
 
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
- with MPRester(MATERIALS_PROJECT_API_KEY) as m:
16
- # Fetch all entries from the Materials Project database
17
- entries = m.get_entries_in_chemsys(element_list, compatible_only=True, inc_structure='final')
18
-
19
- # Fetch elemental entries (they are usually GGA calculations)
20
- elemental_entries = m.get_entries_in_chemsys(element_list, compatible_only=True, inc_structure='final')
21
- elemental_entries = [e for e in elemental_entries if e.composition.is_element]
 
 
 
22
 
23
- # Filter entries based on functional
24
- if functional == "GGA":
25
- entries = [e for e in entries if not e.parameters.get("run_type", "").startswith("GGA+U")]
26
- elif functional == "GGA+U":
27
- entries = [e for e in entries if e.parameters.get("run_type", "").startswith("GGA+U")]
28
- # Add elemental entries to ensure they are included
29
- entries.extend([e for e in elemental_entries if e not in entries])
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: