openmaterials.ai / codes / pycalphad
A Python library that builds symbolic Gibbs energy models per phase from a TDB database and minimizes the multicomponent, multiphase Gibbs energy, with models swapped at run time.
Each phase's molar Gibbs energy is a SymPy expression built from database parameters and decoupled from the solver. A custom Model subclass replaces it without touching the equilibrium code (Otis 2017).
Database('example.tdb') parses the TDB format into phases, sublattice models and parameters, searchable with search() and written back with to_file() (Otis 2017).
The library Model carries the compound energy formalism, Redlich-Kister polynomials with the Muggianu extension and the Inden-Hillert-Jarl magnetic model (Otis 2017).
calculate() gives a property at set T, P and site fractions. equilibrium() minimizes the Gibbs energy for conditions like {v.X('AL'): (0, 1, 0.01), v.T: 600} (Otis 2017).
Results are xarray Datasets with dimensions for conditions, tie-simplex vertex and internal degrees of freedom. eq.MU.sel(component='AL', T=600) picks one (Otis 2017).
SymPy code generation compiles each model and its exact first and second derivatives to machine code on demand (Otis 2017).
ESPEI fits Cu-Mg with pycalphad as engine. 15 degrees of freedom for five phases go through 500 MCMC iterations. The largest liquid Gibbs energy uncertainty is ~1 kJ/mol (Bocklund 2019). Bocklund 2019
In the pycalphad paper, the COST 507 Al-Fe diagram, with lines of constant B2 ordering and the Curie temperature, shows a second-order bcc ordering transition (Otis 2017). Otis 2017
dbf = Database('alfe.tdb'), then list(dbf.phases.keys()) for the phase names.
Choose comps and phases, and optionally a custom Model for all phases or one of them.
conditions = {v.X('AL'): (0, 1, 0.01), v.T: 600}, with T in K and P in Pa.
eq = equilibrium(dbf, comps, phases, conditions, output='HM'), or calculate() per phase.
Slice eq.MU, eq.NP and eq.Phase with xarray, or map the phase diagram and plot it.