crystalcell 0.0.3 → 0.0.4

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