Releases: sinagilassi/PyThermoDB
🚀 Build & Save Mixture ThermoDB
📄 Overview
This release introduces advanced support for mixture thermodynamic databases, including custom references and matrix data handling. The documentation details new features, usage patterns, and example workflows for initializing, building, and loading mixture thermodb objects.
🧩 Features
☑️ Custom References
You can now define custom references for mixtures directly in your code. See the example below for how to structure your reference data and initialize your own thermodynamic database:
REFERENCES = """
REFERENCES:
CUSTOM-REF-1:
DATABOOK-ID: 1
TABLES:
Non-randomness parameters of the NRTL equation-3:
TABLE-ID: 1
DESCRIPTION:
This table provides the NRTL non-randomness parameters for the NRTL equation.
MATRIX-SYMBOL:
- a-constant: a
- b
- c
- alpha
STRUCTURE:
COLUMNS: [No.,Mixture,Name,Formula,State,a_i_1,a_i_2,b_i_1,b_i_2,c_i_1,c_i_2,alpha_i_1,alpha_i_2]
SYMBOL: [None,None,None,None,None,a_i_1,a_i_2,b_i_1,b_i_2,c_i_1,c_i_2,alpha_i_1,alpha_i_2]
UNIT: [None,None,None,None,None,1,1,1,1,1,1,1,1]
VALUES:
- [1,methanol|ethanol,methanol,CH3OH,l,0,1,1,1.564200272,0,35.05450323,0,4.481683583]
- [2,methanol|ethanol,ethanol,C2H5OH,l,2,3,-20.63243601,0,0.059982839,0,4.481683583,0]
- [1,methanol|methane,methanol,CH3OH,l,1,0.300492719,0,1.564200272,0,35.05450323,0,4.481683583]
- [2,methanol|methane,methane,CH4,g,0.380229054,0,-20.63243601,0,0.059982839,0,4.481683583,0]
"""
# Example: check and build mixture thermodb - 1.py
custom_reference = {
'reference': [REFERENCES]
}
thermo_db = ptdb.init(custom_reference=custom_reference)📚 Databook and Table Management
List databooks and tables to explore available data:
db_list = thermo_db.list_databooks()
tb_list = thermo_db.list_tables('CUSTOM-REF-1')🧪 Mixture and Component Handling
Easily create components and mixtures:
methanol = Component(name="methanol", formula="CH3OH", state="l")
ethanol = Component(name="ethanol", formula="C2H5OH", state="l")
mixture_methanol_ethanol = methanol.name + ' | ' + ethanol.name
# NOTE: set databook
databook_ = 'CUSTOM-REF-1'
# NOTE: set table
table_ = 'Non-randomness parameters of the NRTL equation-3'
# ! reference config
reference_config = {
'nrtl': {
'databook': databook_,
'table': table_,
'symbols': {
'alpha': 'alpha',
'a_i_j': 'a_i_j',
'b_i_j': 'b_i_j',
'c_i_j': 'c_i_j',
}
}
}
# >> yaml reference config
reference_config_yaml = '''
methanol | ethanol:
nrtl:
databook: CUSTOM-REF-1
table: Non-randomness parameters of the NRTL equation-3
symbols:
alpha: alpha
a_i_j: a_i_j
b_i_j: b_i_j
c_i_j: c_i_j
methanol | methane | ethanol:
nrtl:
databook: CUSTOM-REF-1
table: Non-randomness parameters of the NRTL equation-3
symbols:
alpha: alpha
a_i_j: a_i_j
b_i_j: b_i_j
c_i_j: c_i_j
'''🏗️ Build Mixture ThermoDB
Build binary or multi-component mixture thermodb objects with flexible configuration:
mixture_thermodb = check_and_build_mixture_thermodb(
components=[methanol, ethanol],
reference_config=reference_config_yaml,
custom_reference=custom_reference,
...
)💾 Load and Inspect Mixture ThermoDB
Load a saved thermodb and inspect its properties and matrix data:
nrtl_thermodb = ptdb.load_thermodb(thermodb_path)
print(nrtl_thermodb.check())🧮 Matrix Data Operations
Query matrix properties and values for mixtures:
nrtl_alpha = nrtl_thermodb.check_property('nrtl')
print(nrtl_alpha.get_matrix_property("a_i_j", [comp1, comp2]))Loop through matrix data for all component pairs:
for comp1 in components:
for comp2 in components:
prop_name = f"b_{comp1}_{comp2}"
prop_value = nrtl_alpha.ij(property=prop_name, mixture_name=mixture_name).get('value')
print(f"Property: {prop_name} = {prop_value}")🛠️ Build Mixture ThermoDB from Reference
This release also introduces the ability to build mixture thermodynamic databases directly from reference content, supporting both binary and multi-component mixtures, saving, and ignoring state for specific properties.
⚡ Example Usage
# Import required modules
from pyThermoDB import build_mixture_thermodb_from_reference, MixtureThermoDB
from pythermodb_settings.models import Component
# Define components
methanol = Component(name='methanol', formula='CH3OH', state='l')
ethanol = Component(name='ethanol', formula='C2H5OH', state='l')
methane = Component(name='methane', formula='CH4', state='g')
# Binary mixture
binary_mixture = [methanol, ethanol]
# Multi-component mixture
multi_component_mixture = [methanol, ethanol, methane]
# Build binary mixture thermodb
thermodb_components_ = build_mixture_thermodb_from_reference(
components=binary_mixture,
reference_content=REFERENCE_CONTENT,
)
print(type(thermodb_components_))
# Build and save thermodb
thermodb_component_save_ = build_mixture_thermodb_from_reference(
components=binary_mixture,
reference_content=REFERENCE_CONTENT,
thermodb_save=True,
thermodb_save_path=parent_path,
)
print(type(thermodb_component_save_))
# Build multi-component mixture thermodb
thermodb_components_multi_ = build_mixture_thermodb_from_reference(
components=multi_component_mixture,
reference_content=REFERENCE_CONTENT,
)
print(type(thermodb_components_multi_))
# Build with mixture names
thermodb_components_multi_ = build_mixture_thermodb_from_reference(
components=multi_component_mixture,
reference_content=REFERENCE_CONTENT,
mixture_names=["methanol | ethanol", "methane | ethanol"],
verbose=True,
)
print(type(thermodb_components_multi_))
# Ignore state for specific properties
ignore_state_props = ['a']
thermodb_component_ignore_state_ = build_mixture_thermodb_from_reference(
components=binary_mixture,
reference_content=REFERENCE_CONTENT,
ignore_state_props=ignore_state_props,
)
print(type(thermodb_component_ignore_state_))
# Build and save with ignore state
thermodb_component_ignore_state_save_ = build_mixture_thermodb_from_reference(
components=binary_mixture,
reference_content=REFERENCE_CONTENT,
ignore_state_props=ignore_state_props,
thermodb_save=True,
thermodb_save_path=parent_path,
thermodb_name=f"{methanol.name}-{ethanol.name} with ignore state props",
)
print(type(thermodb_component_ignore_state_save_))🔍 Highlights
- Build from inline reference content
- Support for binary and multi-component mixtures
- Save thermodb objects to disk
- Optionally ignore state for selected properties
- Specify mixture names for advanced use cases
- Custom mixture references
- Flexible databook/table management
- Binary and multi-component mixture support
- Matrix data querying and inspection
- Rich example scripts for quick adoption
🚀 Build & Save Component ThermoDB
🧩 Component ThermoDB Builder
Easily build a ThermoDB for any chemical component using a reference content block. Just specify the component name, formula, and state, and let build_component_thermodb_from_reference do the rest!
- Example:
thermodb_component = build_component_thermodb_from_reference( component_name="carbon dioxide", component_formula="CO2", component_state="g", reference_content=REFERENCE_CONTENT, )
💾 Save Your ThermoDB
Now you can save your generated ThermoDB to disk for future use!
Set thermodb_save=True and provide a path and name to persist your data.
- Example:
thermodb_component_save = build_component_thermodb_from_reference( ..., thermodb_save=True, thermodb_save_path=parent_path, thermodb_name="CO2_thermodb", )
🛠️ Flexible State Handling
Ignore specific state properties when building your ThermoDB.
Use the ignore_state_props argument to customize which properties to skip.
- Example:
thermodb_component_ignore_state = build_component_thermodb_from_reference( ..., ignore_state_props=["Cp_IG"], )
✅ Validation & Checks
Each ThermoDB object includes a .check() method to validate its integrity and ensure your data is correct.
- Example:
print(thermodb_component.thermodb.check())
Enjoy streamlined ThermoDB creation, saving, and validation for your chemical data workflows!
✨ Extract YAML Reference from String
🚀 Overview
You can now extract a YAML reference section directly from a string that contains both descriptive text and YAML content. This makes it much easier to work with mixed-format reference files and streamlines the process of loading and validating custom references.
📝 How It Works
You can pass a string (e.g., REFERENCE_CONTENT) that includes both text and a YAML block. The function extract_reference_from_str will automatically find and extract the YAML section, returning it as a Python object.
# SECTION: extract reference from string
extracted_reference = extract_reference_from_str(REFERENCE_CONTENT)
print(extracted_reference)
extract_status, extracted_content = extracted_reference
print(f"Extract Status: {extract_status}")
print(f"Extracted Content: {extracted_content_}")🔍 What You Get
extract_status: Indicates if the extraction was successful.extracted_content: Contains the parsed YAML data, ready to use in your workflow.
💡 Why It Matters
This feature allows you to:
- Work with reference files that mix documentation and YAML without manual editing.
- Directly use the extracted YAML for further processing (e.g., checking references, initializing databases).
📂 See Example
For a complete usage example, check:
examples/configs/load & check str.py
This script demonstrates how to use extract_reference_from_str and process the extracted YAML reference in your workflow.
🚀 Reference Mapping
📄 Example Overview
This release demonstrates how to use the reference mapping functionality in pyThermoDB to map reference data to a chemical component. The example is provided in examples/configs/map-reference.py.
🧩 Example Structure
🔗 Imports
The script imports key functions and classes from pyThermoDB:
build_component_thermodb_from_reference,ComponentThermoDBfor building and handling thermodynamic databases.component_reference_mapperfor mapping reference data.Component,ComponentReferenceThermoDBfor representing chemical components and their mapped references.rich.printfor pretty output.
📦 Reference Content
The REFERENCE_CONTENT variable contains a large YAML-formatted string with multiple reference tables, including:
- Ideal Gas Heat Capacity Table
- General Data Table
- Vapor Pressure Table
- NRTL Non-randomness Parameters
Each table provides structured data for various chemical species, including equations, parameters, and values.
🧑🔬 Input: Component Definition
The script defines a component to search for in the reference data:
component_name = 'carbon dioxide'
component_formula = 'CO2'
component_state = 'g'
component = Component(
name=component_name,
formula=component_formula,
state=component_state
)Input:
- Name:
carbon dioxide - Formula:
CO2 - State:
g(gas)
🗺️ Reference Mapping
The core mapping is performed by:
component_ref_thermodb: ComponentReferenceThermoDB = component_reference_mapper(
component=component,
reference_content=REFERENCE_CONTENT,
key='Formula-State',
ignore_component_state=True
)Parameters:
component: TheComponentobject defined above.reference_content: The YAML string with all reference tables.key:'Formula-State'(mapping is based on formula and state).ignore_component_state:True(state is ignored in mapping).
🖨️ Output
The result is printed using rich formatting:
print(
f"[bold green]Component Reference ThermoDB:[/bold green] {component_ref_thermodb}\n")Output:
- A
ComponentReferenceThermoDBobject containing all mapped reference data forcarbon dioxide. - The output includes all relevant tables and values for the component, ready for further use in thermodynamic calculations.
📝 Summary
- This example shows how to map structured reference data to a chemical component using
pyThermoDButilities. - The approach is flexible and can be adapted for other components and reference formats.
For more details, see the full example in examples/configs/map-reference.py.
✨ Building Thermodynamic Property Data and Equations
🛠️ About build_thermo_property and build_components_thermo_property
There are two main methods for building thermodynamic property data and equations:
-
🔧 build_thermo_property: This legacy method accepts a list of component names (as strings) along with the databook and table names. It is simple to use when you only have the component names and do not need to specify additional details like formula or state explicitly.
-
⚡ build_components_thermo_property: This recommended method accepts a list of
Componentobjects, which can include name, formula, and state. It also allows you to specify thecomponent_key(such asName-StateorFormula-State) for more precise and flexible component identification. This method is preferred for new code and when working with more complex or ambiguous component data.
Both methods return either a TableData or TableEquation object, depending on the table type, which can then be used to retrieve properties or perform calculations.
🧬 About Formula-State and Name-State
When working with component data and equations, you can specify how components are identified in the database using a component_key:
- 📝 Name-State: Uses the component's name (e.g., "Carbon Dioxide") and its physical state (e.g., gas, liquid) as the unique identifier. This is useful when the name is descriptive and unambiguous.
- 🧪 Formula-State: Uses the chemical formula (e.g., "CO2") and the state as the unique identifier. This is preferred when the formula is standardized and avoids ambiguity from naming variations.
Selecting the appropriate key ensures accurate matching and retrieval of component properties and equations, especially when a database contains multiple entries for the same substance in different states (e.g., liquid vs. gas).
🔍 Check Component Availability in a Table
Added functionality to check if a specific component is available in a given databook and table.
Supports flexible queries using component name, formula, and state. Returns results in a dictionary format for easy integration and inspection.
📋 Examples:
# 📝 Query by Name and State
comp1 = "carbon Dioxide"
state1 = "G"
column = 'Name'
query = f"Name.str.lower() == '{comp1.lower()}' and State.str.lower() == '{state1.lower()}'"
COMP1_check_availability = thermo_db.check_component(
component_name=comp1,
databook='CUSTOM-REF-1',
table='General-Data',
column_name=query,
query=True,
res_format='dict'
)
print(COMP1_check_availability)
# 🧪 Query by Formula and State
comp1 = "CO2"
query = f"Formula.str.lower() == '{comp1.lower()}' and State == 'g'"
COMP1_check_availability = thermo_db.check_component(
component_name=comp1,
databook='CUSTOM-REF-1',
table='General-Data',
column_name=query,
query=True,
res_format='dict'
)
print(COMP1_check_availability)
# 🎯 Using Component object
from pyThermoDB.models import Component
CO2 = Component(
name="Carbon dioxide",
formula="CO2",
state="g"
)
is_available = thermo_db.is_component_available(
CO2,
'CUSTOM-REF-1',
'General-Data',
component_key='Formula-State',
)
print(is_available)🏗️ Build Data and Build Equations
Introduced methods to build thermodynamic property data and equations for components. Supports both legacy and new approaches:
- 📊 Build data using either component names or
Componentobjects. - 📈 Build equations for properties such as vapor pressure and heat capacity.
- 🔗 Enhanced support for retrieving and calculating properties and equations directly from custom references and tables.
- ✅ Improved type checking and error handling for data and equation objects.
📋 Examples:
📊 Build Data
# 🔧 Using component name (legacy method)
comp1 = "Carbon Dioxide"
data_1 = thermo_db.build_thermo_property(
[comp1],
'CUSTOM-REF-1',
'General-Data'
)
# Check type
if not isinstance(data_1, TableData):
raise TypeError("data_1 is not a TableData instance")
print(data_1.get_property("MW"))
# ⚡ Using Component object (recommended)
comp1_Component = Component(name="Carbon Dioxide", formula="CO2", state="g")
# 📝 Name-State approach
data_1 = thermo_db.build_components_thermo_property(
[comp1_Component],
'CUSTOM-REF-1',
'General-Data',
component_key='Name-State'
)
# 🧪 Formula-State approach
data_1 = thermo_db.build_components_thermo_property(
[comp1_Component],
'CUSTOM-REF-1',
'General-Data',
component_key='Formula-State'
)
print(data_1.get_property("MW"))📈 Build Equations
# 🔧 Using component name (legacy method)
comp1 = "Carbon Dioxide"
comp1_eq_1 = thermo_db.build_thermo_property(
[comp1],
'CUSTOM-REF-1',
'Vapor-Pressure'
)
# Check type
if not isinstance(comp1_eq_1, TableEquation):
raise TypeError("comp1_eq_1 is not a TableEquation instance")
# 📋 Equation details
print(comp1_eq_1.equation_parms())
print(comp1_eq_1.equation_args())
print(comp1_eq_1.equation_body())
print(comp1_eq_1.equation_return())
# 🧮 Calculate at T=290K
res_ = comp1_eq_1.cal(T=290)
print(res_)
# ⚡ Using Component object (recommended)
comp1_Component = Component(name="Carbon Dioxide", formula="CO2", state="g")
# 📝 Name-State approach
comp1_eq_1 = thermo_db.build_components_thermo_property(
[comp1_Component],
'CUSTOM-REF-1',
'Vapor-Pressure',
component_key='Name-State'
)
print(comp1_eq_1.cal(T=290))🧬 Build Component ThermoDB
Introduced comprehensive functionality to build unified thermodynamic property databases for individual components or groups of components. This feature consolidates various thermodynamic properties, equations, and matrix data into easily accessible objects.
The Build Component ThermoDB system supports multiple data types and provides flexible component identification methods for creating complete thermodynamic property collections.
🔧 Key Features:
- 🔗 Unified Access: All thermodynamic properties for a component in one object
- 🎯 Flexible Identification: Multiple ways to identify components (name, formula, state)
- 📈 Mixed Data Types: Supports static data, equations, and matrix parameters
- ✅ Validation: Built-in checking to ensure data integrity
- 💾 Persistence: Can save and reload thermodb objects
📋 Examples:
🏗️ Reference Configuration
First, define which properties to include and their sources:
# Define reference configuration (YAML format)
reference_config_yml = """
ALL:
heat-capacity:
databook: CUSTOM-REF-1
table: Ideal-Gas-Molar-Heat-Capacity
symbol: Cp_IG
vapor-pressure:
databook: CUSTOM-REF-1
table: vapor-pressure
symbol: VaPr
general:
databook: CUSTOM-REF-1
table: general-data
symbols:
Pc: Pc
Tc: Tc
AcFa: AcFa
carbon dioxide:
heat-capacity:
databook: CUSTOM-REF-1
table: Ideal-Gas-Molar-Heat-Capacity
symbol: Cp_IG
vapor-pressure:
databook: CUSTOM-REF-1
table: vapor-pressure
symbol: VaPr
general:
databook: CUSTOM-REF-1
table: general-data
symbols:
Pc: Pc
Tc: Tc
AcFa: AcFa
"""🔧 Single Component ThermoDB
from pyThermoDB.models import Component
# Using component name (legacy method)
thermodb_component = ptdb.build_component_thermodb(
component_name='carbon dioxide',
reference_config=reference_config_yml,
custom_reference=ref
)
# Using component name (by formula)
thermodb_component_ = ptdb.build_component_thermodb(
component_name='CO2',
reference_config=reference_config,
custom_reference=ref,
component_key='Formula'
)
# Using Component object with Formula-State (recommended)
CO2_component = Component(
name='carbon dioxide',
formula='CO2',
state='g'
)
# Formula-State approach
thermodb_component = ptdb.check_and_build_component_thermodb(
component=CO2_component,
reference_config=reference_config_yml,
custom_reference=ref,
component_key='Formula-State'
)
# Name-State approach
print("[bold magenta]By Component and Name-State[/bold magenta]")
thermodb_component_ = ptdb.check_and_build_component_thermodb(
component=CO2_component,
reference_config=reference_config,
custom_reference=ref,
component_key='Name-State'
)
# Name-State with ignore (ignoring state for vapor pressure)
print("[bold magenta]By Component and Name with ignore[/bold magenta]")
thermodb_component_ = ptdb.check_and_build_component_thermodb(
component=CO2_component,
reference_config=reference_config,
custom_reference=ref,
component_key='Name-State',
ignore_state_props=['VaPr'],
)
# Formula-State with ignore (ignoring state for vapor pressure)
print("[bold magenta]By Component and Formula with ignore[/bold magenta]")
thermodb_component_ = ptdb.check_and_build_component_thermodb(
component=CO2_component,
reference_config=reference_config,
custom_reference=ref,
component_key='Formula-State',
ignore_state_props=['VaPr'],
)
# Validation
print(f"Build successful: {thermodb_component.check()}")
print(f"Messages: {thermodb_component.message}")🎯 Multiple Components ThermoDB
# Configuration for binary interaction parameters
reference_config_2 = {
'nrtl': {
'databook': 'CUSTOM-REF-1',
'table': "NRTL Non-randomness parameters-2"
}
}
# Build components thermodb
thermodb_components = ptdb.build_components_thermodb(
component_names=['ethanol', 'methanol'],
reference_config=reference_config_2,
custom_reference=ref
)
print(f"Build successful: {thermodb_components.check()}")🚀 Property Availability Checking
🚀 New Features
Property Availability Checking
This release introduces new methods to check property availability in your data tables and equations. These methods help you quickly verify if a specific property (by symbol or column name) exists in your data or equation objects.
Methods Added
is_property_available(property_name, search_mode='SYMBOL', 'COLUMN', or 'BOTH')
Checks if a property is available in the table or equation, either by its symbol or column name.
📝 Usage Examples
For TableData
# ...existing code...
# Build TableData object
data_1 = thermo_db.build_thermo_property(
[comp1],
'CUSTOM-REF-1',
'General-Data'
)
# Check if a property is available by symbol
print(data_1.is_property_available('GiEnFo')) # False
print(data_1.is_property_available('MW')) # True
# ...existing code...For TableEquation
# ...existing code...
# Build TableEquation object
comp1_eq_1 = thermo_db.build_thermo_property(
[comp1],
'CUSTOM-REF-1',
'Vapor-Pressure'
)
# Check property availability by symbol and column name
print(comp1_eq_1.is_property_available('VaPr')) # True
print(comp1_eq_1.is_property_available('GiEnFo')) # False
print(comp1_eq_1.is_property_available('VaPr', search_mode='SYMBOL')) # True
print(comp1_eq_1.is_property_available('vapor-pressure', search_mode='COLUMN')) # True
# ...existing code...Thank you for using pyThermoDB!
Feel free to open issues or pull requests for feedback and contributions.
🚀 Component ThermoDB Builders
🚀 New Feature: Component ThermoDB Builders
Two new functions have been introduced in pyThermoDB to simplify the creation of thermodynamic databases for individual or multiple chemical components.
🔹 build_component_thermodb
Creates a ThermoDB instance for a single component using a custom reference. This allows the user to extract and organize properties such as:
- Ideal gas heat capacity
- Vapor pressure
- General component data (e.g., critical properties, molecular weight)
Example:
thermodb = ptdb.build_component_thermodb(
component_name='carbon dioxide',
property_source={
'heat-capacity': {'databook': 'CUSTOM-REF-1', 'table': 'Ideal-Gas-Molar-Heat-Capacity'},
'vapor-pressure': {'databook': 'CUSTOM-REF-1', 'table': 'Vapor-Pressure'},
'general': {'databook': 'CUSTOM-REF-1', 'table': 'General-Data'},
},
custom_reference=ref
)🔹 build_components_thermodb
Builds a ThermoDB for multiple components at once. This is especially useful for initializing matrix-based data like binary interaction parameters (e.g., NRTL parameters).
Example:
thermodb_multi = ptdb.build_components_thermodb(
component_names=['ethanol', 'methanol'],
property_source={
'nrtl': {'databook': 'CUSTOM-REF-1', 'table': 'NRTL Non-randomness parameters-2'}
},
custom_reference=ref
)🔄 New Matrix Data Format
New Matrix Data Format
We are excited to announce a new structured format for defining matrix data in the latest update of the package. This enhancement brings clarity, consistency, and better integration for handling thermodynamic models, specifically for NRTL non-randomness parameters.
✨ What's New?
A new standardized structure has been introduced for defining matrix-based parameters like a, b, c, and alpha used in the NRTL model.
📊 Example Entry
STRUCTURE:
- COLUMNS: [No.,Name,Formula,a_i_1,a_i_2,b_i_1,b_i_2,c_i_1,c_i_2,alpha_i_1,alpha_i_2]
- SYMBOL: [None,None,None,a_i_1,a_i_2,b_i_1,b_i_2,c_i_1,c_i_2,alpha_i_1,alpha_i_2]
- UNIT: [None,None,None,1,1,1,1,1,1,1,1]
VALUES:
- [None,None,None,methanol,ethanol,methanol,ethanol,methanol,ethanol,methanol,ethanol]
- [None,None,None,CH3OH,C2H5OH,CH3OH,C2H5OH,CH3OH,C2H5OH,CH3OH,C2H5OH]
- [1,methanol,CH3OH,0,0.300492719,0,1.564200272,0,35.05450323,0,4.481683583]
- [2,ethanol,C2H5OH,0.380229054,0,-20.63243601,0,0.059982839,0,4.481683583,0]OR
STRUCTURE:
- COLUMNS: [No.,Mixture,Name,Formula,a_i_1,a_i_2,b_i_1,b_i_2,c_i_1,c_i_2,alpha_i_1,alpha_i_2]
- SYMBOL: [None,None,None,None,a_i_1,a_i_2,b_i_1,b_i_2,c_i_1,c_i_2,alpha_i_1,alpha_i_2]
- UNIT: [None,None,None,None,1,1,1,1,1,1,1,1]
VALUES:
- [1,methanol|ethanol,methanol,CH3OH,0,0.300492719,0,1.564200272,0,35.05450323,0,4.481683583]
- [2,methanol|ethanol,ethanol,C2H5OH,0.380229054,0,-20.63243601,0,0.059982839,0,4.481683583,0]
- [1,methane|ethanol,methanol,CH3OH,0,0.300492719,0,1.564200272,0,35.05450323,0,4.481683583]
- [2,methane|ethanol,ethanol,C2H5OH,0.380229054,0,-20.63243601,0,0.059982839,0,4.481683583,0]📌 Why It Matters
This format streamlines data integration for multi-component systems and is aligned with modern data-driven thermodynamic modeling. It also simplifies future expansions to support models like UNIQUAC and Wilson.
# REFERENCES
## NRTL-PARAMETERS
DATABOOK-ID: 1
### NRTL Non-randomness parameters-1
TABLE-ID: 4
DESCRIPTION: This table provides the NRTL non-randomness parameters for the NRTL equation.
MATRIX-SYMBOL:
- a
- b
- c
- alpha
STRUCTURE:
- COLUMNS: [No.,Name,Formula,a_i_1,a_i_2,b_i_1,b_i_2,c_i_1,c_i_2,alpha_i_1,alpha_i_2]
- SYMBOL: [None,None,None,a_i_1,a_i_2,b_i_1,b_i_2,c_i_1,c_i_2,alpha_i_1,alpha_i_2]
- UNIT: [None,None,None,1,1,1,1,1,1,1,1]
VALUES
- [None,None,None,methanol,ethanol,methanol,ethanol,methanol,ethanol,methanol,ethanol]
- [None,None,None,CH3OH,C2H5OH,CH3OH,C2H5OH,CH3OH,C2H5OH,CH3OH,C2H5OH]
- [1,methanol,CH3OH,0,0.300492719,0,1.564200272,0,35.05450323,0,4.481683583]
- [2,ethanol,C2H5OH,0.380229054,0,-20.63243601,0,0.059982839,0,4.481683583,0]
### NRTL Non-randomness parameters-2
TABLE-ID: 5
DESCRIPTION: This table provides the NRTL non-randomness parameters for the NRTL equation.
MATRIX-SYMBOL:
- a
- b
- c
- alpha
STRUCTURE:
- COLUMNS: [No.,Mixture,Name,Formula,a_i_1,a_i_2,b_i_1,b_i_2,c_i_1,c_i_2,alpha_i_1,alpha_i_2]
- SYMBOL: [None,None,None,None,a_i_1,a_i_2,b_i_1,b_i_2,c_i_1,c_i_2,alpha_i_1,alpha_i_2]
- UNIT: [None,None,None,None,1,1,1,1,1,1,1,1]
VALUES:
- [1,methanol|ethanol,methanol,CH3OH,0,0.300492719,0,1.564200272,0,35.05450323,0,4.481683583]
- [2,methanol|ethanol,ethanol,C2H5OH,0.380229054,0,-20.63243601,0,0.059982839,0,4.481683583,0]
- [1,methane|ethanol,methanol,CH3OH,0,0.300492719,0,1.564200272,0,35.05450323,0,4.481683583]
- [2,methane|ethanol,ethanol,C2H5OH,0.380229054,0,-20.63243601,0,0.059982839,0,4.481683583,0]
EXTERNAL-REFERENCES:
- url1
- url2📦 Equation/Data Format in Markdown File
✨ New Feature: Load Equations and Data from Markdown Files
We are excited to introduce support for structured thermodynamic data and equations using Markdown (.md) files! This new capability allows users to manage and reference tabulated data and equation sets in a human-readable format.
🧩 Markdown Pattern Format
The accepted markdown file must follow a specific structure. A typical reference file includes:
# REFERENCES
## content
DATABOOK-ID: content
### table-name-1
TABLE-ID: content
DESCRIPTION: content
DATA: []
MATRIX-SYMBOL:
- a
- b
- c
- alpha
EQUATIONS:
- EQ-1:
- BODY:
- content
- content
- BODY-INTEGRAL:
- content
- content
- BODY-FIRST-DERIVATIVE:
- content
- content
- BODY-SECOND-DERIVATIVE:
- content
- content
STRUCTURE:
- COLUMNS: [item1, item2]
- SYMBOL: [item1, item2]
- UNIT: [item1, item2]
- CONVERSION: [item1, item2]
VALUES:
- [item1, item2]
- [item1, item2]
EXTERNAL-REFERENCES:
- url1
- url2🛠️ How to Use in Code
Here's how to integrate your custom markdown reference in the app:
import os
import pyThermoDB as ptdb
# File path
md_file = 'str-ref-1.md'
md_path = os.path.join(parent_dir, md_file)
# Register reference
ref = {'reference': [md_path]}
# Initialize your ThermoDB with the custom markdown reference
thermo_db = ptdb.init(custom_reference=ref)
# Optional: print loaded references
# print(thermo_db.reference)
# Select your reference for use
print(thermo_db.select_reference('CUSTOM-REF-1'))📚 Benefits
- 📄 Readable & Editable: Use plain-text .md files for maintaining your thermodynamic databases.
- 🔁 Reusable: Define equations and structures once, reuse across tables.
- 🔗 Extensible: Easily include external references and structured equations.
🛠️ Direct Table Value Insertion in YAML
You can now directly add table values in the YAML file. This allows for a streamlined process where you can define both data and matrix-data tables in a structured format, making the data entry more efficient and organized.
Examples
- A
datadefined with the following format as:
General-Data:
TABLE-ID: 2
DESCRIPTION:
This table provides the general data of different chemical species participating ....
DATA: []
STRUCTURE:
COLUMNS: [No.,Name,Formula,State,Molecular-Weight,Critical-Temperature,Critical-Pressure,Critical-Molar-Volume,Critical-Compressibility-Factor,Acentric-Factor,Enthalpy-of-Formation,Gibbs-Energy-of-Formation]
SYMBOL: [None,None,None,None,MW,Tc,Pc,Vc,Zc,AcFa,EnFo,GiEnFo]
UNIT: [None,None,None,None,g/mol,K,MPa,m3/kmol,None,None,kJ/mol,kJ/mol]
CONVERSION: [None,None,None,None,1,1,1,1,1,1,1,1]
VALUES:
- [1,'carbon dioxide','CO2','g',44.01,304.21,7.383,0.094,0.274,0.2236,-393.5,-394.4]
- [2,'carbon monoxide','CO','g',28.01,132.92,3.499,0.0944,0.299,0.0482,-110.5,-137.2]- A
matrix-dataas:
NRTL Non-randomness parameters-2:
TABLE-ID: 1
DESCRIPTION:
This table provides the NRTL non-randomness parameters for the NRTL equation.
MATRIX-SYMBOL:
- a
- b
- c
- alpha
STRUCTURE:
COLUMNS: [No.,Name,Formula,a_i_1,a_i_2,b_i_1,b_i_2,c_i_1,c_i_2,alpha_i_1,alpha_i_2]
SYMBOL: [None,None,None,a_i_1,a_i_2,b_i_1,b_i_2,c_i_1,c_i_2,alpha_i_1,alpha_i_2]
UNIT: [None,None,None,1,1,1,1,1,1,1,1]
VALUES:
- [None,None,None,methanol,ethanol,methanol,ethanol,methanol,ethanol,methanol,ethanol]
- [None,None,None,CH3OH,C2H5OH,CH3OH,C2H5OH,CH3OH,C2H5OH,CH3OH,C2H5OH]
- [1,methanol,CH3OH,0,0.300492719,0,1.564200272,0,35.05450323,0,4.481683583]
- [2,ethanol,C2H5OH,0.380229054,0,-20.63243601,0,0.059982839,0,4.481683583,0]