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
- exception pyglenn.calculator.ThermoCalcError[source]
Bases:
ExceptionBase exception for thermochemical calculation errors.
- exception pyglenn.calculator.DatabaseNotConnectedError[source]
Bases:
ThermoCalcErrorRaised when attempting calculation without a database connection.
- exception pyglenn.calculator.SpeciesNotFoundError(species_id)[source]
Bases:
ThermoCalcErrorRaised when a species ID is not found in the database.
- Parameters:
species_id (int)
- Return type:
None
- exception pyglenn.calculator.TemperatureOutOfRangeError(temperature, species_name=None, temp_bounds=None)[source]
Bases:
ThermoCalcErrorRaised when the requested temperature is outside valid intervals.
Carries the requested temperature, the species name, and the overall valid temperature bounds (when known).
- class pyglenn.calculator.ThermochemicalCalculator(db_file=None)[source]
Bases:
objectHigh-level interface for calculating thermochemical properties.
Uses the bundled
thermo.dbby 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)
- connect()[source]
Connect to the database.
- Returns:
True if connection succeeded, False otherwise.
- Return type:
- get_available_species(search_pattern='', exact_match=False)[source]
Return a list of available species, optionally filtered by name.
- Parameters:
- Returns:
List of SpeciesInfo with id, name, phase, molecular_weight.
- Return type:
list[SpeciesInfo]
- calculate_properties(species_id, temperature)[source]
Calculate thermochemical properties at a given temperature.
- Parameters:
- Returns:
ThermoProperties with temperature, cp, h_relative, s, temp_interval, species_name, and phase.
- Raises:
DatabaseNotConnectedError – If not connected to database.
SpeciesNotFoundError – If species_id is not in the database.
TemperatureOutOfRangeError – If temperature is outside all valid intervals for the species.
- Return type:
ThermoProperties
- calculate_enthalpy_change(species_id, T1, T2)[source]
Calculate ΔH°(T₂) − ΔH°(T₁) in J/mol.
Uses absolute H°(T) values (NASA-7 convention).
- Parameters:
- Returns:
Enthalpy change in J/mol.
- Raises:
DatabaseNotConnectedError – If not connected to database.
SpeciesNotFoundError – If species_id is not in the database.
TemperatureOutOfRangeError – If either T1 or T2 is outside valid intervals.
- Return type:
float | None
- calculate_properties_range(species_id, temps, *, strict=False)[source]
Calculate properties for many temperatures, loading data once.
Unlike
get_properties_range(), this loads the species intervals a single time and evaluates all temperatures in memory, preserving input order.- Parameters:
- Returns:
Ordered list of ThermoProperties.
- Raises:
DatabaseNotConnectedError – If not connected to database.
SpeciesNotFoundError – If species_id is not in the database.
TemperatureOutOfRangeError – If
strictand a temperature is outside the valid intervals.
- Return type:
list[ThermoProperties]
Exceptions
- class pyglenn.ThermoCalcError[source]
Bases:
ExceptionBase exception for thermochemical calculation errors.
- class pyglenn.DatabaseNotConnectedError[source]
Bases:
ThermoCalcErrorRaised when attempting calculation without a database connection.
- class pyglenn.SpeciesNotFoundError(species_id)[source]
Bases:
ThermoCalcErrorRaised when a species ID is not found in the database.
- Parameters:
species_id (int)
- class pyglenn.TemperatureOutOfRangeError(temperature, species_name=None, temp_bounds=None)[source]
Bases:
ThermoCalcErrorRaised when the requested temperature is outside valid intervals.
Carries the requested temperature, the species name, and the overall valid temperature bounds (when known).
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:
objectClass for querying thermochemical database.
- Parameters:
db_file (str)
- get_gas_constant_ref()[source]
Return the dataset gas constant, with a safe legacy fallback.
Legacy databases without valid metadata retain the historic universal constant. Database errors are deliberately allowed to propagate instead of being mistaken for a legacy-database condition.
- Return type:
- migrate_metadata()[source]
Add canonical dataset metadata to a connected legacy database.
This explicit, idempotent operation changes only the additive
metadatatable. It never rebuilds or alters thermochemical rows.- Return type:
None
- get_statistics()[source]
Get database statistics.
- Returns:
DatabaseStats with totals, phase counts, and average molecular weight.
- Return type:
DatabaseStats
- 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:
SpeciesData with its
intervalstuple, or None if not found.- Return type:
SpeciesData | None
- get_species_info(species_id)[source]
Get lightweight species metadata without loading intervals.
- Parameters:
species_id (int) – Database ID of the species.
- Returns:
SpeciesInfo, or None if the species is not found.
- Return type:
SpeciesInfo | None
- get_temperature_bounds(species_id)[source]
Return the overall [temp_min, temp_max] covered by a species.
- get_species_for_temperature(species_id, temperature)[source]
Get the interval and coefficients valid at a specific temperature.
- list_all_species()[source]
List every species in a single ordered query.
- Returns:
List of all SpeciesInfo ordered by name.
- Return type:
list[SpeciesInfo]
- static calculate_cp(coeffs, temperature)[source]
Calculate Cp(T)/R using NASA-7 polynomial coefficients.
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:
objectBuild a SQLite database from a thermo.inp file.
- write_metadata()[source]
Write canonical dataset metadata using idempotent upserts.
The method intentionally does not commit; callers can include metadata writes in the same transaction as a database build.
- Return type:
None
- static parse_species_record(line)[source]
Extract species name (cols 1-16) and comments (cols 19-80).
- 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.
- 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.