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

17 statements  

« prev     ^ index     » next       coverage.py v7.5.3, created at 2025-08-02 00:12 +0000

1# fmt: off 

2 

3""" 

4Function-like objects that creates cubic clusters. 

5""" 

6 

7import numpy as np 

8 

9from ase.cluster.compounds import L1_2 

10from ase.cluster.cubic import FaceCenteredCubic 

11 

12 

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

14 """ 

15 Returns Face Centered Cubic clusters of the octahedral class depending 

16 on the choice of cutoff. 

17 

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

19 Type Condition 

20 ============================ ======================= 

21 Regular octahedron cutoff = 0 

22 Truncated octahedron cutoff > 0 

23 Regular truncated octahedron length = 3 * cutoff + 1 

24 Cuboctahedron length = 2 * cutoff + 1 

25 ============================ ======================= 

26 

27 

28 Parameters 

29 ---------- 

30 symbol : str or list 

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

32 

33 length : int 

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

35 

36 cutoff : int, default 0 

37 Number of layers cut at each vertex. 

38 

39 latticeconstant : float, optional 

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

41 `ase.data`. 

42 

43 alloy : bool, default False 

44 If True the L1_2 structure is used. 

45 

46 """ 

47 

48 # Check length and cutoff 

49 if length < 1: 

50 raise ValueError("The length must be at least one.") 

51 

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

53 raise ValueError( 

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

55 

56 # Create cluster 

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

58 if length % 2 == 0: 

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

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

61 else: 

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

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

64 

65 if not alloy: 

66 return FaceCenteredCubic( 

67 symbol, surfaces, layers, latticeconstant, center) 

68 else: 

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