Let StructureContainer figure out mixing energy internally.

I was looking out our tutorial of Constructing a Cluster Expansion and the code was very long and quite far from our vision of a 5 row user interface.

One thing that could reduce the number of lines of code in that example would be to do the mixing energy internally in the structure container.

The code snippet I am talking about

# step 2: Parse the input structures and set up a structure container
db = connect('structures.db')
# get reference energies for the elements
eref = {}
for elem in subelements:
    for row in db.select('{}=1'.format(elem), natoms=1):
        eref[elem] = row.energy / row.natoms
        break
# compile the structures into a structure container and add the mixing energies
atoms_list = []
properties = []
for row in db.select():
    conc = float(row.count_atoms().get('Ag', 0)) / row.natoms
    emix = row.energy / row.natoms
    emix -= conc * eref['Ag'] + (1.0 - conc) * eref['Au']
    properties.append({'energy': emix})
    atoms = row.toatoms()
    atoms.set_positions(row.data['original_positions'])
    atoms_list.append(atoms)
sc = StructureContainer(cs, atoms_list, properties)
print(sc)

couldn't we instead do:

# step 2: Parse the input structures and set up a structure container
db = connect('structures.db')
sc = StructureContainer(cs)
for row in db.select():
    sc.append(row.to_atoms(), row.energy)
print(sc)

or something.. ?

cc @erhart

Edited by Mattias Ångqvist