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

28 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-12-10 11:04 +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(f"Cannot guess the {self.xtal_name} " + 

21 "lattice constant of an element with crystal " + 

22 f"structure {symmetry}.") 

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

24 

25 def set_basis(self): 

26 a = self.lattice_constant 

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

28 raise ValueError( 

29 f"Improper lattice constant for {self.xtal_name} crystal.") 

30 

31 self.lattice_basis = np.array([[a, 0., 0.], 

32 [0., a, 0.], 

33 [0., 0., a]]) 

34 

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

36 

37 

38SimpleCubic = SimpleCubicFactory() 

39 

40 

41class BodyCenteredCubicFactory(SimpleCubicFactory): 

42 spacegroup = 229 

43 

44 xtal_name = 'bcc' 

45 

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

47 [.5, .5, .5]]) 

48 

49 

50BodyCenteredCubic = BodyCenteredCubicFactory() 

51 

52 

53class FaceCenteredCubicFactory(SimpleCubicFactory): 

54 spacegroup = 225 

55 

56 xtal_name = 'fcc' 

57 

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

59 [0., .5, .5], 

60 [.5, 0., .5], 

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

62 

63 

64FaceCenteredCubic = FaceCenteredCubicFactory()