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
« 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
5from gpaw.point_groups import (PointGroup, SymmetryChecker,
6 point_group_names as names)
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()
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]
33@pytest.mark.serial
34@pytest.mark.parametrize('name', names)
35def test_pg(name):
36 pg = PointGroup(name)
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])
43 h = sum(pg.nops)
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
51 # Rows:
52 for i, row1 in enumerate(pg.character_table):
54 # Check normalization:
55 assert (row1**2).dot(pg.nops) == approx(h, 1e-8)
57 for j, row2 in enumerate(pg.character_table):
59 if i >= j:
60 continue
62 # Check orthogonality:
63 assert (row1 * row2).dot(pg.nops) == approx(0, abs=1e-8)
65 # Columns:
66 for i, row1 in enumerate(pg.character_table.T):
68 # Check normalization:
69 assert (row1**2).sum() == approx(h / pg.nops[i], abs=1e-13)
71 for j, row2 in enumerate(pg.character_table.T):
73 if i >= j:
74 continue
76 # Check orthogonality:
77 assert row1.dot(row2) == approx(0, 1e-8)
79 # Checks for complex groups:
80 else:
81 reps = pg.symmetries
82 # Rows:
83 for i, row1 in enumerate(pg.character_table):
85 # Check normalization:
86 norm = (row1**2).dot(pg.nops)
88 # Real rows:
89 if reps[i].find('E') < 0:
90 correctnorm = h
91 else: # complex rows
92 correctnorm = h * 2
94 assert norm == approx(correctnorm, abs=1e-8)
96 for j, row2 in enumerate(pg.character_table):
98 if i >= j:
99 continue
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)):
106 # Check orthogonality:
107 norm = (row1 * row2).dot(pg.nops)
108 assert norm == approx(0, abs=1e-13)