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

Update MOF processing script #8

Closed
Andrew-S-Rosen opened this issue Dec 9, 2021 · 1 comment
Closed

Update MOF processing script #8

Andrew-S-Rosen opened this issue Dec 9, 2021 · 1 comment

Comments

@Andrew-S-Rosen
Copy link

Hey @vxfung, could you update the process.py script for the QMOF Database? I'm changing how the data is structured going forward to better accommodate multiple levels of theory. This script below should work for the future versions while also being backwards compatible with several prior versions of the database.

import os
import csv
import json
import pandas as pd
from pymatgen.core import Structure
from pymatgen.io.ase import AseAtomsAdaptor
from ase.io import write

# Read in QMOF data
with open("qmof.json") as f:
    qmof = json.load(f)
qmof_df = pd.json_normalize(qmof).set_index("qmof_id")

with open("qmof_structure_data.json") as f:
    qmof_struct_data = json.load(f)

# Make MOF_data folder
if not os.path.exists("MOF_data"):
    os.mkdir("MOF_data")

# Write out data
targets = []
for entry in qmof_struct_data:
    qmof_id = entry["qmof_id"]
    print(f"Writing {qmof_id}")
    mof = AseAtomsAdaptor().get_atoms(Structure.from_dict(entry["structure"]))
    write(os.path.join("MOF_data", f"{qmof_id}.json"), mof)
    targets.append([qmof_id, qmof_df.loc[qmof_id]["outputs.pbe.bandgap"]])

with open(os.path.join("MOF_data", "targets.csv"), "w", newline="") as f:
    wr = csv.writer(f)
    wr.writerows(targets)

print(len(targets))

Closes #1 and #7.

@vxfung
Copy link
Collaborator

vxfung commented Dec 9, 2021

Thanks, updated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants