crystalcell 0.0.0 → 0.0.1

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