pycalphad Equilibrium Calculations

pycalphad Equilibrium Calculations

Guides an AI agent to compute phase equilibria, phase fractions and compositions for alloys from thermodynamic TDB databases with pycalphad, with mass-balance checks.

Skill files5 files

assets/

references/

scripts/

SKILL.md135 lines
1
---
2
name: pycalphad
3
description: Computes finite-temperature CALPHAD equilibria, phase fractions, and phase compositions from thermodynamic TDB databases using pycalphad. Use for alloy phase stability, equilibrium temperature sweeps, tie lines, lever-rule checks, or reproducible phase-fraction calculations with explicit components and mole-fraction conditions.
4
license: MIT
5
compatibility: Requires Python 3.12+, pycalphad 0.11.2, and NumPy. Installation needs network access; calculations run locally without credentials. Real-material predictions require a suitable licensed thermodynamic database.
6
metadata:
7
version: "1.1"
8
skill-author: K-Dense Inc.
9
tested-package-version: "0.11.2"
10
last-reviewed: "2026-10-01"
11
---
12
13
# pycalphad: TDB equilibrium calculations
14
15
## When to use
16
17
Use for equilibrium phase fractions and compositions at a fixed bulk elemental mole
18
composition, specified pressure, and a list of finite temperatures. The bundled helper
19
executes real pycalphad equilibria, checks mass balance, repeats at greater sampling
20
density, and exports each stable composition set separately.
21
22
Equilibrium is constrained by the selected database, components, phases, and conditions.
23
It does not predict precipitation rates, retained metastable microstructures, or properties
24
of phases missing from the database. Successful numerical checks do not establish the
25
database's experimental accuracy.
26
27
## Workflow
28
29
1. Identify the TDB's source, license, assessment/publication, valid temperature/pressure
30
and composition range, and required elements. Use the user's database for real alloys.
31
The bundled [assets/ideal-cu-ni.tdb](assets/ideal-cu-ni.tdb) is an original hypothetical
32
teaching model, **not an assessed Cu-Ni database**.
33
2. Inspect database elements and phases. Select the relevant phases deliberately; record
34
exclusions because they can turn the calculation into a metastable constrained result.
35
Include `VA` where required by sublattice models. Vacancies are not an independent bulk
36
mole fraction. Keep coupled order/disorder definitions in the TDB, but do not select
37
both partners as separate candidates when the ordered model already includes the
38
disordered contribution; the helper rejects such filtered candidate lists.
39
3. Copy [assets/equilibrium.json](assets/equilibrium.json). Specify exactly N-1 elemental
40
mole fractions and one dependent non-vacancy element. The dependent fraction is
41
`1 - sum(independent fractions)`; fractions are not silently normalized. Set K and Pa.
42
Convert weight percentages or mass fractions before using this helper.
43
4. Declare the database temperature interval from its assessment if known, or set
44
`database_temperature_range_k` to null if unknown. This is user-supplied evidence,
45
not a range automatically inferred from every TDB function. Requests outside a declared
46
interval fail. Check pressure and composition validity separately.
47
5. Run the calculation. Check finite Gibbs energies, phase fractions summing to one,
48
reconstructed bulk composition, and stability to doubled `pdens` (phase-constitution
49
sampling density). Near transitions, refine temperatures and sampling density further.
50
6. Deliver phase fractions with their **molar** basis, phase compositions, database hash,
51
conditions, excluded phases, and any numerical or assessment limitations.
52
53
Read [references/model-and-validation.md](references/model-and-validation.md) for the
54
analytic example, basis conversion, native Model/Workspace/property/plot contracts,
55
miscibility-gap handling, and convergence limits.
56
57
## Execute the tested example
58
59
From the collection root:
60
61
```bash
62
uv run --no-project --python 3.12 --with pycalphad==0.11.2 --with numpy==2.5.3 \
63
python skills/pycalphad/scripts/equilibrate.py \
64
skills/pycalphad/assets/ideal-cu-ni.tdb \
65
skills/pycalphad/assets/equilibrium.json equilibrium-result
66
```
67
68
Tested on Python 3.12, pycalphad 0.11.2, and NumPy 2.5.3. Use a new output directory.
69
All thermodynamic calculations are local; the script does not upload a TDB.
70
71
For the supplied hypothetical model at X(Ni)=0.5 and 101325 Pa:
72
73
| Temperature | Equilibrium result |
74
| --- | --- |
75
| 900 K | FCC_A1 only |
76
| 1100 K | 0.5 FCC_A1 + 0.5 LIQUID; X(Ni) approximately 0.527307 and 0.472693 respectively |
77
| 1300 K | LIQUID only |
78
79
The suite verifies analytic common-tangent compositions, a noncentral lever-rule case,
80
Gibbs energy, mass balance, both single-phase limits, and actual same-phase miscibility
81
gap vertices. These validate the computational workflow, not real Cu-Ni metallurgy.
82
83
## Outputs and acceptance
84
85
- `report.json`: settings and versions, TDB/settings SHA-256, excluded database phases,
86
requested, solver-imposed, and reconstructed bulk compositions, per-temperature
87
baseline/refined results, and checks. Experimental validity is not evaluated by the helper.
88
- `phase-equilibria.csv`: one row per stable vertex per temperature and sampling run,
89
including phase name, molar phase fraction, and elemental mole fractions. Its Gibbs
90
energy column is the **whole-system molar Gibbs energy**, repeated for each vertex;
91
it is not the individual phase energy.
92
93
Unused pycalphad vertices have blank names and NaN values; those are omitted. Named
94
vertices with invalid values cause failure. Multiple vertices with the same phase name
95
are retained because a miscibility gap can contain two composition sets of one phase.
96
Vertex indices do not track the same physical phase continuously across temperatures.
97
98
In stable 0.11.2, pycalphad clips independent mole fractions to `[1e-10, 1-1e-10]`.
99
Each result records `solver_bulk_mole_fractions` and the largest absolute difference
100
from the requested bulk in `composition_condition_adjustment_absolute_error`.
101
Mass-balance checks still compare against the **requested** composition; a tighter
102
tolerance can therefore fail at an endpoint. Do not claim exact pure-component or
103
ultratrace results from a clipped multicomponent calculation.
104
105
`all_checks_passed` requires each run's phase-sum and bulk-composition residuals within
106
`mass_balance_tolerance`, phase totals stable within `phase_fraction_tolerance`, and
107
system Gibbs energy stable within `gibbs_energy_tolerance_j_per_mol` when `pdens` doubles.
108
This comparison does not certify the global minimum or track individual composition-set
109
movement within a same-phase miscibility gap; inspect their exported compositions too.
110
Failed checks remain visible in the report rather than being relabeled as convergence.
111
112
## Boundaries and upstream contracts
113
114
The helper handles elemental mole fractions, one composition, one pressure, and up to
115
1000 explicit positive temperatures. It validates selected phases through pycalphad's
116
phase-compatibility rules; incompatible or automatically filtered order/disorder phase
117
sets produce an explicit error. It does not silently remove requested phases.
118
119
Charged-species constraints, externally imposed chemical potentials, custom models,
120
activity reference-state changes, and database optimization require additional modeling
121
and are outside this helper's tested scope. Do not extrapolate the pedagogical asset to
122
real material selection or heat-treatment decisions.
123
124
- [Equilibrium dataset semantics](https://pycalphad.org/docs/latest/examples/3_High_Throughput_Analysis/2_UsingCalculationResults.html)
125
- [Phase fractions and composition basis](https://pycalphad.org/docs/latest/examples/2_Computing_Properties/1_PhaseCompositions.html)
126
- [Equilibrium and sampling API](https://pycalphad.org/docs/latest/api/pycalphad.core.html)
127
- [Ordering examples](https://pycalphad.org/docs/latest/examples/2_Computing_Properties/4_EquilibriumWithOrdering.html)
128
- [Stable 0.11.2 source](https://github.com/pycalphad/pycalphad/tree/0.11.2/pycalphad)
129
130
Upstream `latest` documentation currently describes 0.11.3 development builds. The
131
bundled helper and the reference's native examples were exercised against stable
132
0.11.2 on 2026-10-01; the release's source was checked against the installed wheel.
133
No remote thermodynamic calculation or database-fetch API is used. `Database` loads a
134
local path, file-like object, or TDB text; a URL is not a supported download shortcut.
135

© K-Dense Inc. · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 6,373 prompts

More by @OpenSourceBuffGuy

See all
Website Clone Architect prompt image

Website Clone Architect

Reverse-engineers a website section by section, writes component specs, and hands them to parallel builder agents in git worktrees to rebuild it.

agent-skill, orchestrator, parallel-agents, multi-agent, plan-then-execute, web-development, frontend, codebase-analysis, scaffolding, css, html, nextjs, typescript, git, mcp, claude-code, for-developers, for-designers, long-form, advanced, technical-spec, task-decomposition, structured-output, design-systems, ui-ux, tool-use, checklist, report, vibe-coding

Italian Terrace Cafe Candid Portrait prompt image

Italian Terrace Cafe Candid Portrait

Generates a photorealistic candid shot of a woman in a white corset dress laughing at a sunny hotel terrace cafe, written as detailed JSON.

image-prompt, json-prompt, structured-output, photorealistic, portrait, woman, candid, fashion, cottagecore, natural-light, golden-hour, bokeh, summer, travel, cityscape, mountains, medium-shot, vibrant-colors, for-photographers, nano-banana, fashion-shoot, luxury

Night Street Photo With Leashed Cat prompt image

Night Street Photo With Leashed Cat

Generates a flash-lit night street photo of a blonde woman in a retro track jacket walking a hissing tabby cat on a leash.

image-prompt, json-prompt, nano-banana, structured-output, portrait, woman, animals, pet-portrait, night-scene, street-photography, candid, editorial, fashion, dramatic-lighting, photorealistic, vertical-format, medium-shot, graffiti, for-photographers, for-content-creators

1 view

Reviews

Loading reviews…

Discussion

Loading comments…