Introduction
ChemApp for Python is a Python package that makes the ChemApp thermochemistry library developed by GTT-Technologies accessible in Python. It also adds some powerful tools to make it easier and more productive to do thermochemical calculations.
If you frequently work with thermochemistry, you have done basic calculations,
such as calculating the enthalpy of SiO2 at 1000 , and calculating the
equilibrium state of a set of input compounds countless times. ChemApp for
Python helps you take care of those details in a structured and reliable manner
so that you can focus more of your attention on higher-level concepts and
problems.
In this chapter we provide an overview of the contents of the ChemApp for Python package, and then give some background information about the most important tools that you will need when working with ChemApp for Python and Python. This will help to prepare you for working with Python, if you are unfamiliar with it.
Package Contents
The package contains the following modules:
core
moduleThe
core
module contains Python classes for entities like phases, phase constituents, thermochemical systems and calculation results. These classes can be used to create objects that make it easy and flexible to do computational thermochemistry work. We demonstrate this with examples.basic
moduleThis module provides access to ChemApp through the original, very compact
tq*
application programmer’s interface (API).friendly
moduleThis module allows you to work with ChemApp through a more verbose, and more friendly API that is easier to read and remember. This API is also more power, in that you can get more done with fewer lines of code.
density
moduleThe new
density
module provides access to the density estimation functionality of ChemApp. It allows you to estimate the density of phases for given temperature and pressure conditions. There usually is no need to use this module directly, as the functionality is also available through higher-level methods in thefriendly
module.Examples
The distribution package contains a set of examples that demonstrate how to use the different parts of ChemApp for Python, step by step.
Descriptive Naming
Most of the modules in ChemApp for Python use a common naming convention. The
only exception to this is the basic
module, which is meant to be a copy of
the original ChemApp API. It therefore retains all the naming used in
ChemApp.
The purpose of the naming convention is to ensure that Python code that uses ChemApp for Python is easily readable and understandable.
The ChemApp for Python naming convention uses a set of one-, two-, and three-letter abbreviations for frequently used terms. This is shown in the following table.
Abbreviation |
Term |
Abbreviation |
Quantity |
---|---|---|---|
eq |
equilibrium |
A |
amount |
mm |
molar mass |
AC |
relative activity |
ph |
phase |
CP |
heat capacity |
phs |
phases |
E |
energy |
pc |
phase constituent |
G |
Gibbs energy |
pcs |
phase constituents |
H |
enthalpy |
sc |
system component |
IA |
incoming amount |
scs |
system components |
MU |
chemical potential |
st |
stream |
P |
pressure |
sts |
streams |
S |
entropy |
tg |
target |
T |
temperature |
tx |
transition |
V |
volume |
txs |
transitions |
VT |
total volume |
X |
amount fraction |
||
XT |
mole fraction |
||
Y |
mass fraction |
These abbreviations are used to create descriptive and easily readable names for functions and variables. Here are a few examples.
from chemapp.friendly import ThermochemicalSystem
from chemapp.friendly import EquilibriumCalculation
# get the number of system components in the thermochemical system
ThermochemicalSystem.get_count_scs()
# get the molar mass of the system component 'Fe'
mm_Fe = ThermochemicalSystem.get_mm_sc('Fe')
# set the equilibrium pressure and temperature for a calculation
EquilibriumCalculation.set_eq_P(1.0)
EquilibriumCalculation.set_eq_T(1000.0)
# get the equilibrium amounts of all phases after a calculation
amounts = EquilibriumCalculation.get_eq_A_phs()
# get the equilibrium Gibbs energy of a phase after a calculation
G = EquilibriumCalculation.get_eq_G_ph('gas_ideal')
ChemApp
ChemApp is a software library that contains code that can be run by calling it from an application that you create. Since it is a library, ChemApp cannot be run by itself. You need to create an application (write a program) to call its functions.
The ChemApp library contains a set of 75 functions, all of which have a name
that starts with the letters tq
. We refer to this set of functions as
ChemApp’s basic API. An API is a set of components like functions
that programmers can use to call the library when they develop applications. As
you use ChemApp for Python to write programs to do thermochemical calculations,
you can therefore use ChemApp’s basic API, or one of the other APIs
provided within ChemApp for Python.
GTT-Technologies released three different editions of ChemApp, namely Development, Redistributable, and Light. The Development edition is intended for people developing new applications with ChemApp, and the Redistributable edition for packaging and distributing applications that were developed with the Developer edition. The Light edition is provided free of charge for demonstration purposes, but has limited functionality. ChemApp for Python is intended to be a development tool, and is only provided in Development and Light editions.
Important Computing Aspects
You need to understand the following points related to your computer and operating system.
64-bit vs. 32-bit
Since most modern computers use 64-bit central processing units (CPUs), and most modern operating systems are able to make use of the enhanced capacity of these CPUs, we always provide ChemApp for Python in 64-bit form. 32-bit versions of ChemApp for Python do not exist.
Operating system (OS)
We provide ChemApp for Python for use on two operating systems, namely Windows and Linux. Mac OS is not currently supported.
Python version
Due to the slightly sensitive approach of fully compiled python code, the ChemApp for Python package should only be used with Python versions that are exactly, even down to the minor version number identical to the one that we provide. This may be slightly less flexible than many other Python packages.
Python
Python is an open-source, high-level, interpreted, general-purpose programming language. It was created by Guido van Rossum, and was first released in 1991.
The Language
Since Python is open source, you have access to the source code, if you need to see how the internals work. It also means that Python is freely accessible to anyone with a computer. This is one of the reasons why it has a large user community world wide, and why it has been one of the fastest-growing programming languages over the last few years.
Python is a high-level language, which means that you have much less responsibility to take care of detailed computing matters such as memory management and disk access. This is great if you are a scientist or engineer who doesn’t know or care about these things, and you just want to get on with getting your job done.
Since Python is interpreted, you don’t have to compile and build your software before you can run it. You can just type and run. This makes it very productive and easy to work with.
Python’s general-purpose nature means that once you have written a nice application to solve a thermochemical problem, it can be integrated into a web application or some other application written by programmers or other IT people. Python is not like MATLAB, which is purely scientific and technical. It can integrate with and be integrated with virtually any other system.
Our view is that learning Python is a wise investment for any modern scientist and engineer. If you choose to learn it, you will become part of a world-wide movement of people sharing ideas and software, and get access to a multitude of packages related to things like mathematics, chemistry, numerical methods, and much more. If you want a Python module to help you make coffee, you will probably find that as well. (Yup, I just confirmed this. Have a look at this package on GitHub!).
Versions
Python is available in many versions, which may be confusing. The first point to
note is that we only make ChemApp for Python available for 3.x
of Python,
and not for 2.x
versions. You should therefore not download or install
Python 2.6 or 2.7 if you want to work with ChemApp for Python.
Packages and Modules
When working with Python software, we use the terms package and module, and it is important that you understand them.
A package is analogous to a folder. The folder must contain at least an
__init__.py
module to be recognised as a package. It can also contain other
Python modules, and sub-packages.
A module is a file that contains Python code. When you write your first
script, it will be contained in a Python module. Modules can be in the form
of text files with the .py
extension, or it can be compiled binary files
with .so
extensions on Linux, and .pyd
extensions on Windows. A .pyd
file is simply a dynamically linked library (.dll
) with a different
extension.
Anaconda
So how do you get Python? The most direct way is to download it from the Python.org website. We don’t recommend this.
Python Distributions
Python is a little like Linux. Many people take the core of it, and package it into useful distributions. If you want to use Linux, for example, most people would not start at downloading the kernel. This will leave you with A LOT to do before getting to a working operating system. You will probably rather download a distribution like Debian, Ubuntu, Fedora, or openSUSE. They get you up and running, and doing what is interesting to you in a flash.
Today the most common options are Anaconda, Miniconda, and
Miniforge, all of which use the conda
ecosystem. For scientific and
engineering work we recommend Miniforge (lightweight, conda-forge by default) or
Anaconda (larger, batteries-included). Both make it easy to install scientific
packages and manage reproducible environments.
Another perfectly adequate option is uv, a fast, pip-compatible Python package and environment manager. It works well for creating virtual environments, pinning dependencies, and running projects.
If your workflow revolves around Jupyter Notebooks, though, conda-based
distributions (Miniforge/Anaconda) typically integrate more smoothly (kernels,
native dependencies). uv
still works with notebooks, but may require extra
steps (e.g., installing ipykernel
in the environment and registering a
kernel), and some scientific packages are easier to install from conda-forge.
On Virtual Environments
Working productively with Python is easiest when each project lives in its own virtual environment. This keeps dependencies isolated, allows different projects to use different Python versions, prevents version conflicts, and makes your setups lightweight and reproducible. It also means you never have to modify the system Python: create an environment, work inside it, and delete it when you are done.
A virtual environment is simply an isolated directory that contains a Python interpreter together with only the packages needed for a given project. After activating the environment, any Python, package installation, or command-line tools you run operate inside that sandbox.
There are several tools that create and manage such environments. In this manual
we show commands with conda
because it is widely used in scientific and
engineering workflows and integrates smoothly with distributions like Miniforge
and Anaconda. conda
excels at installing packages that depend on native
libraries, thanks to the conda-forge ecosystem, and it makes Jupyter kernel
management straightforward. The trade-off is that environments can be larger and
dependency solving can be slower, and you need to be mindful when mixing
conda
with pip
.
If you prefer a faster, more lightweight approach, uv
is a pip-compatible
alternative that resolves and installs quickly, works directly with PyPI and
standard pyproject.toml
workflows, and can even create environments on the
fly (for example, uv run python
will create and reuse a project-specific
environment automatically). For heavy scientific stacks with complex native
dependencies you may occasionally need compilers or system libraries, and for
notebooks you will typically install ipykernel
in the environment and
register the kernel. The ecosystem is newer, but the day-to-day workflow -
create or activate an environment, install packages, and run code inside it - is
the same.
Where we demonstrate conda
commands, you can generally substitute the
equivalent uv
commands and achieve the same result. IDEs like PyCharm and
VSCode also support creating and managing virtual environments through their
graphical interfaces, both for conda
and uv
workflows.
PyCharm
In most cases Python source code is written in text files that have a .py
extension. You can develop your applications with only a text editor and the
terminal. This is a bit daunting for most people, since they are unfamiliar with
using the terminal. It is for this reason that we encourage you to use an
integrated development environment (IDE).
An IDE is a user-friendly environment within which you can write computer programs. It hides many of the intricacies involved, and allows you to get more done in less time. It also helps you to discover and fix errors quickly and easily.
PyCharm is an IDE developed by JetBrains. It is provided in Professional, Educational, and Community editions. The Community edition is free, but still rich in functionality.
Visual Studio Code
Visual Studio Code (VS Code) is a lightweight, cross-platform editor from
Microsoft that becomes a full-featured Python IDE through extensions.
Install the Python
extension (ms-python.python
) to get code completion,
linting/formatting, testing, debugging, Jupyter notebooks, and an integrated
terminal. VS Code is free and open source, highly customizable, and widely used
in the Python community. It is equally suitable for using ChemApp for Python and
general Python development; choose the tool you prefer.