# Setup bulk silicon configuration.
lattice = FaceCenteredCubic(5.4306*Angstrom)
elements = [Silicon, Silicon]
fractional_coordinates = [[ 0.  ,  0.  ,  0.  ],
                          [ 0.25,  0.25,  0.25]]
bulk_si = BulkConfiguration(
    bravais_lattice=lattice,
    elements=elements,
    fractional_coordinates=fractional_coordinates,
)

# Setup bulk gold configuration.
lattice = FaceCenteredCubic(4.07825*Angstrom)
elements = [Gold]
fractional_coordinates = [[ 0.,  0.,  0.]]
bulk_au = BulkConfiguration(
    bravais_lattice=lattice,
    elements=elements,
    fractional_coordinates=fractional_coordinates,
)

# Cleave each bulk configuration. This is required before using the interface builder.
si_100 = bulk_si.cleave(1, 0, 0)
au_111 = bulk_au.cleave(1, 1, 1)

# Setup interface builder. The configurations should be cleaved first.
interface_builder = InterfaceBuilder(si_100, au_111)

# Get all of the interface matches, specifying that the second surface (gold) should be strained.
# The matches are sorted from lowest to highest mean absolute strain.
matches = interface_builder.matches(strain_method=StrainSecond)

# Loop over all matches and print out information and save each to a hdf5 file.
print('{:>20s} {:>10s}'.format('number of atoms', 'strain (%)'))
for match in matches:
    # Get the number of atoms and strain from the match.
    number_of_atoms = match.numberOfAtoms()
    mean_absolute_strain = 100.0 * match.meanAbsoluteStrain()

    # Print out information about the match.
    print('{:20d} {:10.3f}'.format(number_of_atoms, mean_absolute_strain))

    # Make the interface configuration and save it to a file.
    interface_configuration = match.makeInterface()
    nlsave('matches.hdf5', interface_configuration)

# Scatter plot of number of atoms vs strain.
import pylab
pylab.scatter(
    [100 * match.meanAbsoluteStrain() for match in matches],
    [match.numberOfAtoms() for match in matches],
)
pylab.xlabel('Mean Absolute Strain (%)')
pylab.ylabel('Number of Atoms')
pylab.xscale('log')
pylab.savefig('size_strain_plot.png')
