Releases: sinagilassi/PyThermoDB
🔄 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
data
defined 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-data
as:
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]
🔍 Search a Component Name or Formula
🔍 Search a Component Name or Formula
PyThermoDB now includes a powerful search feature that allows you to locate specific components by their name or formula within the databook and tables. This enhancement streamlines data retrieval and enhances the usability of PyThermoDB.
🔎 Search for a Component
You can initiate a component search using the following Python method:
# import libs
import pyThermoDB as ptdb
# check version
print(ptdb.__version__)
# databook reference initialization
tdb = ptdb.init()
# Search for a component in the databook and tables
# open all tables in the browser
tdb.tables_view()
📋 Search Results
The search results will provide detailed information, including:
- 📚 Databook Name and ID: Identifies the databook where the component is stored.
- 📋 Table Name and ID: Specifies the table containing comprehensive data for the component.
Interactive Databook & Tables Viewer
🆕 Interactive Databook & Tables Viewer
tables_view()
A new convenience method that opens your default web browser and displays all databooks and their tables in a searchable, interactive view.
💡 Usage
To utilize this feature, follow these steps:
- Initialize the pyThermoDB reference:
import pyThermoDB as ptdb
tdb = ptdb.init()
- Launch the browser view of all databooks and tables:
# open browser
tdb.tables_view()
Enhanced Table Viewing in Browser
We are excited to announce the latest update to pyThermoDB! With this release, we have introduced a new feature that allows users to view table contents directly in the browser. This enhancement simplifies the process of selecting a databook and table, making it easier to check the availability of components and perform searches efficiently.
How to Use:
To utilize this feature, follow these steps:
- Initialize the pyThermoDB reference:
import pyThermoDB as ptdb
tdb = ptdb.init()
- View table content in the browser:
tdb.table_view(databook_id or name, table_id or name)
Replace databook_id/name
and table_id/name
with the specific IDs/Names
of the databook and table you want to view.
This update improves usability and accessibility, providing a seamless experience for exploring thermodynamic data using pyThermoDB.
Equation/Data Format in YML File
New Feature: Equation/Data Format in YML File
Description:
Added support for defining thermodynamic equations in YML files, allowing flexible customization and integration with custom thermodynamic databases.
Details:
- EQUATIONS:
Vapor-Pressure:
TABLE-ID: 3
DESCRIPTION:
This table provides the vapor pressure (P) in Pa as a function of temperature (T) in K.
EQUATIONS:
EQ-1:
BODY:
- parms['C1 | C1 | 1'] = parms['C1 | C1 | 1']/1
- parms['C2 | C2 | 1'] = parms['C2 | C2 | 1']/1
- parms['C3 | C3 | 1'] = parms['C3 | C3 | 1']/1
- parms['C4 | C4 | 1'] = parms['C4 | C4 | 1']/1
- parms['C5 | C5 | 1'] = parms['C5 | C5 | 1']/1
- res['vapor-pressure | VaPr | Pa'] = math.exp(parms['C1 | C1 | 1'] + parms['C2 | C2 | 1']/args['temperature | T | K'] + parms['C3 | C3 | 1']*math.log(args['temperature | T | K']) + parms['C4 | C4 | 1']*(args['temperature | T | K']**parms['C5 | C5 | 1']))
BODY-INTEGRAL:
None
BODY-FIRST-DERIVATIVE:
None
BODY-SECOND-DERIVATIVE:
None
- PARAMETERS, ARGS, AND RETURN:
- Defined as
[name of parameter | symbol | unit]
- Defined as
STRUCTURE:
COLUMNS: [No.,Name,Formula,State,C1,C2,C3,C4,C5,Tmin,P(Tmin),Tmax,P(Tmax),Eq]
SYMBOL: [None,None,None,None,C1,C2,C3,C4,C5,Tmin,P(Tmin),Tmax,P(Tmax),VaPr]
UNIT: [None,None,None,None,1,1,1,1,1,K,Pa,K,Pa,Pa]
VALUES:
- [1,'carbon dioxide','CO2','g',140.54,-4735,-21.268,4.09E-02,1,216.58,5.19E+05,304.21,7.39E+06,1]
- DATA:
General-Data:
TABLE-ID: 2
DESCRIPTION:
This table provides the general data of different chemical species participating in the CO2 hydrogenation reaction and includes molecular weight (MW) in g/mol, critical temperature (Tc) in K, critical pressure (Pc) in MPa, and critical molar volume (Vc) in m3/kmol. The table also includes the critical compressibility factor (Zc), acentric factor (AcFa), enthalpy of formation (EnFo) in kJ/mol, and Gibbs energy of formation (GiEnFo) in kJ/mol. The chemical state of the species is also provided in the table and hence the enthalpy of formation and Gibbs energy of formation are provided for the ideal gas and liquid state are designated as EnFo_IG, GiEnFo_IG, EnFo_LIQ, and GiEnFo_LIQ, respectively.
DATA:
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]
- [3,'hydrogen','H2','g',2.016,33.19,1.313,0.064147,0.305,-0.216,0,0]
- [4,'methanol','CH3OH','g',32.04,512.5,8.084,0.117,0.222,0.5658,-200.7,-162]
- [5,'water','H2O','g',18.01,647.096,22.064,0.0559472,0.229,0.3449,-241.8,-228.6]
- [6,'acetylene','C2H2','g',26.037,308.3,6.138,0.112,0.268,0.1912,227.5,210.0]
- [7,'ethanol','C2H6O','l',46.068,514,6.137,0.168,0.241,0.6436,-277.70,-174.80]
- [8,'n-butane','C4H10','g',58.122,425.12,3.796,0.255,0.274,0.2002,-125.80,-16.60]
- [9,'methane','CH4','g',16.042,190.564,4.599,0.0986,0.286,0.0115,-74.50,-50.50]
- [10,'propane','C3H8','g',44.096,369.83,4.248,0.2,0.276,0.1523,-104.70,-24.30]
- [11,'1-butene','C4H8','g',56.106,419.5,4.02,0.241,0.278,0.1845,1.20,70.30]
- [12,"1,3-Butadiene",'C4H6','g',54.090,425,4.32,0.221,0.27,0.1950,109.20,149.80]
- [13,'ethylene','C2H4','g',28.053,282.34,5.041,0.131,0.281,0.0862,52.50,68.50]
- [14,'benzene','C6H6','l',78.112,562.05,4.895,0.256,0.268,0.2103,-49.10,124.5]
- [15,'nitrogen','N2','g',28.013,126.2,3.4,0.08921,0.289,0.0377,0,0]
- [16,'ethane','C2H6','g',30.069,305.32,4.872,0.1455,0.279,0.0995,-83.8,-31.9]
Initialization:
# files
yml_file = 'tests\\source-ref-4.yml'
yml_path = os.path.join(os.getcwd(), yml_file)
# custom ref
ref = {'reference': [yml_path]}
# Initialization of Own Thermo DB
thermo_db = ptdb.init(custom_reference=ref)
YAML-Based Thermodynamic Data Storage
🆕 New Feature: YAML-Based Thermodynamic Data Storage
You can now directly store and load thermodynamic data from .yml
files using a streamlined reference system. This allows for easier data management, version control, and collaboration.
🔧 How It Works
Step 1: Define Your Reference File
import os
# Define path to your YAML data file
yml_file = 'tests\\source-ref-1.yml'
yml_path = os.path.join(os.getcwd(), yml_file)
# Reference dictionary
ref = {'reference': [yml_path]}
Step 2: Initialize the App with the Custom Reference
thermo_db = ptdb.init(custom_reference=ref)
Step 3: Add STRUCTURE
and VALUES
as List to yml file
STRUCTURE:
COLUMNS: [Temperature, Pressure, Enthalpy, ...]
SYMBOL: [T, P, H, ...]
UNIT: [K, bar, kJ/mol, ...]
VALUES:
- [298.15, 1.0, -241.8, ...]
- [350.00, 1.5, -230.2, ...]
...
Let us know if you have feedback or suggestions!
Retrieve 2d-Array From TableMatrixData
New Features
Introducing the ijs Method
: Retrieve data matrix (numpy 2d array) from TableMatrixData with ease.
Example Usage
The following example demonstrates how to use the ijs method to retrieve the "Alpha" property for components comp1 and comp2:
# import packages/modules
import pyThermoDB as ptdb
import os
# COMPONENTS
# comp1
comp1 = "ethanol"
# comp2
comp2 = "butyl-methyl-ether"
# LOAD THERMODB
# ref
thermodb_file = 'thermodb_nrtl_ethanol_butyl-methyl-ether_1.pkl'
thermodb_path = os.path.join(os.getcwd(), thermodb_file)
print(thermodb_path)
# LOAD THERMODB
# load thermodb
nrtl_thermodb = ptdb.load_thermodb(thermodb_path)
print(type(nrtl_thermodb))
# CHECK THERMODB
# check all properties and functions registered
print(nrtl_thermodb.check())
# DATA
# list all data
print(nrtl_thermodb.check_properties())
# load data
nrtl_alpha_data = nrtl_thermodb.check_property('non-randomness-parameters')
print(type(nrtl_alpha_data))
# symbol
print(nrtl_alpha_data.matrix_symbol)
# ij matrix
# format 1
nrtl_data_ = f"alpha_{comp1}_{comp2}"
# format 2
nrtl_data_ = f"alpha | {comp1} | {comp2}"
# load matrix
alpha_ij = nrtl_alpha_data.ijs(nrtl_data_)
print(alpha_ij)
Matrix result:
{'ethanol | ethanol': 0.0, 'ethanol | butyl-methyl-ether': 0.680715, 'butyl-methyl-ether | ethanol': 0.680715, 'butyl-methyl-ether | butyl-methyl-ether': 0.0}
Retrieve From TableMatrixData
New Features
- Introducing the ij Method: Retrieve data from
TableMatrixData
with ease. This new method allows you to access properties using a compact ij notation.
Example Usage
The following example demonstrates how to use the ij method to retrieve the "Alpha" property for components comp1 and comp2:
The following components are available in Table Non-randomness parameters of the NRTL equation-2
.
# component list
comp1 = "methanol"
comp2 = "ethanol"
comp3 = 'benzene'
prop_name = f"Alpha_{comp1}_{comp3}"
print(nrtl_alpha.ij(prop_name))
print(nrtl_alpha.ij(prop_name).get('value'))
You can also loop through matrix data using the ij method:
components = [comp1, comp2, comp3]
for comp1 in components:
for comp2 in components:
prop_name = f"Delta_{comp1}_{comp2}"
prop_value = nrtl_alpha.ij(prop_name).get('value')
print(f"Property: {prop_name} = {prop_value}")