aiidateam / aiida-core

The official repository for the AiiDA code
https://aiida-core.readthedocs.io
Other
413 stars 184 forks source link

StructureData.get_angles() freaks out for zero cell #6375

Open danielhollas opened 2 months ago

danielhollas commented 2 months ago

Sadness in four steps

In [60]: s = StructureData(cell=None)

In [61]: s.cell
Out[61]: [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]

In [62]: s.cell_lengths
Out[62]: [0.0, 0.0, 0.0]

In [63]: s.cell_angles
/home/hollas/atmospec/aiida-core/src/aiida/orm/nodes/data/structure.py:1677: RuntimeWarning: invalid value encountered in scalar divide
  numpy.vdot(cell[1], cell[2]) / lengths[1] / lengths[2],
/home/hollas/atmospec/aiida-core/src/aiida/orm/nodes/data/structure.py:1678: RuntimeWarning: invalid value encountered in scalar divide
  numpy.vdot(cell[0], cell[2]) / lengths[0] / lengths[2],
/home/hollas/atmospec/aiida-core/src/aiida/orm/nodes/data/structure.py:1679: RuntimeWarning: invalid value encountered in scalar divide
  numpy.vdot(cell[0], cell[1]) / lengths[0] / lengths[1],
Out[63]: [nan, nan, nan]

Not sure what the right behaviour is here, but at the very least we shouldn't be dividing by zero.

sphuber commented 2 months ago

I think I would tend to have this raise an exception, because it simply doesn't make sense.

I was going to say that alternatively returning [0, 0 ,0] or [None, None, None] seems wrong to me, but then again, it could be that the cell is 2-dimensional, in which case two angles will have meaning. In that case, the user might still want to get those angles, and then one would be forced to return a list where the ill-defined angles have some sentinel value like nan or None.