Skip to main content

Tools for reading and working with FactSage compound database files.

Project description

Wiki project for Compound Database files (not part of the official FactSage distribution, written by Dr Evgenii Nekhoroshev)

The detailed documentation on the internal workings of the FactSage Compound Database file format is located at:

FactSage Compound Database Project

factsage-compound

factsage-compound is a Python package for reading, inspecting, and editing FactSage Compound Database (.CDB) files.

It parses the fixed-width binary chunk format used by FactSage compound databases and exposes Python objects for:

  • loading a database into memory
  • iterating through compounds and phases
  • inspecting thermodynamic values and heat-capacity ranges
  • editing selected values in memory
  • saving the modified binary back to disk

Features

  • Parses FactSage compound database chunks into structured NumPy-backed objects
  • Provides object wrappers for Database, Compound, Phase, and Range
  • Supports lookup by formula, compound name, and ChemApp-style phase labels
  • Preserves binary layout so modified databases can be written back to disk

Installation from PyPI

From a command window, run

pip install factsage-compound

Installation from the repository (if the PyPI distribution not available)

To install factsage-compound from the GitHub repository at factsage-compound, use

git clone https://github.com/evnekdev/factsage-compound

and later run the installation from inside the cloned directory using poetry tool (pip install poetry):

poetry install

poetry tool automatically builds a wheel and installs it into your current Python directory (a valid Python installation must exist on your computer, of course).

Quick start (Excel interface, database comparison)

If you already installed factsage-compound, xlwings package should be already installed as a requirement.

Locate the xlwings addin in $PYTHONPATH\Lib\site-packages\xlwings\addin through Excel File -> Options -> Add-ins (Manage Excel Addins, Go) interface. If everything goes ok, an xlwings tab appears in the top Excel Ribbon.

In File -> Options -> Trust Center -> Trust Center Settings -> Macro Settings set "Enable VBA macros" toggle button and "Enable Excel 4.0 macros when VBA macros are enabled" and "Trust access to the VBA project object model" ticks.

You can download an xlsm templates from Excel Template.

If you create your own xlsm book from scratch, you will need an xlwings.conf sheet with the following contents:

A B
1 Interpreter_Win $PYTHONPATH\python.exe
2 Interpreter_Mac
3 PYTHONPATH
4 Conda Path
5 Conda Env
6 UDF Modules factsage_compound
7 Debug UDFs FALSE
8 Use UDF Server TRUE
9 Show Console TRUE

Quick start (pure Python)

from factsage_compound import Database

# Load an existing FactSage compound database
db = Database("SENDBASE.CDB")

print(f"Compounds: {len(db.compounds)}")

# Find a compound and inspect its phases
compound = db.find_compound_by_formula("FeO")
if compound is not None:
    print(compound.name)
    for phase in compound.phases:
        print(phase.label, phase.name)

Data model

Database

Database loads the binary .CDB file and parses it into a list of Compound objects.

Useful methods:

  • save() writes the current in-memory chunk array back to the original file
  • find_compound_by_formula(formula) returns the first matching compound
  • find_compound_by_name(name) returns the first compound whose name starts with the provided text
  • find_phase_by_chemapp_name(name) resolves a ChemApp-style identifier and returns the matching phase

Compound

Compound wraps a compound chunk and collects associated phases, heat-capacity ranges, and comments.

Useful attributes and methods:

  • name: human-readable compound name
  • formula: formula string stored in the file
  • coefficients_real: real stoichiometric coefficients array
  • phases: list of Phase instances
  • find_phase_by_name(name)
  • find_phase_by_label_chemapp(label)

Phase

Phase represents one thermodynamic phase of a compound.

Useful attributes:

  • name
  • density
  • state (S, L, G, or Aq)
  • index
  • label
  • label_chemapp
  • ranges
  • kappas

For non-transition phases (chunk_id == CHUNK_TYPE_PHASE1):

  • enthalpy
  • entropy

For transition phases (chunk_id == CHUNK_TYPE_PHASE2):

  • transition_enthalpy
  • transition_temperature

Range

Range stores heat-capacity coefficients for a temperature interval.

Useful attributes:

  • coefficients
  • powers
  • t_min
  • t_max
  • enthalpy
  • entropy

Example workflows

Find a phase by ChemApp label

from factsage_compound import Database

db = Database("SENDBASE.CDB")
phase = db.find_phase_by_chemapp_name("FeO_wustite(s)")

if phase:
    print(phase.name)
    print(phase.label_chemapp)

Update thermodynamic values and save

from factsage_compound import Database

db = Database("SENDBASE.CDB")
compound = db.find_compound_by_formula("FeO")
phase = compound.find_phase_by_name("Wustite")

if phase and not phase.has_transition():
    phase.enthalpy = phase.enthalpy + 100.0
    phase.entropy = phase.entropy + 0.1

 db.save()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

factsage_compound-0.1.0.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

factsage_compound-0.1.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file factsage_compound-0.1.0.tar.gz.

File metadata

  • Download URL: factsage_compound-0.1.0.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.11.7 Windows/10

File hashes

Hashes for factsage_compound-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d6f4850453da28630fa6a4c5db014ff6e1978f8066f4bafbeb657f66dc551379
MD5 eb0dec4fe53ac11ebe7368392c6529db
BLAKE2b-256 3fd3a7c61682644da74cd98cbca3c391194af35da10452af7670bd2578767d21

See more details on using hashes here.

File details

Details for the file factsage_compound-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: factsage_compound-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.11.7 Windows/10

File hashes

Hashes for factsage_compound-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec167750b2f26f81587a23ab772a63a0ec5a060ee0f30d7b6ce24492542317e9
MD5 12b7a00f91ec1c515b42656c8dfbcc1b
BLAKE2b-256 287ffc9c32c09a51153cb752f4d638db17ef686f38d7763f2f8371995774980e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page