API

Calculator

Thermochemical properties calculator.

Computes Cp(T), H°(T), S°(T) from NASA polynomial coefficients stored in a SQLite database.

All values returned as floats in standard units:

Cp, S° → J/(mol·K) H° → J/mol

class pyglenn.calculator.ThermochemicalCalculator(db_file=None)[source]

Bases: object

High-level interface for calculating thermochemical properties.

Uses the bundled thermo.db by default — no manual build step needed.

Supports context-manager protocol for automatic connection management:

with ThermochemicalCalculator() as calc:
    props = calc.calculate_properties(species_id, 1000.0)
Parameters:

db_file (str | None)

property connected: bool

Whether the calculator is connected to the database.

connect()[source]

Connect to the database.

Returns:

True if connection succeeded, False otherwise.

Return type:

bool

close()[source]

Close the database connection.

Return type:

None

get_available_species(search_pattern='')[source]

Return a list of available species, optionally filtered by name.

Parameters:

search_pattern (str) – Optional substring to filter species names.

Returns:

List of species dicts with id, name, phase, molecular_weight.

Return type:

list[dict[str, Any]]

calculate_properties(species_id, temperature)[source]

Calculate thermochemical properties at a given temperature.

Parameters:
  • species_id (int) – Database ID of the species.

  • temperature (float) – Temperature in Kelvin.

Returns:

  • temperature: Input temperature (K) - cp: Heat capacity in J/(mol·K) - h_relative: Enthalpy relative to 0 K in J/mol - s: Absolute entropy in J/(mol·K) - temp_interval: [T_min, T_max] - species_name: Species name - phase: Phase (‘gas’ or ‘condensed’)

Or None if calculation fails.

Return type:

Dictionary with keys

calculate_formation_enthalpy(species_id)[source]

Get enthalpy of formation at 298.15 K in J/mol.

Parameters:

species_id (int) – Database ID of the species.

Returns:

Enthalpy of formation in J/mol, or None if not available.

Return type:

float | None

calculate_enthalpy_change(species_id, T1, T2)[source]

Calculate ΔH°(T₂) − ΔH°(T₁) in J/mol.

Uses H°(T) values relative to 0 K.

Parameters:
  • species_id (int) – Database ID of the species.

  • T1 (float) – Initial temperature in Kelvin.

  • T2 (float) – Final temperature in Kelvin.

Returns:

Enthalpy change in J/mol, or None if calculation fails.

Return type:

float | None

get_properties_range(species_id, temps)[source]

Calculate properties at multiple temperatures.

Parameters:
  • species_id (int) – Database ID of the species.

  • temps (list[float]) – List of temperatures in Kelvin.

Returns:

Dict mapping temperature → property dict, or None if all fail.

Return type:

dict[float, dict[str, Any]] | None

Database

Database query interface for thermochemical data. Provides SQLite access, species lookup, and NASA polynomial calculations.

class pyglenn.database.ThermoDBQuery(db_file='thermo.db')[source]

Bases: object

Class for querying thermochemical database.

Parameters:

db_file (str)

connect()[source]

Connect to database.

Returns:

True if connection succeeded, False otherwise.

Return type:

bool

close()[source]

Close connection.

Return type:

None

get_statistics()[source]

Get database statistics.

Returns:

Dict with total_species, total_intervals, total_coeff_sets, species_by_phase, avg_molecular_weight.

Return type:

dict[str, Any]

find_species(name)[source]

Find species by name (supports partial search).

Parameters:

name (str) – Search pattern (substring match).

Returns:

List of matching species dicts (max 20).

Return type:

list[dict[str, Any]]

get_species_data(species_id)[source]

Get complete data for a species with all its intervals.

Parameters:

species_id (int) – Database ID of the species.

Returns:

Species dict with ‘intervals’ list, or None if not found.

Return type:

dict[str, Any] | None

get_species_for_temperature(species_id, temperature)[source]

Get valid coefficients for a specific temperature.

Parameters:
  • species_id (int) – Database ID of the species.

  • temperature (float) – Temperature in Kelvin.

Returns:

Dict with interval_number, temp_min, temp_max, coefficients, or None if temperature is out of range.

Return type:

dict[str, Any] | None

list_species_page(page=1, page_size=20)[source]

List species with pagination.

Parameters:
  • page (int) – Page number (1-based).

  • page_size (int) – Number of species per page.

Returns:

Tuple of (species_list, total_pages).

Return type:

tuple[list[dict[str, Any]], int]

static calculate_cp(coeffs, temperature)[source]

Calculate Cp(T)/R using NASA-7 polynomial coefficients.

Parameters:
  • coeffs (dict[str, float]) – Dict with keys a1-a7.

  • temperature (float) – Temperature in Kelvin.

Returns:

Dimensionless Cp/R.

Return type:

float

static calculate_h(coeffs, temperature)[source]

Calculate H°(T)/RT using NASA-7 polynomial coefficients.

Parameters:
  • coeffs (dict[str, float]) – Dict with keys a1-a7, b1.

  • temperature (float) – Temperature in Kelvin.

Returns:

Dimensionless H/(RT).

Return type:

float

static calculate_s(coeffs, temperature)[source]

Calculate S°(T)/R using NASA-7 polynomial coefficients.

Parameters:
  • coeffs (dict[str, float]) – Dict with keys a1-a7, b2.

  • temperature (float) – Temperature in Kelvin.

Returns:

Dimensionless S/R.

Return type:

float

Builder

Database builder: converts thermo.inp (NASA FORTRAN format) → SQLite3.

FORTRAN Record Structure (Appendix C):

RECORD 1 – Species identification RECORD 2 – General information RECORD 3 – Temperature interval definition RECORD 4 – First 5 polynomial coefficients RECORD 5 – Last 2 coefficients + integration constants

Records 3–5 repeat for each temperature interval.

class pyglenn.builder.ThermoDBBuilder(inp_file, db_file)[source]

Bases: object

Build a SQLite database from a thermo.inp file.

Parameters:
  • inp_file (str)

  • db_file (str)

connect()[source]

Connect to (or create) the SQLite database.

Return type:

None

close()[source]

Close the database connection.

Return type:

None

create_tables()[source]

Create the normalised table structure.

Return type:

None

static parse_float(value)[source]

Parse a FORTRAN-style float (‘D’ → ‘E’).

Parameters:

value (str) – String possibly in FORTRAN D notation.

Returns:

Float value or None if parsing fails.

Return type:

float | None

static parse_species_record(line)[source]

Extract species name (cols 1-16) and comments (cols 19-80).

Parameters:

line (str) – RECORD 1 line from thermo.inp.

Returns:

Tuple of (species_name, comments).

Return type:

tuple[str, str]

parse_general_info_record(line)[source]

Parse RECORD 2 – general information.

Parameters:

line (str) – RECORD 2 line from thermo.inp.

Returns:

Dict with num_intervals, ref_code, phase, molecular_weight, heat_of_formation.

Return type:

dict[str, Any]

static parse_temp_interval_record(line)[source]

Parse RECORD 3 – temperature interval.

Parameters:

line (str) – RECORD 3 line from thermo.inp.

Returns:

Dict with temp_min, temp_max, h_298_to_0.

Return type:

dict[str, Any]

static parse_coefficients_record(lines)[source]

Parse RECORDS 4-5 – polynomial coefficients.

Parameters:

lines (list[str]) – Two lines containing a1-a7 and b1-b2.

Returns:

Dict with keys a1-a7, b1, b2.

Return type:

dict[str, Any]

read_thermo_file()[source]

Read thermo.inp, stripping comments and blank lines.

Returns:

List of non-empty, non-comment lines.

Return type:

list[str]

static is_temperature_line(line)[source]

Detect RECORD 3 (temperature interval).

A temperature line has two valid floats in cols 0-11 and 11-22 where the first is strictly less than the second.

Parameters:

line (str) – A line from thermo.inp.

Returns:

True if the line appears to be a temperature interval record.

Return type:

bool

static is_coefficient_line(line)[source]

Detect coefficient lines containing FORTRAN D notation.

Uses regex to match the standard FORTRAN double-precision format (e.g. 1.23456789D+01), which is more robust than substring matching.

Parameters:

line (str) – A line from thermo.inp.

Returns:

True if the line contains at least one FORTRAN D-format number.

Return type:

bool

parse_and_load()[source]

Parse the thermo.inp file and populate the database.

Return type:

None