Skip to main content

Blendpy is a computational toolkit for investigating thermodynamic models of alloys using first-principles calculations.

Project description

License: MIT PyPI

Blendpy is a computational toolkit for investigating thermodynamic models of alloys using first-principles calculations.

Table of contents

Installation

Install blendpy effortlessly using pip, Python’s default package manager, by running the following command in your terminal:

pip install --upgrade pip
pip install blendpy

Usage

This comprehensive tutorial guides you through calculating alloy properties. In this section, you'll learn how to determine key parameters—such as the enthalpy of mixing, and the spinodal and binodal decomposition curves derived from phase diagrams. We start by defining the alloy components, move through geometry optimization, and conclude with advanced modeling techniques using 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.[^fn1] 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)

Dilute solution interpolation (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
dsi_model = 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
dsi_model.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 = dsi_model.get_enthalpy_of_mixing(npoints=101)
x = np.linspace(0, 1, len(enthalpy_of_mixing))
df_enthalpy = pd.DataFrame({'x': x, 'enthalpy': enthalpy_of_mixing})

Plotting the enthalpy of mixing

import numpy as np
import matplotlib.pyplot as plt

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

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
color1='#fc4e2a'
ax.plot(df_enthalpy['x'][::5], df_enthalpy['enthalpy'][::5], marker='o', color=color1, markersize=8, linewidth=3, zorder=2, label="DSI Model (MACE)")

# REFERENCE: Okamoto, H. and Massalski, T., The Au-Pt (gold-platinum) system, Bull. Alloy Phase Diagr. 6, 46-56 (1985).
df_exp = pd.read_csv("data/experimental/exp_AuPt.csv")
ax.plot(df_exp['x'], df_exp['enthalpy'], 's', color='grey', 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.

DSI model from pre-calculated data

Using blendpy, we can also calculate the enthalpy of mixing for an alloy based on DFT simulations that are not initiated by the DSIModel class object. Instead, we can use external data for the total energies of the pristine and dilute supercell systems. For instance, using the ab initio simulation software GPAW,[^fn2] we calculate the total energies for the Au-Pt alloy using [3,3,3] supercells of Au and Pt (Atoms(Au27) and Atoms(Pt27)), as well as the dilute systems (Atoms(Au26Pt) and Atoms(Pt26Au)). These total energies are then used to construct the energy matrix (energy_matrix) in the following form:

energy_matrix = np.array([[ -85.940400,  -89.230299],   # [[  Au27, Au26Pt],
                          [-170.278459, -173.891172]])  #  [ Pt26Au,  Pt27]]

Next, we demonstrate how to calculate the enthalpy of mixing using the input energy matrix.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from ase.build import bulk
from ase.io import write
from blendpy import DSIModel

# Create the two bulk structures
gold = bulk('Au', 'fcc')
palladium = bulk('Pt', 'fcc')

# Write the structures to CIF files
write("cif_files/Au.cif", gold)
write("cif_files.Pt.cif", palladium)

# Create the DSI model
alloy_components = ['cif_files/Au.cif', 'cif_files/Pt.cif']
x0 = 1./27
dsi_model= DSIModel(alloy_components=alloy_components, supercell=[3,3,3], x0=x0)

# Set the energy matrix
energy_matrix = np.array([[ -85.940400,  -89.230299],
                          [-170.278459, -173.891172]])

dsi_model.set_energy_matrix(energy_matrix)

enthalpy= dsi_model.get_enthalpy_of_mixing()

x = np.linspace(0, 1, len(enthalpy))

df_enthalpy = pd.DataFrame({'x': x, 'enthalpy': enthalpy})

In this case, it is MANDATORY to specify the minimum dilution factor (x0), the supercell size ([3,3,3]) used in the ab initio simulations, and the unit cell files ('Au.cif' and 'Pt.cif'). The unit cell files do not need to match exactly those used in the ab initio simulations.

Finally, we can plot the enthalpy of mixing and compare it with the experimental data.[^fn3]

# Plot the enthalpy of mixing
fig, ax = plt.subplots(1,1, figsize=(6,6))

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))
ax.set_title("Au$_{1-x}$Pt$_{x}$", fontsize=20, pad=10)

# plot data
# Experimental
df_exp = pd.read_csv("../../data/experimental/exp_AuPt.csv")
ax.plot(df_exp['x'], df_exp['enthalpy'], 's', color='grey', linestyle='--', linewidth=3, markersize=8, label="Exp. Data", zorder=1)

# DSI model
ax.plot(df_enthalpy['x'][::5], df_enthalpy['enthalpy'][::5], marker='o', color='#fc4e2a', markersize=8, linewidth=3, zorder=2, label="DSI model from DFT")

ax.legend(fontsize=16, loc='best')
ax.tick_params(axis='both', which='major', labelsize=20, width=3, length=8, direction='in')
ax.set_box_aspect(1)

for spine in ax.spines.values():
    spine.set_linewidth(3)

plt.tight_layout()
# plt.savefig('enthalpy_of_mixing_AuPt_from_input.png', dpi=400, bbox_inches='tight')
plt.show()

Figure 2 - Enthalpy of mixing of the Au-Pt alloy computed using the DSI model and energy matrix given from input (calculated with GPAW).

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).

References

[^fn1]: Batatia, I., et al., MACE: Higher Order Equivariant Message Passing Neural Networks for Fast and Accurate Force Fields Adv. Neural Inf. Process Syst. 35, 11423 (2022).

[^fn2]: Mortensen, J. J., et al., GPAW: An open Python package for electronic structure calculations J. Chem. Phys. 160, 092503 (2024).

[^fn3]: Okamoto, H. and Massalski, T., The Au−Pt (Gold-Platinum) system Bull. Alloy Phase Diagr. 6, 46-56 (1985).

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-26.4.0.tar.gz (903.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-26.4.0-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for blendpy-26.4.0.tar.gz
Algorithm Hash digest
SHA256 6c0c764e59778ea92f68a83c70790e1436370707ed0ea3e9cbab5838fb22ee79
MD5 ae3c3cdcdedfa774e2b731fe56edb279
BLAKE2b-256 fdff9f144df0193d610e48a95bc6794b7ce64919e80fbbe9df0d5a54f0823d9c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for blendpy-26.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d4b6bbc9823c6f65f192fa34a4e4f818d5ea63260f99320e967cf8de454590ca
MD5 8f07fda566bb3457a3d09f84c4fca640
BLAKE2b-256 1660c46cb5ae5defde7d55e6620ee1f90c3d0bb8c4e027fce2533bd873586bc2

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