<jupyter_start><jupyter_text>Vacancy formation energyUsing the iron GAP, calcualte the vacancy formation energy in a 3x3x3 supercell.<jupyter_code>from __future__ import print_function

# stdlib
import os

# non-stdlib
import ase
import numpy as np
from ase.build import bulk
from ase.constraints import UnitCellFilter
from ase.optimize import LBFGS
# Use quippy for GAP iron model
from quippy import Potential
%matplotlib inline
# primitive cell and bulk with a vacancy
lattice_constant = 2.84

prim = bulk('Fe', a=lattice_constant)
vacancy = (bulk('Fe', a=lattice_constant, cubic=True) * (3, 3, 3))[:-1]
# Initialise the GAP
cwd = os.getcwd()

try:
    os.chdir('/opt/share/potentials/GAP/Iron/gp33b/')
    fe_gap = Potential("IP GAP", param_filename='gp33b.xml')
finally:
    os.chdir(cwd)
# Use primitive cell as the zero energy
prim.set_calculator(fe_gap)

ucf = UnitCellFilter(prim)
opt = LBFGS(ucf)
opt.run(fmax=0.0001)

e_prim = prim.get_potential_energy()
v_prim = prim.get_volume()
# Optimise positions at each volume point
vacancy.set_calculator(fe_gap)

volumes = []
energies = []

for cell_a in np.linspace(vacancy.cell[0][0]*0.98, vacancy.cell[0][0]*1.02, 7):
    vacancy.set_cell((cell_a, cell_a, cell_a), scale_atoms=True)
    opt = LBFGS(vacancy)
    opt.run(fmax=0.001)
    volumes.append(vacancy.get_volume())
    energies.append(vacancy.get_potential_energy())
from ase.eos import EquationOfState
eos = EquationOfState(volumes, [e - len(vacancy) * e_prim for e in energies])
from ase.units import GPa

v0, e0, B = eos.fit()
print('Bulk modulus:              {:9.3f} GPa'.format(B / GPa))
print('Vacancy formation energy:  {:9.3f} eV'.format(e0))
print('Vacancy volume:            {:9.3f} A³'.format(v0 - 53*v_prim))
eos.plot()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12612612612612611, 'fraction_numerical': 0.0259009009009009, 'mean_word_length': 4.826229508196722, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '629807', 'license': 'NRL', 'n_tokens_mistral': 718, 'n_tokens_neox': 676, 'n_words': 162, 'path': 'docker/files/demo.ipynb', 'repo_name': 'Sideboard/QUIP', 'size': '1776'}