Skip to content

Instantly share code, notes, and snippets.

View bocklund's full-sized avatar
💭
Reaching equilibrium

Brandon Bocklund bocklund

💭
Reaching equilibrium
View GitHub Profile
@bocklund
bocklund / legend_generator_plotting.py
Last active January 28, 2026 03:26
Plot PyCalphad phase diagram with ESPEI dataplot containing a fixed set of phases.
# Plot PyCalphad phase diagram with ESPEI dataplot containing a fixed set of phases.
# The legend generator should have the superset of all modeled phases and all data phases
# (usually this is what causes the colors to mismatch - the phases in the model only come from the model and the dataplot phases come only from the data).
from pycalphad import Database, equilibrium, variables as v, ternplot
from pycalphad.plot.utils import phase_legend
from espei.datasets import load_datasets, recursive_glob
from espei.plot import dataplot
import matplotlib.pyplot as plt
@bocklund
bocklund / add_function_to_database.py
Created January 15, 2026 17:08
Programmatically add FUNCTION to a Calphad database and add it to a PARAMETER
from pycalphad import Database, variables as v
from symengine import Symbol
from tinydb import where
dbf = Database("NiTi-92Sau.tdb")
# Add FUNCTION called MYFUNC
myfunc = 1 + 10 * v.T + 100 * v.T**2
dbf.symbols["MYFUNC"] = myfunc
import itertools
cards = ["A", 2, 3, 4, 5, 6, 7, 8, 9, 10, "J", "Q", "K"]
deck = 1*4*cards # 1 deck, 4 suits
def totals_for_hand(hand):
totals = [0]
for i, card in enumerate(hand):
new_totals = []
for j, t in enumerate(totals):
if card == "A":
new_totals.append(t + 1)
@bocklund
bocklund / 2025-04-30-3D-ternary.ipynb
Last active May 3, 2025 23:15
2D shapes towards 3D visualization
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bocklund
bocklund / ElasticProperties.ipynb
Created November 25, 2023 21:14
Elastic model
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bocklund
bocklund / Al-Zn_eutectic_fixed_phase.ipynb
Created August 22, 2022 22:38
PyCalphad: Al-Zn finding eutectic point with fixed phases
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bocklund
bocklund / compute_per_phase_property_loop.py
Last active July 6, 2024 19:54
Compute properties per phase in PyCalphad from the result of equilibrium
# coding: utf-8
import matplotlib.pyplot as plt
import numpy as np
from pycalphad import Database, calculate, equilibrium, variables as v
import pycalphad
dbf = Database('Al-Mg_Zhong.tdb')
comps = ['AL', 'MG', 'VA']
@bocklund
bocklund / Al-Ca-Si-O-demo.ipynb
Created May 29, 2022 20:02
MQMQA multi-component demo
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bocklund
bocklund / sigfigs.py
Created January 16, 2022 01:45
Print floating point to n significant digits
import math
def float_sigfigs(val, sigfigs):
"""Return a string representation of a floating point number rounded to some number of significant figures without scientific notation"""
rounded_val = float(f"{val:0.{sigfigs}g}")
num_digits = int(abs(math.log10(rounded_val))) + sigfigs
return f"{rounded_val:0.{num_digits}f}"
print(float_sigfigs(3.141592653589793e-20, 5)) # 0.000000000000000000031416
@bocklund
bocklund / COST507-modified.tdb
Last active January 8, 2026 19:13
COST507 TDB with several mistakes fixed
$
$
$ VERSION : ROUND II (January 1999)
$
$ FROZEN VERSION
$ COST - 507
$
$ THERMODYNAMIC DATABASE FOR LIGHT METAL ALLOYS
$
$