Coverage for ase/spacegroup/crystal_data.py: 100.00%

28 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-11-27 15:21 +0000

1from ase.lattice import bravais_classes 

2 

3_crystal_family = ( 

4 'Øaammmmmmmmmmmmmoooooooooooooooooooooooooooooooooooooooooo' 

5 'ooooooooooooooooottttttttttttttttttttttttttttttttttttttttt' 

6 'ttttttttttttttttttttttttttthhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh' 

7 'hhhhhhhhhhhhhhhhhhhhhcccccccccccccccccccccccccccccccccccc' 

8) 

9 

10_lattice_centering = ( 

11 'ØPPPPCPPCCPPCPPCPPPPCCFIIPPPPPPPPPPCCCCCCCFFIIIPPPPPPPP' 

12 'PPPPPPPPCCCCCCFFIIIIPPPPIIPIPPPPIIPPPPPPPPIIPPPPPPPPII' 

13 'IIPPPPPPPPIIIIPPPPPPPPPPPPPPPPIIIIPPPRPRPPPPPPRPPPPRRP' 

14 'PPPRRPPPPPPPPPPPPPPPPPPPPPPPPPPPPFIPIPPFFIPIPPFFIPPIPF' 

15 'IPFIPPPPFFFFII' 

16) 

17 

18_point_group_ranges = [ 

19 (1, '1'), 

20 (2, '-1'), 

21 (3, '2'), 

22 (6, 'm'), 

23 (10, '2/m'), 

24 (16, '222'), 

25 (25, 'mm2'), 

26 (47, '2/m 2/m 2/m'), 

27 (75, '4'), 

28 (81, '-4'), 

29 (83, '4/m'), 

30 (89, '422'), 

31 (99, '4mm'), 

32 (111, '-42m'), 

33 (123, '4/m 2/m 2/m'), 

34 (143, '3'), 

35 (147, '-3'), 

36 (149, '32'), 

37 (156, '3m'), 

38 (162, '-3 2/m'), 

39 (168, '6'), 

40 (174, '-6'), 

41 (175, '6/m'), 

42 (177, '622'), 

43 (183, '6mm'), 

44 (187, '-6m2'), 

45 (191, '6/m 2/m 2/m'), 

46 (195, '23'), 

47 (200, '2/m -3'), 

48 (207, '432'), 

49 (215, '-43m'), 

50 (221, '4/m -3 2/m'), 

51 (231, 'Ø'), 

52] 

53 

54_point_groups = ['Ø'] 

55for i, (start, pg) in enumerate(_point_group_ranges[:-1]): 

56 next_start, _ = _point_group_ranges[i + 1] 

57 count = next_start - start 

58 for j in range(start, start + count): 

59 _point_groups.append(pg) 

60 

61 

62def validate_space_group(sg): 

63 sg = int(sg) 

64 if sg < 1: 

65 raise ValueError(f'Spacegroup must be positive, but is {sg}') 

66 if sg > 230: 

67 raise ValueError('Bad spacegroup', sg) 

68 return sg 

69 

70 

71def get_bravais_class(sg): 

72 sg = validate_space_group(sg) 

73 pearson_symbol = _crystal_family[sg] + _lattice_centering[sg] 

74 return bravais_classes[pearson_symbol] 

75 

76 

77def get_point_group(sg): 

78 sg = validate_space_group(sg) 

79 return _point_groups[sg] 

80 

81 

82def polar_space_group(sg): 

83 sg = validate_space_group(sg) 

84 pg = get_point_group(sg) 

85 return pg in ['1', '2', 'm', 'mm2', '4', '4mm', '3', '3m', '6', '6mm']