Skip to main content

Blendpy uses atomistic simulations with ASE calculators to compute alloy properties like enthalpy of mixing. It supports binary and multicomponent systems, including alloys and pseudoalloys.

Project description

License: MIT PyPI

Blendpy uses atomistic simulations with ASE calculators to compute alloy properties like enthalpy of mixing. It supports binary and multicomponent systems, including alloys and pseudoalloys.

Table of contents

Installation

Install blendpy easily using pip, Python’s package manager:

pip install --upgrade pip
pip install blendpy

Usage

Welcome to this step-by-step tutorial on calculating alloy properties. In this guide, you will learn how to compute important parameters, such as the enthalpy of mixing, and the spinodal and binodal decomposition curves derived from the phase diagram. We begin by defining the alloy components, then proceed through geometry optimization, and finally move on to advanced modeling techniques with the DSI model.

To start, provide a list of structure files (e.g., CIF or POSCAR) that represent your alloy components. For best accuracy, it is recommended that these files have been pre-optimized using the same calculator and parameters that will be used in the subsequent alloy property calculations.

If you already have these optimized structures, you may skip ahead to the "DSI model" section. If not, proceed to the "Geometry Optimization" section to prepare your structures for analysis.

Geometry optimization

For example, let's calculate the properties of an Au-Pt alloy. We begin by retrieving the Au (fcc) and Pt (fcc) geometries from ASE. Next, we optimize these geometries using the MACE calculator, which leverages machine learning interatomic potentials. Finally, we save the optimized structures for use in the DSI model. To achieve this, we will follow several key steps.

Step 1: Import the necessary modules from ASE and MACE:

from ase.io import write
from ase.build import bulk
from ase.optimize import BFGSLineSearch
from ase.filters import UnitCellFilter
from mace.calculators import mace_mp

Step 2: Create Atoms objects for gold (Au) and platinum (Pt) using the bulk function:

# Create Au and Pt Atoms object
gold = bulk("Au", cubic=True)
platinum = bulk("Pt", cubic=True)

Step 3: Create a MACE calculator object to optimize the structures and assign the calculator to the Atoms objects:

calc_mace = mace_mp(model="small",
                    dispersion=False,
                    default_dtype="float32",
                    device='cpu')

# Assign the calculator to the Atoms objects
gold.calc = calc_mace
platinum.calc = calc_mace

Step 4: Optimize the unit cells of Au and Pt using the BFGSLineSearch optimizer:

# Optimize Au and Pt unit cells
optimizer_gold = BFGSLineSearch(UnitCellFilter(gold))
optimizer_gold.run(fmax=0.01)

optimizer_platinum = BFGSLineSearch(UnitCellFilter(platinum))
optimizer_platinum.run(fmax=0.01)

Step 5: Save the optimized unit cells to CIF files:

# Save the optimized unit cells for Au and Pt
write("Au_relaxed.cif", gold)
write("Pt_relaxed.cif", platinum)

DSI model

Enthalpy of mixing

Import the DSIModel from blendpy and create a DSIModel object using the optimized structures:

from blendpy import DSIModel

# Create a DSIModel object
blendpy = DSIModel(alloy_components = ['Au_relaxed.cif', 'Pt_relaxed.cif'],
                   supercell = [2,2,2],
                   calculator = calc_mace)

Optimize the structures within the DSIModel object:

# Optimize the structures
blendpy.optimize(method=BFGSLineSearch, fmax=0.01, logfile=None)

Calculate the enthalpy of mixing for the AuPt alloy:

# Calculate the enthalpy of mixing
enthalpy_of_mixing = blendpy.get_enthalpy_of_mixing(npoints=101)

Plotting the enthalpy of mixing

import numpy as np
import matplotlib.pyplot as plt

fig, ax = plt.subplots(1,1, figsize=(5,5))

x = np.linspace(0, 1, 101)
ax.set_xlabel("$x$", fontsize=20)
ax.set_ylabel("$\Delta H_{mix}$ (kJ/mol)", fontsize=20)
ax.set_xlim(0,1)
ax.set_ylim(-7,7)
ax.set_xticks(np.linspace(0,1,6))
ax.set_yticks(np.arange(-6,7,2))

# Plot the data
ax.plot(x, enthalpy_of_mixing, color='#d53e4f', linewidth=3, zorder=2)
ax.scatter(x[::10], enthalpy_of_mixing[::10], color='#d53e4f', s=80, zorder=2, label="Au$_{1-x}$Pt$_{x}$")

# Reference: H. Okamoto and T.B. Massalski, Bull. Alloy Phase Diagrams 1 (1985) 46.
df_exp = pd.read_csv("data/experimental/exp_AuPt.csv")
ax.plot(df_exp['x'][::2], df_exp['enthalpy'][::2], 's', color='#000000', markersize=8, label="Exp. Data", zorder=1)
ax.legend(loc="best", fontsize=16)

ax.tick_params(direction='in', axis='both', which='major', labelsize=20, width=3, length=8)
ax.set_box_aspect(1)
for spine in ax.spines.values():
    spine.set_linewidth(3)

plt.tight_layout()
# plt.savefig("enthalpy_of_mixing.png", dpi=600, format='png', bbox_inches='tight')
plt.show()

Figure 1 - Enthalpy of mixing of the Au-Pt alloy computed using the DSI model and MACE interatomic potentials.

Phase diagram

By analyzing the mixing enthalpies and entropies, we can calculate the Gibbs free energy of the Au–Pt alloy mixture and determine both the spinodal and binodal (solvus) decomposition curves. These curves, which form key features of the alloy's phase diagram, delineate regions of differing stability: below the binodal curve, the solid solution (Au, Pt) is metastable, whereas it becomes unstable beneath the spinodal curve.

We begin by defining a temperature range over which to calculate the spinodal and binodal curves. Optionally, the results can be saved in CSV files.

temperatures = np.arange(300, 3001, 5)

# spinodal curve
df_spinodal = blendpy.get_spinodal_decomposition(temperatures = temperatures, npoints = 501)
df_spinodal.to_csv("data/phase_diagram/spinodal_AuPt.csv", index=False, header=True, sep=',')

# binodal curve
df_binodal = blendpy.get_binodal_curve(temperatures = temperatures, npoints=501)
df_binodal.to_csv("data/phase_diagram/binodal_AuPt.csv", index=False, header=True, sep=',')

To plot the phase diagram featuring the spinodal and binodal decomposition curves, we proceed as follows:

import pandas as pd

# Create figure and axis
fig, ax = plt.subplots(1,1, figsize=(8,8))

x = np.linspace(0, 1, 101)

# Configure axis labels and limits
ax.set_xlabel("$x$", fontsize=20)
ax.set_ylabel("$T$ (K)", fontsize=20)
ax.set_xlim(0,1)
ax.set_ylim(300, 2500)
ax.set_xticks(np.linspace(0,1,6))

# Plot the data
ax.plot(df_spinodal['x'], df_spinodal['t'], color='#d53e4f', linestyle='--', linewidth=3, label="Spinodal curve")
ax.plot(df_binodal['x'], df_binodal['t'], color='#d53e4f', linewidth=3, label="Binodal curve")

# Fill below the curves with transparency (alpha=0.3 means 30% opacity)
ax.fill_between(df_spinodal['x'], df_spinodal['t'], 300, color='#d53e4f', alpha=0.3)
ax.fill_between(df_binodal['x'], df_binodal['t'], 300, color='#d53e4f', alpha=0.3)
ax.legend(loc="best", fontsize=20)

# Add text annotations
ax.text(0.2, 1500, "Stable", fontsize=20, ha='center', va='center')
ax.text(0.4, 950, "Metastable", fontsize=20, ha='center', va='center', rotation=60)
ax.text(0.7, 700, "Unstable", fontsize=20, ha='center', va='center')

# Customize tick parameters
ax.tick_params(direction='in', axis='both', which='major', labelsize=20, width=3, length=8)
ax.set_box_aspect(1)
for spine in ax.spines.values():
    spine.set_linewidth(3)

plt.tight_layout()
# plt.savefig("phase_diagram.png", dpi=600, format='png', bbox_inches='tight')
plt.show()

Figure 2 - Phase diagram of the Au–Pt alloy computed using the DSI model and MACE interatomic potentials.

Polymorphism

DSI model from pre-calculated data

License

This is an open source code under MIT License.

Acknowledgements

We thank financial support from FAPESP (Grant No. 2022/14549-3), INCT Materials Informatics (Grant No. 406447/2022-5), and CNPq (Grant No. 311324/2020-7).

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

blendpy-25.3.16.tar.gz (680.7 kB view details)

Uploaded Source

Built Distribution

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

blendpy-25.3.16-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

Details for the file blendpy-25.3.16.tar.gz.

File metadata

  • Download URL: blendpy-25.3.16.tar.gz
  • Upload date:
  • Size: 680.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for blendpy-25.3.16.tar.gz
Algorithm Hash digest
SHA256 f415a1d5f0b6bbf632c81f02bb1728d811b64b520f3bd7f7d7ea9958cff98f43
MD5 fcee88fc14b204b1b3e0cbcb12d76afa
BLAKE2b-256 8e84effb40b50cfb1728eb005c9202695989773cc59bf6640a593a1cec4ef964

See more details on using hashes here.

File details

Details for the file blendpy-25.3.16-py3-none-any.whl.

File metadata

  • Download URL: blendpy-25.3.16-py3-none-any.whl
  • Upload date:
  • Size: 25.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for blendpy-25.3.16-py3-none-any.whl
Algorithm Hash digest
SHA256 0d62e62e4cb55248d5a1c370f8ce8eb31ada759ef282817e5d84e960a0836cc6
MD5 0a622557a5d522a6c67695d1d21fb07b
BLAKE2b-256 c25060e559421a3f1646e3f5f5d21e577ddb65cb6538118195b8b6757aff1110

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