@@ -131,8 +131,6 @@ def test_chemical_formula_and_ratios() -> None:
131131 assert record ["chemical_formula_anonymous" ] == "A3BC"
132132 assert record ["chemical_formula_descriptive" ] == "FeO3Sm"
133133 assert record ["elements_ratios" ] == [0.2 , 0.6 , 0.2 ]
134- assert record ["nperiodic_dimensions" ] == 3
135- assert record ["dimension_types" ] == [1 , 1 , 1 ]
136134
137135
138136def test_null_structure_serves_null () -> None :
@@ -192,3 +190,41 @@ def test_registration_discovered_via_httk_core() -> None:
192190 provider = factory ({"s-1" : _nacl_like ()})
193191 assert isinstance (provider , StructureEntryProvider )
194192 assert set (provider .entry_types ()) == {"structures" }
193+
194+
195+ # --- periodicity ---
196+
197+
198+ def test_periodicity_is_served_whatever_the_composition () -> None :
199+ """It is not a composition property, and must not null out with the formula.
200+
201+ A `Structure` carries no notion of periodicity, so every one of them is served as a
202+ fully periodic crystal. The bug was that these two travelled with the composition
203+ block, which serves null for any structure that is not fully ordered — so a disordered
204+ alloy, or a structure with attached atoms, reported its periodicity as *unknown* purely
205+ because a whole-atom formula could not be written for it.
206+ """
207+ cell = [[4.0 , 0.0 , 0.0 ], [0.0 , 4.0 , 0.0 ], [0.0 , 0.0 , 4.0 ]]
208+ ordered = Species (name = "Na" , chemical_symbols = ("Na" ,), concentration = (1.0 ,))
209+ disordered = Species (name = "X" , chemical_symbols = ("Na" , "K" ), concentration = (0.5 , 0.5 ))
210+ attached = Species (name = "C" , chemical_symbols = ("C" ,), concentration = (1.0 ,), attached = ("H" ,), nattached = (1 ,))
211+
212+ for label , species in (("ordered" , ordered ), ("disordered" , disordered ), ("attached" , attached )):
213+ structure = Structure (cell , [[0 , 0 , 0 ]], [species ], [species .name ])
214+ (record ,) = list (StructureEntryProvider ({"x" : structure }).records ("structures" ))
215+ assert record ["nperiodic_dimensions" ] == 3 , label
216+ assert record ["dimension_types" ] == [1 , 1 , 1 ], label
217+
218+ # The composition properties still null out for those, which is correct.
219+ (record ,) = list (
220+ StructureEntryProvider ({"x" : Structure (cell , [[0 , 0 , 0 ]], [disordered ], ["X" ])}).records ("structures" )
221+ )
222+ assert record ["chemical_formula_reduced" ] is None
223+ assert record ["elements_ratios" ] is None
224+
225+
226+ def test_an_entry_with_no_structure_still_serves_null_periodicity () -> None :
227+ """There is no structure to describe, so unknown is the honest answer there."""
228+ (record ,) = list (StructureEntryProvider ({"empty" : None }).records ("structures" ))
229+ assert record ["nperiodic_dimensions" ] is None
230+ assert record ["dimension_types" ] is None
0 commit comments