Coverage for gpaw/test/point_groups/test_pointgroup_properties.py: 100%

56 statements  

« prev     ^ index     » next       coverage.py v7.7.1, created at 2025-07-20 00:19 +0000

1import numpy as np 

2import pytest 

3from pytest import approx 

4 

5from gpaw.point_groups import (PointGroup, SymmetryChecker, 

6 point_group_names as names) 

7 

8 

9@pytest.mark.serial 

10@pytest.mark.parametrize('name', names) 

11def test_for_various_errors(name): 

12 pg = PointGroup(name) 

13 print(pg) 

14 pg.get_normalized_table() 

15 

16 

17@pytest.mark.serial 

18@pytest.mark.parametrize('name', names) 

19def test_translations(name): 

20 pg = PointGroup(name) 

21 # Calculate the symmetry representations of p-orbitals: 

22 x = np.linspace(-5, 5, 11) 

23 xyz = np.array(np.meshgrid(x, x, x, indexing='ij')) 

24 r2 = (xyz**2).sum(0) 

25 checker = SymmetryChecker(pg, center=(5, 5, 5), grid_spacing=1.5) 

26 for i in range(3): 

27 func = np.exp(-r2) * xyz[i] 

28 dct = checker.check_function(func, np.eye(3)) 

29 print(i, dct) 

30 assert dct['symmetry'] == pg.translations[i] 

31 

32 

33@pytest.mark.serial 

34@pytest.mark.parametrize('name', names) 

35def test_pg(name): 

36 pg = PointGroup(name) 

37 

38 # Check that the number of irreducible representation 

39 # is equal to the number of symmetry 

40 # transform classes: 

41 assert len(pg.character_table) == len(pg.character_table[0]) 

42 

43 h = sum(pg.nops) 

44 

45 # Checks for groups with real character tables: 

46 if not pg.complex: 

47 # Check that the sum of squared dimensions of the irreps 

48 # equals to the number of symmetry elements h 

49 assert (pg.character_table[:, 0]**2).sum() == h 

50 

51 # Rows: 

52 for i, row1 in enumerate(pg.character_table): 

53 

54 # Check normalization: 

55 assert (row1**2).dot(pg.nops) == approx(h, 1e-8) 

56 

57 for j, row2 in enumerate(pg.character_table): 

58 

59 if i >= j: 

60 continue 

61 

62 # Check orthogonality: 

63 assert (row1 * row2).dot(pg.nops) == approx(0, abs=1e-8) 

64 

65 # Columns: 

66 for i, row1 in enumerate(pg.character_table.T): 

67 

68 # Check normalization: 

69 assert (row1**2).sum() == approx(h / pg.nops[i], abs=1e-13) 

70 

71 for j, row2 in enumerate(pg.character_table.T): 

72 

73 if i >= j: 

74 continue 

75 

76 # Check orthogonality: 

77 assert row1.dot(row2) == approx(0, 1e-8) 

78 

79 # Checks for complex groups: 

80 else: 

81 reps = pg.symmetries 

82 # Rows: 

83 for i, row1 in enumerate(pg.character_table): 

84 

85 # Check normalization: 

86 norm = (row1**2).dot(pg.nops) 

87 

88 # Real rows: 

89 if reps[i].find('E') < 0: 

90 correctnorm = h 

91 else: # complex rows 

92 correctnorm = h * 2 

93 

94 assert norm == approx(correctnorm, abs=1e-8) 

95 

96 for j, row2 in enumerate(pg.character_table): 

97 

98 if i >= j: 

99 continue 

100 

101 # Compare real with real rows and complex with complex rows: 

102 if ((reps[i].find('E') >= 0 and reps[j].find('E') >= 0) 

103 or 

104 (reps[i].find('E') < 0 and reps[j].find('E') < 0)): 

105 

106 # Check orthogonality: 

107 norm = (row1 * row2).dot(pg.nops) 

108 assert norm == approx(0, abs=1e-13)