aiida-core icon indicating copy to clipboard operation
aiida-core copied to clipboard

TrajectoryData does not preserve periodicity information

Open danielhollas opened this issue 1 year ago • 1 comments

How to turn a non-periodic structure into a periodic structure in a few simple steps, going from StructureData to TrajectoryData and back again

In [92]: s = StructureData(cell=None, pbc=(False, False, False))

In [93]: s.append_atom(position=[0.0, 0.0, 0.0], symbols='H')

In [94]: t = TrajectoryData(structurelist=(s,))

In [95]: t.get_step_structure(0).pbc
Out[95]: (True, True, True)

trying to store such a transformed structure leads to sadness (predictably)

----> 1 t.get_step_structure(0).store()

~/atmospec/aiida-core/src/aiida/orm/nodes/node.py in store(self)
    522             self._validate_storability()
--> 523             self._validate()
    524 
~/atmospec/aiida-core/src/aiida/orm/nodes/data/structure.py in _validate(self)
    920 
--> 921         _validate_dimensionality(self.pbc, self.cell)
    922 
~/atmospec/aiida-core/src/aiida/orm/nodes/data/structure.py in _validate_dimensionality(pbc, cell)
   2458     if dim['value'] == 0:
-> 2459         raise ValueError(f'Structure has periodicity {pbc} but {dim["dim"]}-d volume 0.')

Looking at the code, it seems like TrajectoryData does not track periodicity information at all, which is a bad news for everything except 3D-periodic structures.

This is currently a big issue for my app, since I am using TrajectoryData extensively to store molecular conformers.

cc @mbercx

danielhollas avatar Apr 29 '24 01:04 danielhollas

Huh, seems like this is a known behaviour???

https://github.com/aiidateam/aiida-core/blob/212f6163b03b8762509ae2230c30172af8c02fed/src/aiida/orm/nodes/data/array/trajectory.py#L362

danielhollas avatar Apr 29 '24 01:04 danielhollas