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

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

10from ase.data import reference_states as _refstate 

11 

12 

13class SimpleCubicFactory(ClusterFactory): 

14 spacegroup = 221 

15 

16 xtal_name = 'sc' 

17 

18 def get_lattice_constant(self): 

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

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

21 if symmetry != self.xtal_name: 

22 raise ValueError(f"Cannot guess the {self.xtal_name} " + 

23 "lattice constant of an element with crystal " + 

24 f"structure {symmetry}.") 

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 self.lattice_basis = np.array([[a, 0., 0.], 

34 [0., a, 0.], 

35 [0., 0., a]]) 

36 

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

38 

39 

40SimpleCubic = SimpleCubicFactory() 

41 

42 

43class BodyCenteredCubicFactory(SimpleCubicFactory): 

44 spacegroup = 229 

45 

46 xtal_name = 'bcc' 

47 

48 atomic_basis = np.array([[0., 0., 0.], 

49 [.5, .5, .5]]) 

50 

51 

52BodyCenteredCubic = BodyCenteredCubicFactory() 

53 

54 

55class FaceCenteredCubicFactory(SimpleCubicFactory): 

56 spacegroup = 225 

57 

58 xtal_name = 'fcc' 

59 

60 atomic_basis = np.array([[0., 0., 0.], 

61 [0., .5, .5], 

62 [.5, 0., .5], 

63 [.5, .5, 0.]]) 

64 

65 

66FaceCenteredCubic = FaceCenteredCubicFactory()