Coverage for ase/cluster/octahedron.py: 82.35%

17 statements  

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

1""" 

2Function-like objects that creates cubic clusters. 

3""" 

4 

5import numpy as np 

6 

7from ase.cluster.compounds import L1_2 

8from ase.cluster.cubic import FaceCenteredCubic 

9 

10 

11def Octahedron(symbol, length, cutoff=0, latticeconstant=None, alloy=False): 

12 """ 

13 Returns Face Centered Cubic clusters of the octahedral class depending 

14 on the choice of cutoff. 

15 

16 ============================ ======================= 

17 Type Condition 

18 ============================ ======================= 

19 Regular octahedron cutoff = 0 

20 Truncated octahedron cutoff > 0 

21 Regular truncated octahedron length = 3 * cutoff + 1 

22 Cuboctahedron length = 2 * cutoff + 1 

23 ============================ ======================= 

24 

25 

26 Parameters 

27 ---------- 

28 symbol : str or list 

29 The chemical symbol or atomic number of the element(s). 

30 

31 length : int 

32 Number of atoms on the square edges of the complete octahedron. 

33 

34 cutoff : int, default 0 

35 Number of layers cut at each vertex. 

36 

37 latticeconstant : float, optional 

38 The lattice constant. If not given, then it is extracted from 

39 `ase.data`. 

40 

41 alloy : bool, default False 

42 If True the L1_2 structure is used. 

43 

44 """ 

45 

46 # Check length and cutoff 

47 if length < 1: 

48 raise ValueError('The length must be at least one.') 

49 

50 if cutoff < 0 or length < 2 * cutoff + 1: 

51 raise ValueError( 

52 'The cutoff must fulfill: > 0 and <= (length - 1) / 2.' 

53 ) 

54 

55 # Create cluster 

56 surfaces = [(1, 1, 1), (1, 0, 0)] 

57 if length % 2 == 0: 

58 center = np.array([0.5, 0.5, 0.5]) 

59 layers = [length / 2, length - 1 - cutoff] 

60 else: 

61 center = np.array([0.0, 0.0, 0.0]) 

62 layers = [(length - 1) / 2, length - 1 - cutoff] 

63 

64 if not alloy: 

65 return FaceCenteredCubic( 

66 symbol, surfaces, layers, latticeconstant, center 

67 ) 

68 else: 

69 return L1_2(symbol, surfaces, layers, latticeconstant, center)