Esempio n. 1
0
 def compile(self):
     """compile phase (calculation from MAST DiffusionCoefficient.py)"""
     from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
     from pymatgen.matproj.rest import MPRester
     indirs = glob.glob(os.path.join(self.rootdir, "*CuCu*")) + [
         fn for fn in glob.glob(os.path.join(self.rootdir, "*Cu*"))
         if not fnmatch.fnmatch(fn, "*CuCu*")
     ]
     mp_id, E0, nw = None, None, 5  # five-frequency model
     df = None
     for idx, indir in enumerate(indirs):
         element = os.path.basename(indir).split('_')[2][2:]
         struct = self.find_entry_for_directory(os.path.join(
             indir, 'perfect_stat*'),
                                                oszicar=False).structure
         reduced = SpacegroupAnalyzer(
             struct, symprec=1e-2).get_primitive_standard_structure()
         if idx == 0:
             ENDPOINT = "https://www.materialsproject.org/rest"
             with MPRester(endpoint=ENDPOINT) as m:
                 matches = m.find_structure(reduced)
                 if len(matches) == 1: mp_id = matches[0]
                 else:
                     raise ValueError(
                         "found {} matching structure(s) in MP and hence cannot "
                         "assign structure in {}.".format(
                             len(matches), indir))
         a = reduced.lattice.abc[0] * math.sqrt(2) * 10**(-8)
         enebarr = np.array([self.get_barrier(indir, i) for i in range(nw)],
                            dtype=float)
         if idx == 0: E0 = min(enebarr[~np.isnan(enebarr)])
         else: enebarr[0] = E0  # TODO: is this correct?
         v = np.array(
             [self.get_attempt_frequency(indir, i) for i in range(nw)])
         v[0], HVf, kB, f0 = 1.0, 0.4847, 8.6173324e-5, 0.7815  # TODO set v[0] to 1.0? HVf dynamic how?
         t, tempstep, tempend = 0.0, 0.1, 2.0  # default temperature range
         x, y = [], []
         while t < tempend + tempstep:
             v *= np.exp(-enebarr / kB / 1e3 * t)
             alpha = v[4] / v[0]
             F_num = 10 * np.power(alpha, 4) + 180.5 * np.power(alpha, 3)
             F_num += 927 * np.power(alpha, 2) + 1341 * alpha
             F_denom = 2 * np.power(alpha, 4) + 40.2 * np.power(alpha, 3)
             F_denom += 254 * np.power(alpha, 2) + 597 * alpha + 435
             FX = 1 - (1.0 / 7.0) * (F_num / F_denom)
             f2 = 1 + 3.5 * FX * (v[3] / v[1])
             f2 /= 1 + (v[2] / v[1]) + 3.5 * FX * (v[3] / v[1])
             cV = np.exp(-HVf / kB / 1e3 * t) if t > 0. else 1.
             D = f0 * cV * a**2 * v[0] * f2 / f0 * v[4] / v[0] * v[2] / v[3]
             x.append(t)
             y.append(D)
             t += tempstep
         if df is None: df = DataFrame(np.array(x), columns=['1/T'])
         df.loc[:, element] = Series(np.array(y), index=df.index)
     #  generate (physical) MPFile
     mpfile = MPFile()
     mpfile.add_data_table(mp_id, df, 'data')
     #print mpfile
     mpfile.write_file(os.path.join(self.rootdir, 'output.mpf'))
Esempio n. 2
0
 def compile(self):
     """compile phase (calculation from MAST DiffusionCoefficient.py)"""
     from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
     from pymatgen.matproj.rest import MPRester
     indirs = glob.glob(os.path.join(self.rootdir, "*CuCu*")) + [
         fn for fn in glob.glob(os.path.join(self.rootdir, "*Cu*"))
         if not fnmatch.fnmatch(fn, "*CuCu*")
     ]
     mp_id, E0, nw = None, None, 5 # five-frequency model
     df = None
     for idx,indir in enumerate(indirs):
         element = os.path.basename(indir).split('_')[2][2:]
         struct = self.find_entry_for_directory(
             os.path.join(indir, 'perfect_stat*'), oszicar=False
         ).structure
         reduced = SpacegroupAnalyzer(struct, symprec=1e-2).get_primitive_standard_structure()
         if idx == 0:
             ENDPOINT = "https://www.materialsproject.org/rest"
             with MPRester(endpoint=ENDPOINT) as m:
                 matches = m.find_structure(reduced)
                 if len(matches) == 1: mp_id = matches[0]
                 else: raise ValueError(
                     "found {} matching structure(s) in MP and hence cannot "
                     "assign structure in {}.".format(len(matches), indir)
                 )
         a = reduced.lattice.abc[0] * math.sqrt(2) * 10**(-8)
         enebarr = np.array([ self.get_barrier(indir, i) for i in range(nw) ], dtype=float)
         if idx == 0: E0 = min(enebarr[~np.isnan(enebarr)])
         else: enebarr[0] = E0 # TODO: is this correct?
         v = np.array([ self.get_attempt_frequency(indir, i) for i in range(nw) ])
         v[0], HVf, kB, f0 = 1.0, 0.4847, 8.6173324e-5, 0.7815 # TODO set v[0] to 1.0? HVf dynamic how?
         t, tempstep, tempend = 0.0, 0.1, 2.0 # default temperature range
         x, y = [], []
         while t < tempend + tempstep:
             v *= np.exp(-enebarr/kB/1e3*t)
             alpha = v[4]/v[0]
             F_num = 10*np.power(alpha,4) + 180.5*np.power(alpha,3)
             F_num += 927*np.power(alpha,2) + 1341*alpha
             F_denom = 2*np.power(alpha,4) + 40.2*np.power(alpha,3)
             F_denom += 254*np.power(alpha,2) + 597*alpha + 435
             FX = 1-(1.0/7.0)*(F_num/F_denom)
             f2 = 1+3.5*FX*(v[3]/v[1])
             f2 /= 1+(v[2]/v[1]) + 3.5*FX*(v[3]/v[1])
             cV = np.exp(-HVf/kB/1e3*t) if t > 0. else 1.
             D = f0*cV*a**2*v[0] * f2/f0 * v[4]/v[0] * v[2]/v[3]
             x.append(t)
             y.append(D)
             t += tempstep
         if df is None: df = DataFrame(np.array(x), columns=['1/T'])
         df.loc[:,element] = Series(np.array(y), index=df.index)
     #  generate (physical) MPFile
     mpfile = MPFile()
     mpfile.add_data_table(mp_id, df, 'data')
     #print mpfile
     mpfile.write_file(os.path.join(self.rootdir, 'output.mpf'))
            columns_v = ["Hop attempt frequency, v_a [THz]"
                         ] + ["Hop attempt frequency, v_X [THz]"]
            df_v = df[["Solute element name"] + columns_v]
            df_v.columns = ["Solute"] + ["vₐ [THz]"] + ["vₓ [THz]"]
            mpfile.add_data_table(mpid, df_v, "hop_attempt_frequencies")

    print("DONE")


mpfile = MPFile()
mpfile.max_contribs = 15
run(mpfile)
print(mpfile)

filename = f"{project}.txt"
mpfile.write_file(filename=filename)
mpfile = MPFile.from_file(filename)
print(len(mpfile.ids))

table_names = ["D₀_Q", "hop_activation_barriers", "hop_attempt_frequencies"]

for idx, (identifier, content) in enumerate(mpfile.document.items()):
    # doc = {'identifier': identifier, 'project': project, 'content': {}}
    # doc['content']['data'] = content['data']
    # doc['collaborators'] = [{'name': 'Patrick Huck', 'email': '*****@*****.**'}]
    # r = db.contributions.insert_one(doc)
    # cid = r.inserted_id
    # print(idx, ':', cid)

    # tids = []
    # for name in table_names: