crystalcell 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,965 @@
1
+ #! /usr/bin/ruby -w
2
+
3
+ require "pp"
4
+ require 'test/unit'
5
+ require 'stringio'
6
+ require "crystalcell/periodiccell.rb"
7
+ require "crystalcell/latticeaxes.rb"
8
+ require "crystalcell/cell.rb"
9
+
10
+ class PeriodicCell
11
+ public :reset_positions_inside
12
+ end
13
+
14
+ class TC_PeriodicCell < Test::Unit::TestCase
15
+ $tolerance = 10 ** (-10)
16
+
17
+ V_000 = Vector3DInternal[0.0, 0.0, 0.0]
18
+ V_666 = Vector3DInternal[0.6, 0.6, 0.6]
19
+ V_111 = Vector3DInternal[0.1, 0.1, 0.1]
20
+ V_119 = Vector3DInternal[0.1, 0.1, 0.9]
21
+ V_191 = Vector3DInternal[0.1, 0.9, 0.1]
22
+ V_199 = Vector3DInternal[0.1, 0.9, 0.9]
23
+ V_911 = Vector3DInternal[0.9, 0.1, 0.1]
24
+ V_919 = Vector3DInternal[0.9, 0.1, 0.9]
25
+ V_991 = Vector3DInternal[0.9, 0.9, 0.1]
26
+ V_999 = Vector3DInternal[0.9, 0.9, 0.9]
27
+
28
+ def setup
29
+ #原子のないセル。
30
+ vectors00 = [ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0] ]
31
+ @c00 = PeriodicCell.new(vectors00)
32
+ @c00.comment = 'c00'
33
+
34
+ #元素の識別子を数字にしたもの。
35
+ atoms = [
36
+ Atom.new(0, [0.0, 0.0, 0.0]),
37
+ Atom.new(1, [0.1, 0.2, 0.3]),
38
+ ]
39
+ @c01 = PeriodicCell.new(vectors00, atoms)
40
+ @c01.comment = 'c01'
41
+
42
+ #Li と O を1つずつ入れたセル。
43
+ atoms = [
44
+ Atom.new('Li', [0.0, 0.0, 0.0]),
45
+ Atom.new('O' , [0.2, 0.2, 0.2]),
46
+ ]
47
+ @c02 = PeriodicCell.new(vectors00, atoms)
48
+ @c02.comment = 'c02'
49
+
50
+ #原子を追加する順序を逆にしたもの。
51
+ atoms = [
52
+ Atom.new('O' , [0.2, 0.2, 0.2]),
53
+ Atom.new('Li', [0.0, 0.0, 0.0]),
54
+ ]
55
+ @c03 = PeriodicCell.new(vectors00, atoms)
56
+ @c03.comment = 'c03'
57
+
58
+ #原子を add したもの。
59
+ atoms = [
60
+ Atom.new('Li', [0.0, 0.0, 0.0]),
61
+ Atom.new('O' , [0.2, 0.2, 0.2]),
62
+ Atom.new('Li', [0.1, 0.2, 0.3]),
63
+ ]
64
+ @c04 = PeriodicCell.new(vectors00, atoms)
65
+ @c04.comment = 'c04'
66
+
67
+ #原子を remove したもの。
68
+ atoms = [
69
+ Atom.new('Li', [0.0, 0.0, 0.0])
70
+ ]
71
+ @c05 = PeriodicCell.new(vectors00, atoms)
72
+ @c05.comment = 'c05'
73
+
74
+ #Selective dynamics をいれたもの。
75
+ atoms = [
76
+ Atom.new('Li', [0.0, 0.0, 0.0], nil, [true, false, false ]),
77
+ Atom.new('O' , [0.2, 0.2, 0.2]),
78
+ ]
79
+ @c06 = PeriodicCell.new(vectors00, atoms)
80
+ @c06.comment = 'c06'
81
+
82
+ #元素の識別子を数字にしたもの。
83
+ atoms = [
84
+ Atom.new(0, [0.0, 0.0, 0.0]),
85
+ Atom.new(1, [0.2, 0.2, 0.2]),
86
+ ]
87
+ @c07 = PeriodicCell.new(vectors00, atoms)
88
+ @c07.comment = 'c01'
89
+
90
+ # セル外の座標の原子を追加。
91
+ atoms = [
92
+ Atom.new('Li', [ 1.2, 3.4, 5.6], "atom0", [ false, false, true]),
93
+ Atom.new('O', [-1.2, -3.4, -5.6]),
94
+ ]
95
+ @c08 = PeriodicCell.new(vectors00, atoms)
96
+ @c08.comment = 'c08'
97
+ end
98
+
99
+ def test_directions_within_distance
100
+ #A点 (0.1, 0.1, 0.1)_internal
101
+ #cartesian で、
102
+ # 0.1(2, 2, 2)
103
+ #+ 0.1(0, 2, 2)
104
+ #+ 0.1(0, 0, 2)
105
+ #==============
106
+ # 0.1(2, 4, 6) = (0.2, 0.4, 0.6)_cartesian
107
+ #
108
+ #B点 (0.1, 0.1, 0.1)_internal
109
+ #cartesian で、
110
+ # 0.9(2, 2, 2)
111
+ #+ 0.9(0, 2, 2)
112
+ #+ 0.9(0, 0, 2)
113
+ #==============
114
+ # 0.9(2, 4, 6) = (1.8, 3.6, 5.4)_cartesian
115
+ #詳細は test/directions_within_distance.rb を参照。
116
+ #p distance([ (1.8 - 2.0), (3.6 - 4.0), (5.4 - 4.0) ], A) #[-1,-1, 0] 1.2
117
+ #p distance([ (1.8 - 2.0), (3.6 - 2.0), (5.4 - 4.0) ], A) #[-1, 0,-1] 1.49666295470958
118
+ #p distance([ (1.8 - 2.0), (3.6 - 4.0), (5.4 - 6.0) ], A) #[-1,-1,-1] 1.49666295470958
119
+ #p distance([ (1.8 - 0.0), (3.6 - 2.0), (5.4 - 4.0) ], A) #[ 0,-1,-1] 2.1540659228538
120
+ #p distance([ (1.8 - 2.0), (3.6 - 4.0), (5.4 - 2.0) ], A) #[-1,-1,+1] 2.93938769133981
121
+ #p distance([ (1.8 - 2.0), (3.6 - 2.0), (5.4 - 2.0) ], A) #[-1, 0, 0] 3.07245829914744
122
+ #p distance([ (1.8 - 0.0), (3.6 - 2.0), (5.4 - 2.0) ], A) #[ 0,-1, 0] 3.44093010681705
123
+ #p distance([ (1.8 - 2.0), (3.6 - 0.0), (5.4 - 2.0) ], A) #[-1,+1,-1] 4.27083130081252
124
+ #p distance([ (1.8 - 0.0), (3.6 - 0.0), (5.4 - 2.0) ], A) #[ 0, 0,-1] 4.54312667664022
125
+ #p distance([ (1.8 - 2.0), (3.6 - 2.0), (5.4 - 0.0) ], A) #[-1, 0,+1] 4.96386945839634
126
+ #p distance([ (1.8 - 0.0), (3.6 - 2.0), (5.4 + 0.0) ], A) #[ 0,-1,+1] 5.2
127
+ #p distance([ (1.8 + 2.0), (3.6 + 0.0), (5.4 - 2.0) ], A) #[+1,-1,-1] 5.57135531087365
128
+ #p distance([ (1.8 - 2.0), (3.6 - 0.0), (5.4 - 0.0) ], A) #[-1,+1, 0] 5.78273291792039
129
+ #p distance([ (1.8 - 0.0), (3.6 - 0.0), (5.4 + 0.0) ], A) #[ 0, 0, 0] 5.98665181883831
130
+ #p distance([ (1.8 + 2.0), (3.6 + 0.0), (5.4 + 0.0) ], A) #[+1,-1, 0] 6.8
131
+ #p distance([ (1.8 - 0.0), (3.6 + 2.0), (5.4 + 0.0) ], A) #[ 0,+1,-1] 7.25534285888682
132
+ #p distance([ (1.8 - 2.0), (3.6 - 0.0), (5.4 + 2.0) ], A) #[-1,+1,+1] 7.52595508889071
133
+ #p distance([ (1.8 - 0.0), (3.6 - 0.0), (5.4 + 2.0) ], A) #[ 0, 0,+1] 7.68374908491942
134
+ #p distance([ (1.8 + 2.0), (3.6 + 2.0), (5.4 + 0.0) ], A) #[+1, 0,-1] 7.93977329651168
135
+ #p distance([ (1.8 + 2.0), (3.6 + 0.0), (5.4 + 2.0) ], A) #[+1,-1,+1] 8.33306666239986
136
+ #p distance([ (1.8 - 0.0), (3.6 + 2.0), (5.4 + 2.0) ], A) #[ 0,+1, 0] 8.7086164228309
137
+ #p distance([ (1.8 + 2.0), (3.6 + 2.0), (5.4 + 2.0) ], A) #[+1, 0, 0] 9.28654941299512
138
+ #p distance([ (1.8 - 0.0), (3.6 + 2.0), (5.4 + 4.0) ], A) #[ 0,+1,+1] 10.3460137251021
139
+ #p distance([ (1.8 + 2.0), (3.6 + 4.0), (5.4 + 2.0) ], A) #[+1,+1,-1] 10.5375518978556
140
+ #p distance([ (1.8 + 2.0), (3.6 + 2.0), (5.4 + 4.0) ], A) #[+1, 0,+1] 10.8369737473153
141
+ #p distance([ (1.8 + 2.0), (3.6 + 4.0), (5.4 + 4.0) ], A) #[+1,+1, 0] 11.9264412127005
142
+ #p distance([ (1.8 + 2.0), (3.6 + 4.0), (5.4 + 6.0) ], A) #[+1,+1,+1] 13.4699665923862
143
+
144
+ assert_equal([], @c00.directions_within_distance(V_111, V_999, 1.19))
145
+ assert_equal([[-1,-1,0]], @c00.directions_within_distance(V_111, V_999, 1.21))
146
+ assert_equal([[-1,-1,0]], @c00.directions_within_distance(V_111, V_999, 1.49))
147
+ assert_equal([[-1,-1,-1],[-1,-1,0],[-1,0,-1]], @c00.directions_within_distance(V_111, V_999, 1.50))
148
+ assert_equal([[-1,-1,-1],[-1,-1,0],[-1,0,-1]], @c00.directions_within_distance(V_111, V_999, 2.15))
149
+ assert_equal([[-1,-1,-1],[-1,-1,0],[-1,0,-1],[0,-1,-1]], @c00.directions_within_distance(V_111, V_999, 2.16))
150
+ assert_equal([[-1,-1,-1],[-1,-1,0],[-1,0,-1],[0,-1,-1]], @c00.directions_within_distance(V_111, V_999, 2.93))
151
+ assert_equal([[-1,-1,-1],[-1,-1,0],[-1,-1,+1],[-1,0,-1],[0,-1,-1]], @c00.directions_within_distance(V_111, V_999, 2.94))
152
+ assert_equal([[-1,-1,-1],[-1,-1,0],[-1,-1,+1],[-1,0,-1],[0,-1,-1]], @c00.directions_within_distance(V_111, V_999, 3.07))
153
+ assert_equal([[-1,-1,-1],[-1,-1,0],[-1,-1,+1],[-1,0,-1],[-1,0,0],[0,-1,-1]], @c00.directions_within_distance(V_111, V_999, 3.08))
154
+ assert_equal([[-1,-1,-1],[-1,-1,0],[-1,-1,+1],[-1,0,-1],[-1,0,0],[0,-1,-1]], @c00.directions_within_distance(V_111, V_999, 3.44))
155
+ assert_equal([[-1,-1,-1],[-1,-1,0],[-1,-1,+1],[-1,0,-1],[-1,0,0],[0,-1,-1],[0,-1,0]], @c00.directions_within_distance(V_111, V_999, 3.45))
156
+ #あとは省略。
157
+
158
+ end
159
+
160
+ def test_nearest_direction
161
+ assert_equal(
162
+ Vector3DInternal[ 0, 0, 0],
163
+ @c00.nearest_direction(Vector3DInternal[-0.9, -0.9, -0.9], V_111)
164
+ )
165
+
166
+ assert_equal(Vector3DInternal[-1, -1, 0], @c00.nearest_direction(V_111, V_999))
167
+ assert_equal(Vector3DInternal[-1, -1, 0], @c00.nearest_direction(V_119, V_999))
168
+ assert_equal(Vector3DInternal[-1, 0, -1], @c00.nearest_direction(V_191, V_999))
169
+ assert_equal(Vector3DInternal[-1, 0, 0], @c00.nearest_direction(V_199, V_999))
170
+ assert_equal(Vector3DInternal[ 0, -1, -1], @c00.nearest_direction(V_911, V_999))
171
+ assert_equal(Vector3DInternal[ 0, -1, 0], @c00.nearest_direction(V_919, V_999))
172
+ assert_equal(Vector3DInternal[ 0, 0, -1], @c00.nearest_direction(V_991, V_999))
173
+ assert_equal(Vector3DInternal[ 0, 0, 0], @c00.nearest_direction(V_999, V_999))
174
+ assert_equal(Vector3DInternal[ 1, 1, 0], @c00.nearest_direction(V_999, V_111))
175
+ assert_equal(Vector3DInternal[ 1, 1, 0], @c00.nearest_direction(V_999, V_119))
176
+ assert_equal(Vector3DInternal[ 1, 0, 1], @c00.nearest_direction(V_999, V_191))
177
+ assert_equal(Vector3DInternal[ 1, 0, 0], @c00.nearest_direction(V_999, V_199))
178
+ assert_equal(Vector3DInternal[ 0, 1, 1], @c00.nearest_direction(V_999, V_911))
179
+ assert_equal(Vector3DInternal[ 0, 1, 0], @c00.nearest_direction(V_999, V_919))
180
+ assert_equal(Vector3DInternal[ 0, 0, 1], @c00.nearest_direction(V_999, V_991))
181
+ assert_equal(Vector3DInternal[ 0, 0, 0], @c00.nearest_direction(V_999, V_999))
182
+
183
+ assert_equal(Vector3DInternal[ 1, 0, 1], @c00.nearest_direction(V_666, V_000))
184
+ assert_equal(Vector3DInternal[-1, 0, -1], @c00.nearest_direction(V_000, V_666))
185
+
186
+ assert_raise(PeriodicCell::TypeError){
187
+ @c00.nearest_direction([ 0.1, 0.1, 0.1 ], [ 0.9, 0.9, 0.9 ])
188
+ }
189
+ end
190
+
191
+ def test_nearest_distance
192
+ assert_in_delta(Math::sqrt(0.56), @c00.nearest_distance(V_000, Vector3DInternal[0.1, 0.1, 0.1]), $tolerance)
193
+ assert_in_delta(Math::sqrt(0.88), @c00.nearest_distance(V_000, Vector3DInternal[0.8, 0.9, 1.0]), $tolerance)
194
+
195
+ assert_raise(PeriodicCell::TypeError){@c00.nearest_distance([0.0, 0.0, 0.0], [0.1, 0.1, 0.1])}
196
+ assert_raise(PeriodicCell::TypeError){@c00.nearest_distance([0.0, 0.0, 0.0], [0.8, 0.9, 1.0])}
197
+ end
198
+
199
+
200
+ def test_find_bonds
201
+ atoms = [
202
+ Atom.new('Li', [ 0.1, 0.1, 0.1 ]),
203
+ Atom.new('O', [ 0.9, 0.9, 0.9 ]),
204
+ ]
205
+ pc00 = PeriodicCell.new([ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0] ] , atoms)
206
+
207
+ assert_equal([],
208
+ pc00.find_bonds('Li', 'O' , 0.0, 0.00)
209
+ )
210
+
211
+ #境界を越えて見つけられる。
212
+ t = pc00.find_bonds('Li', 'O' , 0.0, 1.21)
213
+ assert_equal(2, t.size)
214
+ assert_in_delta(0.1, t[0][0][0], $tolerance)
215
+ assert_in_delta(0.1, t[0][0][1], $tolerance)
216
+ assert_in_delta(0.1, t[0][0][2], $tolerance)
217
+ assert_in_delta(-0.1, t[0][1][0], $tolerance)
218
+ assert_in_delta(-0.1, t[0][1][1], $tolerance)
219
+ assert_in_delta(0.9, t[0][1][2], $tolerance)
220
+ assert_in_delta(0.9, t[1][0][0], $tolerance)
221
+ assert_in_delta(0.9, t[1][0][1], $tolerance)
222
+ assert_in_delta(0.9, t[1][0][2], $tolerance)
223
+ assert_in_delta(1.1, t[1][1][0], $tolerance)
224
+ assert_in_delta(1.1, t[1][1][1], $tolerance)
225
+ assert_in_delta(0.1, t[1][1][2], $tolerance)
226
+
227
+ #元素の順序を変えても等価な結果が返る。
228
+ t = pc00.find_bonds('O' , 'Li', 0.0, 1.21)
229
+ assert_equal(2, t.size)
230
+ assert_in_delta(0.1, t[0][0][0], $tolerance)
231
+ assert_in_delta(0.1, t[0][0][1], $tolerance)
232
+ assert_in_delta(0.1, t[0][0][2], $tolerance)
233
+ assert_in_delta(-0.1, t[0][1][0], $tolerance)
234
+ assert_in_delta(-0.1, t[0][1][1], $tolerance)
235
+ assert_in_delta(0.9, t[0][1][2], $tolerance)
236
+ assert_in_delta(0.9, t[1][0][0], $tolerance)
237
+ assert_in_delta(0.9, t[1][0][1], $tolerance)
238
+ assert_in_delta(0.9, t[1][0][2], $tolerance)
239
+ assert_in_delta(1.1, t[1][1][0], $tolerance)
240
+ assert_in_delta(1.1, t[1][1][1], $tolerance)
241
+ assert_in_delta(0.1, t[1][1][2], $tolerance)
242
+
243
+
244
+ pc01 = PeriodicCell.new([ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0] ])
245
+ pc01.add_atom(Atom.new('Li', [ 0.5, 0.5, 0.4 ]))
246
+ pc01.add_atom(Atom.new('Li', [ 0.5, 0.5, 0.5 ]))
247
+ pc01.add_atom(Atom.new('O', [ 0.5, 0.5, 0.6 ]))
248
+ pc01.add_atom(Atom.new('O', [ 0.5, 0.5, 0.7 ]))
249
+
250
+ t = pc01.find_bonds('Li', 'Li' , 0.0, 0.10)
251
+ assert_equal([], t)
252
+
253
+ #Li-Li、元素の区別
254
+ t = pc01.find_bonds('Li', 'Li' , 0.0, 0.30)
255
+ assert_equal(
256
+ [ [Vector3DInternal[0.5, 0.5, 0.4], Vector3DInternal[0.5, 0.5, 0.5 ] ] ],
257
+ t
258
+ )
259
+
260
+ #O-O、元素の区別
261
+ t = pc01.find_bonds('O', 'O' , 0.0, 0.30)
262
+ assert_equal(
263
+ [ [ Vector3DInternal[0.5, 0.5, 0.6], Vector3DInternal[0.5, 0.5, 0.7]]],
264
+ t
265
+ )
266
+
267
+ #Li-O、元素の区別
268
+ t = pc01.find_bonds('Li', 'O' , 0.0, 0.30)
269
+ assert_equal(
270
+ [ [ Vector3DInternal[0.5, 0.5, 0.5], Vector3DInternal[0.5, 0.5, 0.6] ] ],
271
+ t
272
+ )
273
+
274
+ #O-Li, 逆順でも等価
275
+ t = pc01.find_bonds('O' , 'Li', 0.0, 0.30)
276
+ assert_equal(
277
+ [[ Vector3DInternal[0.5, 0.5, 0.5], Vector3DInternal[0.5, 0.5, 0.6]]],
278
+ t
279
+ )
280
+
281
+ #距離の下限
282
+ t = pc01.find_bonds('Li', 'O' , 0.5, 0.7)
283
+ assert_equal(
284
+ [ [ Vector3DInternal[0.5, 0.5, 0.4], Vector3DInternal[0.5, 0.5, 0.7]]],
285
+ t
286
+ )
287
+
288
+ #距離の上限は pc00 で。
289
+
290
+ end
291
+
292
+ def test_pairs_within_distance
293
+ pc00 = PeriodicCell.new([ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0] ])
294
+ pc00.add_atom(Atom.new('Li', [ 0.1, 0.1, 0.1 ]))
295
+ pc00.add_atom(Atom.new('O', [ 0.9, 0.9, 0.9 ]))
296
+
297
+ #0-1 間
298
+ # [-1,-1, 0] 1.2
299
+ # [-1, 0,-1] 1.49666295470958
300
+ # [-1,-1,-1] 1.49666295470958
301
+ # [ 0,-1,-1] 2.1540659228538
302
+ # [-1,-1,+1] 2.93938769133981
303
+ # [-1, 0, 0] 3.07245829914744
304
+
305
+ ##0-0, 1-1
306
+ #[ 0, 0, 1] 2.0
307
+ #[ 0, 0,-1] 2.0
308
+ #[ 0,-1, 1] 2.0
309
+ #[ 0, 1,-1] 2.0
310
+ #[-1, 1, 0] 2.0
311
+ #[ 1,-1, 0] 2.0
312
+
313
+ assert_equal([], pc00.pairs_within_distance(0.0))
314
+ assert_equal([], pc00.pairs_within_distance(1.19))
315
+ assert_equal(
316
+ [ [0,1,[-1,-1, 0]], [1,0,[ 1, 1, 0]] ],
317
+ pc00.pairs_within_distance(1.21))
318
+ assert_equal(
319
+ [ [0,1,[-1,-1, 0]], [1,0,[ 1, 1, 0]] ],
320
+ pc00.pairs_within_distance(1.49))
321
+ assert_equal(
322
+ [
323
+ [0,1,[-1,-1,-1]],
324
+ [0,1,[-1,-1, 0]],
325
+ [0,1,[-1, 0,-1]],
326
+ [1,0,[ 1, 0, 1]],
327
+ [1,0,[ 1, 1, 0]],
328
+ [1,0,[ 1, 1, 1]]
329
+ ], pc00.pairs_within_distance(1.50)
330
+ )
331
+ assert_equal(
332
+ [
333
+ [0,1,[-1,-1,-1]],
334
+ [0,1,[-1,-1, 0]],
335
+ [0,1,[-1, 0,-1]],
336
+ [1,0,[ 1, 0, 1]],
337
+ [1,0,[ 1, 1, 0]],
338
+ [1,0,[ 1, 1, 1]]
339
+ ], pc00.pairs_within_distance(1.99)
340
+ )
341
+
342
+ t = pc00.pairs_within_distance(2.01)
343
+ assert_equal(18, t.size)
344
+ assert_equal([0,0,[-1, 1, 0]], t[ 0])
345
+ assert_equal([0,0,[ 0,-1, 1]], t[ 1])
346
+ assert_equal([0,0,[ 0, 0,-1]], t[ 2])
347
+ assert_equal([0,0,[ 0, 0, 1]], t[ 3])
348
+ assert_equal([0,0,[ 0, 1,-1]], t[ 4])
349
+ assert_equal([0,0,[ 1,-1, 0]], t[ 5])
350
+ assert_equal([0,1,[-1,-1,-1]], t[ 6])
351
+ assert_equal([0,1,[-1,-1, 0]], t[ 7])
352
+ assert_equal([0,1,[-1, 0,-1]], t[ 8])
353
+ assert_equal([1,0,[ 1, 0, 1]], t[ 9])
354
+ assert_equal([1,0,[ 1, 1, 0]], t[10])
355
+ assert_equal([1,0,[ 1, 1, 1]], t[11])
356
+ assert_equal([1,1,[-1, 1, 0]], t[12])
357
+ assert_equal([1,1,[ 0,-1, 1]], t[13])
358
+ assert_equal([1,1,[ 0, 0,-1]], t[14])
359
+ assert_equal([1,1,[ 0, 0, 1]], t[15])
360
+ assert_equal([1,1,[ 0, 1,-1]], t[16])
361
+ assert_equal([1,1,[ 1,-1, 0]], t[17])
362
+
363
+ t = pc00.pairs_within_distance(2.15)
364
+ assert_equal(18, t.size)
365
+ assert_equal([0,0,[-1, 1, 0]], t[ 0])
366
+ assert_equal([0,0,[ 0,-1, 1]], t[ 1])
367
+ assert_equal([0,0,[ 0, 0,-1]], t[ 2])
368
+ assert_equal([0,0,[ 0, 0, 1]], t[ 3])
369
+ assert_equal([0,0,[ 0, 1,-1]], t[ 4])
370
+ assert_equal([0,0,[ 1,-1, 0]], t[ 5])
371
+ assert_equal([0,1,[-1,-1,-1]], t[ 6])
372
+ assert_equal([0,1,[-1,-1, 0]], t[ 7])
373
+ assert_equal([0,1,[-1, 0,-1]], t[ 8])
374
+ assert_equal([1,0,[ 1, 0, 1]], t[ 9])
375
+ assert_equal([1,0,[ 1, 1, 0]], t[10])
376
+ assert_equal([1,0,[ 1, 1, 1]], t[11])
377
+ assert_equal([1,1,[-1, 1, 0]], t[12])
378
+ assert_equal([1,1,[ 0,-1, 1]], t[13])
379
+ assert_equal([1,1,[ 0, 0,-1]], t[14])
380
+ assert_equal([1,1,[ 0, 0, 1]], t[15])
381
+ assert_equal([1,1,[ 0, 1,-1]], t[16])
382
+ assert_equal([1,1,[ 1,-1, 0]], t[17])
383
+
384
+ t = pc00.pairs_within_distance(2.16)
385
+ assert_equal(20, t.size)
386
+ assert_equal([0,0,[-1, 1, 0]], t[ 0])
387
+ assert_equal([0,0,[ 0,-1, 1]], t[ 1])
388
+ assert_equal([0,0,[ 0, 0,-1]], t[ 2])
389
+ assert_equal([0,0,[ 0, 0, 1]], t[ 3])
390
+ assert_equal([0,0,[ 0, 1,-1]], t[ 4])
391
+ assert_equal([0,0,[ 1,-1, 0]], t[ 5])
392
+ assert_equal([0,1,[-1,-1,-1]], t[ 6])
393
+ assert_equal([0,1,[-1,-1, 0]], t[ 7])
394
+ assert_equal([0,1,[-1, 0,-1]], t[ 8])
395
+ assert_equal([0,1,[ 0,-1,-1]], t[ 9])
396
+ assert_equal([1,0,[ 0, 1, 1]], t[10])
397
+ assert_equal([1,0,[ 1, 0, 1]], t[11])
398
+ assert_equal([1,0,[ 1, 1, 0]], t[12])
399
+ assert_equal([1,0,[ 1, 1, 1]], t[13])
400
+ assert_equal([1,1,[-1, 1, 0]], t[14])
401
+ assert_equal([1,1,[ 0,-1, 1]], t[15])
402
+ assert_equal([1,1,[ 0, 0,-1]], t[16])
403
+ assert_equal([1,1,[ 0, 0, 1]], t[17])
404
+ assert_equal([1,1,[ 0, 1,-1]], t[18])
405
+ assert_equal([1,1,[ 1,-1, 0]], t[19])
406
+
407
+ t = pc00.pairs_within_distance(2.82)
408
+ assert_equal(20, t.size)
409
+ assert_equal([0,0,[-1, 1, 0]], t[ 0])
410
+ assert_equal([0,0,[ 0,-1, 1]], t[ 1])
411
+ assert_equal([0,0,[ 0, 0,-1]], t[ 2])
412
+ assert_equal([0,0,[ 0, 0, 1]], t[ 3])
413
+ assert_equal([0,0,[ 0, 1,-1]], t[ 4])
414
+ assert_equal([0,0,[ 1,-1, 0]], t[ 5])
415
+ assert_equal([0,1,[-1,-1,-1]], t[ 6])
416
+ assert_equal([0,1,[-1,-1, 0]], t[ 7])
417
+ assert_equal([0,1,[-1, 0,-1]], t[ 8])
418
+ assert_equal([0,1,[ 0,-1,-1]], t[ 9])
419
+ assert_equal([1,0,[ 0, 1, 1]], t[10])
420
+ assert_equal([1,0,[ 1, 0, 1]], t[11])
421
+ assert_equal([1,0,[ 1, 1, 0]], t[12])
422
+ assert_equal([1,0,[ 1, 1, 1]], t[13])
423
+ assert_equal([1,1,[-1, 1, 0]], t[14])
424
+ assert_equal([1,1,[ 0,-1, 1]], t[15])
425
+ assert_equal([1,1,[ 0, 0,-1]], t[16])
426
+ assert_equal([1,1,[ 0, 0, 1]], t[17])
427
+ assert_equal([1,1,[ 0, 1,-1]], t[18])
428
+ assert_equal([1,1,[ 1,-1, 0]], t[19])
429
+
430
+ t = pc00.pairs_within_distance(2.83)
431
+ assert_equal(36, t.size)
432
+ assert_equal([0,0,[-1, 0, 1]], t[ 0])
433
+ assert_equal([0,0,[-1, 1,-1]], t[ 1])
434
+ assert_equal([0,0,[-1, 1, 0]], t[ 2])
435
+ assert_equal([0,0,[-1, 1, 1]], t[ 3])
436
+ assert_equal([0,0,[ 0,-1, 0]], t[ 4])
437
+ assert_equal([0,0,[ 0,-1, 1]], t[ 5])
438
+ assert_equal([0,0,[ 0, 0,-1]], t[ 6])
439
+ assert_equal([0,0,[ 0, 0, 1]], t[ 7])
440
+ assert_equal([0,0,[ 0, 1,-1]], t[ 8])
441
+ assert_equal([0,0,[ 0, 1, 0]], t[ 9])
442
+ assert_equal([0,0,[ 1,-1,-1]], t[10])
443
+ assert_equal([0,0,[ 1,-1, 0]], t[11])
444
+ assert_equal([0,0,[ 1,-1, 1]], t[12])
445
+ assert_equal([0,0,[ 1, 0,-1]], t[13])
446
+ assert_equal([0,1,[-1,-1,-1]], t[14])
447
+ assert_equal([0,1,[-1,-1, 0]], t[15])
448
+ assert_equal([0,1,[-1, 0,-1]], t[16])
449
+ assert_equal([0,1,[ 0,-1,-1]], t[17])
450
+ assert_equal([1,0,[ 0, 1, 1]], t[18])
451
+ assert_equal([1,0,[ 1, 0, 1]], t[19])
452
+ assert_equal([1,0,[ 1, 1, 0]], t[20])
453
+ assert_equal([1,0,[ 1, 1, 1]], t[21])
454
+ assert_equal([1,1,[-1, 0, 1]], t[22])
455
+ assert_equal([1,1,[-1, 1,-1]], t[23])
456
+ assert_equal([1,1,[-1, 1, 0]], t[24])
457
+ assert_equal([1,1,[-1, 1, 1]], t[25])
458
+ assert_equal([1,1,[ 0,-1, 0]], t[26])
459
+ assert_equal([1,1,[ 0,-1, 1]], t[27])
460
+ assert_equal([1,1,[ 0, 0,-1]], t[28])
461
+ assert_equal([1,1,[ 0, 0, 1]], t[29])
462
+ assert_equal([1,1,[ 0, 1,-1]], t[30])
463
+ assert_equal([1,1,[ 0, 1, 0]], t[31])
464
+ assert_equal([1,1,[ 1,-1,-1]], t[32])
465
+ assert_equal([1,1,[ 1,-1, 0]], t[33])
466
+ assert_equal([1,1,[ 1,-1, 1]], t[34])
467
+ assert_equal([1,1,[ 1, 0,-1]], t[35])
468
+ end
469
+
470
+ def test_add_atom
471
+ tmp = Marshal.load(Marshal.dump(@c00))
472
+ tmp.add_atom(Atom.new(0, [1.0, 2.3, -2.3]))
473
+ assert_equal(1, tmp.positions.size)
474
+ assert_equal(Vector3DInternal, tmp.positions[0].class)
475
+ assert_in_delta(0.0, tmp.positions[0][0], $tolerance)
476
+ assert_in_delta(0.3, tmp.positions[0][1], $tolerance)
477
+ assert_in_delta(0.7, tmp.positions[0][2], $tolerance)
478
+ end
479
+
480
+ def test_rotate
481
+ @c02.add_atom(Atom.new('Li', [1.1, 1.2, 1.3]))
482
+
483
+ # Check new instance.
484
+ assert_equal(3, @c02.rotate([[-1, 0, 0],[0, -1, 0],[0, 0, -1]]).positions.size)
485
+ assert_equal(Vector3DInternal, @c02.rotate([[-1, 0, 0],[0, -1, 0],[0, 0, -1]]).positions[0].class)
486
+ assert_equal(Vector3DInternal, @c02.rotate([[-1, 0, 0],[0, -1, 0],[0, 0, -1]]).positions[1].class)
487
+ assert_equal(Vector3DInternal, @c02.rotate([[-1, 0, 0],[0, -1, 0],[0, 0, -1]]).positions[2].class)
488
+ assert_in_delta(0.0, @c02.rotate([[-1, 0, 0],[0, -1, 0],[0, 0, -1]]).positions[0][0], $tolerance)
489
+ assert_in_delta(0.0, @c02.rotate([[-1, 0, 0],[0, -1, 0],[0, 0, -1]]).positions[0][1], $tolerance)
490
+ assert_in_delta(0.0, @c02.rotate([[-1, 0, 0],[0, -1, 0],[0, 0, -1]]).positions[0][2], $tolerance)
491
+ assert_in_delta(0.8, @c02.rotate([[-1, 0, 0],[0, -1, 0],[0, 0, -1]]).positions[1][0], $tolerance)
492
+ assert_in_delta(0.8, @c02.rotate([[-1, 0, 0],[0, -1, 0],[0, 0, -1]]).positions[1][1], $tolerance)
493
+ assert_in_delta(0.8, @c02.rotate([[-1, 0, 0],[0, -1, 0],[0, 0, -1]]).positions[1][2], $tolerance)
494
+ assert_in_delta(0.9, @c02.rotate([[-1, 0, 0],[0, -1, 0],[0, 0, -1]]).positions[2][0], $tolerance)
495
+ assert_in_delta(0.8, @c02.rotate([[-1, 0, 0],[0, -1, 0],[0, 0, -1]]).positions[2][1], $tolerance)
496
+ assert_in_delta(0.7, @c02.rotate([[-1, 0, 0],[0, -1, 0],[0, 0, -1]]).positions[2][2], $tolerance)
497
+
498
+ # Check not destructed.
499
+ assert_equal(3, @c02.positions.size)
500
+ assert_equal(Vector3DInternal, @c02.positions[0].class)
501
+ assert_equal(Vector3DInternal, @c02.positions[1].class)
502
+ assert_equal(Vector3DInternal, @c02.positions[2].class)
503
+ assert_in_delta(0.0 , @c02.positions[0][0], $tolerance)
504
+ assert_in_delta(0.0 , @c02.positions[0][1], $tolerance)
505
+ assert_in_delta(0.0 , @c02.positions[0][2], $tolerance)
506
+ assert_in_delta(0.2 , @c02.positions[1][0], $tolerance)
507
+ assert_in_delta(0.2 , @c02.positions[1][1], $tolerance)
508
+ assert_in_delta(0.2 , @c02.positions[1][2], $tolerance)
509
+ assert_in_delta(0.1 , @c02.positions[2][0], $tolerance)
510
+ assert_in_delta(0.2 , @c02.positions[2][1], $tolerance)
511
+ assert_in_delta(0.3 , @c02.positions[2][2], $tolerance)
512
+ end
513
+
514
+ def test_rotate!
515
+ @c02.add_atom(Atom.new('Li', [0.1, 0.2, 0.3]))
516
+ @c02.rotate!([[-1, 0, 0],[0, -1, 0],[0, 0, -1]])
517
+ assert_equal(
518
+ [ Vector3DInternal[ 0.0, 0.0, 0.0 ],
519
+ Vector3DInternal[ 0.8, 0.8, 0.8 ],
520
+ Vector3DInternal[ 0.9, 0.8, 0.7 ]
521
+ ],
522
+ @c02.positions
523
+ )
524
+ end
525
+
526
+ def test_translate
527
+ poss = @c02.translate([1.1, 1.2, 1.3]).positions
528
+ assert_in_delta(0.1, poss[0][0], $tolerance)
529
+ assert_in_delta(0.2, poss[0][1], $tolerance)
530
+ assert_in_delta(0.3, poss[0][2], $tolerance)
531
+ assert_in_delta(0.3, poss[1][0], $tolerance)
532
+ assert_in_delta(0.4, poss[1][1], $tolerance)
533
+ assert_in_delta(0.5, poss[1][2], $tolerance)
534
+
535
+ poss = @c02.translate([-0.3,-0.3,-0.3]).positions
536
+ assert_in_delta( 0.7, poss[0][0], $tolerance)
537
+ assert_in_delta( 0.7, poss[0][1], $tolerance)
538
+ assert_in_delta( 0.7, poss[0][2], $tolerance)
539
+ assert_in_delta( 0.9, poss[1][0], $tolerance)
540
+ assert_in_delta( 0.9, poss[1][1], $tolerance)
541
+ assert_in_delta( 0.9, poss[1][2], $tolerance)
542
+
543
+ # Check not destructed.
544
+ assert_equal(
545
+ [ Vector3DInternal[ 0.0, 0.0, 0.0 ],
546
+ Vector3DInternal[ 0.2, 0.2, 0.2 ]
547
+ ],
548
+ @c02.positions
549
+ )
550
+ end
551
+
552
+ def test_translate!
553
+ @c02.translate!([1.1, 1.2, 1.3])
554
+ poss = @c02.positions
555
+
556
+ assert_in_delta(0.1, poss[0][0], $tolerance)
557
+ assert_in_delta(0.2, poss[0][1], $tolerance)
558
+ assert_in_delta(0.3, poss[0][2], $tolerance)
559
+ assert_in_delta(0.3, poss[1][0], $tolerance)
560
+ assert_in_delta(0.4, poss[1][1], $tolerance)
561
+ assert_in_delta(0.5, poss[1][2], $tolerance)
562
+ end
563
+
564
+ def test_to_cell
565
+ t = @c01.to_cell
566
+ assert_equal(Cell, t.class)
567
+ assert_equal(LatticeAxes, t.axes.class)
568
+ assert_in_delta(2.0, t.axes[0][0], $tolerance)
569
+ assert_in_delta(2.0, t.axes[0][1], $tolerance)
570
+ assert_in_delta(2.0, t.axes[0][2], $tolerance)
571
+ assert_in_delta(0.0, t.axes[1][0], $tolerance)
572
+ assert_in_delta(2.0, t.axes[1][1], $tolerance)
573
+ assert_in_delta(2.0, t.axes[1][2], $tolerance)
574
+ assert_in_delta(0.0, t.axes[2][0], $tolerance)
575
+ assert_in_delta(0.0, t.axes[2][1], $tolerance)
576
+ assert_in_delta(2.0, t.axes[2][2], $tolerance)
577
+
578
+ assert_equal(2, t.atoms.size)
579
+ assert_equal(Atom.new(0, [0.0, 0.0, 0.0]), t.atoms[0])
580
+ assert_equal(Atom.new(1, [0.1, 0.2, 0.3]), t.atoms[1])
581
+ assert_equal("c01", t.comment)
582
+ end
583
+
584
+ def test_center_of_atoms
585
+ # No atoms
586
+ assert_raise(NoMethodError){ @c00.center_of_atoms }
587
+
588
+ # Including atoms
589
+ assert_raise(NoMethodError){ @c01.center_of_atoms }
590
+ end
591
+
592
+ def test_inverse_axis!
593
+ @c02.inverse_axis!(0)
594
+ t = @c02
595
+ assert_equal(PeriodicCell, t.class)
596
+ assert_in_delta(t.axes[0][0],-2.0, $tolerance)
597
+ assert_in_delta(t.axes[0][1],-2.0, $tolerance)
598
+ assert_in_delta(t.axes[0][2],-2.0, $tolerance)
599
+ assert_in_delta(t.axes[1][0], 0.0, $tolerance)
600
+ assert_in_delta(t.axes[1][1], 2.0, $tolerance)
601
+ assert_in_delta(t.axes[1][2], 2.0, $tolerance)
602
+ assert_in_delta(t.axes[2][0], 0.0, $tolerance)
603
+ assert_in_delta(t.axes[2][1], 0.0, $tolerance)
604
+ assert_in_delta(t.axes[2][2], 2.0, $tolerance)
605
+ assert_equal(2, t.atoms.size)
606
+ # checking atom 0
607
+ assert_equal('Li' , t.atoms[0].element)
608
+ assert_equal(Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
609
+ assert_equal(nil , t.atoms[0].name)
610
+ # checking atom 1
611
+ assert_equal('O' , t.atoms[1].element)
612
+ assert_equal(Vector3DInternal[ 0.8, 0.2, 0.2], t.atoms[1].position)
613
+ assert_equal(nil , t.atoms[1].name)
614
+ end
615
+
616
+
617
+ def test_inverse_axis
618
+ # x 軸反転
619
+ t = @c02.inverse_axis(0)
620
+ assert_equal(PeriodicCell, t.class)
621
+ assert_in_delta(t.axes[0][0],-2.0, $tolerance)
622
+ assert_in_delta(t.axes[0][1],-2.0, $tolerance)
623
+ assert_in_delta(t.axes[0][2],-2.0, $tolerance)
624
+ assert_in_delta(t.axes[1][0], 0.0, $tolerance)
625
+ assert_in_delta(t.axes[1][1], 2.0, $tolerance)
626
+ assert_in_delta(t.axes[1][2], 2.0, $tolerance)
627
+ assert_in_delta(t.axes[2][0], 0.0, $tolerance)
628
+ assert_in_delta(t.axes[2][1], 0.0, $tolerance)
629
+ assert_in_delta(t.axes[2][2], 2.0, $tolerance)
630
+ assert_equal(2, t.atoms.size)
631
+ # checking atom 0
632
+ assert_equal('Li' , t.atoms[0].element)
633
+ assert_equal(Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
634
+ assert_equal(nil , t.atoms[0].name)
635
+ # checking atom 1
636
+ assert_equal('O' , t.atoms[1].element)
637
+ assert_equal(Vector3DInternal[ 0.8, 0.2, 0.2], t.atoms[1].position)
638
+ assert_equal(nil , t.atoms[1].name)
639
+
640
+ # y 軸反転
641
+ # [ [ ax, ay, az], [ 0, by, bz], [ 0, 0, cz] ]
642
+ # ↓ y 軸反転
643
+ # [ [ ax, ay, az], [ 0,-by,-bz], [ 0, 0, cz] ]
644
+ # ↓ b vector の y 成分が正になるようにする。
645
+ # すなわち z 軸回りに半回転し、全ての x, y 成分が反転する。
646
+ # [ [-ax,-ay, az], [ 0, by,-bz], [ 0, 0, cz] ]
647
+ t = @c02.inverse_axis(1)
648
+ assert_equal(PeriodicCell, t.class)
649
+ assert_in_delta(t.axes[0][0],-2.0, $tolerance)
650
+ assert_in_delta(t.axes[0][1],-2.0, $tolerance)
651
+ assert_in_delta(t.axes[0][2], 2.0, $tolerance)
652
+ assert_in_delta(t.axes[1][0], 0.0, $tolerance)
653
+ assert_in_delta(t.axes[1][1], 2.0, $tolerance)
654
+ assert_in_delta(t.axes[1][2],-2.0, $tolerance)
655
+ assert_in_delta(t.axes[2][0], 0.0, $tolerance)
656
+ assert_in_delta(t.axes[2][1], 0.0, $tolerance)
657
+ assert_in_delta(t.axes[2][2], 2.0, $tolerance)
658
+ assert_equal(2, t.atoms.size)
659
+ # checking atom 0
660
+ assert_equal('Li' , t.atoms[0].element)
661
+ assert_equal(Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
662
+ assert_equal(nil , t.atoms[0].name)
663
+ # checking atom 1
664
+ assert_equal('O' , t.atoms[1].element)
665
+ assert_equal(Vector3DInternal[ 0.2, 0.8, 0.2], t.atoms[1].position)
666
+ assert_equal(nil , t.atoms[1].name)
667
+
668
+ # z 軸反転
669
+ # [ [ ax, ay, az], [ 0, by, bz], [ 0, 0, cz] ]
670
+ # ↓ z 軸反転
671
+ # [ [ ax, ay, az], [ 0, by, bz], [ 0, 0,-cz] ]
672
+ # ↓ c vector の z 成分が正になるようにする。
673
+ # b vector の y 成分も正であることを保存する回転は、
674
+ # y 軸回りに半回転し、全ての x, z 成分が反転する。
675
+ # [ [-ax, ay,-az], [ 0, by,-bz], [ 0, 0, cz] ]
676
+ t = @c02.inverse_axis(2)
677
+ assert_equal(PeriodicCell, t.class)
678
+ assert_in_delta(t.axes[0][0],-2.0, $tolerance)
679
+ assert_in_delta(t.axes[0][1], 2.0, $tolerance)
680
+ assert_in_delta(t.axes[0][2],-2.0, $tolerance)
681
+ assert_in_delta(t.axes[1][0], 0.0, $tolerance)
682
+ assert_in_delta(t.axes[1][1], 2.0, $tolerance)
683
+ assert_in_delta(t.axes[1][2],-2.0, $tolerance)
684
+ assert_in_delta(t.axes[2][0], 0.0, $tolerance)
685
+ assert_in_delta(t.axes[2][1], 0.0, $tolerance)
686
+ assert_in_delta(t.axes[2][2], 2.0, $tolerance)
687
+ assert_equal(2, t.atoms.size)
688
+ # checking atom 0
689
+ assert_equal('Li' , t.atoms[0].element)
690
+ assert_equal(Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
691
+ assert_equal(nil , t.atoms[0].name)
692
+ # checking atom 1
693
+ assert_equal('O' , t.atoms[1].element)
694
+ assert_equal(Vector3DInternal[ 0.2, 0.2, 0.8], t.atoms[1].position)
695
+ assert_equal(nil , t.atoms[1].name)
696
+ end
697
+
698
+ def test_exchange_axes!
699
+ # b, c の交換。
700
+ @c08.exchange_axes!([ 1, 2 ])
701
+ t = @c08
702
+ assert_equal(PeriodicCell, t.class)
703
+ lc = t.axes.get_lattice_constants
704
+ assert_in_delta(2.0 * Math::sqrt(3.0) , lc[0], $tolerance)
705
+ assert_in_delta(2.0 , lc[1], $tolerance)
706
+ assert_in_delta(2.0 * Math::sqrt(2.0) , lc[2], $tolerance)
707
+ assert_in_delta(45.0000000000000, lc[3], $tolerance)
708
+ assert_in_delta(35.2643896827547, lc[4], $tolerance)
709
+ assert_in_delta(54.7356103172453, lc[5], $tolerance)
710
+ assert_equal(true, t.axes.lefthand?)
711
+ assert_equal(2, t.atoms.size)
712
+ # checking atom 0
713
+ assert_equal('Li' , t.atoms[0].element)
714
+ assert_equal(Vector3DInternal, t.atoms[0].position.class)
715
+ assert_in_delta(0.2, t.atoms[0].position[0], $tolerance)
716
+ assert_in_delta(0.6, t.atoms[0].position[1], $tolerance)
717
+ assert_in_delta(0.4, t.atoms[0].position[2], $tolerance)
718
+ assert_equal('atom0' , t.atoms[0].name)
719
+ assert_equal([ false, false, true] , t.atoms[0].movable_flags)
720
+ # checking atom 1
721
+ assert_equal('O' , t.atoms[1].element)
722
+ assert_equal(Vector3DInternal, t.atoms[1].position.class)
723
+ assert_in_delta(0.8, t.atoms[1].position[0], $tolerance)
724
+ assert_in_delta(0.4, t.atoms[1].position[1], $tolerance)
725
+ assert_in_delta(0.6, t.atoms[1].position[2], $tolerance)
726
+ assert_equal(nil , t.atoms[1].name)
727
+ end
728
+
729
+ def test_exchange_axes
730
+ assert_raise(Cell::ArgumentError){ @c02.exchange_axes([ 0 ]) }
731
+ assert_raise(Cell::ArgumentError){ @c02.exchange_axes([ 0, 1, 2]) }
732
+ assert_raise(Cell::AxesRangeError){ @c02.exchange_axes([0, 3]) }
733
+ assert_raise(Cell::AxesRangeError){ @c02.exchange_axes([-1, 2]) }
734
+ assert_raise(Cell::SameAxesError){ @c02.exchange_axes([ 1,1]) }
735
+
736
+ # b, c の交換。
737
+ t = @c08.exchange_axes([ 1, 2 ])
738
+ assert_equal(PeriodicCell, t.class)
739
+ lc = t.axes.get_lattice_constants
740
+ assert_in_delta(2.0 * Math::sqrt(3.0) , lc[0], $tolerance)
741
+ assert_in_delta(2.0 , lc[1], $tolerance)
742
+ assert_in_delta(2.0 * Math::sqrt(2.0) , lc[2], $tolerance)
743
+ assert_in_delta(45.0000000000000, lc[3], $tolerance)
744
+ assert_in_delta(35.2643896827547, lc[4], $tolerance)
745
+ assert_in_delta(54.7356103172453, lc[5], $tolerance)
746
+ assert_equal(true, t.axes.lefthand?)
747
+ assert_equal(2, t.atoms.size)
748
+ # checking atom 0
749
+ assert_equal('Li' , t.atoms[0].element)
750
+ assert_equal(Vector3DInternal, t.atoms[0].position.class)
751
+ assert_in_delta(0.2, t.atoms[0].position[0], $tolerance)
752
+ assert_in_delta(0.6, t.atoms[0].position[1], $tolerance)
753
+ assert_in_delta(0.4, t.atoms[0].position[2], $tolerance)
754
+ assert_equal('atom0' , t.atoms[0].name)
755
+ # checking atom 1
756
+ assert_equal('O' , t.atoms[1].element)
757
+ assert_equal(Vector3DInternal, t.atoms[1].position.class)
758
+ assert_in_delta(0.8, t.atoms[1].position[0], $tolerance)
759
+ assert_in_delta(0.4, t.atoms[1].position[1], $tolerance)
760
+ assert_in_delta(0.6, t.atoms[1].position[2], $tolerance)
761
+ assert_equal(nil , t.atoms[1].name)
762
+
763
+ # b, c の交換によって非破壊であることを確認。
764
+ t = @c08
765
+ assert_equal(PeriodicCell, t.class)
766
+ lc = t.axes.get_lattice_constants
767
+ assert_in_delta(2.0 * Math::sqrt(3.0) , lc[0], $tolerance)
768
+ assert_in_delta(2.0 * Math::sqrt(2.0) , lc[1], $tolerance)
769
+ assert_in_delta(2.0 , lc[2], $tolerance)
770
+ assert_in_delta(45.0000000000000, lc[3], $tolerance)
771
+ assert_in_delta(54.7356103172453, lc[4], $tolerance)
772
+ assert_in_delta(35.2643896827547, lc[5], $tolerance)
773
+ assert_equal(false, t.axes.lefthand?)
774
+ assert_equal(2, t.atoms.size)
775
+ # checking atom 0
776
+ assert_equal('Li' , t.atoms[0].element)
777
+ assert_equal(Vector3DInternal, t.atoms[0].position.class)
778
+ assert_in_delta(0.2, t.atoms[0].position[0], $tolerance)
779
+ assert_in_delta(0.4, t.atoms[0].position[1], $tolerance)
780
+ assert_in_delta(0.6, t.atoms[0].position[2], $tolerance)
781
+ assert_equal('atom0' , t.atoms[0].name)
782
+ # checking atom 1
783
+ assert_equal('O' , t.atoms[1].element)
784
+ assert_equal(Vector3DInternal, t.atoms[1].position.class)
785
+ assert_in_delta(0.8, t.atoms[1].position[0], $tolerance)
786
+ assert_in_delta(0.6, t.atoms[1].position[1], $tolerance)
787
+ assert_in_delta(0.4, t.atoms[1].position[2], $tolerance)
788
+ assert_equal(nil , t.atoms[1].name)
789
+ end
790
+
791
+ def test_reflect!
792
+ @c08.reflect!
793
+ t = @c08
794
+ assert_equal(PeriodicCell, t.class)
795
+ lc = t.axes.get_lattice_constants
796
+ assert_in_delta(2.0 * Math::sqrt(3.0) , lc[0], $tolerance)
797
+ assert_in_delta(2.0 * Math::sqrt(2.0) , lc[1], $tolerance)
798
+ assert_in_delta(2.0 , lc[2], $tolerance)
799
+ assert_in_delta(45.0000000000000, lc[3], $tolerance)
800
+ assert_in_delta(54.7356103172453, lc[4], $tolerance)
801
+ assert_in_delta(35.2643896827547, lc[5], $tolerance)
802
+ assert_equal(true, t.axes.lefthand?)
803
+ assert_equal(2, t.atoms.size)
804
+ # checking atom 0
805
+ assert_equal('Li' , t.atoms[0].element)
806
+ assert_equal(Vector3DInternal, t.atoms[0].position.class)
807
+ assert_in_delta(0.2, t.atoms[0].position[0], $tolerance)
808
+ assert_in_delta(0.4, t.atoms[0].position[1], $tolerance)
809
+ assert_in_delta(0.6, t.atoms[0].position[2], $tolerance)
810
+ assert_equal('atom0' , t.atoms[0].name)
811
+ # checking atom 1
812
+ assert_equal('O' , t.atoms[1].element)
813
+ assert_equal(Vector3DInternal, t.atoms[1].position.class)
814
+ assert_in_delta(0.8, t.atoms[1].position[0], $tolerance)
815
+ assert_in_delta(0.6, t.atoms[1].position[1], $tolerance)
816
+ assert_in_delta(0.4, t.atoms[1].position[2], $tolerance)
817
+ assert_equal(nil , t.atoms[1].name)
818
+ end
819
+
820
+ def test_reflect
821
+ t = @c08.reflect
822
+ assert_equal(PeriodicCell, t.class)
823
+ lc = t.axes.get_lattice_constants
824
+ assert_in_delta(2.0 * Math::sqrt(3.0) , lc[0], $tolerance)
825
+ assert_in_delta(2.0 * Math::sqrt(2.0) , lc[1], $tolerance)
826
+ assert_in_delta(2.0 , lc[2], $tolerance)
827
+ assert_in_delta(45.0000000000000, lc[3], $tolerance)
828
+ assert_in_delta(54.7356103172453, lc[4], $tolerance)
829
+ assert_in_delta(35.2643896827547, lc[5], $tolerance)
830
+ assert_equal(true, t.axes.lefthand?)
831
+ assert_equal(2, t.atoms.size)
832
+ # checking atom 0
833
+ assert_equal('Li' , t.atoms[0].element)
834
+ assert_equal(Vector3DInternal, t.atoms[0].position.class)
835
+ assert_in_delta(0.2, t.atoms[0].position[0], $tolerance)
836
+ assert_in_delta(0.4, t.atoms[0].position[1], $tolerance)
837
+ assert_in_delta(0.6, t.atoms[0].position[2], $tolerance)
838
+ assert_equal('atom0' , t.atoms[0].name)
839
+ # checking atom 1
840
+ assert_equal('O' , t.atoms[1].element)
841
+ assert_equal(Vector3DInternal, t.atoms[1].position.class)
842
+ assert_in_delta(0.8, t.atoms[1].position[0], $tolerance)
843
+ assert_in_delta(0.6, t.atoms[1].position[1], $tolerance)
844
+ assert_in_delta(0.4, t.atoms[1].position[2], $tolerance)
845
+ assert_equal(nil , t.atoms[1].name)
846
+
847
+ # 非破壊であることを確認。
848
+ t = @c08
849
+ assert_equal(PeriodicCell, t.class)
850
+ lc = t.axes.get_lattice_constants
851
+ assert_in_delta(2.0 * Math::sqrt(3.0) , lc[0], $tolerance)
852
+ assert_in_delta(2.0 * Math::sqrt(2.0) , lc[1], $tolerance)
853
+ assert_in_delta(2.0 , lc[2], $tolerance)
854
+ assert_in_delta(45.0000000000000, lc[3], $tolerance)
855
+ assert_in_delta(54.7356103172453, lc[4], $tolerance)
856
+ assert_in_delta(35.2643896827547, lc[5], $tolerance)
857
+ assert_equal(true, t.axes.righthand?)
858
+ assert_equal(2, t.atoms.size)
859
+ # checking atom 0
860
+ assert_equal('Li' , t.atoms[0].element)
861
+ assert_equal(Vector3DInternal, t.atoms[0].position.class)
862
+ assert_in_delta(0.2, t.atoms[0].position[0], $tolerance)
863
+ assert_in_delta(0.4, t.atoms[0].position[1], $tolerance)
864
+ assert_in_delta(0.6, t.atoms[0].position[2], $tolerance)
865
+ assert_equal('atom0' , t.atoms[0].name)
866
+ # checking atom 1
867
+ assert_equal('O' , t.atoms[1].element)
868
+ assert_equal(Vector3DInternal, t.atoms[1].position.class)
869
+ assert_in_delta(0.8, t.atoms[1].position[0], $tolerance)
870
+ assert_in_delta(0.6, t.atoms[1].position[1], $tolerance)
871
+ assert_in_delta(0.4, t.atoms[1].position[2], $tolerance)
872
+ assert_equal(nil , t.atoms[1].name)
873
+
874
+ end
875
+
876
+ # private
877
+
878
+ def test_reset_positions_inside
879
+ tmp = Marshal.load(Marshal.dump(@c00))
880
+ tmp.add_atom(Atom.new(0, [1.0, 2.3, -2.3]))
881
+ tmp.atoms[0].set_position([1.0, 2.3, -2.3])
882
+ tmp.reset_positions_inside
883
+ assert_equal(1, tmp.positions.size)
884
+ assert_equal(Vector3DInternal, tmp.positions[0].class)
885
+ assert_in_delta(0.0, tmp.positions[0][0], $tolerance)
886
+ assert_in_delta(0.3, tmp.positions[0][1], $tolerance)
887
+ assert_in_delta(0.7, tmp.positions[0][2], $tolerance)
888
+ end
889
+
890
+ #undef test_directions_within_distance
891
+ #undef test_nearest_direction
892
+ #undef test_nearest_distance
893
+ #undef test_find_bonds
894
+ #undef test_pairs_within_distance
895
+ #undef test_add_atom
896
+ #undef test_rotate
897
+ #undef test_rotate!
898
+ #undef test_translate
899
+ #undef test_translate!
900
+ #undef test_to_cell
901
+ #undef test_center_of_atoms
902
+ #undef test_inverse_axis!
903
+ #undef test_inverse_axis
904
+ #undef test_exchange_axes!
905
+ #undef test_exchange_axes
906
+ #undef test_reflect!
907
+ #undef test_reflect
908
+ #undef test_reset_positions_inside
909
+
910
+ end
911
+
912
+ class TC_Cell_EXTENSION < Test::Unit::TestCase
913
+ $tolerance = 10 ** (-10)
914
+
915
+ def test_to_pcell
916
+ c08 = Cell.new([ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0] ])
917
+ c08.add_atom(Atom.new('Li', [ 1.2, 3.4, 5.6], "atom0", [ false, false, true]))
918
+ c08.add_atom(Atom.new('O', [-1.2, -3.4, -5.6]))
919
+ c08.comment = 'c08'
920
+ #
921
+ t = c08.to_pcell
922
+ assert_equal(PeriodicCell, t.class)
923
+ assert_equal(LatticeAxes, t.axes.class)
924
+ assert_in_delta(2.0, t.axes[0][0], $tolerance)
925
+ assert_in_delta(2.0, t.axes[0][1], $tolerance)
926
+ assert_in_delta(2.0, t.axes[0][2], $tolerance)
927
+ assert_in_delta(0.0, t.axes[1][0], $tolerance)
928
+ assert_in_delta(2.0, t.axes[1][1], $tolerance)
929
+ assert_in_delta(2.0, t.axes[1][2], $tolerance)
930
+ assert_in_delta(0.0, t.axes[2][0], $tolerance)
931
+ assert_in_delta(0.0, t.axes[2][1], $tolerance)
932
+ assert_in_delta(2.0, t.axes[2][2], $tolerance)
933
+ #
934
+ assert_equal(2, t.atoms.size)
935
+ assert_equal(Atom, t.atoms[0].class)
936
+ assert_equal(Atom, t.atoms[1].class)
937
+ assert_in_delta(0.2, t.atoms[0].position[0], $tolerance)
938
+ assert_in_delta(0.4, t.atoms[0].position[1], $tolerance)
939
+ assert_in_delta(0.6, t.atoms[0].position[2], $tolerance)
940
+ assert_in_delta(0.8, t.atoms[1].position[0], $tolerance)
941
+ assert_in_delta(0.6, t.atoms[1].position[1], $tolerance)
942
+ assert_in_delta(0.4, t.atoms[1].position[2], $tolerance)
943
+ #
944
+ assert_equal("atom0", t.atoms[0].name)
945
+ assert_equal(nil , t.atoms[1].name)
946
+ #
947
+ assert_equal([ false, false, true ], t.atoms[0].movable_flags)
948
+ assert_equal(nil, t.atoms[1].movable_flags)
949
+ #
950
+ assert_equal("c08", t.comment)
951
+
952
+ # 破壊的でないことを確認。
953
+ t = c08
954
+ assert_equal(2, t.atoms.size)
955
+ assert_equal(Atom, t.atoms[0].class)
956
+ assert_equal(Atom, t.atoms[1].class)
957
+ assert_in_delta( 1.2, t.atoms[0].position[0], $tolerance)
958
+ assert_in_delta( 3.4, t.atoms[0].position[1], $tolerance)
959
+ assert_in_delta( 5.6, t.atoms[0].position[2], $tolerance)
960
+ assert_in_delta(-1.2, t.atoms[1].position[0], $tolerance)
961
+ assert_in_delta(-3.4, t.atoms[1].position[1], $tolerance)
962
+ assert_in_delta(-5.6, t.atoms[1].position[2], $tolerance)
963
+ end
964
+
965
+ end