crystalcell 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,292 +4,308 @@ require "helper"
4
4
  require "rubygems"
5
5
 
6
6
  class CrystalCell::LatticeAxes
7
- #public :triangulate, :rotate
8
- #public :rotate
7
+ #public :triangulate, :rotate
8
+ #public :rotate
9
9
  end
10
10
 
11
11
  class TC_LatticeAxes < Test::Unit::TestCase
12
- $tolerance = 10 ** (-10)
13
-
14
- include Math
15
-
16
- def setup
17
- @axes1 = [ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0] ]
18
-
19
- @lc1 = CrystalCell::LatticeAxes.new([ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0] ])
20
- @lc2 = CrystalCell::LatticeAxes.new([ [0.5, 0.5, 0.0], [0.5, 0.0, 0.5], [0.0, 0.5, 0.5] ])
21
- @lc3 = CrystalCell::LatticeAxes.new(CrystalCell::LatticeAxes.lc_to_axes([1.0, 1.0, 1.0, 90.0, 90.0, 90.0]))
22
- @lc4 = CrystalCell::LatticeAxes.new(
23
- CrystalCell::LatticeAxes.lc_to_axes(
24
- [ Math::sqrt(0.5), Math::sqrt(0.5), Math::sqrt(0.5),
25
- 60.0, 60.0, 60.0]) # Math::sqrt(0.5) == 0.5* Math::sqrt(2.0)
26
- )
27
- @lc5 = CrystalCell::LatticeAxes.new([ [1.0, 1.0, 1.0], [0.0, 1.0, 1.0], [0.0, 0.0, 1.0] ])
28
- @lc6 = CrystalCell::LatticeAxes.new([ [1.0, 1.0, 1.0], [0.0,-1.0,-1.0], [0.0, 0.0, 1.0] ])
29
-
30
- @vec_x = Mageo::Vector3D[ 1.0, 0.0, 0.0 ]
31
- @vec_y = Mageo::Vector3D[ 0.0, 1.0, 0.0 ]
32
- @vec_z = Mageo::Vector3D[ 0.0, 0.0, 1.0 ]
33
- @vec_0 = Mageo::Vector3D[ 0.0, 0.0, 0.0 ]
34
- @vec_1 = Mageo::Vector3D[ 1.0, 1.0, 0.0 ]
35
- end
36
-
37
- def test_initialize
38
- assert_raise(ArgumentError) { CrystalCell::LatticeAxes.new }
39
- assert_raise(CrystalCell::LatticeAxes::InitializeError) { CrystalCell::LatticeAxes.new([]) }
40
- assert_raise(CrystalCell::LatticeAxes::InitializeError) {
41
- CrystalCell::LatticeAxes.new([1.0, 1.0, 1.0, 90.0, 90.0, 90.0])
42
- }
43
-
44
- assert_raise(CrystalCell::LatticeAxes::InitializeError) {CrystalCell::LatticeAxes.new([0,1])}
45
- assert_raise(CrystalCell::LatticeAxes::InitializeError) {CrystalCell::LatticeAxes.new([0,1,2,3])}
46
- assert_nothing_raised {CrystalCell::LatticeAxes.new([ @vec_x, @vec_y, @vec_z ]) }
47
- assert_raise(CrystalCell::LatticeAxes::InitializeError) {CrystalCell::LatticeAxes.new([ @vec_x, @vec_y, @vec_0 ]) }
48
- assert_raise(CrystalCell::LatticeAxes::InitializeError) {CrystalCell::LatticeAxes.new([ @vec_x, @vec_y, [1, 2, 3, 4] ]) }
49
-
50
- assert_in_delta(1.0, @lc1.axes[0][0], $tolerance)
51
- assert_in_delta(0.0, @lc1.axes[0][1], $tolerance)
52
- assert_in_delta(0.0, @lc1.axes[0][2], $tolerance)
53
- assert_in_delta(0.0, @lc1.axes[1][0], $tolerance)
54
- assert_in_delta(1.0, @lc1.axes[1][1], $tolerance)
55
- assert_in_delta(0.0, @lc1.axes[1][2], $tolerance)
56
- assert_in_delta(0.0, @lc1.axes[2][0], $tolerance)
57
- assert_in_delta(0.0, @lc1.axes[2][1], $tolerance)
58
- assert_in_delta(1.0, @lc1.axes[2][2], $tolerance)
59
-
60
- assert_in_delta(- 0.577350269189626, @lc2.axes[0][0], $tolerance)
61
- assert_in_delta( 0.204124145231932, @lc2.axes[0][1], $tolerance)
62
- assert_in_delta( 0.353553390593274, @lc2.axes[0][2], $tolerance)
63
- assert_in_delta( 0.000000000000000, @lc2.axes[1][0], $tolerance)
64
- assert_in_delta( 0.612372435695795, @lc2.axes[1][1], $tolerance)
65
- assert_in_delta( 0.353553390593274, @lc2.axes[1][2], $tolerance)
66
- assert_in_delta( 0.000000000000000, @lc2.axes[2][0], $tolerance)
67
- assert_in_delta( 0.000000000000000, @lc2.axes[2][1], $tolerance)
68
- assert_in_delta( 0.707106781186548, @lc2.axes[2][2], $tolerance)
69
-
70
- assert_in_delta(1.0, @lc3.axes[0][0], $tolerance)
71
- assert_in_delta(0.0, @lc3.axes[0][1], $tolerance)
72
- assert_in_delta(0.0, @lc3.axes[0][2], $tolerance)
73
- assert_in_delta(0.0, @lc3.axes[1][0], $tolerance)
74
- assert_in_delta(1.0, @lc3.axes[1][1], $tolerance)
75
- assert_in_delta(0.0, @lc3.axes[1][2], $tolerance)
76
- assert_in_delta(0.0, @lc3.axes[2][0], $tolerance)
77
- assert_in_delta(0.0, @lc3.axes[2][1], $tolerance)
78
- assert_in_delta(1.0, @lc3.axes[2][2], $tolerance)
79
-
80
- assert_in_delta(0.577350269189626, @lc4.axes[0][0], $tolerance)
81
- assert_in_delta(0.204124145231932, @lc4.axes[0][1], $tolerance)
82
- assert_in_delta(0.353553390593274, @lc4.axes[0][2], $tolerance)
83
- assert_in_delta(0.000000000000000, @lc4.axes[1][0], $tolerance)
84
- assert_in_delta(0.612372435695795, @lc4.axes[1][1], $tolerance)
85
- assert_in_delta(0.353553390593274, @lc4.axes[1][2], $tolerance)
86
- assert_in_delta(0.000000000000000, @lc4.axes[2][0], $tolerance)
87
- assert_in_delta(0.000000000000000, @lc4.axes[2][1], $tolerance)
88
- assert_in_delta(0.707106781186548, @lc4.axes[2][2], $tolerance)
89
-
90
- # triangulate の結果、b 軸の y 成分は 正方向であるべき。
91
- assert_in_delta(-1.0, @lc6.axes[0][0], $tolerance)
92
- assert_in_delta(-1.0, @lc6.axes[0][1], $tolerance)
93
- assert_in_delta(1.0, @lc6.axes[0][2], $tolerance)
94
- assert_in_delta(0.0, @lc6.axes[1][0], $tolerance)
95
- assert_in_delta(1.0, @lc6.axes[1][1], $tolerance)
96
- assert_in_delta(-1.0, @lc6.axes[1][2], $tolerance)
97
- assert_in_delta(0.0, @lc6.axes[2][0], $tolerance)
98
- assert_in_delta(0.0, @lc6.axes[2][1], $tolerance)
99
- assert_in_delta(1.0, @lc6.axes[2][2], $tolerance)
100
- end
101
-
102
- ## Class methods.
103
- #
104
- def test_new_lc
105
- result = CrystalCell::LatticeAxes.new_lc([1.0, 1.0, 1.0, 90.0, 90.0, 90.0])
106
- assert_equal(@lc3, result)
107
- end
108
-
109
- #def test_self_triangulate
110
- # result = CrystalCell::LatticeAxes.triangulate([ [0.5, 0.5, 0.0], [0.0, 0.5, 0.5], [0.5, 0.0, 0.5] ])
111
- # assert_in_delta(0.577350269189626, result[0][0], $tolerance)
112
- # assert_in_delta(0.204124145231932, result[0][1], $tolerance)
113
- # assert_in_delta(0.353553390593274, result[0][2], $tolerance)
114
- # assert_in_delta(0.000000000000000, result[1][0], $tolerance)
115
- # assert_in_delta(0.612372435695795, result[1][1], $tolerance)
116
- # assert_in_delta(0.353553390593274, result[1][2], $tolerance)
117
- # assert_in_delta(0.000000000000000, result[2][0], $tolerance)
118
- # assert_in_delta(0.000000000000000, result[2][1], $tolerance)
119
- # assert_in_delta(0.707106781186548, result[2][2], $tolerance)
120
- #end
121
-
122
- def test_self_lc_to_axes
123
- axes = CrystalCell::LatticeAxes.lc_to_axes([ 1.0, 1.0, 1.0, 90.0, 90.0, 90.0 ])
124
- assert_in_delta(@axes1[0][0], axes[0][0], $tolerance)
125
- assert_in_delta(@axes1[0][1], axes[0][1], $tolerance)
126
- assert_in_delta(@axes1[0][2], axes[0][2], $tolerance)
127
- assert_in_delta(@axes1[1][0], axes[1][0], $tolerance)
128
- assert_in_delta(@axes1[1][1], axes[1][1], $tolerance)
129
- assert_in_delta(@axes1[1][2], axes[1][2], $tolerance)
130
- assert_in_delta(@axes1[2][0], axes[2][0], $tolerance)
131
- assert_in_delta(@axes1[2][1], axes[2][1], $tolerance)
132
- assert_in_delta(@axes1[2][2], axes[2][2], $tolerance)
133
-
134
- axes = CrystalCell::LatticeAxes.lc_to_axes([ 1.0, 1.0, 1.0, 90.0, 90.0, 90.0 ], false)
135
- assert_in_delta(- @axes1[0][0], axes[0][0], $tolerance)
136
- assert_in_delta( @axes1[0][1], axes[0][1], $tolerance)
137
- assert_in_delta( @axes1[0][2], axes[0][2], $tolerance)
138
- assert_in_delta( @axes1[1][0], axes[1][0], $tolerance)
139
- assert_in_delta( @axes1[1][1], axes[1][1], $tolerance)
140
- assert_in_delta( @axes1[1][2], axes[1][2], $tolerance)
141
- assert_in_delta( @axes1[2][0], axes[2][0], $tolerance)
142
- assert_in_delta( @axes1[2][1], axes[2][1], $tolerance)
143
- assert_in_delta( @axes1[2][2], axes[2][2], $tolerance)
144
- end
145
-
146
- def test_self_axes_to_lc
147
- correct = [ 1.0, 1.0, 1.0, 90.0, 90.0, 90.0 ]
148
- assert_equal(correct, CrystalCell::LatticeAxes.axes_to_lc(@axes1))
149
-
150
- #correct = [ 1.0, 1.0, 1.0, 90.0, 90.0, 90.0 ]
151
- #assert_equal(correct, CrystalCell::LatticeAxes.axes_to_lc(@axes1))
152
- end
153
-
154
- def test_equal_in_delta?
155
- assert_equal(true , @lc1.equal_in_delta?(@lc1, 0.01, 1.0))
156
- assert_equal(false, @lc1.equal_in_delta?(@lc2, 0.01, 1.0))
157
- assert_equal(false, @lc1.equal_in_delta?(@lc4, 0.01, 1.0))
158
- assert_equal(false, @lc2.equal_in_delta?(@lc1, 0.01, 1.0))
159
- assert_equal(true , @lc2.equal_in_delta?(@lc2, 0.01, 1.0))
160
- assert_equal(true , @lc2.equal_in_delta?(@lc4, 0.01, 1.0))
161
- assert_equal(false, @lc4.equal_in_delta?(@lc1, 0.01, 1.0))
162
- assert_equal(true , @lc4.equal_in_delta?(@lc2, 0.01, 1.0))
163
- assert_equal(true , @lc4.equal_in_delta?(@lc4, 0.01, 1.0))
164
- end
165
-
166
- def test_self_righthand?
167
- # Righthand
168
- assert_equal(true , CrystalCell::LatticeAxes.righthand?([ @vec_x, @vec_y, @vec_z ]))
169
- assert_equal(true , CrystalCell::LatticeAxes.righthand?([ @vec_y, @vec_z, @vec_x ]))
170
- assert_equal(true , CrystalCell::LatticeAxes.righthand?([ @vec_z, @vec_x, @vec_y ]))
171
-
172
- # Lefthand
173
- assert_equal(false, CrystalCell::LatticeAxes.righthand?([ @vec_z, @vec_y, @vec_x ]))
174
- assert_equal(false, CrystalCell::LatticeAxes.righthand?([ @vec_x, @vec_z, @vec_y ]))
175
- assert_equal(false, CrystalCell::LatticeAxes.righthand?([ @vec_y, @vec_x, @vec_z ]))
176
-
177
- # Including zero vector.
178
- assert_equal(false, CrystalCell::LatticeAxes.righthand?([ @vec_0, @vec_y, @vec_z ]))
179
- assert_equal(false, CrystalCell::LatticeAxes.righthand?([ @vec_0, @vec_z, @vec_x ]))
180
- assert_equal(false, CrystalCell::LatticeAxes.righthand?([ @vec_0, @vec_x, @vec_y ]))
181
-
182
- # One vector is on the plane of residual two vectors.
183
- assert_equal(false, CrystalCell::LatticeAxes.righthand?([ @vec_x, @vec_y, @vec_1 ]))
184
- end
185
-
186
- def test_self_lefthand?
187
- # Righthand
188
- assert_equal(false, CrystalCell::LatticeAxes.lefthand?([ @vec_x, @vec_y, @vec_z ]))
189
- assert_equal(false, CrystalCell::LatticeAxes.lefthand?([ @vec_y, @vec_z, @vec_x ]))
190
- assert_equal(false, CrystalCell::LatticeAxes.lefthand?([ @vec_z, @vec_x, @vec_y ]))
191
-
192
- # Lefthand
193
- assert_equal(true , CrystalCell::LatticeAxes.lefthand?([ @vec_z, @vec_y, @vec_x ]))
194
- assert_equal(true , CrystalCell::LatticeAxes.lefthand?([ @vec_x, @vec_z, @vec_y ]))
195
- assert_equal(true , CrystalCell::LatticeAxes.lefthand?([ @vec_y, @vec_x, @vec_z ]))
196
-
197
- # Including zero vector.
198
- assert_equal(false, CrystalCell::LatticeAxes.lefthand?([ @vec_0, @vec_y, @vec_z ]))
199
- assert_equal(false, CrystalCell::LatticeAxes.lefthand?([ @vec_0, @vec_z, @vec_x ]))
200
- assert_equal(false, CrystalCell::LatticeAxes.lefthand?([ @vec_0, @vec_x, @vec_y ]))
201
-
202
- # One vector is on the plane of residual two vectors.
203
- assert_equal(false, CrystalCell::LatticeAxes.lefthand?([ @vec_x, @vec_y, @vec_1 ]))
204
- end
205
-
206
- ## Instance methods.
207
-
208
- def test_get_lattice_constants
209
- assert_in_delta( 1.0, @lc1.get_lattice_constants[0], $tolerance)
210
- assert_in_delta( 1.0, @lc1.get_lattice_constants[1], $tolerance)
211
- assert_in_delta( 1.0, @lc1.get_lattice_constants[2], $tolerance)
212
- assert_in_delta(90.0, @lc1.get_lattice_constants[3], $tolerance)
213
- assert_in_delta(90.0, @lc1.get_lattice_constants[4], $tolerance)
214
- assert_in_delta(90.0, @lc1.get_lattice_constants[5], $tolerance)
215
- assert_in_delta(Math::sqrt(0.5), @lc2.get_lattice_constants[0], $tolerance)
216
- assert_in_delta(Math::sqrt(0.5), @lc2.get_lattice_constants[1], $tolerance)
217
- assert_in_delta(Math::sqrt(0.5), @lc2.get_lattice_constants[2], $tolerance)
218
- assert_in_delta(60.0, @lc2.get_lattice_constants[3], $tolerance)
219
- assert_in_delta(60.0, @lc2.get_lattice_constants[4], $tolerance)
220
- assert_in_delta(60.0, @lc2.get_lattice_constants[5], $tolerance)
221
- assert_in_delta( 1.0, @lc3.get_lattice_constants[0], $tolerance)
222
- assert_in_delta( 1.0, @lc3.get_lattice_constants[1], $tolerance)
223
- assert_in_delta( 1.0, @lc3.get_lattice_constants[2], $tolerance)
224
- assert_in_delta(90.0, @lc3.get_lattice_constants[3], $tolerance)
225
- assert_in_delta(90.0, @lc3.get_lattice_constants[4], $tolerance)
226
- assert_in_delta(90.0, @lc3.get_lattice_constants[5], $tolerance)
227
- assert_in_delta(Math::sqrt(0.5), @lc4.get_lattice_constants[0], $tolerance)
228
- assert_in_delta(Math::sqrt(0.5), @lc4.get_lattice_constants[1], $tolerance)
229
- assert_in_delta(Math::sqrt(0.5), @lc4.get_lattice_constants[2], $tolerance)
230
- assert_in_delta(60.0, @lc4.get_lattice_constants[3], $tolerance)
231
- assert_in_delta(60.0, @lc4.get_lattice_constants[4], $tolerance)
232
- assert_in_delta(60.0, @lc4.get_lattice_constants[5], $tolerance)
233
- end
234
-
235
- def test_righthand?
236
- assert_equal(true , @lc1.righthand?)
237
- assert_equal(false, @lc2.righthand?)
238
- end
239
-
240
- def test_lefthand?
241
- assert_equal(false, @lc1.lefthand?)
242
- assert_equal(true , @lc2.lefthand?)
243
- end
244
-
245
- #def test_internal2cartesian
246
- # assert_raise(CrystalCell::LatticeAxes::TypeError){
247
- # @lc5.internal2cartesian([ 2.0, 3.0, 4.0 ])
248
- # }
249
- # assert_in_delta(2.0, @lc5.internal2cartesian([ 2.0, 3.0, 4.0 ])[0], $tolerance)
250
- # assert_in_delta(5.0, @lc5.internal2cartesian([ 2.0, 3.0, 4.0 ])[1], $tolerance)
251
- # assert_in_delta(9.0, @lc5.internal2cartesian([ 2.0, 3.0, 4.0 ])[2], $tolerance)
252
- #end
253
-
254
- #def test_cartesian2internal
255
- # assert_in_delta(2.0, @lc5.cartesian2internal([ 2.0, 5.0, 9.0 ])[0], $tolerance)
256
- # assert_in_delta(3.0, @lc5.cartesian2internal([ 2.0, 5.0, 9.0 ])[1], $tolerance)
257
- # assert_in_delta(4.0, @lc5.cartesian2internal([ 2.0, 5.0, 9.0 ])[2], $tolerance)
258
- #end
259
-
260
- def test_equal
261
- assert_equal(true , @lc1 == @lc1)
262
- assert_equal(true , @lc2 == @lc2)
263
- assert_equal(true , @lc3 == @lc3)
264
-
265
- assert_equal(false, @lc1 == @lc2)
266
- assert_equal(false, @lc2 == @lc3)
267
- assert_equal(true , @lc3 == @lc1)
268
-
269
- assert_equal(true , @lc1 == @lc3)
270
- assert_equal(false, @lc2 == @lc1)
271
- assert_equal(false, @lc3 == @lc2)
272
- end
273
-
274
- def test_triangulate
275
- t = CrystalCell::LatticeAxes.new([ [0.5, 0.5, 0.0], [0.0, 0.5, 0.5], [0.5, 0.0, 0.5] ])
276
- assert_in_delta(0.577350269189626, t[0][0], $tolerance)
277
- assert_in_delta(0.204124145231932, t[0][1], $tolerance)
278
- assert_in_delta(0.353553390593274, t[0][2], $tolerance)
279
- assert_in_delta(0.000000000000000, t[1][0], $tolerance)
280
- assert_in_delta(0.612372435695795, t[1][1], $tolerance)
281
- assert_in_delta(0.353553390593274, t[1][2], $tolerance)
282
- assert_in_delta(0.000000000000000, t[2][0], $tolerance)
283
- assert_in_delta(0.000000000000000, t[2][1], $tolerance)
284
- assert_in_delta(0.707106781186548, t[2][2], $tolerance)
285
- end
286
-
287
- #def test_rotate
288
- # #@lc1 = CrystalCell::LatticeAxes.new([ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0] ])
289
- # @lc1.rotate(0, 1, 2)
290
- #
291
- # TODO
292
- #end
12
+ $tolerance = 10 ** (-10)
13
+
14
+ include Math
15
+
16
+ def setup
17
+ @axes1 = [ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0] ]
18
+
19
+ @lc1 = CrystalCell::LatticeAxes.new([ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0] ])
20
+ @lc2 = CrystalCell::LatticeAxes.new([ [0.5, 0.5, 0.0], [0.5, 0.0, 0.5], [0.0, 0.5, 0.5] ])
21
+ @lc3 = CrystalCell::LatticeAxes.new(CrystalCell::LatticeAxes.lc_to_axes([1.0, 1.0, 1.0, 90.0, 90.0, 90.0]))
22
+ @lc4 = CrystalCell::LatticeAxes.new(
23
+ CrystalCell::LatticeAxes.lc_to_axes(
24
+ [ Math::sqrt(0.5), Math::sqrt(0.5), Math::sqrt(0.5),
25
+ 60.0, 60.0, 60.0]) # Math::sqrt(0.5) == 0.5* Math::sqrt(2.0)
26
+ )
27
+ @lc5 = CrystalCell::LatticeAxes.new([ [1.0, 1.0, 1.0], [0.0, 1.0, 1.0], [0.0, 0.0, 1.0] ])
28
+ @lc6 = CrystalCell::LatticeAxes.new([ [1.0, 1.0, 1.0], [0.0,-1.0,-1.0], [0.0, 0.0, 1.0] ])
29
+
30
+ @vec_x = Mageo::Vector3D[ 1.0, 0.0, 0.0 ]
31
+ @vec_y = Mageo::Vector3D[ 0.0, 1.0, 0.0 ]
32
+ @vec_z = Mageo::Vector3D[ 0.0, 0.0, 1.0 ]
33
+ @vec_0 = Mageo::Vector3D[ 0.0, 0.0, 0.0 ]
34
+ @vec_1 = Mageo::Vector3D[ 1.0, 1.0, 0.0 ]
35
+ end
36
+
37
+ def test_initialize
38
+ assert_raise(ArgumentError) { CrystalCell::LatticeAxes.new }
39
+ assert_raise(CrystalCell::LatticeAxes::InitializeError) { CrystalCell::LatticeAxes.new([]) }
40
+ assert_raise(CrystalCell::LatticeAxes::InitializeError) {
41
+ CrystalCell::LatticeAxes.new([1.0, 1.0, 1.0, 90.0, 90.0, 90.0])
42
+ }
43
+
44
+ assert_raise(CrystalCell::LatticeAxes::InitializeError) {CrystalCell::LatticeAxes.new([0,1])}
45
+ assert_raise(CrystalCell::LatticeAxes::InitializeError) {CrystalCell::LatticeAxes.new([0,1,2,3])}
46
+ assert_nothing_raised {CrystalCell::LatticeAxes.new([ @vec_x, @vec_y, @vec_z ]) }
47
+ assert_raise(CrystalCell::LatticeAxes::InitializeError) {CrystalCell::LatticeAxes.new([ @vec_x, @vec_y, @vec_0 ]) }
48
+ assert_raise(CrystalCell::LatticeAxes::InitializeError) {CrystalCell::LatticeAxes.new([ @vec_x, @vec_y, [1, 2, 3, 4] ]) }
49
+
50
+ assert_in_delta(1.0, @lc1.axes[0][0], $tolerance)
51
+ assert_in_delta(0.0, @lc1.axes[0][1], $tolerance)
52
+ assert_in_delta(0.0, @lc1.axes[0][2], $tolerance)
53
+ assert_in_delta(0.0, @lc1.axes[1][0], $tolerance)
54
+ assert_in_delta(1.0, @lc1.axes[1][1], $tolerance)
55
+ assert_in_delta(0.0, @lc1.axes[1][2], $tolerance)
56
+ assert_in_delta(0.0, @lc1.axes[2][0], $tolerance)
57
+ assert_in_delta(0.0, @lc1.axes[2][1], $tolerance)
58
+ assert_in_delta(1.0, @lc1.axes[2][2], $tolerance)
59
+
60
+ assert_in_delta(- 0.577350269189626, @lc2.axes[0][0], $tolerance)
61
+ assert_in_delta( 0.204124145231932, @lc2.axes[0][1], $tolerance)
62
+ assert_in_delta( 0.353553390593274, @lc2.axes[0][2], $tolerance)
63
+ assert_in_delta( 0.000000000000000, @lc2.axes[1][0], $tolerance)
64
+ assert_in_delta( 0.612372435695795, @lc2.axes[1][1], $tolerance)
65
+ assert_in_delta( 0.353553390593274, @lc2.axes[1][2], $tolerance)
66
+ assert_in_delta( 0.000000000000000, @lc2.axes[2][0], $tolerance)
67
+ assert_in_delta( 0.000000000000000, @lc2.axes[2][1], $tolerance)
68
+ assert_in_delta( 0.707106781186548, @lc2.axes[2][2], $tolerance)
69
+
70
+ assert_in_delta(1.0, @lc3.axes[0][0], $tolerance)
71
+ assert_in_delta(0.0, @lc3.axes[0][1], $tolerance)
72
+ assert_in_delta(0.0, @lc3.axes[0][2], $tolerance)
73
+ assert_in_delta(0.0, @lc3.axes[1][0], $tolerance)
74
+ assert_in_delta(1.0, @lc3.axes[1][1], $tolerance)
75
+ assert_in_delta(0.0, @lc3.axes[1][2], $tolerance)
76
+ assert_in_delta(0.0, @lc3.axes[2][0], $tolerance)
77
+ assert_in_delta(0.0, @lc3.axes[2][1], $tolerance)
78
+ assert_in_delta(1.0, @lc3.axes[2][2], $tolerance)
79
+
80
+ assert_in_delta(0.577350269189626, @lc4.axes[0][0], $tolerance)
81
+ assert_in_delta(0.204124145231932, @lc4.axes[0][1], $tolerance)
82
+ assert_in_delta(0.353553390593274, @lc4.axes[0][2], $tolerance)
83
+ assert_in_delta(0.000000000000000, @lc4.axes[1][0], $tolerance)
84
+ assert_in_delta(0.612372435695795, @lc4.axes[1][1], $tolerance)
85
+ assert_in_delta(0.353553390593274, @lc4.axes[1][2], $tolerance)
86
+ assert_in_delta(0.000000000000000, @lc4.axes[2][0], $tolerance)
87
+ assert_in_delta(0.000000000000000, @lc4.axes[2][1], $tolerance)
88
+ assert_in_delta(0.707106781186548, @lc4.axes[2][2], $tolerance)
89
+
90
+ # triangulate の結果、b 軸の y 成分は 正方向であるべき。
91
+ assert_in_delta(-1.0, @lc6.axes[0][0], $tolerance)
92
+ assert_in_delta(-1.0, @lc6.axes[0][1], $tolerance)
93
+ assert_in_delta(1.0, @lc6.axes[0][2], $tolerance)
94
+ assert_in_delta(0.0, @lc6.axes[1][0], $tolerance)
95
+ assert_in_delta(1.0, @lc6.axes[1][1], $tolerance)
96
+ assert_in_delta(-1.0, @lc6.axes[1][2], $tolerance)
97
+ assert_in_delta(0.0, @lc6.axes[2][0], $tolerance)
98
+ assert_in_delta(0.0, @lc6.axes[2][1], $tolerance)
99
+ assert_in_delta(1.0, @lc6.axes[2][2], $tolerance)
100
+ end
101
+
102
+ ## Class methods.
103
+ #
104
+ def test_new_lc
105
+ result = CrystalCell::LatticeAxes.new_lc([1.0, 1.0, 1.0, 90.0, 90.0, 90.0])
106
+ assert_equal(@lc3, result)
107
+ end
108
+
109
+ #def test_self_triangulate
110
+ # result = CrystalCell::LatticeAxes.triangulate([ [0.5, 0.5, 0.0], [0.0, 0.5, 0.5], [0.5, 0.0, 0.5] ])
111
+ # assert_in_delta(0.577350269189626, result[0][0], $tolerance)
112
+ # assert_in_delta(0.204124145231932, result[0][1], $tolerance)
113
+ # assert_in_delta(0.353553390593274, result[0][2], $tolerance)
114
+ # assert_in_delta(0.000000000000000, result[1][0], $tolerance)
115
+ # assert_in_delta(0.612372435695795, result[1][1], $tolerance)
116
+ # assert_in_delta(0.353553390593274, result[1][2], $tolerance)
117
+ # assert_in_delta(0.000000000000000, result[2][0], $tolerance)
118
+ # assert_in_delta(0.000000000000000, result[2][1], $tolerance)
119
+ # assert_in_delta(0.707106781186548, result[2][2], $tolerance)
120
+ #end
121
+
122
+ def test_self_lc_to_axes
123
+ axes = CrystalCell::LatticeAxes.lc_to_axes([ 1.0, 1.0, 1.0, 90.0, 90.0, 90.0 ])
124
+ assert_in_delta(@axes1[0][0], axes[0][0], $tolerance)
125
+ assert_in_delta(@axes1[0][1], axes[0][1], $tolerance)
126
+ assert_in_delta(@axes1[0][2], axes[0][2], $tolerance)
127
+ assert_in_delta(@axes1[1][0], axes[1][0], $tolerance)
128
+ assert_in_delta(@axes1[1][1], axes[1][1], $tolerance)
129
+ assert_in_delta(@axes1[1][2], axes[1][2], $tolerance)
130
+ assert_in_delta(@axes1[2][0], axes[2][0], $tolerance)
131
+ assert_in_delta(@axes1[2][1], axes[2][1], $tolerance)
132
+ assert_in_delta(@axes1[2][2], axes[2][2], $tolerance)
133
+
134
+ axes = CrystalCell::LatticeAxes.lc_to_axes([ 1.0, 1.0, 1.0, 90.0, 90.0, 90.0 ], false)
135
+ assert_in_delta(- @axes1[0][0], axes[0][0], $tolerance)
136
+ assert_in_delta( @axes1[0][1], axes[0][1], $tolerance)
137
+ assert_in_delta( @axes1[0][2], axes[0][2], $tolerance)
138
+ assert_in_delta( @axes1[1][0], axes[1][0], $tolerance)
139
+ assert_in_delta( @axes1[1][1], axes[1][1], $tolerance)
140
+ assert_in_delta( @axes1[1][2], axes[1][2], $tolerance)
141
+ assert_in_delta( @axes1[2][0], axes[2][0], $tolerance)
142
+ assert_in_delta( @axes1[2][1], axes[2][1], $tolerance)
143
+ assert_in_delta( @axes1[2][2], axes[2][2], $tolerance)
144
+ end
145
+
146
+ def test_self_axes_to_lc
147
+ correct = [ 1.0, 1.0, 1.0, 90.0, 90.0, 90.0 ]
148
+ assert_equal(correct, CrystalCell::LatticeAxes.axes_to_lc(@axes1))
149
+ end
150
+
151
+ def test_equal_in_delta?
152
+ assert_equal(true , @lc1.equal_in_delta?(@lc1, 0.01, 1.0))
153
+ assert_equal(false, @lc1.equal_in_delta?(@lc2, 0.01, 1.0))
154
+ assert_equal(false, @lc1.equal_in_delta?(@lc4, 0.01, 1.0))
155
+ assert_equal(false, @lc2.equal_in_delta?(@lc1, 0.01, 1.0))
156
+ assert_equal(true , @lc2.equal_in_delta?(@lc2, 0.01, 1.0))
157
+ assert_equal(true , @lc2.equal_in_delta?(@lc4, 0.01, 1.0))
158
+ assert_equal(false, @lc4.equal_in_delta?(@lc1, 0.01, 1.0))
159
+ assert_equal(true , @lc4.equal_in_delta?(@lc2, 0.01, 1.0))
160
+ assert_equal(true , @lc4.equal_in_delta?(@lc4, 0.01, 1.0))
161
+ end
162
+
163
+ def test_self_righthand?
164
+ # Righthand
165
+ assert_equal(true , CrystalCell::LatticeAxes.righthand?([ @vec_x, @vec_y, @vec_z ]))
166
+ assert_equal(true , CrystalCell::LatticeAxes.righthand?([ @vec_y, @vec_z, @vec_x ]))
167
+ assert_equal(true , CrystalCell::LatticeAxes.righthand?([ @vec_z, @vec_x, @vec_y ]))
168
+
169
+ # Lefthand
170
+ assert_equal(false, CrystalCell::LatticeAxes.righthand?([ @vec_z, @vec_y, @vec_x ]))
171
+ assert_equal(false, CrystalCell::LatticeAxes.righthand?([ @vec_x, @vec_z, @vec_y ]))
172
+ assert_equal(false, CrystalCell::LatticeAxes.righthand?([ @vec_y, @vec_x, @vec_z ]))
173
+
174
+ # Including zero vector.
175
+ assert_equal(false, CrystalCell::LatticeAxes.righthand?([ @vec_0, @vec_y, @vec_z ]))
176
+ assert_equal(false, CrystalCell::LatticeAxes.righthand?([ @vec_0, @vec_z, @vec_x ]))
177
+ assert_equal(false, CrystalCell::LatticeAxes.righthand?([ @vec_0, @vec_x, @vec_y ]))
178
+
179
+ # One vector is on the plane of residual two vectors.
180
+ assert_equal(false, CrystalCell::LatticeAxes.righthand?([ @vec_x, @vec_y, @vec_1 ]))
181
+ end
182
+
183
+ def test_self_lefthand?
184
+ # Righthand
185
+ assert_equal(false, CrystalCell::LatticeAxes.lefthand?([ @vec_x, @vec_y, @vec_z ]))
186
+ assert_equal(false, CrystalCell::LatticeAxes.lefthand?([ @vec_y, @vec_z, @vec_x ]))
187
+ assert_equal(false, CrystalCell::LatticeAxes.lefthand?([ @vec_z, @vec_x, @vec_y ]))
188
+
189
+ # Lefthand
190
+ assert_equal(true , CrystalCell::LatticeAxes.lefthand?([ @vec_z, @vec_y, @vec_x ]))
191
+ assert_equal(true , CrystalCell::LatticeAxes.lefthand?([ @vec_x, @vec_z, @vec_y ]))
192
+ assert_equal(true , CrystalCell::LatticeAxes.lefthand?([ @vec_y, @vec_x, @vec_z ]))
193
+
194
+ # Including zero vector.
195
+ assert_equal(false, CrystalCell::LatticeAxes.lefthand?([ @vec_0, @vec_y, @vec_z ]))
196
+ assert_equal(false, CrystalCell::LatticeAxes.lefthand?([ @vec_0, @vec_z, @vec_x ]))
197
+ assert_equal(false, CrystalCell::LatticeAxes.lefthand?([ @vec_0, @vec_x, @vec_y ]))
198
+
199
+ # One vector is on the plane of residual two vectors.
200
+ assert_equal(false, CrystalCell::LatticeAxes.lefthand?([ @vec_x, @vec_y, @vec_1 ]))
201
+ end
202
+
203
+ ## Instance methods.
204
+
205
+ def test_get_lattice_constants
206
+ assert_in_delta( 1.0, @lc1.get_lattice_constants[0], $tolerance)
207
+ assert_in_delta( 1.0, @lc1.get_lattice_constants[1], $tolerance)
208
+ assert_in_delta( 1.0, @lc1.get_lattice_constants[2], $tolerance)
209
+ assert_in_delta(90.0, @lc1.get_lattice_constants[3], $tolerance)
210
+ assert_in_delta(90.0, @lc1.get_lattice_constants[4], $tolerance)
211
+ assert_in_delta(90.0, @lc1.get_lattice_constants[5], $tolerance)
212
+ assert_in_delta(Math::sqrt(0.5), @lc2.get_lattice_constants[0], $tolerance)
213
+ assert_in_delta(Math::sqrt(0.5), @lc2.get_lattice_constants[1], $tolerance)
214
+ assert_in_delta(Math::sqrt(0.5), @lc2.get_lattice_constants[2], $tolerance)
215
+ assert_in_delta(60.0, @lc2.get_lattice_constants[3], $tolerance)
216
+ assert_in_delta(60.0, @lc2.get_lattice_constants[4], $tolerance)
217
+ assert_in_delta(60.0, @lc2.get_lattice_constants[5], $tolerance)
218
+ assert_in_delta( 1.0, @lc3.get_lattice_constants[0], $tolerance)
219
+ assert_in_delta( 1.0, @lc3.get_lattice_constants[1], $tolerance)
220
+ assert_in_delta( 1.0, @lc3.get_lattice_constants[2], $tolerance)
221
+ assert_in_delta(90.0, @lc3.get_lattice_constants[3], $tolerance)
222
+ assert_in_delta(90.0, @lc3.get_lattice_constants[4], $tolerance)
223
+ assert_in_delta(90.0, @lc3.get_lattice_constants[5], $tolerance)
224
+ assert_in_delta(Math::sqrt(0.5), @lc4.get_lattice_constants[0], $tolerance)
225
+ assert_in_delta(Math::sqrt(0.5), @lc4.get_lattice_constants[1], $tolerance)
226
+ assert_in_delta(Math::sqrt(0.5), @lc4.get_lattice_constants[2], $tolerance)
227
+ assert_in_delta(60.0, @lc4.get_lattice_constants[3], $tolerance)
228
+ assert_in_delta(60.0, @lc4.get_lattice_constants[4], $tolerance)
229
+ assert_in_delta(60.0, @lc4.get_lattice_constants[5], $tolerance)
230
+ end
231
+
232
+ def test_righthand?
233
+ assert_equal(true , @lc1.righthand?)
234
+ assert_equal(false, @lc2.righthand?)
235
+ end
236
+
237
+ def test_lefthand?
238
+ assert_equal(false, @lc1.lefthand?)
239
+ assert_equal(true , @lc2.lefthand?)
240
+ end
241
+
242
+ #def test_internal2cartesian
243
+ # assert_raise(CrystalCell::LatticeAxes::TypeError){
244
+ # @lc5.internal2cartesian([ 2.0, 3.0, 4.0 ])
245
+ # }
246
+ # assert_in_delta(2.0, @lc5.internal2cartesian([ 2.0, 3.0, 4.0 ])[0], $tolerance)
247
+ # assert_in_delta(5.0, @lc5.internal2cartesian([ 2.0, 3.0, 4.0 ])[1], $tolerance)
248
+ # assert_in_delta(9.0, @lc5.internal2cartesian([ 2.0, 3.0, 4.0 ])[2], $tolerance)
249
+ #end
250
+
251
+ #def test_cartesian2internal
252
+ # assert_in_delta(2.0, @lc5.cartesian2internal([ 2.0, 5.0, 9.0 ])[0], $tolerance)
253
+ # assert_in_delta(3.0, @lc5.cartesian2internal([ 2.0, 5.0, 9.0 ])[1], $tolerance)
254
+ # assert_in_delta(4.0, @lc5.cartesian2internal([ 2.0, 5.0, 9.0 ])[2], $tolerance)
255
+ #end
256
+
257
+ def test_equal
258
+ assert_equal(true , @lc1 == @lc1)
259
+ assert_equal(true , @lc2 == @lc2)
260
+ assert_equal(true , @lc3 == @lc3)
261
+
262
+ assert_equal(false, @lc1 == @lc2)
263
+ assert_equal(false, @lc2 == @lc3)
264
+ assert_equal(true , @lc3 == @lc1)
265
+
266
+ assert_equal(true , @lc1 == @lc3)
267
+ assert_equal(false, @lc2 == @lc1)
268
+ assert_equal(false, @lc3 == @lc2)
269
+ end
270
+
271
+ def test_triangulate
272
+ t = CrystalCell::LatticeAxes.new([ [0.5, 0.5, 0.0], [0.0, 0.5, 0.5], [0.5, 0.0, 0.5] ])
273
+ assert_in_delta(0.577350269189626, t[0][0], $tolerance)
274
+ assert_in_delta(0.204124145231932, t[0][1], $tolerance)
275
+ assert_in_delta(0.353553390593274, t[0][2], $tolerance)
276
+ assert_in_delta(0.000000000000000, t[1][0], $tolerance)
277
+ assert_in_delta(0.612372435695795, t[1][1], $tolerance)
278
+ assert_in_delta(0.353553390593274, t[1][2], $tolerance)
279
+ assert_in_delta(0.000000000000000, t[2][0], $tolerance)
280
+ assert_in_delta(0.000000000000000, t[2][1], $tolerance)
281
+ assert_in_delta(0.707106781186548, t[2][2], $tolerance)
282
+ end
283
+
284
+ def test_multiply
285
+ assert_equal(
286
+ CrystalCell::LatticeAxes.new([ [2.0, 2.0, 0.0], [2.0, 0.0, 2.0], [0.0, 2.0, 2.0] ]),
287
+ @lc2 * 4.0
288
+ )
289
+ end
290
+
291
+ def test_to_a
292
+ results = @lc1.to_a
293
+ corrects = [ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0] ]
294
+ assert_equal(corrects.size, results.size)
295
+ assert_equal(corrects[0].size, results[0].size)
296
+ assert_equal(corrects[1].size, results[1].size)
297
+ assert_equal(corrects[2].size, results[2].size)
298
+ assert_in_delta(corrects[0][0], results[0][0])
299
+ assert_in_delta(corrects[0][1], results[0][1])
300
+ assert_in_delta(corrects[0][2], results[0][2])
301
+ assert_in_delta(corrects[1][0], results[1][0])
302
+ assert_in_delta(corrects[1][1], results[1][1])
303
+ assert_in_delta(corrects[1][2], results[1][2])
304
+ assert_in_delta(corrects[2][0], results[2][0])
305
+ assert_in_delta(corrects[2][1], results[2][1])
306
+ assert_in_delta(corrects[2][2], results[2][2])
307
+ end
308
+
293
309
 
294
310
 
295
311
  end