StructureContainer: Initialize _structure_list even if no atoms list is given to init

Description

It would be nice to be able to initialize a StructureContainer without any list of atoms, but then add structures afterwards one by one. This does not work now. The following snippet

cs = ClusterSpace(prim, cutoffs, subelements)
sc = StructureContainer(cs)
for structure in enumerate_structures(prim, range(4), subelements):
    calc = EMT()
    structure.set_calculator(calc)
    energy = structure.get_potential_energy()
    sc.add_structure(structure)

throws an error

  File "/home/magnus/repos/icet/icet/core/structure_container.py", line 225, in add_structure
    self._structure_list.append(structure)
AttributeError: 'StructureContainer' object has no attribute '_structure_list'

because the _structure_list is not initialized if no list_of_atoms is given at initialization.

This can be resolved by simply moving the line self._structure_list = [] a few lines up. As far as I can see, there is no reason for not doing so.

Summary of changes

One line moved in icet/core/structure_container.py's __init__ function.

Edited by Magnus Rahm

Merge request reports

Loading