Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"""Function-like object creating triclinic lattices. 

2 

3The following lattice creator is defined: 

4 Triclinic 

5""" 

6 

7from ase.lattice.bravais import Bravais 

8import numpy as np 

9from ase.data import reference_states as _refstate 

10 

11 

12class TriclinicFactory(Bravais): 

13 "A factory for creating triclinic lattices." 

14 

15 # The name of the crystal structure in ChemicalElements 

16 xtal_name = "triclinic" 

17 

18 # The natural basis vectors of the crystal structure 

19 int_basis = np.array([[1, 0, 0], 

20 [0, 1, 0], 

21 [0, 0, 1]]) 

22 basis_factor = 1.0 

23 

24 # Converts the natural basis back to the crystallographic basis 

25 inverse_basis = np.array([[1, 0, 0], 

26 [0, 1, 0], 

27 [0, 0, 1]]) 

28 inverse_basis_factor = 1.0 

29 

30 def get_lattice_constant(self): 

31 """Get the lattice constant of an element with triclinic 

32 crystal structure.""" 

33 if _refstate[self.atomicnumber]['symmetry'] != self.xtal_name: 

34 raise ValueError(('Cannot guess the %s lattice constant of' 

35 + ' an element with crystal structure %s.') 

36 % (self.xtal_name, 

37 _refstate[self.atomicnumber]['symmetry'])) 

38 return _refstate[self.atomicnumber].copy() 

39 

40 def make_crystal_basis(self): 

41 """Make the basis matrix for the crystal unit cell and the system 

42 unit cell.""" 

43 lattice = self.latticeconstant 

44 if isinstance(lattice, type({})): 

45 a = lattice['a'] 

46 try: 

47 b = lattice['b'] 

48 except KeyError: 

49 b = a * lattice['b/a'] 

50 try: 

51 c = lattice['c'] 

52 except KeyError: 

53 c = a * lattice['c/a'] 

54 alpha = lattice['alpha'] 

55 beta = lattice['beta'] 

56 gamma = lattice['gamma'] 

57 else: 

58 if len(lattice) == 6: 

59 (a, b, c, alpha, beta, gamma) = lattice 

60 else: 

61 raise ValueError( 

62 "Improper lattice constants for triclinic crystal.") 

63 

64 degree = np.pi / 180.0 

65 cosa = np.cos(alpha * degree) 

66 cosb = np.cos(beta * degree) 

67 sinb = np.sin(beta * degree) 

68 cosg = np.cos(gamma * degree) 

69 sing = np.sin(gamma * degree) 

70 lattice = np.array( 

71 [[a, 0, 0], 

72 [b * cosg, b * sing, 0], 

73 [c * cosb, c * (cosa - cosb * cosg) / sing, 

74 c * np.sqrt(sinb**2 - ((cosa - cosb * cosg) / sing)**2)]]) 

75 self.latticeconstant = lattice 

76 self.miller_basis = lattice 

77 self.crystal_basis = (self.basis_factor * 

78 np.dot(self.int_basis, lattice)) 

79 self.basis = np.dot(self.directions, self.crystal_basis) 

80 assert abs(np.dot(lattice[0], lattice[1]) - a * b * cosg) < 1e-5 

81 assert abs(np.dot(lattice[0], lattice[2]) - a * c * cosb) < 1e-5 

82 assert abs(np.dot(lattice[1], lattice[2]) - b * c * cosa) < 1e-5 

83 assert abs(np.dot(lattice[0], lattice[0]) - a * a) < 1e-5 

84 assert abs(np.dot(lattice[1], lattice[1]) - b * b) < 1e-5 

85 assert abs(np.dot(lattice[2], lattice[2]) - c * c) < 1e-5 

86 

87 

88Triclinic = TriclinicFactory()