Skip to main content

Python bindings for the Julia package Clapeyron.jl

Project description

pyclapeyron

Python wrapper for Clapeyron.jl.

Installation

Install pyclapeyron from PyPI via pip or uv:

pip install pyclapeyron

or

uv add pyclapeyron

Documentation

See the Clapeyron.jl documentation.

In general, pyclapeyron only acts as a wrapper around the Julia functions using the same syntax. In the following, notable deviations from the Julia syntax are highlighted.

  • Julia functions with !: Functions ending with ! in Julia (often used for inplace operations) are renamed to end with _b, e.g. fun!(...) in Julia is fun_b(...) in Python.
  • Array type: All numeric arrays passed to Clapeyron functions need to be numpy arrays, e.g.
import pyclapeyron as cl
import numpy as np

model = cl.vdW(["nitrogen", "argon"], userlocations={
    "Tc": np.array([127., 150.]),
    "Pc": np.array([34e5., 49e5]),
    "Mw": np.array([28.01, 39.95])
})

cl.molar_density(model, 1e5, 300., np.array([0.5,0.5]))
  • Syntax for group-contribution (GC) models: The components for group contribution models that include the groups need to be passed in the form ("component name", {"group1": n1, ...}, ...). The dict replaces Julias' Vector{Pair} as there is no direct equivalent in Python, e.g.
import pyclapeyron as cl

model = cl.CompositeModel(
    ["water", "ethanol", ("ibuprofen", {"ACH": 4, "ACCH2": 1, "ACCH": 1, "CH3": 3, "COOH": 1, "CH": 1})],
    liquid=cl.UNIFAC, solid=cl.SolidHfus
)
  • Electrolyte models: Similar to GC models, salts in electrolyte models need to be defined as salts = (("sodium chloride", [("sodium", 1), ("chloride", 1)]),).
  • Functions as function arguments: If you need to pass a Clapeyron function to another function, e.g. as in partial_property, you need to pass the original Clapeyron.some_func function, e.g. cl.partial_property(model, p, T, z, cl.Clapeyron.volume).

Examples

  • pure substance VLE
import pyclapeyron as cl
import numpy as np
import matplotlib.pyplot as plt

model = cl.PCSAFT("benzene")
Tc, pc, vc = cl.crit_pure(model)

Tx = np.linspace(0.5*Tc, Tc, 100)
ps, vl, vv = np.zeros(100), np.zeros(100), np.zeros(100)
for (i,Ti) in enumerate(Tx):
    ps[i], vl[i], vv[i] = cl.saturation_pressure(model, Ti)

fig, axs = plt.subplots(nrows=1, ncols=2, sharey=True, figsize=(6,3), tight_layout=True)
axs[0].plot(1e-3/np.concat([vl,np.flip(vv)]), np.concat([ps,np.flip(ps)])/1e5, c="blue")
axs[1].plot(Tx, ps/1e5, c="blue")
axs[0].scatter(1e-3/vc, pc/1e5, marker="*", c="blue")
axs[1].scatter(Tc, pc/1e5, marker="*", c="blue")
axs[0].set(yscale="log", xlabel="ϱ / mol l⁻¹", ylabel="p / bar")
axs[1].set(xlabel="T / K")

  • mixture VLE
import pyclapeyron as cl
import numpy as np
import matplotlib.pyplot as plt

components = ["methanol", "r123"]
components_with_groups = [("methanol", {"CH3OH": 1}), ("r123", {"CF3": 1, "CHCL2": 1})]
model = cl.UNIFAC2(components_with_groups, puremodel=cl.AntoineEqSat(components))

T_iso = 300.
x1 = np.linspace(0.,1.,100)
ps, y1 = np.zeros(100), np.zeros(100)
for (i,x1i) in enumerate(x1):
    ps[i], _, _, yi = cl.dew_pressure(model, T_iso, np.array([x1i,1-x1i]))
    y1[i] = yi[0]

fig, ax = plt.subplots(figsize=(4,3), tight_layout=True)
ax.plot(x1, ps/1e5, c="red")
ax.plot(y1, ps/1e5, c="red")
ax.set(xlim=(0,1), xlabel="x₁ / mol l⁻¹", ylabel="p / bar")

For Developers

  • Use uv add --dev path/to/local/pyclapeyron to add pyclapeyron to a local env.
  • You can optionally use a local dev version of Clapeyron.jl by replacing the line
"Clapeyron": {
    "uuid": "7c7805af-46cc-48c9-995b-ed0ed2dc909a",
    "version": "X.X.X"
}

by

"Clapeyron": {
    "uuid": "7c7805af-46cc-48c9-995b-ed0ed2dc909a",
    "dev": true,
    "path": "/path/to/.julia/dev/Clapeyron"
},

in the pyclapeyron/juliapkg.json file.

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

pyclapeyron-0.1.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

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

pyclapeyron-0.1.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyclapeyron-0.1.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyclapeyron-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3a027cba572328681a17b613994dabebf487e19a54dd49c5105e6c88abfb0a9c
MD5 1eef31f2f8097b70392d2e65d3dc99f1
BLAKE2b-256 bb3c03708a6190e7793dffb060016aca5ca6c38fc205b034873c7c385d807849

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyclapeyron-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyclapeyron-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5448b91754b5626901c158303806339a1164ea51df1bb1b127da7339d570db8e
MD5 7a458a8be2b6aea52aeb9391f961b813
BLAKE2b-256 6f6ea7780a8a2c919a1ef2733c851501d8cd132913f3e583c659d19728871341

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