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 objects creating orthorhombic lattices. 

2 

3The following lattice creators are defined: 

4 SimleOrthorhombic 

5 BaseCenteredOrthorhombic 

6 BodyCenteredOrthorhombic 

7 FaceCenteredOrthorhombic 

8""" 

9 

10from ase.lattice.bravais import Bravais 

11import numpy as np 

12from ase.data import reference_states as _refstate 

13 

14 

15class SimpleOrthorhombicFactory(Bravais): 

16 "A factory for creating simple orthorhombic lattices." 

17 

18 # The name of the crystal structure in ChemicalElements 

19 xtal_name = "orthorhombic" 

20 

21 # The natural basis vectors of the crystal structure 

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

23 [0, 1, 0], 

24 [0, 0, 1]]) 

25 basis_factor = 1.0 

26 

27 # Converts the natural basis back to the crystallographic basis 

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

29 [0, 1, 0], 

30 [0, 0, 1]]) 

31 inverse_basis_factor = 1.0 

32 

33 def get_lattice_constant(self): 

34 "Get the lattice constant of an element with orhtorhombic crystal structure." 

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

36 raise ValueError(("Cannot guess the %s lattice constant of" 

37 + " an element with crystal structure %s.") 

38 % (self.xtal_name, 

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

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

41 

42 def make_crystal_basis(self): 

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

44 lattice = self.latticeconstant 

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

46 a = lattice['a'] 

47 try: 

48 b = lattice['b'] 

49 except KeyError: 

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

51 try: 

52 c = lattice['c'] 

53 except KeyError: 

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

55 else: 

56 if len(lattice) == 3: 

57 (a, b, c) = lattice 

58 else: 

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

60 

61 lattice = np.array([[a, 0, 0], [0, b, 0], [0, 0, c]]) 

62 self.latticeconstant = lattice 

63 self.miller_basis = lattice 

64 self.crystal_basis = (self.basis_factor * 

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

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

67 self.check_basis_volume() 

68 

69 def check_basis_volume(self): 

70 "Check the volume of the unit cell." 

71 vol1 = abs(np.linalg.det(self.basis)) 

72 vol2 = self.calc_num_atoms() * np.linalg.det(self.latticeconstant) 

73 if self.bravais_basis is not None: 

74 vol2 /= len(self.bravais_basis) 

75 if abs(vol1-vol2) > 1e-5: 

76 print("WARNING: Got volume %f, expected %f" % (vol1, vol2)) 

77 

78 

79SimpleOrthorhombic = SimpleOrthorhombicFactory() 

80 

81 

82class BaseCenteredOrthorhombicFactory(SimpleOrthorhombicFactory): 

83 "A factory for creating base-centered orthorhombic lattices." 

84 

85 # The natural basis vectors of the crystal structure 

86 int_basis = np.array([[1, -1, 0], 

87 [1, 1, 0], 

88 [0, 0, 2]]) 

89 basis_factor = 0.5 

90 

91 # Converts the natural basis back to the crystallographic basis 

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

93 [-1, 1, 0], 

94 [0, 0, 1]]) 

95 inverse_basis_factor = 1.0 

96 

97 def check_basis_volume(self): 

98 "Check the volume of the unit cell." 

99 vol1 = abs(np.linalg.det(self.basis)) 

100 vol2 = self.calc_num_atoms() * np.linalg.det(self.latticeconstant) / 2.0 

101 if abs(vol1-vol2) > 1e-5: 

102 print("WARNING: Got volume %f, expected %f" % (vol1, vol2)) 

103 

104 

105BaseCenteredOrthorhombic = BaseCenteredOrthorhombicFactory() 

106 

107 

108class BodyCenteredOrthorhombicFactory(SimpleOrthorhombicFactory): 

109 "A factory for creating body-centered orthorhombic lattices." 

110 

111 int_basis = np.array([[-1, 1, 1], 

112 [1, -1, 1], 

113 [1, 1, -1]]) 

114 basis_factor = 0.5 

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

116 [1, 0, 1], 

117 [1, 1, 0]]) 

118 inverse_basis_factor = 1.0 

119 

120 def check_basis_volume(self): 

121 "Check the volume of the unit cell." 

122 vol1 = abs(np.linalg.det(self.basis)) 

123 vol2 = self.calc_num_atoms() * np.linalg.det(self.latticeconstant) / 2.0 

124 if abs(vol1-vol2) > 1e-5: 

125 print("WARNING: Got volume %f, expected %f" % (vol1, vol2)) 

126 

127 

128BodyCenteredOrthorhombic = BodyCenteredOrthorhombicFactory() 

129 

130 

131class FaceCenteredOrthorhombicFactory(SimpleOrthorhombicFactory): 

132 "A factory for creating face-centered orthorhombic lattices." 

133 

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

135 [1, 0, 1], 

136 [1, 1, 0]]) 

137 basis_factor = 0.5 

138 inverse_basis = np.array([[-1, 1, 1], 

139 [1, -1, 1], 

140 [1, 1, -1]]) 

141 inverse_basis_factor = 1.0 

142 

143 def check_basis_volume(self): 

144 "Check the volume of the unit cell." 

145 vol1 = abs(np.linalg.det(self.basis)) 

146 vol2 = self.calc_num_atoms() * np.linalg.det(self.latticeconstant) / 4.0 

147 if abs(vol1-vol2) > 1e-5: 

148 print("WARNING: Got volume %f, expected %f" % (vol1, vol2)) 

149 

150 

151FaceCenteredOrthorhombic = FaceCenteredOrthorhombicFactory()