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 °C, 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:
coremoduleThe
coremodule 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.basicmoduleThis module provides access to ChemApp through the original, very compact
tq*application programmer’s interface (API).friendlymoduleThis 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.
densitymoduleThe new
densitymodule 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 thefriendlymodule.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.
Supported Platforms
ChemApp for Python includes compiled libraries. Choose a wheel built for your operating system (Windows or Linux) and a 64-bit x86 Python interpreter. On Linux, the system libraries must also be compatible with the wheel. Getting Started explains how to select and install the matching release file.
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
Use the CPython major and minor version specified by your ChemApp wheel. For
example, a wheel tagged cp313-cp313 works with standard CPython 3.13 across
patch releases.
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.
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.