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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| from pymatgen.core.periodic_table import get_el_sp from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from pymatgen import Structure from qmpy import Entry
def run_one(a): """ Take one OQMD 'Entry' object, search all the calculations associated and take the best calculation in order to insert its data into the PyChemia Database
:param a: OQMD Entry object :return: """ energy = 1E10 try: select=a.c['static'] if len(select.errors)>0: select=None except: select = None if select is None: return None, None band_gap = select.band_gap if band_gap is None: return None, None
cell = select.output.cell elements = select.output.atomic_numbers reduced = select.output.coords
structure = Structure(cell, elements, reduced) structure_id = select.output_id entry_id = a.id calculation_id = select.id
energy = select.energy
try: spacegroup_number = select.output.spacegroup.number except ValueError: spacegroup_number = None
symm = SpacegroupAnalyzer(structure) sym2 = symm.get_space_group_number()
properties = {'oqmd': {'structure_id': structure_id, 'entry_id': entry_id, 'calculation_id': calculation_id, 'energy': energy, 'band_gap': band_gap,
'spacegroup_number': spacegroup_number}, 'spacegroup_number': {'value': sym2, 'symprec': 1E-2}}
return structure, properties
if __name__=="__main__": import json import time icount=32004 queryset = Entry.objects.all() entry_ids = [entry.id for entry in queryset] print('Number of entries in OQMD: %d' % len(entry_ids)) for entry_id in entry_ids[51331:]: try: a = Entry.objects.get(id=entry_id) st,pr=run_one(a) if st is not None and pr is not None: icount+=1 fname="ustc-"+str(icount)+'.json' new_dict={'structure':{'cell':st.lattice.matrix.tolist(),'species':[x.symbol for x in st.species],'coords':st.frac_coords.tolist()},'properties':pr}
with open('./data/'+fname,'w') as f: json.dump(new_dict,f) if icount%1000==0: print("number %d"%(icount)) time.sleep(5) except: pass
|