Skip to content

ENH: introducing atom labels

Yashasvi S. Ranawat requested to merge yashasvi-ranawat/ase:atom_labels into master

This merge requests introduces atom labels.

Changes:

  • bug fixes in ase.utils.arraywrapper.arraylike !1618 (merged)
  • jsonio notices that dct is arraylike and uses the array (to correct failed jsonio test)
  • atom labels introduced in ase.atoms
  • atom numbers are represented by ase.numbers.Numbers class which is arraylike. It has explicit __setitem__ and __set__ to change labels when changed.

Details:

They are implemented just like masses. When set, they make a numpy.ndarray in atom.arrays. The labels auto updates/roll-backs to chemical symbol, when atom number or chemical symbol is changed.

Changes in atoms.numbers:

The atomic numbers are still stored in atom.arrays. However, atom.numbers is made into a ase.utils.arraywrapper.arraylike class -- exactly like atoms.cell. This numbers class is initiated with the atoms object. This way the class can read numbers data in atoms.arrays. This numbers class also has explicity defined __set__ and __setitem__ methods. This way, it is easy to track any user initiated changes to numbers, and atom labels are updated accordingly.

The implementation causes following effects:

import ase

atoms = ase.Atoms('H2', cell=[0, 0, 1])
atoms.set_labels(['H1', 'H2'])
print(atoms.arrays)
{'labels': array(['H1', 'H2'], dtype=object), 'positions': array([[0., 0., 0.],
       [0., 0., 0.]]), 'numbers': array([1, 1])}
atoms.numbers[0] = 2

print(atoms.get_labels())
print(atoms.numbers)
['He' 'H2']
[2 1]
atoms.set_atomic_numbers([2, 2])

print(atoms.get_labels())
print(atoms.numbers)
['He' 'He']
[2 2]
atoms.set_chemical_symbols(['He', 'Li'])

print(atoms.get_labels())
print(atoms.numbers)
['He' 'Li']
[2 3]
Edited by Yashasvi S. Ranawat

Merge request reports