Structures and energetics

Mixing energy of a solid solution

Place Mg and Ca at random on the cation sites of a 64-atom supercell of MgO and CaO, and compute the mixing energy at each composition from the difference to the pure oxides.

Category
Structures and energetics
APIs used
ase.build.bulkAtoms.symbolsnumpy.randomscf_must_conv
Script
alloy_mixing.py

The mixing energy is a basic quantity for the stability of alloys and solid solutions. The energies of the pure materials, weighted by the composition, are subtracted from the energy of the solid solution A1−xBx. N is the number of mixed sites.

Emix(x)=E(A1−xBx)N−(1−x)E(A)N−xE(B)N

A negative Emix means a tendency to mix, a positive one a tendency to separate. A random solid solution needs a large supercell with randomly placed atoms. Advance/OF-DFT, whose cost grows almost linearly with the number of atoms, is well suited to such calculations.

The example is the solid solution Mg1−xCaxO of MgO and CaO in the rock-salt structure. The oxygen sites are left as they are, and Mg and Ca are placed at random on the cation sites. In the formula above, A is MgO, B is CaO and N is the number of cations.

The solid solution of MgO and CaO has a large mixing energy, several hundred meV per cation. For systems whose mixing energy is a few tens of meV/atom or less, such as many alloys, the error of the v1.0.0 model (Crystal26) is comparable to the mixing energy, so its sign cannot be determined.

alloy_mixing.pyDownload
"""
Advance/OF-DFT example: mixing energy of the random solid solution Mg(1-x)Ca(x)O
(rock-salt structure).

    E_mix(x) = E(Mg[1-x] Ca[x] O) / N - (1 - x) E(MgO) / N - x E(CaO) / N

N is the number of cation sites. Only the cation sites are mixed; the oxygen
sites are unchanged. The pure oxides are calculated in supercells of the same
shape and with the same settings as the solid solutions.

Copyright (C) 2026 AdvanceSoft Corporation, All rights reserved.
"""

import time

import numpy as np
from ase.build import bulk

from aofdft.calculator import AOFDFTCalculator

VPS_DIR = "path/to/DFT_DATA19_AS/VPS"  # edit these two paths for your environment
PAO_DIR = "path/to/DFT_DATA19_AS/PAO"

A_MGO, A_CAO = 4.212, 4.811      # experimental lattice constants (Angstrom)
SIZE       = 2                   # 2x2x2 conventional cells = 64 atoms (32 cation sites)
X_CA       = (0.25, 0.50, 0.75)  # Ca fractions of the cation sites
N_CONFIG   = 2                   # random configurations per composition
rng = np.random.default_rng(seed=1)


def energy_per_cation(atoms, label):
    atoms.calc = AOFDFTCalculator(
        console       = False,
        logging_file  = f"{label}.log",
        kin_type      = "AS26",
        kin_model     = "Crystal26",
        vps_dir       = VPS_DIR,
        pao_dir       = PAO_DIR,
        scf_must_conv = True,
    )
    return atoms.get_potential_energy() / (len(atoms) // 2)


def supercell(x_ca):
    a = (1.0 - x_ca) * A_MGO + x_ca * A_CAO  # Vegard's law
    atoms = bulk("MgO", "rocksalt", a=a, cubic=True).repeat((SIZE, SIZE, SIZE))
    cations = [atom.index for atom in atoms if atom.symbol == "Mg"]
    n_ca = round(x_ca * len(cations))
    atoms.symbols[rng.choice(cations, n_ca, replace=False)] = "Ca"  # random occupation
    return atoms


t0 = time.perf_counter()
e_mgo = energy_per_cation(supercell(0.0), "MgO")
e_cao = energy_per_cation(supercell(1.0), "CaO")
print(f"MgO: {e_mgo:.6f} eV/cation, CaO: {e_cao:.6f} eV/cation  ({time.perf_counter() - t0:.0f} s)")

print(" x(Ca) | config | E_mix (meV/cation) |  time")
results = {}
for x in X_CA:
    for k in range(N_CONFIG):
        t0 = time.perf_counter()
        e = energy_per_cation(supercell(x), f"MgCaO_x{x:.2f}_{k}")
        e_mix = (e - (1.0 - x) * e_mgo - x * e_cao) * 1000.0
        results.setdefault(x, []).append(e_mix)
        print(f"  {x:.2f} |   {k}    | {e_mix:18.1f} | {time.perf_counter() - t0:5.0f} s", flush=True)

print("\n x(Ca) | E_mix average (meV/cation)")
for x, values in results.items():
    print(f"  {x:.2f} | {np.mean(values):8.1f}")

Example output

Results with v1.0.0 (Crystal26). The FFT grid ranges from 87×87×87 (MgO) to 100×100×100 (CaO).

text
MgO: -482.770580 eV/cation, CaO: -484.914548 eV/cation  (431 s)
 x(Ca) | config | E_mix (meV/cation) |  time
  0.25 |   0    |              654.5 |   204 s
  0.25 |   1    |              681.6 |   266 s
  0.50 |   0    |              670.1 |   415 s
  0.50 |   1    |              712.9 |   385 s
  0.75 |   0    |              391.7 |   432 s
  0.75 |   1    |              363.0 |   577 s

 x(Ca) | E_mix average (meV/cation)
  0.25 |    668.1
  0.50 |    691.5
  0.75 |    377.4

The mixing energy is positive at all compositions, which indicates a tendency of MgO and CaO to separate. It is not symmetric in the composition: it is larger on the Mg-rich side (x = 0.25) than on the Ca-rich side (x = 0.75).

Notes

  • Only the cation sites are mixed. The cation sites are selected with atom.symbol == "Mg", and the number of sites given by the composition is chosen at random with rng.choice and replaced by Ca. To mix all sites, as in an alloy, choose from all atoms.
  • The pure MgO and CaO are calculated in the same 64-atom supercell and with the same settings as the solid solutions. Differences between calculations with different numbers of atoms, cell shapes or settings have larger errors.
  • The 64-atom supercell has a short edge of 8.4 to 8.7 Å at Mg-rich compositions. With v1.0.0, results change when the cell has a short period. When the same ordered arrangements are calculated in cells of 64 and 216 atoms, the mixing energies differ by 23 meV at x = 0.25 and by less than 3 meV at x = 0.5 and 0.75. For a new system, check that a larger cell gives the same results.
  • The lattice constant follows Vegard's law (linear interpolation of the lattice constants of the pure materials), and the atoms stay at the ideal rock-salt positions. Since the lattice constants of MgO and CaO differ by 14%, relaxing the atomic positions lowers the energy of the solid solution, and the mixing energy becomes smaller than the values obtained here. For a quantitative evaluation, optimize the volume and atomic positions at each composition (see Stress tensor and cell optimization).
  • The random configurations are generated with numpy.random.default_rng(seed=1). Since the energy depends on the configuration even at the same composition, calculate several configurations and check the mean and the spread. Special quasirandom structures (SQS) represent a random configuration with fewer atoms.
  • The two configurations of each composition differ by about 30 to 40 meV, less than a tenth of the mixing energy itself (400 to 700 meV). At Mg-rich compositions, however, this difference is comparable to the change with the cell size mentioned above. To discuss differences between configurations, check them in a larger cell.
  • The mixing energy is a small difference between large total energies. Set scf_must_conv=True and make sure that the SCF has converged in all calculations.