Getting started with pyglenn
This notebook walks through the essential workflow of the pyglenn library:
Connect to the thermochemical database (bundled, no manual setup);
Look up a chemical species;
Compute \(C_p(T)\), \(H^\circ(T)\) and \(S^\circ(T)\) at a given temperature.
The thermo.db database ships inside the package — just instantiate
ThermochemicalCalculator with no arguments.
from pyglenn import ThermochemicalCalculator
print('pyglenn imported successfully')
pyglenn imported successfully
Looking up a species
Use get_available_species with a search pattern to find the identifier
(id) of the species you want.
with ThermochemicalCalculator() as calc:
species = calc.get_available_species('CH4')
for s in species[:5]:
print(f"id={s['id']:>5} {s['name']:<12} phase={s['phase']}")
id= 296 CH4 phase=gas
Computing thermochemical properties
With the id in hand, calculate_properties(species_id, temperature)
returns a dictionary with \(C_p\), \(H^\circ\) (relative to 0 K) and \(S^\circ\).
with ThermochemicalCalculator() as calc:
species_id = calc.get_available_species('CH4')[0]['id']
result = calc.calculate_properties(species_id, 298.15)
print(f"Species : {result['species_name']} ({result['phase']})")
print(f"T : {result['temperature']:.2f} K")
print(f"Cp : {result['cp']:.3f} J/(mol·K)")
print(f"H° : {result['h_relative']:.3f} J/mol")
print(f"S° : {result['s']:.3f} J/(mol·K)")
Species : CH4 (gas)
T : 298.15 K
Cp : 35.691 J/(mol·K)
H° : -74599.575 J/mol
S° : 186.370 J/(mol·K)
Sweeping a temperature range
A common task is to evaluate \(C_p\) across several temperatures.
temperatures = [300.0, 500.0, 800.0, 1000.0, 1500.0]
with ThermochemicalCalculator() as calc:
species_id = calc.get_available_species('CH4')[0]['id']
print(f"{'T (K)':>8} | {'Cp (J/mol·K)':>14}")
print('-' * 27)
for T in temperatures:
r = calc.calculate_properties(species_id, T)
print(f"{T:>8.1f} | {r['cp']:>14.3f}")
T (K) | Cp (J/mol·K)
---------------------------
300.0 | 35.760
500.0 | 46.584
800.0 | 64.012
1000.0 | 73.676
1500.0 | 90.865