# Genetic algorithm Search for stable FCC alloys¶

In this tutorial we will emulate an older paper [Johannesson] and determine the most stable FCC alloy using the genetic algorithm. Since the purpose is only the tutorial we will limit the phase space to the elements supported by the EMT potential. The search is also equivalent to the recent search for mixed metal ammines with superior properties for ammonia storage described here:

P. B. Jensen, S. Lysgaard, U. J. Quaade and T. Vegge
Physical Chemistry Chemical Physics, Vol 16, No. 36, pp. 19732-19740, (2014)

## Setting up reference database¶

Now we need to set up a database in which reference calculations can be stored. This can either be in a central database server where keywords distinguish between different references or dedicated separate databases for each different type of reference calculations.

In the following script, ga_fcc_references.py, we put the references in the database file refs.db. Our model structure is fcc which is loaded with ase.lattice.cubic.FaceCenteredCubic(). We perform a volume relaxation to find the optimal lattice constant and lowest energy, which we save in the database as key-value pairs for quick retrieval.

import numpy as np

from ase.lattice.cubic import FaceCenteredCubic
from ase.calculators.emt import EMT
from ase.eos import EquationOfState
from ase.db import connect

db = connect('refs.db')

metals = ['Al', 'Au', 'Cu', 'Ag', 'Pd', 'Pt', 'Ni']
for m in metals:
atoms = FaceCenteredCubic(m)
atoms.calc = EMT()
e0 = atoms.get_potential_energy()
a = atoms.cell

eps = 0.05
volumes = (a * np.linspace(1 - eps, 1 + eps, 9))**3
energies = []
for v in volumes:
atoms.set_cell([v**(1. / 3)] * 3, scale_atoms=True)
energies.append(atoms.get_potential_energy())

eos = EquationOfState(volumes, energies)
v1, e1, B = eos.fit()

atoms.set_cell([v1**(1. / 3)] * 3, scale_atoms=True)
ef = atoms.get_potential_energy()

db.write(atoms, metal=m,
latticeconstant=v1**(1. / 3),
energy_per_atom=ef / len(atoms))