Skip to content

Commit 47b440d

Browse files
committed
add input,expected to tests for adp getters
1 parent 6259c38 commit 47b440d

1 file changed

Lines changed: 146 additions & 141 deletions

File tree

tests/test_structure.py

Lines changed: 146 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -707,165 +707,170 @@ def test_get_cartesian_coordinates(datafile):
707707

708708

709709
@pytest.mark.parametrize(
710-
"return_array",
711-
[ # case: user wants ADPs as an array
710+
"input,expected",
711+
[ # case: user wants ADPs as an array so they set return_array=True
712712
# expected: a 3D array of shape (num_atoms, 3, 3) with the Uij values
713-
True,
714-
# case: user wants ADPs as a dictionary
713+
[
714+
True,
715+
np.array(
716+
[
717+
[[0.0211, 0.0, 0.0109], [0.0, 0.0195, 0.0], [0.0109, 0.0, 0.016]],
718+
[[0.0223, 0.0, 0.0179], [0.0, 0.018, 0.0], [0.0179, 0.0, 0.0254]],
719+
[[0.025, 0.0, 0.0226], [0.0, 0.0234, 0.0], [0.0226, 0.0, 0.0345]],
720+
[[0.0234, 0.0, 0.0138], [0.0, 0.0295, 0.0], [0.0138, 0.0, 0.0253]],
721+
]
722+
),
723+
],
724+
# case: user wants ADPs as a dictionary so they set return_array=False (default behavior)
715725
# expected: a dictionary with keys like "I_8_11" and values as the corresponding Uij values
716-
False,
726+
[
727+
False,
728+
{
729+
# Iodine
730+
"I_8_11": 0.025,
731+
"I_8_12": 0.0,
732+
"I_8_13": 0.0226,
733+
"I_8_22": 0.0234,
734+
"I_8_23": 0.0,
735+
"I_8_33": 0.0345,
736+
"I_9_11": 0.025,
737+
"I_9_12": 0.0,
738+
"I_9_13": 0.0226,
739+
"I_9_22": 0.0234,
740+
"I_9_23": 0.0,
741+
"I_9_33": 0.0345,
742+
"I_10_11": 0.025,
743+
"I_10_12": 0.0,
744+
"I_10_13": 0.0226,
745+
"I_10_22": 0.0234,
746+
"I_10_23": 0.0,
747+
"I_10_33": 0.0345,
748+
"I_11_11": 0.025,
749+
"I_11_12": 0.0,
750+
"I_11_13": 0.0226,
751+
"I_11_22": 0.0234,
752+
"I_11_23": 0.0,
753+
"I_11_33": 0.0345,
754+
"I_12_11": 0.0234,
755+
"I_12_12": 0.0,
756+
"I_12_13": 0.0138,
757+
"I_12_22": 0.0295,
758+
"I_12_23": 0.0,
759+
"I_12_33": 0.0253,
760+
"I_13_11": 0.0234,
761+
"I_13_12": 0.0,
762+
"I_13_13": 0.0138,
763+
"I_13_22": 0.0295,
764+
"I_13_23": 0.0,
765+
"I_13_33": 0.0253,
766+
"I_14_11": 0.0234,
767+
"I_14_12": 0.0,
768+
"I_14_13": 0.0138,
769+
"I_14_22": 0.0295,
770+
"I_14_23": 0.0,
771+
"I_14_33": 0.0253,
772+
"I_15_11": 0.0234,
773+
"I_15_12": 0.0,
774+
"I_15_13": 0.0138,
775+
"I_15_22": 0.0295,
776+
"I_15_23": 0.0,
777+
"I_15_33": 0.0253,
778+
# Tellurium
779+
"Te_0_11": 0.0211,
780+
"Te_0_12": 0.0,
781+
"Te_0_13": 0.0109,
782+
"Te_0_22": 0.0195,
783+
"Te_0_23": 0.0,
784+
"Te_0_33": 0.016,
785+
"Te_1_11": 0.0211,
786+
"Te_1_12": 0.0,
787+
"Te_1_13": 0.0109,
788+
"Te_1_22": 0.0195,
789+
"Te_1_23": 0.0,
790+
"Te_1_33": 0.016,
791+
"Te_2_11": 0.0211,
792+
"Te_2_12": 0.0,
793+
"Te_2_13": 0.0109,
794+
"Te_2_22": 0.0195,
795+
"Te_2_23": 0.0,
796+
"Te_2_33": 0.016,
797+
"Te_3_11": 0.0211,
798+
"Te_3_12": 0.0,
799+
"Te_3_13": 0.0109,
800+
"Te_3_22": 0.0195,
801+
"Te_3_23": 0.0,
802+
"Te_3_33": 0.016,
803+
"Te_4_11": 0.0223,
804+
"Te_4_12": 0.0,
805+
"Te_4_13": 0.0179,
806+
"Te_4_22": 0.018,
807+
"Te_4_23": 0.0,
808+
"Te_4_33": 0.0254,
809+
"Te_5_11": 0.0223,
810+
"Te_5_12": 0.0,
811+
"Te_5_13": 0.0179,
812+
"Te_5_22": 0.018,
813+
"Te_5_23": 0.0,
814+
"Te_5_33": 0.0254,
815+
"Te_6_11": 0.0223,
816+
"Te_6_12": 0.0,
817+
"Te_6_13": 0.0179,
818+
"Te_6_22": 0.018,
819+
"Te_6_23": 0.0,
820+
"Te_6_33": 0.0254,
821+
"Te_7_11": 0.0223,
822+
"Te_7_12": 0.0,
823+
"Te_7_13": 0.0179,
824+
"Te_7_22": 0.018,
825+
"Te_7_23": 0.0,
826+
"Te_7_33": 0.0254,
827+
},
828+
],
717829
],
718830
)
719-
def test_get_anisotropic_displacement_parameters(datafile, return_array):
831+
def test_get_anisotropic_displacement_parameters(datafile, input, expected):
720832
"""Check Structure.get_anisotropic_displacement_parameters()"""
721833
tei_stru = Structure(filename=datafile("TeI.cif"))
722-
actual_displacement = tei_stru.get_anisotropic_displacement_parameters(return_array=return_array)
723-
if return_array:
724-
expected_one_atom = np.array(
725-
[
726-
[[0.0211, 0.0, 0.0109], [0.0, 0.0195, 0.0], [0.0109, 0.0, 0.016]],
727-
[[0.0223, 0.0, 0.0179], [0.0, 0.018, 0.0], [0.0179, 0.0, 0.0254]],
728-
[[0.025, 0.0, 0.0226], [0.0, 0.0234, 0.0], [0.0226, 0.0, 0.0345]],
729-
[[0.0234, 0.0, 0.0138], [0.0, 0.0295, 0.0], [0.0138, 0.0, 0.0253]],
730-
]
731-
)
732-
expected_displacement = np.repeat(expected_one_atom, 4, axis=0)
834+
actual_displacement = tei_stru.get_anisotropic_displacement_parameters(return_array=input)
835+
if isinstance(expected, np.ndarray):
836+
expected_displacement = np.repeat(expected, 4, axis=0)
733837
assert np.allclose(actual_displacement, expected_displacement)
734-
else:
735-
expected_displacement = {
736-
# Iodine
737-
"I_8_11": 0.025,
738-
"I_8_12": 0.0,
739-
"I_8_13": 0.0226,
740-
"I_8_22": 0.0234,
741-
"I_8_23": 0.0,
742-
"I_8_33": 0.0345,
743-
"I_9_11": 0.025,
744-
"I_9_12": 0.0,
745-
"I_9_13": 0.0226,
746-
"I_9_22": 0.0234,
747-
"I_9_23": 0.0,
748-
"I_9_33": 0.0345,
749-
"I_10_11": 0.025,
750-
"I_10_12": 0.0,
751-
"I_10_13": 0.0226,
752-
"I_10_22": 0.0234,
753-
"I_10_23": 0.0,
754-
"I_10_33": 0.0345,
755-
"I_11_11": 0.025,
756-
"I_11_12": 0.0,
757-
"I_11_13": 0.0226,
758-
"I_11_22": 0.0234,
759-
"I_11_23": 0.0,
760-
"I_11_33": 0.0345,
761-
"I_12_11": 0.0234,
762-
"I_12_12": 0.0,
763-
"I_12_13": 0.0138,
764-
"I_12_22": 0.0295,
765-
"I_12_23": 0.0,
766-
"I_12_33": 0.0253,
767-
"I_13_11": 0.0234,
768-
"I_13_12": 0.0,
769-
"I_13_13": 0.0138,
770-
"I_13_22": 0.0295,
771-
"I_13_23": 0.0,
772-
"I_13_33": 0.0253,
773-
"I_14_11": 0.0234,
774-
"I_14_12": 0.0,
775-
"I_14_13": 0.0138,
776-
"I_14_22": 0.0295,
777-
"I_14_23": 0.0,
778-
"I_14_33": 0.0253,
779-
"I_15_11": 0.0234,
780-
"I_15_12": 0.0,
781-
"I_15_13": 0.0138,
782-
"I_15_22": 0.0295,
783-
"I_15_23": 0.0,
784-
"I_15_33": 0.0253,
785-
# Tellurium
786-
"Te_0_11": 0.0211,
787-
"Te_0_12": 0.0,
788-
"Te_0_13": 0.0109,
789-
"Te_0_22": 0.0195,
790-
"Te_0_23": 0.0,
791-
"Te_0_33": 0.016,
792-
"Te_1_11": 0.0211,
793-
"Te_1_12": 0.0,
794-
"Te_1_13": 0.0109,
795-
"Te_1_22": 0.0195,
796-
"Te_1_23": 0.0,
797-
"Te_1_33": 0.016,
798-
"Te_2_11": 0.0211,
799-
"Te_2_12": 0.0,
800-
"Te_2_13": 0.0109,
801-
"Te_2_22": 0.0195,
802-
"Te_2_23": 0.0,
803-
"Te_2_33": 0.016,
804-
"Te_3_11": 0.0211,
805-
"Te_3_12": 0.0,
806-
"Te_3_13": 0.0109,
807-
"Te_3_22": 0.0195,
808-
"Te_3_23": 0.0,
809-
"Te_3_33": 0.016,
810-
"Te_4_11": 0.0223,
811-
"Te_4_12": 0.0,
812-
"Te_4_13": 0.0179,
813-
"Te_4_22": 0.018,
814-
"Te_4_23": 0.0,
815-
"Te_4_33": 0.0254,
816-
"Te_5_11": 0.0223,
817-
"Te_5_12": 0.0,
818-
"Te_5_13": 0.0179,
819-
"Te_5_22": 0.018,
820-
"Te_5_23": 0.0,
821-
"Te_5_33": 0.0254,
822-
"Te_6_11": 0.0223,
823-
"Te_6_12": 0.0,
824-
"Te_6_13": 0.0179,
825-
"Te_6_22": 0.018,
826-
"Te_6_23": 0.0,
827-
"Te_6_33": 0.0254,
828-
"Te_7_11": 0.0223,
829-
"Te_7_12": 0.0,
830-
"Te_7_13": 0.0179,
831-
"Te_7_22": 0.018,
832-
"Te_7_23": 0.0,
833-
"Te_7_33": 0.0254,
834-
}
835-
assert actual_displacement == expected_displacement
838+
if isinstance(expected, dict):
839+
assert actual_displacement == expected
836840

837841

838842
@pytest.mark.parametrize(
839-
"return_array",
843+
"input,expected",
840844
[ # case: user wants isotropic displacement parameters as an array
845+
# so they set return_array=True
841846
# expected: a 1D array of shape (num_atoms,) with the Uiso values
842-
True,
847+
[True, np.array([0.0225566, 0.0225566, 0.0225566, 0.0225566, 0.0155528, 0.0155528, 0.0155528, 0.0155528])],
843848
# case: user wants isotropic displacement parameters as a dictionary
849+
# so they set return_array=False (default behavior)
844850
# expected: a dictionary with keys like "I_Uiso" and values as the corresponding Uiso values
845-
False,
851+
[
852+
False,
853+
{
854+
"Pb_1_Uiso": 0.0225566,
855+
"Pb_2_Uiso": 0.0225566,
856+
"Pb_3_Uiso": 0.0225566,
857+
"Pb_4_Uiso": 0.0225566,
858+
"Te_5_Uiso": 0.0155528,
859+
"Te_6_Uiso": 0.0155528,
860+
"Te_7_Uiso": 0.0155528,
861+
"Te_8_Uiso": 0.0155528,
862+
},
863+
],
846864
],
847865
)
848-
def test_get_isotropic_displacement_parameters(datafile, return_array):
866+
def test_get_isotropic_displacement_parameters(datafile, input, expected):
849867
"""Check Structure.get_isotropic_displacement_parameters()"""
850868
pbte_stru = Structure(filename=datafile("PbTe.cif"))
851-
actual_isotropic_displacement = pbte_stru.get_isotropic_displacement_parameters(return_array=return_array)
852-
if return_array:
853-
expected_isotropic_displacement = np.array(
854-
[0.0225566, 0.0225566, 0.0225566, 0.0225566, 0.0155528, 0.0155528, 0.0155528, 0.0155528]
855-
)
856-
assert np.allclose(actual_isotropic_displacement, expected_isotropic_displacement)
857-
else:
858-
expected_isotropic_displacement = {
859-
"Pb_1_Uiso": 0.0225566,
860-
"Pb_2_Uiso": 0.0225566,
861-
"Pb_3_Uiso": 0.0225566,
862-
"Pb_4_Uiso": 0.0225566,
863-
"Te_5_Uiso": 0.0155528,
864-
"Te_6_Uiso": 0.0155528,
865-
"Te_7_Uiso": 0.0155528,
866-
"Te_8_Uiso": 0.0155528,
867-
}
868-
assert actual_isotropic_displacement == expected_isotropic_displacement
869+
actual_isotropic_displacement = pbte_stru.get_isotropic_displacement_parameters(return_array=input)
870+
if isinstance(expected, np.ndarray):
871+
assert np.allclose(actual_isotropic_displacement, expected)
872+
if isinstance(expected, dict):
873+
assert actual_isotropic_displacement == expected
869874

870875

871876
def test_get_occupancies(datafile):

0 commit comments

Comments
 (0)