Skip to content

🚀 Build & Save Mixture ThermoDB

Latest

Choose a tag to compare

@sinagilassi sinagilassi released this 08 Oct 22:27
· 883 commits to main since this release

📄 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