Ramlaoui commited on
Commit
3de9b87
·
1 Parent(s): 9a2fc0b

Use sparse matrix and don't store df

Browse files
Files changed (1) hide show
  1. app.py +24 -12
app.py CHANGED
@@ -38,7 +38,7 @@ subsets = [
38
  subsets_ds = {}
39
  for subset in subsets:
40
  dataset = load_dataset(
41
- "LeMaterial/leMat1",
42
  subset,
43
  token=HF_TOKEN,
44
  columns=[
@@ -52,10 +52,13 @@ for subset in subsets:
52
  "functional",
53
  ],
54
  )
55
- subsets_ds[subset] = dataset["train"].to_pandas()
56
 
57
- elements_df = {k: subset["elements"] for k, subset in subsets_ds.items()}
 
 
58
 
 
59
 
60
  all_elements = {str(el): i for i, el in enumerate(periodictable.elements)}
61
  elements_indices = {}
@@ -70,6 +73,12 @@ for subset, df in elements_df.items():
70
 
71
  df = df.reset_index().apply(map_elements, axis=1)
72
 
 
 
 
 
 
 
73
  map_functional = {
74
  "PBE": "compatible_pbe",
75
  "PBESol (No correction scheme)": "compatible_pbesol",
@@ -108,7 +117,7 @@ def create_phase_diagram(
108
 
109
  print(indices_with_only_elements)
110
 
111
- entries_df = subsets_ds[subset_name].loc[indices_with_only_elements]
112
 
113
  entries_df = entries_df[~entries_df["immutable_id"].isna()]
114
 
@@ -116,18 +125,18 @@ def create_phase_diagram(
116
 
117
  # Fetch all entries from the Materials Project database
118
  def get_energy_correction(energy_correction, row):
119
- if energy_correction == "Database specific, or MP2020" and functional == 'PBE':
120
- print('applying MP corrections')
121
  return (
122
  row["energy_corrected"] - row["energy"]
123
  if not np.isnan(row["energy_corrected"])
124
  else 0
125
  )
126
- elif energy_correction == "The 110 PBE Method" and functional == 'PBE':
127
- print('applying PBE110 corrections')
128
- return row["energy"] * 1.1-row['energy']
129
- elif map_functional[functional] != 'pbe':
130
- print('not applying any corrections')
131
  return 0
132
 
133
  entries = [
@@ -199,7 +208,10 @@ energy_correction_dropdown = gr.Dropdown(
199
  label="Energy correction",
200
  )
201
  plot_style_dropdown = gr.Dropdown(choices=["2D", "3D"], label="Plot Style")
202
- functional_dropdown = gr.Dropdown(choices=["PBE", "PBESol (No correction scheme)", "SCAN (No correction scheme)"], label="Functional")
 
 
 
203
  finite_temp_toggle = gr.Checkbox(label="Enable Finite Temperature Estimation")
204
 
205
  warning_message = "⚠️ This application uses energy correction schemes directly"
 
38
  subsets_ds = {}
39
  for subset in subsets:
40
  dataset = load_dataset(
41
+ "LeMaterial/LeMat-Bulk",
42
  subset,
43
  token=HF_TOKEN,
44
  columns=[
 
52
  "functional",
53
  ],
54
  )
55
+ subsets_ds[subset] = dataset["train"]
56
 
57
+ elements_df = {
58
+ k: subset.select_columns("elements").to_pandas() for k, subset in subsets_ds.items()
59
+ }
60
 
61
+ from scipy.sparse import csr_matrix
62
 
63
  all_elements = {str(el): i for i, el in enumerate(periodictable.elements)}
64
  elements_indices = {}
 
73
 
74
  df = df.reset_index().apply(map_elements, axis=1)
75
 
76
+ import ipdb
77
+
78
+ ipdb.set_trace()
79
+
80
+ elements_indices[subset] = csr_matrix(elements_indices[subset])
81
+
82
  map_functional = {
83
  "PBE": "compatible_pbe",
84
  "PBESol (No correction scheme)": "compatible_pbesol",
 
117
 
118
  print(indices_with_only_elements)
119
 
120
+ entries_df = subsets_ds[subset_name].select(indices_with_only_elements).to_pandas()
121
 
122
  entries_df = entries_df[~entries_df["immutable_id"].isna()]
123
 
 
125
 
126
  # Fetch all entries from the Materials Project database
127
  def get_energy_correction(energy_correction, row):
128
+ if energy_correction == "Database specific, or MP2020" and functional == "PBE":
129
+ print("applying MP corrections")
130
  return (
131
  row["energy_corrected"] - row["energy"]
132
  if not np.isnan(row["energy_corrected"])
133
  else 0
134
  )
135
+ elif energy_correction == "The 110 PBE Method" and functional == "PBE":
136
+ print("applying PBE110 corrections")
137
+ return row["energy"] * 1.1 - row["energy"]
138
+ elif map_functional[functional] != "pbe":
139
+ print("not applying any corrections")
140
  return 0
141
 
142
  entries = [
 
208
  label="Energy correction",
209
  )
210
  plot_style_dropdown = gr.Dropdown(choices=["2D", "3D"], label="Plot Style")
211
+ functional_dropdown = gr.Dropdown(
212
+ choices=["PBE", "PBESol (No correction scheme)", "SCAN (No correction scheme)"],
213
+ label="Functional",
214
+ )
215
  finite_temp_toggle = gr.Checkbox(label="Enable Finite Temperature Estimation")
216
 
217
  warning_message = "⚠️ This application uses energy correction schemes directly"