本文整理汇总了Python中pymatgen.phasediagram.pdanalyzer.PDAnalyzer.get_e_above_hull方法的典型用法代码示例。如果您正苦于以下问题:Python PDAnalyzer.get_e_above_hull方法的具体用法?Python PDAnalyzer.get_e_above_hull怎么用?Python PDAnalyzer.get_e_above_hull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.phasediagram.pdanalyzer.PDAnalyzer
的用法示例。
在下文中一共展示了PDAnalyzer.get_e_above_hull方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PDAnalyzerTest
# 需要导入模块: from pymatgen.phasediagram.pdanalyzer import PDAnalyzer [as 别名]
# 或者: from pymatgen.phasediagram.pdanalyzer.PDAnalyzer import get_e_above_hull [as 别名]
class PDAnalyzerTest(unittest.TestCase):
def setUp(self):
module_dir = os.path.dirname(os.path.abspath(__file__))
(elements, entries) = PDEntryIO.from_csv(os.path.join(module_dir,
"pdentries_test.csv"))
self.pd = PhaseDiagram(entries)
self.analyzer = PDAnalyzer(self.pd)
def test_get_e_above_hull(self):
for entry in self.pd.stable_entries:
self.assertLess(self.analyzer.get_e_above_hull(entry), 1e-11,
"Stable entries should have e above hull of zero!")
for entry in self.pd.all_entries:
if entry not in self.pd.stable_entries:
e_ah = self.analyzer.get_e_above_hull(entry)
self.assertGreaterEqual(e_ah, 0)
self.assertTrue(isinstance(e_ah, Number))
def test_get_equilibrium_reaction_energy(self):
for entry in self.pd.stable_entries:
self.assertLessEqual(
self.analyzer.get_equilibrium_reaction_energy(entry), 0,
"Stable entries should have negative equilibrium reaction energy!")
def test_get_decomposition(self):
for entry in self.pd.stable_entries:
self.assertEquals(len(self.analyzer.get_decomposition(entry.composition)), 1,
"Stable composition should have only 1 decomposition!")
dim = len(self.pd.elements)
for entry in self.pd.all_entries:
ndecomp = len(self.analyzer.get_decomposition(entry.composition))
self.assertTrue(ndecomp > 0 and ndecomp <= dim,
"The number of decomposition phases can at most be equal to the number of components.")
#Just to test decomp for a ficitious composition
ansdict = {entry.composition.formula: amt
for entry, amt in
self.analyzer.get_decomposition(Composition("Li3Fe7O11")).items()}
expected_ans = {"Fe2 O2": 0.0952380952380949,
"Li1 Fe1 O2": 0.5714285714285714,
"Fe6 O8": 0.33333333333333393}
for k, v in expected_ans.items():
self.assertAlmostEqual(ansdict[k], v)
def test_get_transition_chempots(self):
for el in self.pd.elements:
self.assertLessEqual(len(self.analyzer.get_transition_chempots(el)),
len(self.pd.facets))
def test_get_element_profile(self):
for el in self.pd.elements:
for entry in self.pd.stable_entries:
if not (entry.composition.is_element):
self.assertLessEqual(len(self.analyzer.get_element_profile(el, entry.composition)),
len(self.pd.facets))
def test_get_get_chempot_range_map(self):
elements = [el for el in self.pd.elements if el.symbol != "Fe"]
self.assertEqual(len(self.analyzer.get_chempot_range_map(elements)), 10)
示例2: test_get_stability
# 需要导入模块: from pymatgen.phasediagram.pdanalyzer import PDAnalyzer [as 别名]
# 或者: from pymatgen.phasediagram.pdanalyzer.PDAnalyzer import get_e_above_hull [as 别名]
def test_get_stability(self):
entries = self.rester.get_entries("Fe-O")
modified_entries = []
for entry in entries:
# Create modified entries with energies that are 0.01eV higher
# than the corresponding entries.
if entry.composition.reduced_formula == "Fe2O3":
modified_entries.append(
ComputedEntry(entry.composition,
entry.uncorrected_energy + 0.01,
parameters=entry.parameters,
entry_id="mod_{}".format(entry.entry_id)))
rest_ehulls = self.rester.get_stability(modified_entries)
all_entries = entries + modified_entries
compat = MaterialsProjectCompatibility()
all_entries = compat.process_entries(all_entries)
pd = PhaseDiagram(all_entries)
a = PDAnalyzer(pd)
for e in all_entries:
if str(e.entry_id).startswith("mod"):
for d in rest_ehulls:
if d["entry_id"] == e.entry_id:
data = d
break
self.assertAlmostEqual(a.get_e_above_hull(e),
data["e_above_hull"])
示例3: get_contour_pd_plot
# 需要导入模块: from pymatgen.phasediagram.pdanalyzer import PDAnalyzer [as 别名]
# 或者: from pymatgen.phasediagram.pdanalyzer.PDAnalyzer import get_e_above_hull [as 别名]
def get_contour_pd_plot(self):
"""
Plot a contour phase diagram plot, where phase triangles are colored
according to degree of instability by interpolation. Currently only
works for 3-component phase diagrams.
Returns:
A matplotlib plot object.
"""
from scipy import interpolate
from matplotlib import cm
pd = self._pd
entries = pd.qhull_entries
data = np.array(pd.qhull_data)
plt = self._get_2d_plot()
analyzer = PDAnalyzer(pd)
data[:, 0:2] = triangular_coord(data[:, 0:2]).transpose()
for i, e in enumerate(entries):
data[i, 2] = analyzer.get_e_above_hull(e)
gridsize = 0.005
xnew = np.arange(0, 1.0, gridsize)
ynew = np.arange(0, 1, gridsize)
f = interpolate.LinearNDInterpolator(data[:, 0:2], data[:, 2])
znew = np.zeros((len(ynew), len(xnew)))
for (i, xval) in enumerate(xnew):
for (j, yval) in enumerate(ynew):
znew[j, i] = f(xval, yval)
plt.contourf(xnew, ynew, znew, 1000, cmap=cm.autumn_r)
plt.colorbar()
return plt
示例4: PDAnalyzerTest
# 需要导入模块: from pymatgen.phasediagram.pdanalyzer import PDAnalyzer [as 别名]
# 或者: from pymatgen.phasediagram.pdanalyzer.PDAnalyzer import get_e_above_hull [as 别名]
class PDAnalyzerTest(unittest.TestCase):
def setUp(self):
module_dir = os.path.dirname(os.path.abspath(__file__))
(elements, entries) = PDEntryIO.from_csv(os.path.join(module_dir,
"pdentries_test.csv"))
self.pd = PhaseDiagram(entries)
self.analyzer = PDAnalyzer(self.pd)
def test_get_e_above_hull(self):
for entry in self.pd.stable_entries:
self.assertLess(self.analyzer.get_e_above_hull(entry), 1e-11,
"Stable entries should have e above hull of zero!")
for entry in self.pd.all_entries:
if entry not in self.pd.stable_entries:
e_ah = self.analyzer.get_e_above_hull(entry)
self.assertGreaterEqual(e_ah, 0)
self.assertTrue(isinstance(e_ah, Number))
def test_get_equilibrium_reaction_energy(self):
for entry in self.pd.stable_entries:
self.assertLessEqual(
self.analyzer.get_equilibrium_reaction_energy(entry), 0,
"Stable entries should have negative equilibrium reaction energy!")
def test_get_decomposition(self):
for entry in self.pd.stable_entries:
self.assertEquals(len(self.analyzer.get_decomposition(entry.composition)), 1,
"Stable composition should have only 1 decomposition!")
dim = len(self.pd.elements)
for entry in self.pd.all_entries:
ndecomp = len(self.analyzer.get_decomposition(entry.composition))
self.assertTrue(ndecomp > 0 and ndecomp <= dim,
"The number of decomposition phases can at most be equal to the number of components.")
#Just to test decomp for a ficitious composition
ansdict = {entry.composition.formula: amt
for entry, amt in
self.analyzer.get_decomposition(Composition("Li3Fe7O11")).items()}
expected_ans = {"Fe2 O2": 0.0952380952380949,
"Li1 Fe1 O2": 0.5714285714285714,
"Fe6 O8": 0.33333333333333393}
for k, v in expected_ans.items():
self.assertAlmostEqual(ansdict[k], v)
def test_get_transition_chempots(self):
for el in self.pd.elements:
self.assertLessEqual(len(self.analyzer.get_transition_chempots(el)),
len(self.pd.facets))
def test_get_element_profile(self):
for el in self.pd.elements:
for entry in self.pd.stable_entries:
if not (entry.composition.is_element):
self.assertLessEqual(len(self.analyzer.get_element_profile(el, entry.composition)),
len(self.pd.facets))
def test_get_get_chempot_range_map(self):
elements = [el for el in self.pd.elements if el.symbol != "Fe"]
self.assertEqual(len(self.analyzer.get_chempot_range_map(elements)), 10)
def test_getmu_vertices_stability_phase(self):
results = self.analyzer.getmu_vertices_stability_phase(Composition.from_formula("LiFeO2"), Element("O"))
self.assertAlmostEqual(len(results), 6)
test_equality = False
for c in results:
if abs(c[Element("O")]+7.115) < 1e-2 and abs(c[Element("Fe")]+6.596) < 1e-2 and \
abs(c[Element("Li")]+3.931) < 1e-2:
test_equality = True
self.assertTrue(test_equality,"there is an expected vertex missing in the list")
def test_getmu_range_stability_phase(self):
results = self.analyzer.get_chempot_range_stability_phase(
Composition("LiFeO2"), Element("O"))
self.assertAlmostEqual(results[Element("O")][1], -4.4501812249999997)
self.assertAlmostEqual(results[Element("Fe")][0], -6.5961470999999996)
self.assertAlmostEqual(results[Element("Li")][0], -3.6250022625000007)
示例5: PhaseDiagram
# 需要导入模块: from pymatgen.phasediagram.pdanalyzer import PDAnalyzer [as 别名]
# 或者: from pymatgen.phasediagram.pdanalyzer.PDAnalyzer import get_e_above_hull [as 别名]
sys.exit()
syms = [el.symbol for el in entry.composition.elements]
#This gets all entries belonging to the relevant system.
entries = a.get_entries_in_chemsys(syms)
entries.append(entry)
#Process entries with Materials Project compatibility.
entries = compat.process_entries(entries)
print [e.composition.reduced_formula for e in entries]
pd = PhaseDiagram(entries)
analyzer = PDAnalyzer(pd)
ehull = analyzer.get_e_above_hull(entry) * 1000
print "Run contains formula {} with corrected energy {:.3f} eV.".format(
entry.composition, entry.energy
)
print "Energy above convex hull = {:.1f} meV".format(ehull)
if ehull < 1:
print "Entry is stable."
elif ehull < 30:
print "Entry is metastable and could be stable at finite temperatures."
elif ehull < 50:
print "Entry has a low probability of being stable."
else:
print "Entry is very unlikely to be stable."
if ehull > 0:
示例6: _get_2d_plot
# 需要导入模块: from pymatgen.phasediagram.pdanalyzer import PDAnalyzer [as 别名]
# 或者: from pymatgen.phasediagram.pdanalyzer.PDAnalyzer import get_e_above_hull [as 别名]
#.........这里部分代码省略.........
font.set_weight("bold")
font.set_size(24)
# Sets a nice layout depending on the type of PD. Also defines a
# "center" for the PD, which then allows the annotations to be spread
# out in a nice manner.
if len(self._pd.elements) == 3:
plt.axis("equal")
plt.xlim((-0.1, 1.2))
plt.ylim((-0.1, 1.0))
plt.axis("off")
center = (0.5, math.sqrt(3) / 6)
else:
all_coords = labels.keys()
miny = min([c[1] for c in all_coords])
ybuffer = max(abs(miny) * 0.1, 0.1)
plt.xlim((-0.1, 1.1))
plt.ylim((miny - ybuffer, ybuffer))
center = (0.5, miny / 2)
plt.xlabel("Fraction", fontsize=28, fontweight='bold')
plt.ylabel("Formation energy (eV/fu)", fontsize=28,
fontweight='bold')
for coords in sorted(labels.keys(), key=lambda x: -x[1]):
entry = labels[coords]
label = entry.name
# The follow defines an offset for the annotation text emanating
# from the center of the PD. Results in fairly nice layouts for the
# most part.
vec = (np.array(coords) - center)
vec = vec / np.linalg.norm(vec) * 10 if np.linalg.norm(vec) != 0 \
else vec
valign = "bottom" if vec[1] > 0 else "top"
if vec[0] < -0.01:
halign = "right"
elif vec[0] > 0.01:
halign = "left"
else:
halign = "center"
if label_stable:
if process_attributes and entry.attribute == 'new':
plt.annotate(latexify(label), coords, xytext=vec,
textcoords="offset points",
horizontalalignment=halign,
verticalalignment=valign,
fontproperties=font,
color='g')
else:
plt.annotate(latexify(label), coords, xytext=vec,
textcoords="offset points",
horizontalalignment=halign,
verticalalignment=valign,
fontproperties=font)
if self.show_unstable:
font = FontProperties()
font.set_size(16)
pda = PDAnalyzer(self._pd)
energies_unstable = [pda.get_e_above_hull(entry)
for entry, coord in unstable.items()]
if energy_colormap is not None:
energies.extend(energies_unstable)
vals_unstable = _map.to_rgba(energies_unstable)
ii = 0
for entry, coords in unstable.items():
vec = (np.array(coords) - center)
vec = vec / np.linalg.norm(vec) * 10 \
if np.linalg.norm(vec) != 0 else vec
label = entry.name
if energy_colormap is None:
plt.plot(coords[0], coords[1], "ks", linewidth=3,
markeredgecolor="k", markerfacecolor="r",
markersize=8)
else:
plt.plot(coords[0], coords[1], "s", linewidth=3,
markeredgecolor="k",
markerfacecolor=vals_unstable[ii],
markersize=8)
if label_unstable:
plt.annotate(latexify(label), coords, xytext=vec,
textcoords="offset points",
horizontalalignment=halign, color="b",
verticalalignment=valign,
fontproperties=font)
ii += 1
if energy_colormap is not None and show_colorbar:
_map.set_array(energies)
cbar = plt.colorbar(_map)
cbar.set_label(
'Energy [meV/at] above hull (in red)\nInverse energy ['
'meV/at] above hull (in green)',
rotation=-90, ha='left', va='center')
ticks = cbar.ax.get_yticklabels()
cbar.ax.set_yticklabels(['${v}$'.format(
v=float(t.get_text().strip('$'))*1000.0) for t in ticks])
f = plt.gcf()
f.set_size_inches((8, 6))
plt.subplots_adjust(left=0.09, right=0.98, top=0.98, bottom=0.07)
return plt