def test_phasediagram(): """Test example from docs.""" refs = [('Cu', 0.0), ('Au', 0.0), ('CuAu2', -0.2), ('CuAu', -0.5), ('Cu2Au', -0.7)] pd = PhaseDiagram(refs) energy, indices, coefs = pd.decompose('Cu3Au') assert energy == pytest.approx(-0.7) assert (indices == [4, 0]).all() assert coefs == pytest.approx(1.0)
# creates: ktao-2d.png, ktao-3d.png import matplotlib.pyplot as plt from ase.phasediagram import PhaseDiagram references = [('K', 0), ('Ta', 0), ('O2', 0), ('K3TaO8', -16.167), ('KO2', -2.288), ('KO3', -2.239), ('Ta2O5', -19.801), ('TaO3', -8.556), ('TaO', -1.967), ('K2O', -3.076), ('K2O2', -4.257), ('KTaO3', -13.439)] pd = PhaseDiagram(references) for d in [2, 3]: pd.plot(dims=d, show=False) plt.savefig('ktao-{}d.png'.format(d))
import numpy as np import matplotlib.pyplot as plt from ase.phasediagram import PhaseDiagram from ase.db import connect from ase.io import write db = connect('hull.db') # Select the evaluated candidates and retrieve the chemical formula and mixing # energy for the phase diagram refs = [] dcts = list(db.select('relaxed=1')) for dct in dcts: refs.append((dct.formula, -dct.raw_score)) pd = PhaseDiagram(refs) ax = pd.plot( show=not True, # set to True to show plot only_label_simplices=True) plt.savefig('hull.png') # View the simplices of the convex hull simplices = [] toview = sorted(np.array(dcts)[pd.hull], key=lambda x: x.mass) for dct in toview: simplices.append(dct.toatoms()) write('hull.traj', simplices)
import numpy as np from ase.phasediagram import PhaseDiagram from ase.db import connect from ase.io import write db = connect('hull.db') # Select the evaluated candidates and retrieve the chemical formula and mixing # energy for the phase diagram refs = [] dcts = list(db.select('relaxed=1')) for dct in dcts: refs.append((dct.formula, -dct.raw_score)) pd = PhaseDiagram(refs) pd.plot(only_label_simplices=True) # View the simplices of the convex hull simplices = [] toview = sorted(np.array(dcts)[pd.hull], key=lambda x: x.mass) for dct in toview: simplices.append(dct.toatoms()) write('hull.traj', simplices)
from __future__ import print_function import ase.db from ase.phasediagram import PhaseDiagram con = ase.db.connect('cubic_perovskites.db') references = [(row.formula, row.energy) for row in con.select('reference')] fd = open('abo3.csv', 'w') print('# id, formula, heat of formation [eV/atom]', file=fd) for row in con.select(combination='ABO3'): pd = PhaseDiagram(references, filter=row.formula, verbose=False) energy = pd.decompose(row.formula)[0] heat = (row.energy - energy) / row.natoms if (heat < 0.21 and (3.1 > row.gllbsc_ind_gap > 1.4 or 3.1 > row.gllbsc_dir_gap > 1.4) and (row.VB_ind - 4.5 > 1.23 and row.CB_ind - 4.5 < 0 or row.VB_dir - 4.5 > 1.23 and row.CB_dir - 4.5 < 0)): formula = row.A_ion + row.B_ion + row.anion print('{0}, {1}, {2:.3f}'.format(row.id, formula, heat), file=fd)
# creates: cuau.png import matplotlib.pyplot as plt from ase.phasediagram import PhaseDiagram refs = [('Cu', 0.0), ('Au', 0.0), ('CuAu2', -0.2), ('CuAu', -0.5), ('Cu2Au', -0.7)] pd = PhaseDiagram(refs) pd.plot(show=False) plt.savefig('cuau.png') print(pd.decompose('Cu3Au'))
# creates: cuau.png import matplotlib.pyplot as plt from ase.phasediagram import PhaseDiagram refs = [('Cu', 0.0), ('Au', 0.0), ('CuAu2', -0.2), ('CuAu', -0.5), ('Cu2Au', -0.7)] pd = PhaseDiagram(refs) pd.plot() plt.savefig('cuau.png') print(pd.decompose('Cu3Au'))