Coverage for /builds/ase/ase/ase/spacegroup/crystal_data.py: 100.00%
28 statements
« prev ^ index » next coverage.py v7.5.3, created at 2025-08-02 00:12 +0000
« prev ^ index » next coverage.py v7.5.3, created at 2025-08-02 00:12 +0000
1# fmt: off
3from ase.lattice import bravais_classes
5_crystal_family = ('Øaammmmmmmmmmmmmoooooooooooooooooooooooooooooooooooooooooo'
6 'ooooooooooooooooottttttttttttttttttttttttttttttttttttttttt'
7 'ttttttttttttttttttttttttttthhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh'
8 'hhhhhhhhhhhhhhhhhhhhhcccccccccccccccccccccccccccccccccccc')
10_lattice_centering = ('ØPPPPCPPCCPPCPPCPPPPCCFIIPPPPPPPPPPCCCCCCCFFIIIPPPPPPPP'
11 'PPPPPPPPCCCCCCFFIIIIPPPPIIPIPPPPIIPPPPPPPPIIPPPPPPPPII'
12 'IIPPPPPPPPIIIIPPPPPPPPPPPPPPPPIIIIPPPRPRPPPPPPRPPPPRRP'
13 'PPPRRPPPPPPPPPPPPPPPPPPPPPPPPPPPPFIPIPPFFIPIPPFFIPPIPF'
14 'IPFIPPPPFFFFII')
16_point_group_ranges = [(1, '1'),
17 (2, '-1'),
18 (3, '2'),
19 (6, 'm'),
20 (10, '2/m'),
21 (16, '222'),
22 (25, 'mm2'),
23 (47, '2/m 2/m 2/m'),
24 (75, '4'),
25 (81, '-4'),
26 (83, '4/m'),
27 (89, '422'),
28 (99, '4mm'),
29 (111, '-42m'),
30 (123, '4/m 2/m 2/m'),
31 (143, '3'),
32 (147, '-3'),
33 (149, '32'),
34 (156, '3m'),
35 (162, '-3 2/m'),
36 (168, '6'),
37 (174, '-6'),
38 (175, '6/m'),
39 (177, '622'),
40 (183, '6mm'),
41 (187, '-6m2'),
42 (191, '6/m 2/m 2/m'),
43 (195, '23'),
44 (200, '2/m -3'),
45 (207, '432'),
46 (215, '-43m'),
47 (221, '4/m -3 2/m'),
48 (231, 'Ø')]
50_point_groups = ['Ø']
51for i, (start, pg) in enumerate(_point_group_ranges[:-1]):
52 next_start, _ = _point_group_ranges[i + 1]
53 count = next_start - start
54 for j in range(start, start + count):
55 _point_groups.append(pg)
58def validate_space_group(sg):
59 sg = int(sg)
60 if sg < 1:
61 raise ValueError(f'Spacegroup must be positive, but is {sg}')
62 if sg > 230:
63 raise ValueError('Bad spacegroup', sg)
64 return sg
67def get_bravais_class(sg):
68 sg = validate_space_group(sg)
69 pearson_symbol = _crystal_family[sg] + _lattice_centering[sg]
70 return bravais_classes[pearson_symbol]
73def get_point_group(sg):
74 sg = validate_space_group(sg)
75 return _point_groups[sg]
78def polar_space_group(sg):
79 sg = validate_space_group(sg)
80 pg = get_point_group(sg)
81 return pg in ['1', '2', 'm', 'mm2', '4', '4mm', '3', '3m', '6', '6mm']