Ejemplo n.º 1
0
 def test_compound_operations(self):
     g = 10 * Length(1, "m") / (Time(1, "s") ** 2)
     e = Mass(1, "kg") * g * Length(1, "m")
     self.assertEqual(str(e), "10.0 N m")
     form_e = FloatWithUnit(10, unit="kJ mol^-1")
     self.assertEqual(str(form_e.to("eV atom^-1")), "0.103642691905 eV atom^-1")
     self.assertRaises(UnitError, form_e.to, "m s^-1")
     a = FloatWithUnit(1.0, "Ha^3")
     self.assertEqual(str(a.to("J^3")), "8.28672661615e-53 J^3")
     a = FloatWithUnit(1.0, "Ha bohr^-2")
     self.assertEqual(str(a.to("J m^-2")), "1556.89291457 J m^-2")
Ejemplo n.º 2
0
 def test_compound_operations(self):
     g = 10 * Length(1, "m") / (Time(1, "s")**2)
     e = Mass(1, "kg") * g * Length(1, "m")
     self.assertEqual(str(e), "10.0 N m")
     form_e = FloatWithUnit(10, unit="kJ mol^-1").to("eV atom^-1")
     self.assertAlmostEqual(float(form_e), 0.103642691905)
     self.assertEqual(str(form_e.unit), "eV atom^-1")
     self.assertRaises(UnitError, form_e.to, "m s^-1")
     a = FloatWithUnit(1.0, "Ha^3")
     b = a.to("J^3")
     self.assertAlmostEqual(b, 8.28672661615e-53)
     self.assertEqual(str(b.unit), "J^3")
     a = FloatWithUnit(1.0, "Ha bohr^-2")
     b = a.to("J m^-2")
     self.assertAlmostEqual(b, 1556.893078472351)
     self.assertEqual(str(b.unit), "J m^-2")
Ejemplo n.º 3
0
 def test_compound_operations(self):
     g = 10 * Length(1, "m") / (Time(1, "s") ** 2)
     e = Mass(1, "kg") * g * Length(1, "m")
     self.assertEqual(str(e), "10.0 N m")
     form_e = FloatWithUnit(10, unit="kJ mol^-1").to("eV atom^-1")
     self.assertAlmostEqual(float(form_e), 0.103642691905)
     self.assertEqual(str(form_e.unit), "eV atom^-1")
     self.assertRaises(UnitError, form_e.to, "m s^-1")
     a = FloatWithUnit(1.0, "Ha^3")
     b = a.to("J^3")
     self.assertAlmostEqual(b, 8.28672661615e-53)
     self.assertEqual(str(b.unit), "J^3")
     a = FloatWithUnit(1.0, "Ha bohr^-2")
     b = a.to("J m^-2")
     self.assertAlmostEqual(b, 1556.893078472351)
     self.assertEqual(str(b.unit), "J m^-2")
Ejemplo n.º 4
0
    print(error)
    exit()

# print stable_result.name, phase.get_form_energy(stable_result)
(compo,
 factor) = stable_result.composition.get_reduced_composition_and_factor()
form_energy[stable_result.name] = phase.get_form_energy(stable_result) / factor

reaction = ComputedReaction(stable_formula, [stable_result])
energy = FloatWithUnit(reaction.calculated_reaction_energy, "eV atom^-1")

json_result = dict()
json_result["reaction"] = str(reaction)

value1 = dict()
value1["value"] = energy.to("kJ mol^-1")
value1["unit"] = "kJ mol^-1"

value2 = dict()
value2["value"] = energy.to("eV atom^-1")
value2["unit"] = "eV"

json_result["value1"] = value1
json_result["value2"] = value2
json_result["formationenergy"] = form_energy

final_dir = output_path + "/" + "output.json"
print(final_dir)
with open(final_dir, 'w') as outfile:
    json.dump(json_result, outfile)
Ejemplo n.º 5
0
def find_theo_redenth(compstr):
    """
    Finds theoretical redox enthalpies from the Materials Project from perovskite to brownmillerite
    based partially on https://github.com/materialsproject/pymatgen/blob/b3e972e293885c5b3c69fb3e9aa55287869d4d84/
    examples/Calculating%20Reaction%20Energies%20with%20the%20Materials%20API.ipynb

    :param compstr: composition as a string

    :return:
    red_enth:  redox enthalpy in kJ/mol O
    """
    compstr_perovskite = compstr.split("O")[0] + "O3"

    comp_spl = split_comp(compstr)
    chem_sys = ""
    for i in range(len(comp_spl)):
        if comp_spl[i] is not None:
            chem_sys = chem_sys + comp_spl[i][0] + "-"
    chem_sys = chem_sys + "O"
    chem_sys = chem_sys.split("-")

    all_entries = mpr.get_entries_in_chemsys(chem_sys)

    # This method simply gets the lowest energy entry for all entries with the same composition.
    def get_most_stable_entry(formula):
        relevant_entries = [entry for entry in all_entries if
        entry.composition.reduced_formula == Composition(formula).reduced_formula]
        relevant_entries = sorted(relevant_entries, key=lambda e: e.energy_per_atom)
        return relevant_entries[0]

    formula_spl = [''.join(g) for _, g in groupby(str(compstr), str.isalpha)]
    perov_formula = []
    for k in range(len(formula_spl)):
        try:
            perov_formula += str(int(float(formula_spl[k]) * 8))
        except ValueError:
            perov_formula += str(formula_spl[k])
    perov_formula = "".join(perov_formula)
    perov_formula = str(perov_formula).split("O")[0] + "O24"
    perovskite = get_most_stable_entry(perov_formula)

    brownm_formula = []
    for k in range(len(formula_spl)):
        try:
            brownm_formula += str(int(float(formula_spl[k]) * 32))
        except ValueError:
            brownm_formula += str(formula_spl[k])
    brownm_formula = "".join(brownm_formula)
    brownm_formula = str(brownm_formula).split("O")[0] + "O80"
    brownmillerite = get_most_stable_entry(brownm_formula)

    # for oxygen: do not use the most stable phase O8 but the most stable O2 phase
    def get_oxygen():
        relevant_entries = [entry for entry in all_entries if
        entry.composition == Composition("O2")]
        relevant_entries = sorted(relevant_entries, key=lambda e: e.energy_per_atom)
        return relevant_entries[0]

    oxygen = get_oxygen()

    reaction = ComputedReaction([perovskite], [brownmillerite, oxygen])
    energy = FloatWithUnit(reaction.calculated_reaction_energy, "eV atom^-1")

    # figure out the stoichiometry of O2 in the reaction equation in order to normalize the energies per mol of O
    try:
        o_stoich = float(str(str(reaction.as_dict).split(" O2")[0]).split()[-1])
    except ValueError:
        o_stoich = 1
    # energy in J/mol per mol of O2
    ener = (float(energy.to("kJ mol^-1")) * 1000) / o_stoich
    # per mol of O
    ener = ener / 2

    return ener
    relevant_entries = sorted(relevant_entries,
                              key=lambda e: e.energy_per_atom)
    return relevant_entries[0]


CaO = get_most_stable_entry("CaO")
CO2 = get_most_stable_entry("CO2")
CaCO3 = get_most_stable_entry("CaCO3")

reaction = ComputedReaction([CaO, CO2], [CaCO3])  #得到化学反应
energy = FloatWithUnit(reaction.calculated_reaction_energy,
                       "eV atom^-1")  #计算化学反应的能量,并且转换单位

print("Caculated")
print(reaction)
print("Reaction energy = {}".format(energy.to("kJ mol^-1")))

# The following portions demonstrate how to get the experimental values as well.
exp_CaO = a.get_exp_entry("CaO")  #获得ExpEntry对象,可用于实验数据分析
exp_CaCO3 = a.get_exp_entry("CaCO3")

#Unfortunately, the Materials Project database does not have gas phase experimental entries. This is the value from NIST. We manually create the entry.
#这是一个气相实验,而且数据库没有关于这个的数据条目,所以我们要自己创建
#NIST是化学信息的标准参考数据库
exp_CO2 = ComputedEntry("CO2", -393.51)  #Exp entries should be in kJ/mol.

exp_reaction = ComputedReaction([exp_CaO, exp_CO2], [exp_CaCO3])

print("Experimental")
print(exp_reaction)
print("Reaction energy = {} kJ mol^-1".format(