Comparison with target data

In this step the performance of the cluster expansion constructed in the previous step will be tested against the target data. After loading the CE from file, we loop over all configurations in the structures.db database and compile the silver concentration as well as the target and predicted mixing energies into a list. Note that the latter of the three values is calculated by calling the ClusterExpansion.predict() method with the ASE Atoms object that represents the present structure as input argument.

ce = ClusterExpansion.read('cluster_expansion.icet')
data = []
db = connect('structures.db')
for row in db.select():
    emix_ce = ce.predict(row.toatoms())
    data.append([row.conc, row.emix, emix_ce])
data = np.array(data).T

Once the list is complete the predicted and target mixing energies are plotted as functions of the concentration of silver atoms.

fig, ax = plt.subplots(figsize=(4, 3))
ax.set_xlabel(r'Ag concentration')
ax.set_ylabel(r'Mixing energy (meV/atom)')
ax.set_xlim([0, 1])
ax.scatter(data[0], 1e3 * data[1], marker='o')
ax.scatter(data[0], 1e3 * data[2], marker='x')
plt.savefig('mixing-energy-comparison.png', bbox_inches='tight')

The figure generated by this diagram is shown below.

../_images/mixing-energy-comparison.png

Predicted (crosses) and target (open circles) mixing energies versus silver concentration for the structures used in the construction of the cluster expansion.

Source code

The complete source code is available in tutorial/basic/3_compare_to_target_data.py
import matplotlib.pyplot as plt
import numpy as np
from ase.db import connect
from icet import ClusterExpansion

# step 1: Compare predicted and target data
ce = ClusterExpansion.read('cluster_expansion.icet')
data = []
db = connect('structures.db')
for row in db.select():
    emix_ce = ce.predict(row.toatoms())
    data.append([row.conc, row.emix, emix_ce])
data = np.array(data).T

# step 2: Plot results
fig, ax = plt.subplots(figsize=(4, 3))
ax.set_xlabel(r'Ag concentration')
ax.set_ylabel(r'Mixing energy (meV/atom)')
ax.set_xlim([0, 1])
ax.scatter(data[0], 1e3 * data[1], marker='o')
ax.scatter(data[0], 1e3 * data[2], marker='x')
plt.savefig('mixing-energy-comparison.png', bbox_inches='tight')