text: from pymatgen.ext.matproj import MPRester
  import re
  from pymatgen.io.cif import CifWriter
  import numpy as np
  
  
  class CifDownload:
      def __init__(self):
          # self.mp_rest_obj = MPRester("pc0rARlba5Ae3SArM09")
          self.mp_rest_obj = MPRester("OnQDHiVv3hzqx6p2")
  
      def to_cif(self, id):
          id = 'mp-' + str(id)
          conventional_structure = self.mp_rest_obj.get_structure_by_material_id(id,
                                                                                 conventional_unit_cell=True)
          # conventional_structure = self.mp_rest_obj.get_structure_by_material_id(id)
  
          cif_writer_obj = CifWriter(conventional_structure, write_magmoms=True)
          material = re.findall('Full\sFormula\s(.*?)\n', str(conventional_structure))[0].lstrip('(').rstrip(')')
          name = material + "-" + str(id)
          cif_writer_obj.write_file(r'../data/conventional_cell/{}.cif'.format(name))
  
  
  if __name__ == '__main__':
      cif_download_obj = CifDownload()
      # 324854
      for i in range(324854, 350000):
          try:
              cif_download_obj.to_cif(i)
              print(i)
          except Exception as e:
              # ...
              print(e)
  