Download a subset from MOFDB and Quick Cluster

In this tutorial, we see how to download a subset of structures from the MOFDB database using a wrapper function in mofography. MOFDB is a large database of nanoporous materials, including MOFs and zeolites that is hosted by Northwestern University. https://mof.tech.northwestern.edu/

For a lot of the materials workflows, it is very convenient to have a subset of structures to be used as a starting point, and to be saved as a pandas dataframe, that some of the textural properties of the material along with its crystallographic information. However, downloading large datasets can be cumbersome. Hence, mofography provides a wrapper that can do this asynchronously, meaning, the pages and pages of your search results will be downloaded in parallel, saving a lot of time. Note that at the time of writing, MOFDB itself has a python API that does this, https://github.com/n8ta/mofdb-client, the comparison of speeds of the two codes is not tested, but you are welcome to test it out as well.

Note that in order to avoid excessive strain on the MOFDB website, it is recommended you save the downloaded dataset locally (we will show this at the end) instead of downloading it every time.

Once we have the dataset, we can create ASE atoms objects from it, pick one or more at random and perform a mofography workflo. In this example, we simply perform the quick cluster workflow, but feel free to build one of your own. If you don’t remember what the Quick Cluster workflow does, please go check out the Quick Cluster notebook in the tutorials.

Set paths and import mofography

Show code
import mofography as mgr

Now grabbing data from MOFDB using mofography is very easy. There are many options by which you can filter the data, you can find them here: https://mof.tech.northwestern.edu/api

As an example, let’s download all the materials with void fraction between 0.7 and 0.8, and with a largest cavity diameter between 12 and 13 angstroms from the CoREMOF-2019 database. Granted this is only small subset, selected purely for demonstration purposes. It takes about 4 mins on a regular day with this set of parameters

Show code
# get_data_from_mofdb is async: it must be awaited (top-level await in a notebook,
# asyncio.run(...) in a script)
df = await mgr.get_data_from_mofdb(params={'vf_min': 0.7, 'vf_max': 0.75, 'lcd_min': 12, 'lcd_max': 14, 'database': 'CoREMOF 2019'})


Let’s look at the first few rows of this dataframe

Show code
df.head(10)
id mofid mofkey hashkey name void_fraction surface_area_m2g surface_area_m2cm3 pld lcd ... pore_size_distribution database batch_number elements cif url adsorbates heats isotherms mofdb_version
0 173921 None None c83f3cb36e0bdad5ead5471ad8a1b89225c7fb6f5504e1... acs.inorgchem.6b02413_ic6b02413_si_002_clean 0.7400 2730.07 2195.74 6.88163 13.3773 ... None CoREMOF 2019 41 [] data_image0\n_cell_length_a 27.546\n_cel... /mofs/173921.json [{'id': 80, 'InChIKey': 'IJGRMHOSHXDMSA-UHFFFA... [] [{'batch_number': 41, 'adsorbates': [{'id': 80... dc8a0295db
1 173987 None None 79e851559c2af43b378a63b4b468ccadf6804dd517e3d2... AGABIU_clean 0.7402 2773.67 1794.91 10.82740 12.5710 ... None CoREMOF 2019 41 [] data_image0\n_cell_length_a 18.605\n_cel... /mofs/173987.json [{'id': 80, 'InChIKey': 'IJGRMHOSHXDMSA-UHFFFA... [] [{'batch_number': 41, 'adsorbates': [{'id': 80... dc8a0295db
2 174106 None None 70afd8ccd600fd030504ce0c97919d5110cebead9459fa... ANOMOG_clean 0.7198 2698.05 2116.78 5.50166 12.8003 ... None CoREMOF 2019 41 [] data_image0\n_cell_length_a 32.461\n_cel... /mofs/174106.json [{'id': 80, 'InChIKey': 'IJGRMHOSHXDMSA-UHFFFA... [] [{'batch_number': 41, 'adsorbates': [{'id': 80... dc8a0295db
3 174196 None None 29a7e26bd38915ad1c147d2088d54906bffb579ec86021... ASINEX_clean 0.7014 2801.34 1848.81 7.27061 12.5357 ... None CoREMOF 2019 41 [] data_image0\n_cell_length_a 74.91\n_cell... /mofs/174196.json [{'id': 80, 'InChIKey': 'IJGRMHOSHXDMSA-UHFFFA... [] [{'batch_number': 41, 'adsorbates': [{'id': 80... dc8a0295db
4 174197 None None e2eb2e4b54ff5bc14d64019746578c77fe71402d8a8eaa... ASINIB_clean 0.7130 2773.85 1847.56 7.22634 12.4005 ... None CoREMOF 2019 41 [] data_image0\n_cell_length_a 75.033\n_cel... /mofs/174197.json [{'id': 80, 'InChIKey': 'IJGRMHOSHXDMSA-UHFFFA... [] [{'batch_number': 41, 'adsorbates': [{'id': 80... dc8a0295db
5 174278 None None 5842c228d724798a90bc4599997bd3d766e1f4a42995c9... AVIVUW_clean 0.7162 2491.03 1817.90 6.91892 12.0408 ... None CoREMOF 2019 41 [] data_image0\n_cell_length_a 22.963\n_cel... /mofs/174278.json [{'id': 80, 'InChIKey': 'IJGRMHOSHXDMSA-UHFFFA... [] [{'batch_number': 41, 'adsorbates': [{'id': 80... dc8a0295db
6 174294 None None c2eeca1b812f60d10f8e08b7e6d31126b754d4039c9c76... AWASEY_clean 0.7186 1646.54 1906.22 7.26209 12.0509 ... None CoREMOF 2019 41 [] data_image0\n_cell_length_a 30.332\n_cel... /mofs/174294.json [{'id': 80, 'InChIKey': 'IJGRMHOSHXDMSA-UHFFFA... [] [{'batch_number': 41, 'adsorbates': [{'id': 80... dc8a0295db
7 174429 None None 594e605ccc2636780d8a4d1047ec910d12c302481211a5... BAZJET_clean 0.7420 3450.50 2143.77 12.10120 13.3702 ... None CoREMOF 2019 41 [] data_BAZJET_clean\n_audit_creation_date ... /mofs/174429.json [{'id': 80, 'InChIKey': 'IJGRMHOSHXDMSA-UHFFFA... [] [{'batch_number': 41, 'adsorbates': [{'id': 80... dc8a0295db
8 174549 None None 2e72bfca4ff457bde255581761a55cc102f95820e003f4... BINCUY_manual 0.7246 3760.71 2196.14 8.62623 13.3117 ... None CoREMOF 2019 41 [] data_BINCUY_clean_b\n_audit_creation_date ... /mofs/174549.json [{'id': 80, 'InChIKey': 'IJGRMHOSHXDMSA-UHFFFA... [] [{'batch_number': 41, 'adsorbates': [{'id': 80... dc8a0295db
9 174550 None None 47936b6cf988f16f2f51b47970dad99122035c3190cd0d... BINDAF_manual 0.7212 3638.73 2185.42 8.49712 13.1432 ... None CoREMOF 2019 41 [] data_BINDAF_clean_b\n_audit_creation_date ... /mofs/174550.json [{'id': 80, 'InChIKey': 'IJGRMHOSHXDMSA-UHFFFA... [] [{'batch_number': 41, 'adsorbates': [{'id': 80... dc8a0295db

10 rows × 21 columns

Show code
df.columns
Index(['id', 'mofid', 'mofkey', 'hashkey', 'name', 'void_fraction',
       'surface_area_m2g', 'surface_area_m2cm3', 'pld', 'lcd', 'pxrd',
       'pore_size_distribution', 'database', 'batch_number', 'elements', 'cif',
       'url', 'adsorbates', 'heats', 'isotherms', 'mofdb_version'],
      dtype='object')

Write dataset to file

Since what you have is a pandas dataframe, you can save it to a file for the future, using any of thre pandas write functions. For example, to save as a feather file use the following code

Show code

# df.to_feather('mofdb_data.feather')

Create ASE atoms objects

Since all the calculations in mofography start with an ASE atoms, object, let’s convert make a list of ASE atoms objects for all the materiasl in this dataframe.

Show code
atoms_list = mgr.atoms_from_mofdb_df(df)

We can now do a workflow on one or more of this atoms objects, parallelize them whichever way we want and whatnot. Let’s save that for another tutorial. For the time being, let’s just pick one at random and run the quick cluster workflow on it and visualize

If you don’t remember what the quick cluster workflow does, pleae go back and refer to the Quick Cluster notebook in the docs.

Show code
import random 
index = random.randint(0,len(atoms_list)-1)
mat_atoms = atoms_list[index]
mat_updated = mgr.update_with_covalent_bonds(mat_atoms)

Let’s see what we chose

Show code
df.loc[index]
id                                                                   179343
mofid                                                                  None
mofkey                                                                 None
hashkey                   c04fb14ffad3d21bd199eb7faed1c0d1d9dee9ebf3de0b...
name                                                           LUDLIH_clean
void_fraction                                                        0.7124
surface_area_m2g                                                    2404.81
surface_area_m2cm3                                                  2107.58
pld                                                                 6.67449
lcd                                                                 13.2324
pxrd                                                                   None
pore_size_distribution                                                 None
database                                                       CoREMOF 2019
batch_number                                                             41
elements                                                                 []
cif                       data_image0\n_cell_length_a       26.37\n_cell...
url                                                       /mofs/179343.json
adsorbates                [{'id': 80, 'InChIKey': 'IJGRMHOSHXDMSA-UHFFFA...
heats                                                                    []
isotherms                 [{'batch_number': 41, 'adsorbates': [{'id': 80...
mofdb_version                                                    dc8a0295db
Name: 56, dtype: object

Segment the pore space

Now run the standard workflow from the Quick start on this atoms object: distance grid, periodic segmentation, then plot.

Show code
import numpy as np
spacing = 0.5
dgrid = mgr.dgrid_from_atoms_rust(mat_atoms, spacing=spacing).astype(np.float32)
seg = mgr.do_periodic_segmentation_rust(
    dgrid, mat_atoms, spacing=spacing,
    mask_thickness=0.05, h=0.2, min_distance=1.5, threshold_abs=1.5,
    compute_connections=True, return_dgrid=True, disable_tqdm=True,
)
print(f"Pockets (PBC-merged): {len(seg['maxima_pbc'])}")

Let’s visualize the result. Change the ‘renderer’ to ‘notebook_connected’ for an interactive plot in the notebook, or to ‘browser’ for a browser tab.

Show code
fig = mgr.show_mof_plotly(seg, mat_atoms, stylize=True)
fig.show(renderer='png')