33import numpy as np
44import pytest
55
6+ from aiida .common .warnings import AiidaDeprecationWarning
67from aiida .orm import StructureData , TrajectoryData , load_node
78
89
@@ -147,8 +148,8 @@ def test_trajectory_get_step_structure(self, trajectory_data):
147148 with pytest .raises (IndexError ):
148149 trajectory .get_step_structure (500 )
149150
150- def test_trajectory_pbc (self , trajectory_data ):
151- """Test the `pbc` for the `TrajectoryData`."""
151+ def test_trajectory_pbc_structures (self , trajectory_data ):
152+ """Test the `pbc` for the `TrajectoryData` using structure inputs ."""
152153 # Test non-pbc structure with no cell
153154 structure = StructureData (cell = None , pbc = [False , False , False ])
154155 structure .append_atom (position = [0.0 , 0.0 , 0.0 ], symbols = 'H' )
@@ -174,3 +175,62 @@ def test_trajectory_pbc(self, trajectory_data):
174175
175176 with pytest .raises (ValueError , match = 'All structures should have the same `pbc`' ):
176177 TrajectoryData (structurelist = (structure_periodic , structure_non_periodic ))
178+
179+ def test_trajectory_pbc_set_trajectory (self ):
180+ """Test the `pbc` for the `TrajectoryData` using `set_trajectory`."""
181+ data = {
182+ 'symbols' : ['H' ],
183+ 'positions' : np .array (
184+ [
185+ [
186+ [0.0 , 0.0 , 0.0 ],
187+ ]
188+ ]
189+ ),
190+ }
191+ trajectory = TrajectoryData ()
192+
193+ data .update (
194+ {
195+ 'cells' : None ,
196+ 'pbc' : None ,
197+ }
198+ )
199+ trajectory .set_trajectory (** data )
200+ assert trajectory .get_step_structure (0 ).pbc == (False , False , False )
201+
202+ data .update (
203+ {
204+ 'cells' : None ,
205+ 'pbc' : [False , False , False ],
206+ }
207+ )
208+ trajectory .set_trajectory (** data )
209+ assert trajectory .get_step_structure (0 ).pbc == (False , False , False )
210+
211+ data .update (
212+ {
213+ 'cells' : None ,
214+ 'pbc' : [True , False , False ],
215+ }
216+ )
217+ with pytest .raises (ValueError , match = 'Periodic boundary conditions are only possible when a cell is defined' ):
218+ trajectory .set_trajectory (** data )
219+
220+ data .update (
221+ {
222+ 'cells' : np .array ([[[1.0 , 0.0 , 0.0 ], [0.0 , 1.0 , 0.0 ], [0.0 , 0.0 , 1.0 ]]]),
223+ 'pbc' : None ,
224+ }
225+ )
226+ with pytest .warns (AiidaDeprecationWarning , match = "When 'cells' is not None, the periodic" ):
227+ trajectory .set_trajectory (** data )
228+
229+ data .update (
230+ {
231+ 'cells' : np .array ([[[1.0 , 0.0 , 0.0 ], [0.0 , 1.0 , 0.0 ], [0.0 , 0.0 , 1.0 ]]]),
232+ 'pbc' : (True , False , False ),
233+ }
234+ )
235+ trajectory .set_trajectory (** data )
236+ assert trajectory .get_step_structure (0 ).pbc == (True , False , False )
0 commit comments