Coverage for ase/cluster/cubic.py: 92.86%

28 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.factory import ClusterFactory 

8from ase.data import reference_states as _refstate 

9 

10 

11class SimpleCubicFactory(ClusterFactory): 

12 spacegroup = 221 

13 

14 xtal_name = 'sc' 

15 

16 def get_lattice_constant(self): 

17 "Get the lattice constant of an element with cubic crystal structure." 

18 symmetry = _refstate[self.atomic_numbers[0]]['symmetry'] 

19 if symmetry != self.xtal_name: 

20 raise ValueError( 

21 f'Cannot guess the {self.xtal_name} ' 

22 + 'lattice constant of an element with crystal ' 

23 + f'structure {symmetry}.' 

24 ) 

25 return _refstate[self.atomic_numbers[0]]['a'] 

26 

27 def set_basis(self): 

28 a = self.lattice_constant 

29 if not isinstance(a, (int, float)): 

30 raise ValueError( 

31 f'Improper lattice constant for {self.xtal_name} crystal.' 

32 ) 

33 

34 self.lattice_basis = np.array( 

35 [[a, 0.0, 0.0], [0.0, a, 0.0], [0.0, 0.0, a]] 

36 ) 

37 

38 self.resiproc_basis = self.get_resiproc_basis(self.lattice_basis) 

39 

40 

41SimpleCubic = SimpleCubicFactory() 

42 

43 

44class BodyCenteredCubicFactory(SimpleCubicFactory): 

45 spacegroup = 229 

46 

47 xtal_name = 'bcc' 

48 

49 atomic_basis = np.array([[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]]) 

50 

51 

52BodyCenteredCubic = BodyCenteredCubicFactory() 

53 

54 

55class FaceCenteredCubicFactory(SimpleCubicFactory): 

56 """ 

57 Class to create FCC atom clusters. 

58 

59 Examples 

60 -------- 

61 

62 This example sets up a nanoparticle of copper in the FCC crystal structure, 

63 by specifying 6 layers in the (100) directions, 9 in the (110) directions 

64 and 5 in the (111) directions:: 

65 

66 >>> from ase.cluster.cubic import FaceCenteredCubic 

67 

68 >>> surfaces = [(1, 0, 0), (1, 1, 0), (1, 1, 1)] 

69 >>> layers = [6, 9, 5] 

70 >>> lc = 3.61000 

71 >>> atoms = FaceCenteredCubic('Cu', surfaces, layers, latticeconstant=lc) 

72 """ 

73 

74 spacegroup = 225 

75 

76 xtal_name = 'fcc' 

77 

78 atomic_basis = np.array( 

79 [[0.0, 0.0, 0.0], [0.0, 0.5, 0.5], [0.5, 0.0, 0.5], [0.5, 0.5, 0.0]] 

80 ) 

81 

82 

83FaceCenteredCubic = FaceCenteredCubicFactory()