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 crystal structure." 

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

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

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

35 % (self.xtal_name, 

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

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

38 

39 def make_crystal_basis(self): 

40 "Make the basis matrix for the crystal unit cell and the system unit cell." 

41 lattice = self.latticeconstant 

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

43 a = lattice['a'] 

44 try: 

45 b = lattice['b'] 

46 except KeyError: 

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

48 try: 

49 c = lattice['c'] 

50 except KeyError: 

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

52 alpha = lattice['alpha'] 

53 beta = lattice['beta'] 

54 gamma = lattice['gamma'] 

55 else: 

56 if len(lattice) == 6: 

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

58 else: 

59 raise ValueError("Improper lattice constants for triclinic crystal.") 

60 

61 degree = np.pi / 180.0 

62 cosa = np.cos(alpha*degree) 

63 cosb = np.cos(beta*degree) 

64 sinb = np.sin(beta*degree) 

65 cosg = np.cos(gamma*degree) 

66 sing = np.sin(gamma*degree) 

67 lattice = np.array([[a, 0, 0], 

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

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

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

71 self.latticeconstant = lattice 

72 self.miller_basis = lattice 

73 self.crystal_basis = (self.basis_factor * 

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

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

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

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

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

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

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

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

82 

83 

84Triclinic = TriclinicFactory()