Getting started with pyglenn

This notebook walks through the essential workflow of the pyglenn library:

  1. Connect to the thermochemical database (bundled, no manual setup);

  2. Look up a chemical species;

  3. 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. Tip: use exact_match=True for exact, case-insensitive lookups (e.g. 'N2' returns only N2, not Be3N2).

with ThermochemicalCalculator() as calc:
    species = calc.get_available_species('CO2', exact_match=True)

for s in species:
    print(f"id={s.id:>5}  {s.name:<12}  phase={s.phase}")
id=  316  CO2           phase=gas

Computing thermochemical properties

With the id in hand, calculate_properties(species_id, temperature) returns a ThermoProperties dataclass with \(C_p\), \(H^\circ(T)\) and \(S^\circ\).

with ThermochemicalCalculator() as calc:
    species_id = calc.get_available_species('CO2', exact_match=True)[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 : CO2 (gas)
T       : 298.15 K
Cp      : 37.135 J/(mol·K)
H°      : -393510.000 J/mol
S°      : 213.787 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('CO2', exact_match=True)[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 |         37.220
   500.0 |         44.624
   800.0 |         51.432
  1000.0 |         54.309
  1500.0 |         58.374