OQMD 材料数据库结构查询


TOC

以下是OQMD数据库用法的简单说明,关于更详细的新特性了解,可参考这里

  • 介绍(introductions)
  • 使用(useage)
  • 其它(others)

1. 介绍

OQMD 数据库是由美国西北大学的Chris Wolverton组维护开发的材料数据库,总共有 815,654 条材料数据记录,包括了通过DFT计算的材料的热力学和结构信息. 该数据库为MySQL关系型数据库,可以自由下载和使用,通过qmpy可以很方便的进行数据查询。

2. 使用

在调用OQMD数据库时,可以通过qmpy对结构进行查找,再用pymatgen对查找到的结构进行分析后处理。

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:
    """
    #print('Entry: %6d  Number of Calculations: %3d ' % (a.id, a.calculation_set.count()))
    #print('Entry: %6d  Number of Calculations: %3d  Energies: %s' % (a.id, a.calculation_set.count(),
    #                                                                 str([c.energy for c in a.calculation_set.all()])))
    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_pa = select.energy_pa
    energy = select.energy
#    settings = select.settings
    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,
#                           'settings': settings,
                           '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))
  #  print(entry_ids[1:1000])
  #  quit()
    for entry_id in entry_ids[51331:]:
  #      entry_id=entry_ids[0]
        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'
              #print('-'*40)
              #print(st.formula)
              #print(pr['oqmd']['band_gap'])
              new_dict={'structure':{'cell':st.lattice.matrix.tolist(),'species':[x.symbol for x in st.species],'coords':st.frac_coords.tolist()},'properties':pr}
#              new_dict={'structure':st.as_dict(),'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

文章作者: ustc-haidi
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 ustc-haidi !
  目录