2727 GeneratorSite ,
2828 SymmetryConstraints ,
2929 _Position2Tuple ,
30+ equal_positions ,
31+ equalPositions ,
32+ expand_position ,
3033 expandPosition ,
3134 is_constant_formula ,
3235 is_space_group_latt_parms ,
3336 isconstantFormula ,
3437 isSpaceGroupLatPar ,
3538 nearest_site_index ,
3639 nearestSiteIndex ,
40+ null_space ,
41+ nullSpace ,
3742 position_difference ,
3843 positionDifference ,
3944 pruneFormulaDictionary ,
@@ -127,6 +132,17 @@ def test_expandPosition(self):
127132 self .assertEqual (4 , pmult )
128133 return
129134
135+ def test_expand_position (self ):
136+ """Check expand_position()"""
137+ # ok again Ni example
138+ fcc = GetSpaceGroup (225 )
139+ pos , pops , pmult = expand_position (fcc , [0 , 0 , 0 ])
140+ self .assertTrue (numpy .all (pos [0 ] == 0.0 ))
141+ self .assertEqual (4 , len (pos ))
142+ self .assertEqual (192 , sum ([len (line ) for line in pops ]))
143+ self .assertEqual (4 , pmult )
144+ return
145+
130146 def test_pruneFormulaDictionary (self ):
131147 """Check pruneFormulaDictionary()"""
132148 fmdict = {"x" : "3*y-0.17" , "y" : "0" , "z" : "0.13" }
@@ -152,6 +168,12 @@ def test_is_constant_formula(self):
152168 self .assertTrue (is_constant_formula ("+13/ 9" ))
153169 return
154170
171+ def test_equalPositions (self ):
172+ """Check equalPositions()"""
173+ self .assertTrue (equalPositions ([0.1 , 0.2 , 0.3 ], [0.1 , 0.2 , 0.3 ], 1.0e-5 ))
174+ self .assertTrue (equalPositions ([0.1 + 0.5e-5 , 0.2 + 0.5e-5 , 0.3 + 0.5e-5 ], [0.1 , 0.2 , 0.3 ], 1.0e-5 ))
175+ self .assertFalse (equalPositions ([0.2 , 0.2 , 0.3 ], [0.1 , 0.2 , 0.3 ], 1.0e-5 ))
176+
155177
156178# End of class TestRoutines
157179
@@ -704,5 +726,85 @@ def test_nearest_site_index(sites, xyz, expected):
704726 assert actual == expected
705727
706728
729+ @pytest .mark .parametrize (
730+ "xyz0, xyz1, eps, expected" ,
731+ [
732+ pytest .param ([0.1 , 0.2 , 0.3 ], [0.1 , 0.2 , 0.3 ], 1.0e-5 , True ), # C1: same position
733+ pytest .param (
734+ [0.1 + 0.5e-5 , 0.2 + 0.5e-5 , 0.3 + 0.5e-5 ], [0.1 , 0.2 , 0.3 ], 1.0e-5 , True
735+ ), # C2: same position with some tolerance
736+ pytest .param ([0.2 , 0.2 , 0.3 ], [0.1 , 0.2 , 0.3 ], 1.0e-5 , False ), # C3: different positions
737+ ],
738+ )
739+ def test_equal_positions (xyz0 , xyz1 , eps , expected ):
740+ """Check equalPositions."""
741+ actual = equal_positions (xyz0 , xyz1 , eps )
742+ assert actual == expected
743+
744+
745+ @pytest .mark .parametrize (
746+ "A, expected_dim" ,
747+ [
748+ pytest .param ( # C1: full-rank 2x2 matrix
749+ [[1.0 , 0.0 ], [0.0 , 1.0 ]],
750+ 0 ,
751+ ),
752+ pytest .param ( # C2: Nullspace has dim 1
753+ [[1.0 , 0.0 , 0.0 ], [0.0 , 0.0 , 0.0 ], [0.0 , 0.0 , 2.0 ]],
754+ 1 ,
755+ ),
756+ pytest .param ( # C3: Nullspace has dim 2
757+ [[1.0 , 2.0 , 3.0 ], [2.0 , 4.0 , 6.0 ], [0.0 , 0.0 , 0.0 ]],
758+ 2 ,
759+ ),
760+ pytest .param ( # C4: Nullspace has dim 2
761+ [[0.0 , 0.0 ], [0.0 , 0.0 ]],
762+ 2 ,
763+ ),
764+ ],
765+ )
766+ def test_nullSpace (A , expected_dim ):
767+ """Check nullSpace returns an orthonormal basis on supported square
768+ matrices."""
769+ A = numpy .asarray (A , dtype = float )
770+ actual = nullSpace (A )
771+
772+ assert actual .shape == (expected_dim , A .shape [1 ])
773+ assert numpy .allclose (A @ actual .T , numpy .zeros ((A .shape [0 ], expected_dim )), atol = 1e-12 )
774+ assert numpy .allclose (actual @ actual .T , numpy .eye (expected_dim ), atol = 1e-12 )
775+
776+
777+ @pytest .mark .parametrize (
778+ "A, expected_dim" ,
779+ [
780+ pytest .param ( # C1: full-rank 2x2 matrix
781+ [[1.0 , 0.0 ], [0.0 , 1.0 ]],
782+ 0 ,
783+ ),
784+ pytest .param ( # C2: Nullspace has dim 1
785+ [[1.0 , 0.0 , 0.0 ], [0.0 , 0.0 , 0.0 ], [0.0 , 0.0 , 2.0 ]],
786+ 1 ,
787+ ),
788+ pytest .param ( # C3: Nullspace has dim 2
789+ [[1.0 , 2.0 , 3.0 ], [2.0 , 4.0 , 6.0 ], [0.0 , 0.0 , 0.0 ]],
790+ 2 ,
791+ ),
792+ pytest .param ( # C4: Nullspace has dim 2
793+ [[0.0 , 0.0 ], [0.0 , 0.0 ]],
794+ 2 ,
795+ ),
796+ ],
797+ )
798+ def test_null_space (A , expected_dim ):
799+ """Check null_space returns an orthonormal basis on supported square
800+ matrices."""
801+ A = numpy .asarray (A , dtype = float )
802+ actual = null_space (A )
803+
804+ assert actual .shape == (expected_dim , A .shape [1 ])
805+ assert numpy .allclose (A @ actual .T , numpy .zeros ((A .shape [0 ], expected_dim )), atol = 1e-12 )
806+ assert numpy .allclose (actual @ actual .T , numpy .eye (expected_dim ), atol = 1e-12 )
807+
808+
707809if __name__ == "__main__" :
708810 unittest .main ()
0 commit comments