-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDownload_CIFS.py
46 lines (35 loc) · 1.4 KB
/
Download_CIFS.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# from pymatgen.core.structure import Structure
import pandas as pd
import tqdm
import os
ids_df = pd.read_csv('database/targets_MEGNet_2018.csv')
print(ids_df)
ids = ids_df['id'].to_list()
print(len(ids))
folder = "database/cif"
filenames = os.listdir(folder)
filenames_without_extension = [os.path.splitext(f)[0] for f in filenames]
folder_set = set(filenames_without_extension)
ids_set = set(ids)
result = list(ids_set - folder_set)
print(result)
print(len(result))
#FOR NEW MPRester API
# from mp_api.client import MPRester
# with MPRester("42J8zZHSxx98mcKn0EucWVjKZPETd9ia") as mpr:
# # docs = mpr.summary.search(material_ids=["mp-31369"], fields=['material_id', 'pretty_formula', 'structure'])
# docs = mpr.summary.search(material_ids=result, fields=['material_id', 'structure'])
#
# for doc in docs:
# mat_id = doc.material_id
# structure = doc.structure
# structure.to(filename=f'database/cif/{mat_id}.cif', fmt='cif')
# print(f"structure for {mat_id} saved")
# FOR OLD MPRester API
from pymatgen.ext.matproj import MPRester ## to access MP database
with MPRester("gCZ2GADLIPQQRNXUejPT") as mpr:
docs = mpr.query(criteria={"material_id": {"$in": result}}, properties=["material_id", "structure"])
for doc in docs:
structure = doc['structure']
structure.to(filename='database/cif/' + doc['material_id'] + '.cif', fmt='cif')
print(f"structure for {doc['material_id']} saved")