Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First draft of fast featurizer preset and fix initial scripts #12

Merged
merged 6 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion experiments/1_ingesting_refractive_index/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pandas
optimade[http_client]
optimade[http-client]
tqdm
11 changes: 10 additions & 1 deletion experiments/1_ingesting_refractive_index/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

data_path = Path(__file__).parent.parent / "data"
db_path = data_path / "db.csv"
structures_path = data_path / "structures.json"
structures_path = data_path / "structures-2024.json"

if not db_path.exists():
import urllib.request
Expand All @@ -42,6 +42,9 @@
continue

filter_ = f'id = "{mp_id}"'
structure = {}
structure["attributes"] = {}


try:
# redirect output from stdout to dev null
Expand All @@ -51,6 +54,12 @@
]["data"][0]
except Exception:
print(f"No structure found for {mp_id}")
continue

if structure["id"] != mp_id:
print(f"Structure ID {structure['id']} does not match MP ID {mp_id}")
continue

structure["attributes"]["_naccarato_refractive_index"] = np.mean(
[
row["Ref_index (1)"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
modnet==0.2.1
optimade
optimade~=0.25
matminer==0.8.0
pymatgen==2023.9.2
ruamel.yaml<0.18
66 changes: 40 additions & 26 deletions experiments/2_featurizing_refractive_index_data/run.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
import json
from pathlib import Path
from modnet.featurizers.presets import Matminer2023Featurizer

import tqdm
from modnet.preprocessing import MODData
from optimade.adapters import Structure
from optimade.models.utils import reduce_formula

N_CPU = 6

data_path = Path(__file__).absolute().parent.parent / "data"
db_path = data_path / "db.csv"
structures_path = data_path / "structures.json"


with open(structures_path) as f:
structures = json.load(f)
structures_path = data_path / "structures-2024.json"
moddata_path = Path("./mod.data")
feature_selected_path = Path("./mod-feature-selected.data")

if not moddata_path.exists():

with open(structures_path) as f:
structures = json.load(f)

pmg_structures = []
targets = []

for ind, s in tqdm.tqdm(enumerate(structures.items())):
s[1]["attributes"]["chemical_formula_reduced"] = reduce_formula(
s[1]["attributes"]["chemical_formula_reduced"]
)
targets.append(
s[1]["attributes"]["_naccarato_refractive_index"],
)
if s[0] == "mp-505722":
breakpoint()
pmg_structures.append(Structure(s[1]).as_pymatgen)

moddata = MODData(
materials=pmg_structures,
targets=targets,
featurizer=Matminer2023Featurizer(fast_oxid=True),
target_names=["refractive_index"],
structure_ids=structures.keys(),
)
moddata.featurizer.featurizer_mode = "single"
moddata.featurize(n_jobs=N_CPU)

pmg_structures = []
targets = []
moddata.save("mod.data")

for ind, s in tqdm.tqdm(enumerate(structures.items())):
s[1]["attributes"]["chemical_formula_reduced"] = reduce_formula(
s[1]["attributes"]["chemical_formula_reduced"]
)
targets.append(
s[1]["attributes"]["_naccarato_refractive_index"],
)
pmg_structures.append(Structure(s[1]).as_pymatgen)

moddata = MODData(
materials=pmg_structures,
targets=targets,
target_names=["refractive_index"],
structure_ids=structures.keys(),
)
moddata.featurizer.featurizer_mode = "single"
moddata.featurize(n_jobs=6)

moddata.save("mod.data")
if not feature_selected_path.exists():
moddata = MODData.load("mod.data")
moddata.feature_selection(n=-1, n_jobs=N_CPU)
moddata.save("mod-feature-selected.data")
4 changes: 3 additions & 1 deletion experiments/7_scraping_other_databases/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
optimade[http-client]~=1.0
optimade[http-client]<1.0
modnet
pymatgen==2023.9.2
Loading
Loading