crystalcell 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_cell.rb ADDED
@@ -0,0 +1,1167 @@
1
+ #! /usr/bin/ruby1.9 -W
2
+
3
+ require 'test/unit'
4
+ require 'stringio'
5
+ require 'crystalcell/cell.rb'
6
+ require "rubygems"
7
+ gem "mageo"
8
+ require "mageo/vector3dinternal.rb"
9
+
10
+ class FooCell < Cell; end
11
+
12
+ class TC_Cell < Test::Unit::TestCase
13
+ $tolerance = 10 ** (-10)
14
+
15
+ def setup
16
+ # 原子のないセル。
17
+ vectors00 = [[2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0]]
18
+ #@c00 = Cell.new(vectors00)
19
+ #
20
+ axes00 = LatticeAxes.new([[2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0]])
21
+ @c00 = Cell.new(axes00)
22
+ @c00.comment = 'c00'
23
+
24
+ # 元素の識別子を数字にしたもの。
25
+ atoms = [
26
+ Atom.new( 0, [0.0, 0.0, 0.0] ),
27
+ Atom.new( 1, [0.1, 0.2, 0.3] ),
28
+ ]
29
+ @c01 = Cell.new(axes00, atoms)
30
+ @c01.comment = 'c01'
31
+
32
+ # Li と O を1つずつ入れたセル。
33
+ # @c02 = Cell.new( [ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0] ] )
34
+ atoms = [
35
+ Atom.new( 'Li', [0.0, 0.0, 0.0] ),
36
+ Atom.new( 'O' , [0.2, 0.2, 0.2] ),
37
+ ]
38
+ @c02 = Cell.new(vectors00, atoms)
39
+ @c02.comment = 'c02'
40
+
41
+ # 原子の順序を逆にしたもの。
42
+ atoms = [
43
+ Atom.new( 'O' , [0.2, 0.2, 0.2] ),
44
+ Atom.new( 'Li', [0.0, 0.0, 0.0] ),
45
+ ]
46
+ @c03 = Cell.new(vectors00, atoms)
47
+ @c03.comment = 'c03'
48
+
49
+ # 原子の順序がいりまじったもの
50
+ atoms = [
51
+ Atom.new( 'Li', [0.0, 0.0, 0.0] ),
52
+ Atom.new( 'O' , [0.2, 0.2, 0.2] ),
53
+ Atom.new( 'Li', [0.1, 0.2, 0.3] ),
54
+ ]
55
+ @c04 = Cell.new(vectors00, atoms)
56
+ @c04.comment = 'c04'
57
+
58
+ # 原子が不足しているもの。
59
+ atoms = [
60
+ Atom.new( 'Li', [0.0, 0.0, 0.0] ),
61
+ ]
62
+ @c05 = Cell.new(vectors00, atoms)
63
+ @c05.comment = 'c05'
64
+
65
+ # Selective dynamics をいれたもの。
66
+ atoms = [
67
+ Atom.new( 'Li', [0.0, 0.0, 0.0], nil, [true, false, false ] ),
68
+ Atom.new( 'O' , [0.2, 0.2, 0.2] ),
69
+ ]
70
+ @c06 = Cell.new(vectors00, atoms)
71
+ @c06.comment = 'c06'
72
+
73
+ # 元素の識別子を数字にしたもの。
74
+ atoms = [
75
+ Atom.new( 0, Vector3DInternal[0.0, 0.0, 0.0] ),
76
+ Atom.new( 1, Vector3DInternal[0.2, 0.2, 0.2] ),
77
+ ]
78
+ @c07 = Cell.new(vectors00, atoms)
79
+ @c07.comment = 'c07'
80
+
81
+ # セル外の座標の原子を追加。
82
+ atoms = [
83
+ Atom.new( 'Li', [ 1.2, 3.4, 5.6], "atom0", [ false, false, true] ),
84
+ Atom.new( 'O', [-1.2, -3.4, -5.6] ),
85
+ ]
86
+ @c08 = Cell.new(vectors00, atoms)
87
+ @c08.comment = 'c08'
88
+ end
89
+
90
+ def test_initialize
91
+ la = LatticeAxes.new( [ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0] ] )
92
+ c10 = Cell.new( la )
93
+ c10.comment = 'c00'
94
+ assert_equal( Cell, c10.class )
95
+ assert_in_delta( 2.0, c10.axes[0][0], $tolerance )
96
+ assert_in_delta( 2.0, c10.axes[0][1], $tolerance )
97
+ assert_in_delta( 2.0, c10.axes[0][2], $tolerance )
98
+ assert_in_delta( 0.0, c10.axes[1][0], $tolerance )
99
+ assert_in_delta( 2.0, c10.axes[1][1], $tolerance )
100
+ assert_in_delta( 2.0, c10.axes[1][2], $tolerance )
101
+ assert_in_delta( 0.0, c10.axes[2][0], $tolerance )
102
+ assert_in_delta( 0.0, c10.axes[2][1], $tolerance )
103
+ assert_in_delta( 2.0, c10.axes[2][2], $tolerance )
104
+
105
+
106
+ end
107
+
108
+ def test_positions
109
+ assert_equal( [], @c00.positions)
110
+ assert_equal( [ Vector3DInternal[0.0, 0.0, 0.0], Vector3DInternal[0.2, 0.2, 0.2] ], @c02.positions )
111
+ assert_equal( [ Vector3DInternal[0.0, 0.0, 0.0], Vector3DInternal[0.1, 0.2, 0.3] ], @c01.positions )
112
+ end
113
+
114
+ def test_select_indices
115
+ assert_equal( [], @c00.select_indices{ |i| i.element == "" } )
116
+ assert_equal( [], @c00.select_indices{ |i| i.element == "Li" } )
117
+
118
+ assert_equal( [] , @c01.select_indices{ |i| i.element == "" } )
119
+ assert_equal( [] , @c01.select_indices{ |i| i.element == "Li" } )
120
+ #@c01.select_indices{ |i| p i.element }
121
+ assert_equal( [0], @c01.select_indices{ |i| i.element == 0 } )
122
+
123
+ assert_equal( [1], @c01.select_indices{ |i| i.element == 1 } )
124
+
125
+ assert_equal( [] , @c04.select_indices{ |i| i.element == "" } )
126
+ assert_equal( [0, 2], @c04.select_indices{ |i| i.element == "Li" } )
127
+ assert_equal( [1], @c04.select_indices{ |i| i.element == "O" } )
128
+ assert_equal( [ ], @c04.select_indices{ |i| i.element == 0 } )
129
+ assert_equal( [ ], @c04.select_indices{ |i| i.element == 1 } )
130
+
131
+ assert_equal( [1, 2], @c04.select_indices{ |i| i.position[0] > 0.05 } )
132
+ end
133
+
134
+ def test_atoms_in_supercell
135
+ t = @c02.atoms_in_supercell( 0, 0, 0, 0, 0, 1 )
136
+ assert_equal( 'Li', t[0].element )
137
+ assert_equal( 'Li', t[1].element )
138
+ assert_equal( 'O' , t[2].element )
139
+ assert_equal( 'O' , t[3].element )
140
+
141
+ assert_equal( Vector3DInternal[0.0, 0.0, 0.0], t[0].position )
142
+ assert_equal( Vector3DInternal[0.0, 0.0, 1.0], t[1].position )
143
+ assert_equal( Vector3DInternal[0.2, 0.2, 0.2], t[2].position )
144
+ assert_equal( Vector3DInternal[0.2, 0.2, 1.2], t[3].position )
145
+
146
+ t = @c02.atoms_in_supercell(-1, 1,-1, 1,-1, 1 )
147
+ assert_equal( ['Li']*27 + ['O'] * 27 , t.map{|i| i.element} )
148
+ assert_equal( Vector3DInternal[-1.0, -1.0, -1.0], t[ 0].position )
149
+ assert_equal( Vector3DInternal[-1.0, -1.0, 0.0], t[ 1].position )
150
+ assert_equal( Vector3DInternal[-1.0, -1.0, 1.0], t[ 2].position )
151
+ assert_equal( Vector3DInternal[-1.0, 0.0, -1.0], t[ 3].position )
152
+ assert_equal( Vector3DInternal[-1.0, 0.0, 0.0], t[ 4].position )
153
+ assert_equal( Vector3DInternal[-1.0, 0.0, 1.0], t[ 5].position )
154
+ assert_equal( Vector3DInternal[-1.0, 1.0, -1.0], t[ 6].position )
155
+ assert_equal( Vector3DInternal[-1.0, 1.0, 0.0], t[ 7].position )
156
+ assert_equal( Vector3DInternal[-1.0, 1.0, 1.0], t[ 8].position )
157
+ assert_equal( Vector3DInternal[ 0.0, -1.0, -1.0], t[ 9].position )
158
+ assert_equal( Vector3DInternal[ 0.0, -1.0, 0.0], t[10].position )
159
+ assert_equal( Vector3DInternal[ 0.0, -1.0, 1.0], t[11].position )
160
+ assert_equal( Vector3DInternal[ 0.0, 0.0, -1.0], t[12].position )
161
+ assert_equal( Vector3DInternal[ 0.0, 0.0, 0.0], t[13].position )
162
+ assert_equal( Vector3DInternal[ 0.0, 0.0, 1.0], t[14].position )
163
+ assert_equal( Vector3DInternal[ 0.0, 1.0, -1.0], t[15].position )
164
+ assert_equal( Vector3DInternal[ 0.0, 1.0, 0.0], t[16].position )
165
+ assert_equal( Vector3DInternal[ 0.0, 1.0, 1.0], t[17].position )
166
+ assert_equal( Vector3DInternal[ 1.0, -1.0, -1.0], t[18].position )
167
+ assert_equal( Vector3DInternal[ 1.0, -1.0, 0.0], t[19].position )
168
+ assert_equal( Vector3DInternal[ 1.0, -1.0, 1.0], t[20].position )
169
+ assert_equal( Vector3DInternal[ 1.0, 0.0, -1.0], t[21].position )
170
+ assert_equal( Vector3DInternal[ 1.0, 0.0, 0.0], t[22].position )
171
+ assert_equal( Vector3DInternal[ 1.0, 0.0, 1.0], t[23].position )
172
+ assert_equal( Vector3DInternal[ 1.0, 1.0, -1.0], t[24].position )
173
+ assert_equal( Vector3DInternal[ 1.0, 1.0, 0.0], t[25].position )
174
+ assert_equal( Vector3DInternal[ 1.0, 1.0, 1.0], t[26].position )
175
+ assert_equal( Vector3DInternal[-0.8, -0.8, -0.8], t[27].position )
176
+ assert_equal( Vector3DInternal[-0.8, -0.8, 0.2], t[28].position )
177
+ assert_equal( Vector3DInternal[-0.8, -0.8, 1.2], t[29].position )
178
+ assert_equal( Vector3DInternal[-0.8, 0.2, -0.8], t[30].position )
179
+ assert_equal( Vector3DInternal[-0.8, 0.2, 0.2], t[31].position )
180
+ assert_equal( Vector3DInternal[-0.8, 0.2, 1.2], t[32].position )
181
+ assert_equal( Vector3DInternal[-0.8, 1.2, -0.8], t[33].position )
182
+ assert_equal( Vector3DInternal[-0.8, 1.2, 0.2], t[34].position )
183
+ assert_equal( Vector3DInternal[-0.8, 1.2, 1.2], t[35].position )
184
+ assert_equal( Vector3DInternal[ 0.2, -0.8, -0.8], t[36].position )
185
+ assert_equal( Vector3DInternal[ 0.2, -0.8, 0.2], t[37].position )
186
+ assert_equal( Vector3DInternal[ 0.2, -0.8, 1.2], t[38].position )
187
+ assert_equal( Vector3DInternal[ 0.2, 0.2, -0.8], t[39].position )
188
+ assert_equal( Vector3DInternal[ 0.2, 0.2, 0.2], t[40].position )
189
+ assert_equal( Vector3DInternal[ 0.2, 0.2, 1.2], t[41].position )
190
+ assert_equal( Vector3DInternal[ 0.2, 1.2, -0.8], t[42].position )
191
+ assert_equal( Vector3DInternal[ 0.2, 1.2, 0.2], t[43].position )
192
+ assert_equal( Vector3DInternal[ 0.2, 1.2, 1.2], t[44].position )
193
+ assert_equal( Vector3DInternal[ 1.2, -0.8, -0.8], t[45].position )
194
+ assert_equal( Vector3DInternal[ 1.2, -0.8, 0.2], t[46].position )
195
+ assert_equal( Vector3DInternal[ 1.2, -0.8, 1.2], t[47].position )
196
+ assert_equal( Vector3DInternal[ 1.2, 0.2, -0.8], t[48].position )
197
+ assert_equal( Vector3DInternal[ 1.2, 0.2, 0.2], t[49].position )
198
+ assert_equal( Vector3DInternal[ 1.2, 0.2, 1.2], t[50].position )
199
+ assert_equal( Vector3DInternal[ 1.2, 1.2, -0.8], t[51].position )
200
+ assert_equal( Vector3DInternal[ 1.2, 1.2, 0.2], t[52].position )
201
+ assert_equal( Vector3DInternal[ 1.2, 1.2, 1.2], t[53].position )
202
+ end
203
+
204
+ def test_elements
205
+ assert_equal( [], @c00.elements)
206
+ assert_equal( [ 'Li', 'O' ], @c02.elements )
207
+ assert_equal( [ 0, 1 ], @c01.elements )
208
+ end
209
+
210
+ def test_add_atom
211
+ assert_raise(ArgumentError){
212
+ @c00.add_atom('Li', [0.5, 0.5, 0.5] )
213
+ }
214
+
215
+ @c00.add_atom(Atom.new( 'Li', [0.5, 0.5, 0.5] ))
216
+ assert_equal( 1 , @c00.atoms.size)
217
+ assert_equal( 'Li' , @c00.atoms[0].element)
218
+ assert_equal( Vector3DInternal[0.5, 0.5, 0.5], @c00.atoms[0].position)
219
+ assert_equal( nil , @c00.atoms[0].name )
220
+
221
+ @c00.add_atom(Atom.new( nil , [0.5, 0.5, 0.5], 'A' ))
222
+ assert_equal( 2 , @c00.atoms.size)
223
+ assert_equal( nil , @c00.atoms[1].element)
224
+ assert_equal( Vector3DInternal[0.5, 0.5, 0.5], @c00.atoms[1].position)
225
+ assert_equal( 'A' , @c00.atoms[1].name )
226
+
227
+ @c02.add_atom(Atom.new( 'Li', [0.5, 0.5, 0.5] ))
228
+ assert_equal( 3 , @c02.atoms.size)
229
+ assert_equal( 'Li' , @c02.atoms[0].element)
230
+ assert_equal( Vector3DInternal[0.0, 0.0, 0.0], @c02.atoms[0].position)
231
+ assert_equal( 'O' , @c02.atoms[1].element)
232
+ assert_equal( Vector3DInternal[0.2, 0.2, 0.2], @c02.atoms[1].position)
233
+ assert_equal( 'Li' , @c02.atoms[2].element)
234
+ assert_equal( Vector3DInternal[0.5, 0.5, 0.5], @c02.atoms[2].position)
235
+
236
+ @c01.add_atom(Atom.new( 'Li', [0.5, 0.5, 0.5] ))
237
+ assert_equal( 3 , @c01.atoms.size)
238
+ assert_equal( 0 , @c01.atoms[0].element)
239
+ assert_equal( Vector3DInternal[0.0, 0.0, 0.0], @c01.atoms[0].position)
240
+ assert_equal( 1 , @c01.atoms[1].element)
241
+ assert_equal( Vector3DInternal[0.1, 0.2, 0.3], @c01.atoms[1].position)
242
+ assert_equal( 'Li' , @c01.atoms[2].element)
243
+ assert_equal( Vector3DInternal[0.5, 0.5, 0.5], @c01.atoms[2].position)
244
+
245
+ end
246
+
247
+ def test_delete_atom
248
+ # assert_raise(RuntimeError ) {@c00.delete_atom( 0 ) }
249
+ assert_equal(nil, @c00.delete_atom( 0 ) )
250
+ assert_equal([], @c00.positions )
251
+ assert_equal([], @c00.elements )
252
+
253
+ @c02.delete_atom( 0 )
254
+ assert_equal( [ Vector3DInternal[0.2, 0.2, 0.2] ], @c02.positions)
255
+ assert_equal( [ 'O' ], @c02.elements )
256
+ @c02.delete_atom( 0 )
257
+ assert_equal( [], @c02.positions)
258
+ assert_equal( [], @c02.elements )
259
+
260
+ @c01.delete_atom( 0 )
261
+ assert_equal( [ Vector3DInternal[0.1, 0.2, 0.3] ], @c01.positions)
262
+ assert_equal( [ 1 ], @c01.elements )
263
+ end
264
+
265
+ def test_set_elements
266
+ # 原子がないので変更されない。
267
+ @c00.set_elements( [] )
268
+ assert_equal( [], @c00.atoms )
269
+
270
+ # 0 -> 'Li、 1 -> 'O' に変更。
271
+ tmp = Marshal.load( Marshal.dump( @c01 ))
272
+ tmp.set_elements( [ 'Li', 'O' ] )
273
+ assert_equal( 'Li', tmp.atoms[0].element )
274
+ assert_equal( 'O', tmp.atoms[1].element )
275
+
276
+ # 0 -> 'Li, 片方だけ変更。
277
+ tmp = Marshal.load( Marshal.dump( @c01 ))
278
+ tmp.set_elements( [ 'Li' ] )
279
+ assert_equal( 'Li', tmp.atoms[0].element )
280
+ assert_equal( 1, tmp.atoms[1].element )
281
+
282
+ # 元々整数値以外にセットされているのでマッチせず変更されない。
283
+ tmp = Marshal.load( Marshal.dump( @c02 ))
284
+ tmp.set_elements( [ 'O', 'Li' ] )
285
+ assert_equal( 'Li', tmp.atoms[0].element )
286
+ assert_equal( 'O', tmp.atoms[1].element )
287
+
288
+ # Hash argument.
289
+ # 0 -> 'Li、 1 -> 'O' に変更。
290
+ tmp = Marshal.load( Marshal.dump( @c01 ))
291
+ tmp.set_elements( { 0 => 'Li', 1 => 'O' } )
292
+ assert_equal( 'Li', tmp.atoms[0].element )
293
+ assert_equal( 'O', tmp.atoms[1].element )
294
+
295
+ # 'Li' -> 'Na', 'O' -> 'S' に変更。
296
+ tmp = Marshal.load( Marshal.dump( @c02 ))
297
+ tmp.set_elements( { 'Li' => 'Na', 'O' => 'S' } )
298
+ assert_equal( 'Na', tmp.atoms[0].element )
299
+ assert_equal( 'S', tmp.atoms[1].element )
300
+
301
+ # 'Li' -> 'Na'、 片方だけ変更。
302
+ tmp = Marshal.load( Marshal.dump( @c02 ))
303
+ tmp.set_elements( { 'Li' => 'Na' } )
304
+ assert_equal( 'Na', tmp.atoms[0].element )
305
+ assert_equal( 'O', tmp.atoms[1].element )
306
+ end
307
+
308
+ def test_equal_lattice_in_delta?
309
+ assert_equal( true , @c00.equal_lattice_in_delta?(@c00, 0.001, 0.1) )
310
+ assert_equal( true , @c00.equal_lattice_in_delta?(@c02, 0.001, 0.1) )
311
+ assert_equal( true , @c00.equal_lattice_in_delta?(@c01, 0.001, 0.1) )
312
+ assert_equal( true , @c02.equal_lattice_in_delta?(@c00, 0.001, 0.1) )
313
+ assert_equal( true , @c02.equal_lattice_in_delta?(@c02, 0.001, 0.1) )
314
+ assert_equal( true , @c02.equal_lattice_in_delta?(@c01, 0.001, 0.1) )
315
+ assert_equal( true , @c01.equal_lattice_in_delta?(@c00, 0.001, 0.1) )
316
+ assert_equal( true , @c01.equal_lattice_in_delta?(@c02, 0.001, 0.1) )
317
+ assert_equal( true , @c01.equal_lattice_in_delta?(@c01, 0.001, 0.1) )
318
+
319
+ end
320
+
321
+ def test_equal_atoms_in_delta?
322
+ assert_equal( true , @c00.equal_atoms_in_delta?( @c00, 0.01 ) )
323
+ assert_equal( false, @c00.equal_atoms_in_delta?( @c02, 0.01 ) )
324
+ assert_equal( false, @c00.equal_atoms_in_delta?( @c01, 0.01 ) )
325
+ assert_equal( false, @c00.equal_atoms_in_delta?( @c03, 0.01 ) )
326
+ assert_equal( false, @c00.equal_atoms_in_delta?( @c04, 0.01 ) )
327
+ assert_equal( false, @c00.equal_atoms_in_delta?( @c05, 0.01 ) )
328
+ assert_equal( false, @c02.equal_atoms_in_delta?( @c00, 0.01 ) )
329
+ assert_equal( true , @c02.equal_atoms_in_delta?( @c02, 0.01 ) )
330
+ assert_equal( false, @c02.equal_atoms_in_delta?( @c01, 0.01 ) )
331
+ assert_equal( true , @c02.equal_atoms_in_delta?( @c03, 0.01 ) )
332
+ assert_equal( false, @c02.equal_atoms_in_delta?( @c04, 0.01 ) )
333
+ assert_equal( false, @c02.equal_atoms_in_delta?( @c05, 0.01 ) )
334
+ assert_equal( false, @c01.equal_atoms_in_delta?( @c00, 0.01 ) )
335
+ assert_equal( false, @c01.equal_atoms_in_delta?( @c02, 0.01 ) )
336
+ assert_equal( true , @c01.equal_atoms_in_delta?( @c01, 0.01 ) )
337
+ assert_equal( false, @c01.equal_atoms_in_delta?( @c03, 0.01 ) )
338
+ assert_equal( false, @c01.equal_atoms_in_delta?( @c04, 0.01 ) )
339
+ assert_equal( false, @c01.equal_atoms_in_delta?( @c05, 0.01 ) )
340
+ assert_equal( false, @c03.equal_atoms_in_delta?( @c00, 0.01 ) )
341
+ assert_equal( true , @c03.equal_atoms_in_delta?( @c02, 0.01 ) )
342
+ assert_equal( false, @c03.equal_atoms_in_delta?( @c01, 0.01 ) )
343
+ assert_equal( true , @c03.equal_atoms_in_delta?( @c03, 0.01 ) )
344
+ assert_equal( false, @c03.equal_atoms_in_delta?( @c04, 0.01 ) )
345
+ assert_equal( false, @c03.equal_atoms_in_delta?( @c05, 0.01 ) )
346
+ assert_equal( false, @c04.equal_atoms_in_delta?( @c00, 0.01 ) )
347
+ assert_equal( false, @c04.equal_atoms_in_delta?( @c02, 0.01 ) )
348
+ assert_equal( false, @c04.equal_atoms_in_delta?( @c01, 0.01 ) )
349
+ assert_equal( false, @c04.equal_atoms_in_delta?( @c03, 0.01 ) )
350
+ assert_equal( true , @c04.equal_atoms_in_delta?( @c04, 0.01 ) )
351
+ assert_equal( false, @c04.equal_atoms_in_delta?( @c05, 0.01 ) )
352
+ assert_equal( false, @c05.equal_atoms_in_delta?( @c00, 0.01 ) )
353
+ assert_equal( false, @c05.equal_atoms_in_delta?( @c02, 0.01 ) )
354
+ assert_equal( false, @c05.equal_atoms_in_delta?( @c01, 0.01 ) )
355
+ assert_equal( false, @c05.equal_atoms_in_delta?( @c03, 0.01 ) )
356
+ assert_equal( false, @c05.equal_atoms_in_delta?( @c04, 0.01 ) )
357
+ assert_equal( true , @c05.equal_atoms_in_delta?( @c05, 0.01 ) )
358
+ end
359
+
360
+ def test_equal_in_delta?
361
+ assert_equal(true , @c00.equal_in_delta?( @c00, 0.001, 0.1, 0.01 ) )
362
+ assert_equal(false, @c00.equal_in_delta?( @c01, 0.001, 0.1, 0.01 ) )
363
+ assert_equal(false, @c00.equal_in_delta?( @c02, 0.001, 0.1, 0.01 ) )
364
+ assert_equal(false, @c00.equal_in_delta?( @c03, 0.001, 0.1, 0.01 ) )
365
+ assert_equal(false, @c00.equal_in_delta?( @c04, 0.001, 0.1, 0.01 ) )
366
+ assert_equal(false, @c00.equal_in_delta?( @c05, 0.001, 0.1, 0.01 ) )
367
+
368
+ assert_equal(false, @c02.equal_in_delta?( @c00, 0.001, 0.1, 0.01 ) )
369
+ assert_equal(false, @c02.equal_in_delta?( @c01, 0.001, 0.1, 0.01 ) )
370
+ assert_equal(true , @c02.equal_in_delta?( @c02, 0.001, 0.1, 0.01 ) )
371
+ assert_equal(true , @c02.equal_in_delta?( @c03, 0.001, 0.1, 0.01 ) )
372
+ assert_equal(false, @c02.equal_in_delta?( @c04, 0.001, 0.1, 0.01 ) )
373
+ assert_equal(false, @c02.equal_in_delta?( @c05, 0.001, 0.1, 0.01 ) )
374
+
375
+ assert_equal(false, @c01.equal_in_delta?( @c00, 0.001, 0.1, 0.01 ) )
376
+ assert_equal(true , @c01.equal_in_delta?( @c01, 0.001, 0.1, 0.01 ) )
377
+ assert_equal(false, @c01.equal_in_delta?( @c02, 0.001, 0.1, 0.01 ) )
378
+ assert_equal(false, @c01.equal_in_delta?( @c03, 0.001, 0.1, 0.01 ) )
379
+ assert_equal(false, @c01.equal_in_delta?( @c04, 0.001, 0.1, 0.01 ) )
380
+ assert_equal(false, @c01.equal_in_delta?( @c05, 0.001, 0.1, 0.01 ) )
381
+
382
+ assert_equal(false, @c03.equal_in_delta?( @c00, 0.001, 0.1, 0.01 ) )
383
+ assert_equal(false, @c03.equal_in_delta?( @c01, 0.001, 0.1, 0.01 ) )
384
+ assert_equal(true , @c03.equal_in_delta?( @c02, 0.001, 0.1, 0.01 ) )
385
+ assert_equal(true , @c03.equal_in_delta?( @c03, 0.001, 0.1, 0.01 ) )
386
+ assert_equal(false, @c03.equal_in_delta?( @c04, 0.001, 0.1, 0.01 ) )
387
+ assert_equal(false, @c03.equal_in_delta?( @c05, 0.001, 0.1, 0.01 ) )
388
+
389
+ assert_equal(false, @c04.equal_in_delta?( @c00, 0.001, 0.1, 0.01 ) )
390
+ assert_equal(false, @c04.equal_in_delta?( @c01, 0.001, 0.1, 0.01 ) )
391
+ assert_equal(false, @c04.equal_in_delta?( @c02, 0.001, 0.1, 0.01 ) )
392
+ assert_equal(false, @c04.equal_in_delta?( @c03, 0.001, 0.1, 0.01 ) )
393
+ assert_equal(true , @c04.equal_in_delta?( @c04, 0.001, 0.1, 0.01 ) )
394
+ assert_equal(false, @c04.equal_in_delta?( @c05, 0.001, 0.1, 0.01 ) )
395
+
396
+ assert_equal(false, @c05.equal_in_delta?( @c00, 0.001, 0.1, 0.01 ) )
397
+ assert_equal(false, @c05.equal_in_delta?( @c01, 0.001, 0.1, 0.01 ) )
398
+ assert_equal(false, @c05.equal_in_delta?( @c02, 0.001, 0.1, 0.01 ) )
399
+ assert_equal(false, @c05.equal_in_delta?( @c03, 0.001, 0.1, 0.01 ) )
400
+ assert_equal(false, @c05.equal_in_delta?( @c04, 0.001, 0.1, 0.01 ) )
401
+ assert_equal(true , @c05.equal_in_delta?( @c05, 0.001, 0.1, 0.01 ) )
402
+ end
403
+
404
+ def test_equal
405
+ cell = Cell.new( LatticeAxes.new([ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0]]))
406
+ assert_equal( true , @c00 == cell )
407
+ assert_equal( false, @c01 == cell )
408
+
409
+ cell = Cell.new( LatticeAxes.new([ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0]]))
410
+ cell.add_atom(Atom.new( 0, [0.0, 0.0, 0.0] ))
411
+ cell.add_atom(Atom.new( 1, [0.1, 0.2, 0.3] ))
412
+ assert_equal( false, @c00 == cell )
413
+ assert_equal( true , @c01 == cell )
414
+ end
415
+
416
+ def test_distance
417
+ assert_raise(Cell::TypeError){@c00.distance([0,0,0], [1,1,1])}
418
+ assert_raise(Cell::TypeError){@c00.distance([0,0,0], Vector3DInternal[1,1,1])}
419
+ assert_raise(Cell::TypeError){@c00.distance([0,0,0], Vector3D[1,1,1])}
420
+
421
+ assert_in_delta(
422
+ Math::sqrt(0.56),
423
+ @c00.distance(Vector3DInternal[0.0, 0.0, 0.0], Vector3DInternal[0.1, 0.1, 0.1] ),
424
+ $tolerance
425
+ )
426
+ assert_in_delta( Math::sqrt( 1.6**2 + 3.4**2 + 5.4**2),
427
+ @c00.distance( Vector3DInternal[0.0, 0.0, 0.0], Vector3DInternal[0.8, 0.9, 1.0] ), $tolerance
428
+ )
429
+
430
+ assert_in_delta( Math::sqrt(0.56), @c00.distance( Vector3DInternal[0.0, 0.0, 0.0], Vector3DInternal[0.1, 0.1, 0.1] ), $tolerance )
431
+ assert_in_delta( Math::sqrt( 1.6**2 + 3.4**2 + 5.4**2),
432
+ @c00.distance( Vector3DInternal[0.0, 0.0, 0.0], Vector3DInternal[0.8, 0.9, 1.0] ), $tolerance
433
+ )
434
+ end
435
+
436
+ def test_dump_poscar
437
+ c00_str = [
438
+ 'c00',
439
+ '1.0',
440
+ ' 2.00000000000000 2.00000000000000 2.00000000000000',
441
+ ' 0.00000000000000 2.00000000000000 2.00000000000000',
442
+ ' 0.00000000000000 0.00000000000000 2.00000000000000',
443
+ '',
444
+ 'Direct'
445
+ ].join("\n")
446
+
447
+ c02_str = [
448
+ 'c02',
449
+ '1.0',
450
+ ' 2.00000000000000 2.00000000000000 2.00000000000000',
451
+ ' 0.00000000000000 2.00000000000000 2.00000000000000',
452
+ ' 0.00000000000000 0.00000000000000 2.00000000000000',
453
+ ' 1 1',
454
+ 'Direct',
455
+ ' 0.00000000000000 0.00000000000000 0.00000000000000',
456
+ ' 0.20000000000000 0.20000000000000 0.20000000000000'
457
+ ].join("\n")
458
+
459
+ c01_str = [
460
+ 'c01',
461
+ '1.0',
462
+ ' 2.00000000000000 2.00000000000000 2.00000000000000',
463
+ ' 0.00000000000000 2.00000000000000 2.00000000000000',
464
+ ' 0.00000000000000 0.00000000000000 2.00000000000000',
465
+ ' 1 1',
466
+ 'Direct',
467
+ ' 0.00000000000000 0.00000000000000 0.00000000000000',
468
+ ' 0.10000000000000 0.20000000000000 0.30000000000000'
469
+ ].join("\n")
470
+
471
+ c03_str = [
472
+ 'c03',
473
+ '1.0',
474
+ ' 2.00000000000000 2.00000000000000 2.00000000000000',
475
+ ' 0.00000000000000 2.00000000000000 2.00000000000000',
476
+ ' 0.00000000000000 0.00000000000000 2.00000000000000',
477
+ ' 1 1',
478
+ 'Direct',
479
+ ' 0.00000000000000 0.00000000000000 0.00000000000000',
480
+ ' 0.20000000000000 0.20000000000000 0.20000000000000'
481
+ ].join("\n")
482
+
483
+ c04_str = [
484
+ 'c04',
485
+ '1.0',
486
+ ' 2.00000000000000 2.00000000000000 2.00000000000000',
487
+ ' 0.00000000000000 2.00000000000000 2.00000000000000',
488
+ ' 0.00000000000000 0.00000000000000 2.00000000000000',
489
+ ' 2 1',
490
+ 'Direct',
491
+ ' 0.00000000000000 0.00000000000000 0.00000000000000',
492
+ ' 0.10000000000000 0.20000000000000 0.30000000000000',
493
+ ' 0.20000000000000 0.20000000000000 0.20000000000000'
494
+ ].join("\n")
495
+
496
+ c05_str = [
497
+ 'c05',
498
+ '1.0',
499
+ ' 2.00000000000000 2.00000000000000 2.00000000000000',
500
+ ' 0.00000000000000 2.00000000000000 2.00000000000000',
501
+ ' 0.00000000000000 0.00000000000000 2.00000000000000',
502
+ ' 1',
503
+ 'Direct',
504
+ ' 0.00000000000000 0.00000000000000 0.00000000000000'
505
+ ].join("\n")
506
+
507
+ c06_str = [
508
+ 'c06',
509
+ '1.0',
510
+ ' 2.00000000000000 2.00000000000000 2.00000000000000',
511
+ ' 0.00000000000000 2.00000000000000 2.00000000000000',
512
+ ' 0.00000000000000 0.00000000000000 2.00000000000000',
513
+ ' 1 1',
514
+ 'Selective dynamics',
515
+ 'Direct',
516
+ ' 0.00000000000000 0.00000000000000 0.00000000000000 T F F',
517
+ ' 0.20000000000000 0.20000000000000 0.20000000000000 T T T'
518
+ ].join("\n")
519
+
520
+ # Raise exception
521
+ # assert_raise( RuntimeError ){ @c00.dump_poscar( [], io ) }
522
+ assert_raise( RuntimeError ){ @c00.dump_poscar( [0] ) }
523
+ assert_raise( RuntimeError ){ @c00.dump_poscar( [0, 1] ) }
524
+ assert_raise( RuntimeError ){ @c00.dump_poscar( ['Li'] ) }
525
+ assert_raise( RuntimeError ){ @c00.dump_poscar( ['Li', 'O'] ) }
526
+ assert_raise( RuntimeError ){ @c02.dump_poscar( [] ) }
527
+ assert_raise( RuntimeError ){ @c02.dump_poscar( [0] ) }
528
+ assert_raise( RuntimeError ){ @c02.dump_poscar( [0, 1] ) }
529
+ assert_raise( RuntimeError ){ @c02.dump_poscar( ['Li'] ) }
530
+ assert_raise( RuntimeError ){ @c01.dump_poscar( [] ) }
531
+ assert_raise( RuntimeError ){ @c01.dump_poscar( [0] ) }
532
+ assert_raise( RuntimeError ){ @c01.dump_poscar( ['Li'] ) }
533
+ assert_raise( RuntimeError ){ @c01.dump_poscar( ['Li', 'O'] ) }
534
+ assert_raise( RuntimeError ){ @c04.dump_poscar( [] ) }
535
+ assert_raise( RuntimeError ){ @c04.dump_poscar( [0] ) }
536
+ assert_raise( RuntimeError ){ @c04.dump_poscar( [0, 1] ) }
537
+ assert_raise( RuntimeError ){ @c04.dump_poscar( ['Li'] ) }
538
+ assert_raise( RuntimeError ){ @c05.dump_poscar( [] ) }
539
+ assert_raise( RuntimeError ){ @c05.dump_poscar( [0] ) }
540
+ assert_raise( RuntimeError ){ @c05.dump_poscar( [0, 1] ) }
541
+ assert_raise( RuntimeError ){ @c05.dump_poscar( ['Li', 'O'] ) }
542
+ assert_raise( RuntimeError ){ @c03.dump_poscar( [] ) }
543
+ assert_raise( RuntimeError ){ @c03.dump_poscar( [0] ) }
544
+ assert_raise( RuntimeError ){ @c03.dump_poscar( [0, 1] ) }
545
+ assert_raise( RuntimeError ){ @c03.dump_poscar( ['Li'] ) }
546
+
547
+ #
548
+ StringIO.new do |io|
549
+ @c00.dump_poscar( [], io )
550
+ assert_equal( c00_str, io.read )
551
+ end
552
+
553
+ StringIO.new do |io|
554
+ @c02.dump_poscar( [ 'Li', 'O' ], io )
555
+ assert_equal( c02, io.read )
556
+ end
557
+
558
+ StringIO.new do |io|
559
+ @c01.dump_poscar( [ 0, 1 ], io )
560
+ assert_equal( c01, io.read )
561
+ end
562
+
563
+ StringIO.new do |io|
564
+ @c03.dump_poscar( [ 'Li', 'O' ], io )
565
+ assert_equal( c03, io.read )
566
+ end
567
+
568
+ StringIO.new do |io|
569
+ @c04.dump_poscar( [ 'Li', 'O' ], io )
570
+ assert_equal( c04, io.read )
571
+ end
572
+
573
+ StringIO.new do |io|
574
+ @c05.dump_poscar( [ 'Li', 'O' ], io )
575
+ assert_equal( c05, io.read )
576
+ end
577
+
578
+ assert_equal( c00_str, @c00.dump_poscar( [ ], nil ) )
579
+ assert_equal( c01_str, @c01.dump_poscar( [ 0 , 1 ], nil ) )
580
+ assert_equal( c02_str, @c02.dump_poscar( [ 'Li', 'O' ], nil ) )
581
+ assert_equal( c03_str, @c03.dump_poscar( [ 'Li', 'O' ], nil ) )
582
+ assert_equal( c04_str, @c04.dump_poscar( [ 'Li', 'O' ], nil ) )
583
+ assert_equal( c05_str, @c05.dump_poscar( [ 'Li' ], nil ) )
584
+
585
+ assert_equal( c00_str, @c00.dump_poscar( [ ] ) )
586
+ assert_equal( c01_str, @c01.dump_poscar( [ 0 , 1 ] ) )
587
+ assert_equal( c02_str, @c02.dump_poscar( [ 'Li', 'O' ] ) )
588
+ assert_equal( c03_str, @c03.dump_poscar( [ 'Li', 'O' ] ) )
589
+ assert_equal( c04_str, @c04.dump_poscar( [ 'Li', 'O' ] ) )
590
+ assert_equal( c05_str, @c05.dump_poscar( [ 'Li' ] ) )
591
+
592
+ assert_equal( c06_str, @c06 .dump_poscar( [ 'Li', 'O' ] ) )
593
+
594
+ end
595
+
596
+ def test_rotate
597
+ @c02.add_atom(Atom.new( 'Li', [1.1, 1.2, 1.3] ))
598
+ assert_equal(
599
+ [ Vector3DInternal[ 0.0, 0.0, 0.0 ],
600
+ Vector3DInternal[ -0.2, -0.2, -0.2 ],
601
+ Vector3DInternal[ -1.1, -1.2, -1.3 ]
602
+ ],
603
+ @c02.rotate( [[-1, 0, 0],[0, -1, 0],[0, 0, -1]] ).positions
604
+ )
605
+
606
+ # Check not destructed.
607
+ assert_equal(
608
+ [ Vector3DInternal[ 0.0, 0.0, 0.0 ],
609
+ Vector3DInternal[ 0.2, 0.2, 0.2 ],
610
+ Vector3DInternal[ 1.1, 1.2, 1.3 ]
611
+ ],
612
+ @c02.positions
613
+ )
614
+ end
615
+
616
+ def test_rotate!
617
+ @c02.add_atom(Atom.new( 'Li', [0.1, 0.2, 0.3] ))
618
+ @c02.rotate!( [[-1, 0, 0],[0, -1, 0],[0, 0, -1]] )
619
+ assert_equal(
620
+ [ Vector3DInternal[ 0.0, 0.0, 0.0 ],
621
+ Vector3DInternal[ -0.2, -0.2, -0.2 ],
622
+ Vector3DInternal[ -0.1, -0.2, -0.3 ]
623
+ ],
624
+ @c02.positions
625
+ )
626
+ end
627
+
628
+ def test_translate
629
+ poss = @c02.translate( [1.1, 1.2, 1.3] ).positions
630
+ assert_in_delta( 1.1, poss[0][0], $tolerance )
631
+ assert_in_delta( 1.2, poss[0][1], $tolerance )
632
+ assert_in_delta( 1.3, poss[0][2], $tolerance )
633
+ assert_in_delta( 1.3, poss[1][0], $tolerance )
634
+ assert_in_delta( 1.4, poss[1][1], $tolerance )
635
+ assert_in_delta( 1.5, poss[1][2], $tolerance )
636
+
637
+ poss = @c02.translate( [-0.3,-0.3,-0.3] ).positions
638
+ assert_in_delta( -0.3, poss[0][0], $tolerance )
639
+ assert_in_delta( -0.3, poss[0][1], $tolerance )
640
+ assert_in_delta( -0.3, poss[0][2], $tolerance )
641
+ assert_in_delta( -0.1, poss[1][0], $tolerance )
642
+ assert_in_delta( -0.1, poss[1][1], $tolerance )
643
+ assert_in_delta( -0.1, poss[1][2], $tolerance )
644
+
645
+ # Check not destructed.
646
+ assert_equal(
647
+ [ Vector3DInternal[ 0.0, 0.0, 0.0 ],
648
+ Vector3DInternal[ 0.2, 0.2, 0.2 ]
649
+ ],
650
+ @c02.positions
651
+ )
652
+ end
653
+
654
+ def test_translate!
655
+ @c02.translate!( [1.1, 1.2, 1.3] )
656
+ poss = @c02.positions
657
+
658
+ assert_in_delta( 1.1, poss[0][0], $tolerance )
659
+ assert_in_delta( 1.2, poss[0][1], $tolerance )
660
+ assert_in_delta( 1.3, poss[0][2], $tolerance )
661
+ assert_in_delta( 1.3, poss[1][0], $tolerance )
662
+ assert_in_delta( 1.4, poss[1][1], $tolerance )
663
+ assert_in_delta( 1.5, poss[1][2], $tolerance )
664
+ end
665
+
666
+ def test_center_of_atoms
667
+ # No atom in the cell.
668
+ assert_raise( Cell::NoAtomError ){ @c00.center_of_atoms }
669
+
670
+ assert_equal( Vector3DInternal[0.05, 0.1, 0.15], @c01.center_of_atoms )
671
+ assert_equal( Vector3DInternal[0.1, 0.1, 0.1], @c02.center_of_atoms )
672
+ assert_equal( Vector3DInternal[0.1, 0.1, 0.1], @c03.center_of_atoms )
673
+ assert_equal( Vector3DInternal[0.1, 4.0/30.0, 5.0/30.0], @c04.center_of_atoms )
674
+ assert_equal( Vector3DInternal[0.0, 0.0, 0.0], @c05.center_of_atoms )
675
+ assert_equal( Vector3DInternal[0.1, 0.1, 0.1], @c06.center_of_atoms )
676
+ assert_equal( Vector3DInternal[0.1, 0.1, 0.1], @c07.center_of_atoms )
677
+ end
678
+
679
+ def test_calc_volume
680
+ # @c00 = Cell.new( [ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0] ] )
681
+ assert_in_delta( 8.00, @c00.calc_volume, $tolerance)
682
+
683
+ c10 = Cell.new( [ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0] ] )
684
+ c11 = Cell.new( [ [0.5, 0.5, 0.0], [0.5, 0.0, 0.5], [0.0, 0.5, 0.5] ] )
685
+ assert_in_delta( 1.00, c10.calc_volume, $tolerance)
686
+ assert_in_delta( 0.25, c11.calc_volume, $tolerance)
687
+ end
688
+
689
+ def test_cell_of_elements
690
+ t = @c04.cell_of_elements( [ 'Li' ] )
691
+ assert_equal( Cell, t.class )
692
+ assert_in_delta( 2.0, t.axes[0][0], $tolerance )
693
+ assert_in_delta( 2.0, t.axes[0][1], $tolerance )
694
+ assert_in_delta( 2.0, t.axes[0][2], $tolerance )
695
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
696
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
697
+ assert_in_delta( 2.0, t.axes[1][2], $tolerance )
698
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
699
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
700
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
701
+ assert_equal( 2, t.atoms.size )
702
+ # checking atom 0
703
+ assert_equal( 'Li' , t.atoms[0].element)
704
+ assert_equal( Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
705
+ assert_equal( nil , t.atoms[0].name )
706
+ # checking atom 1
707
+ assert_equal( 'Li' , t.atoms[1].element)
708
+ assert_equal( Vector3DInternal[0.1, 0.2, 0.3], t.atoms[1].position)
709
+ assert_equal( nil , t.atoms[1].name )
710
+
711
+ t = @c04.cell_of_elements( [ 'Li', 'O' ] )
712
+ assert_equal( Cell, t.class )
713
+ assert_in_delta( 2.0, t.axes[0][0], $tolerance )
714
+ assert_in_delta( 2.0, t.axes[0][1], $tolerance )
715
+ assert_in_delta( 2.0, t.axes[0][2], $tolerance )
716
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
717
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
718
+ assert_in_delta( 2.0, t.axes[1][2], $tolerance )
719
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
720
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
721
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
722
+ assert_equal( 3, t.atoms.size )
723
+ # checking atom 0
724
+ assert_equal( 'Li' , t.atoms[0].element)
725
+ assert_equal( Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
726
+ assert_equal( nil , t.atoms[0].name )
727
+ # checking atom 1
728
+ assert_equal( 'O' , t.atoms[1].element)
729
+ assert_equal( Vector3DInternal[0.2, 0.2, 0.2], t.atoms[1].position)
730
+ assert_equal( nil , t.atoms[1].name )
731
+ # checking atom 2
732
+ assert_equal( 'Li' , t.atoms[2].element)
733
+ assert_equal( Vector3DInternal[0.1, 0.2, 0.3], t.atoms[2].position)
734
+ assert_equal( nil , t.atoms[2].name )
735
+
736
+ t = @c04.cell_of_elements( [ 'O' ] )
737
+ assert_equal( Cell, t.class )
738
+ assert_in_delta( 2.0, t.axes[0][0], $tolerance )
739
+ assert_in_delta( 2.0, t.axes[0][1], $tolerance )
740
+ assert_in_delta( 2.0, t.axes[0][2], $tolerance )
741
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
742
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
743
+ assert_in_delta( 2.0, t.axes[1][2], $tolerance )
744
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
745
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
746
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
747
+ assert_equal( 1, t.atoms.size )
748
+ # checking atom 0
749
+ assert_equal( 'O' , t.atoms[0].element)
750
+ assert_equal( Vector3DInternal[0.2, 0.2, 0.2], t.atoms[0].position)
751
+ assert_equal( nil , t.atoms[0].name )
752
+
753
+ t = @c04.cell_of_elements( [ 'F' ] )
754
+ assert_equal( Cell, t.class )
755
+ assert_in_delta( 2.0, t.axes[0][0], $tolerance )
756
+ assert_in_delta( 2.0, t.axes[0][1], $tolerance )
757
+ assert_in_delta( 2.0, t.axes[0][2], $tolerance )
758
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
759
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
760
+ assert_in_delta( 2.0, t.axes[1][2], $tolerance )
761
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
762
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
763
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
764
+ assert_equal( 0, t.atoms.size )
765
+
766
+
767
+ # サブクラスで使用したときに、サブクラスで作られるか?
768
+ fc04 = FooCell.new( [ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0] ] )
769
+ fc04.add_atom(Atom.new( 'Li', [0.0, 0.0, 0.0] ))
770
+ fc04.add_atom(Atom.new( 'O' , [0.2, 0.2, 0.2] ))
771
+ fc04.add_atom(Atom.new( 'Li', [0.1, 0.2, 0.3] ))
772
+ fc04.comment = 'fc04'
773
+ t = fc04.cell_of_elements( [ 'Li' ] )
774
+ assert_equal( FooCell, t.class )
775
+ assert_in_delta( 2.0, t.axes[0][0], $tolerance )
776
+ assert_in_delta( 2.0, t.axes[0][1], $tolerance )
777
+ assert_in_delta( 2.0, t.axes[0][2], $tolerance )
778
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
779
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
780
+ assert_in_delta( 2.0, t.axes[1][2], $tolerance )
781
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
782
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
783
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
784
+ assert_equal( 2, t.atoms.size )
785
+ # checking atom 0
786
+ assert_equal( 'Li' , t.atoms[0].element)
787
+ assert_equal( Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
788
+ assert_equal( nil , t.atoms[0].name )
789
+ # checking atom 1
790
+ assert_equal( 'Li' , t.atoms[1].element)
791
+ assert_equal( Vector3DInternal[0.1, 0.2, 0.3], t.atoms[1].position)
792
+ assert_equal( nil , t.atoms[1].name )
793
+ end
794
+
795
+ def test_unite
796
+ ## 格子定数が違えば例外。将来的な feature.
797
+ #t = Cell.new( [ [2.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 2.0] ] )
798
+ #t.add_atom(Atom.new( 'Li', [0.0, 0.0, 0.0] ))
799
+ #t.comment = 't'
800
+ #assert_raise( Cell::AxesMismatchError ){ @c05.unite( t ) }
801
+ t = Cell.new( [ [2.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 2.0] ] )
802
+ t.add_atom(Atom.new( 'Li', [0.0, 0.0, 0.0] ))
803
+ t.comment = 't'
804
+ assert_nothing_raised{ @c05.unite( t ) }
805
+
806
+ # unite
807
+ # 同じ座標のものがあっても気にせず統合する。
808
+ t = @c05.unite( @c06 )
809
+ assert_equal( Cell, t.class )
810
+ assert_in_delta( 2.0, t.axes[0][0], $tolerance )
811
+ assert_in_delta( 2.0, t.axes[0][1], $tolerance )
812
+ assert_in_delta( 2.0, t.axes[0][2], $tolerance )
813
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
814
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
815
+ assert_in_delta( 2.0, t.axes[1][2], $tolerance )
816
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
817
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
818
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
819
+ assert_equal( 3, t.atoms.size )
820
+ # checking atom 0
821
+ assert_equal( 'Li' , t.atoms[0].element)
822
+ assert_equal( Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
823
+ assert_equal( nil , t.atoms[0].name )
824
+ # checking atom 1
825
+ assert_equal( 'Li' , t.atoms[1].element)
826
+ assert_equal( Vector3DInternal[0.0, 0.0, 0.0], t.atoms[1].position)
827
+ assert_equal( nil , t.atoms[1].name )
828
+ # checking atom 2
829
+ assert_equal( 'O' , t.atoms[2].element)
830
+ assert_equal( Vector3DInternal[0.2, 0.2, 0.2], t.atoms[2].position)
831
+ assert_equal( nil , t.atoms[2].name )
832
+ end
833
+
834
+ def test_inverse_axis!
835
+ @c02.inverse_axis!( 0 )
836
+ t = @c02
837
+ assert_equal( Cell, t.class )
838
+ assert_in_delta(-2.0, t.axes[0][0], $tolerance )
839
+ assert_in_delta(-2.0, t.axes[0][1], $tolerance )
840
+ assert_in_delta(-2.0, t.axes[0][2], $tolerance )
841
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
842
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
843
+ assert_in_delta( 2.0, t.axes[1][2], $tolerance )
844
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
845
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
846
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
847
+ assert_equal( 2, t.atoms.size )
848
+ # checking atom 0
849
+ assert_equal( 'Li' , t.atoms[0].element)
850
+ assert_equal( Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
851
+ assert_equal( nil , t.atoms[0].name )
852
+ # checking atom 1
853
+ assert_equal( 'O' , t.atoms[1].element)
854
+ assert_equal( Vector3DInternal[-0.2, 0.2, 0.2], t.atoms[1].position)
855
+ assert_equal( nil , t.atoms[1].name )
856
+ end
857
+
858
+ def test_inverse_axis
859
+ assert_raise( Cell::AxesRangeError ){ @c02.inverse_axis( -1 ) }
860
+ assert_raise( Cell::AxesRangeError ){ @c02.inverse_axis( 3 ) }
861
+
862
+ # x 軸反転
863
+ t = @c02.inverse_axis( 0 )
864
+ assert_equal( Cell, t.class )
865
+ assert_in_delta( -2.0, t.axes[0][0], $tolerance )
866
+ assert_in_delta( -2.0, t.axes[0][1], $tolerance )
867
+ assert_in_delta( -2.0, t.axes[0][2], $tolerance )
868
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
869
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
870
+ assert_in_delta( 2.0, t.axes[1][2], $tolerance )
871
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
872
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
873
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
874
+ assert_equal( 2, t.atoms.size )
875
+ # checking atom 0
876
+ assert_equal( 'Li' , t.atoms[0].element)
877
+ assert_equal( Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
878
+ assert_equal( nil , t.atoms[0].name )
879
+ # checking atom 1
880
+ assert_equal( 'O' , t.atoms[1].element)
881
+ assert_equal( Vector3DInternal[-0.2, 0.2, 0.2], t.atoms[1].position)
882
+ assert_equal( nil , t.atoms[1].name )
883
+ # checking non-destructive
884
+ assert_equal( Cell, t.class )
885
+ assert_in_delta( 2.0, @c02.axes[0][0], $tolerance )
886
+ assert_in_delta( 2.0, @c02.axes[0][1], $tolerance )
887
+ assert_in_delta( 2.0, @c02.axes[0][2], $tolerance )
888
+ assert_in_delta( 0.0, @c02.axes[1][0], $tolerance )
889
+ assert_in_delta( 2.0, @c02.axes[1][1], $tolerance )
890
+ assert_in_delta( 2.0, @c02.axes[1][2], $tolerance )
891
+ assert_in_delta( 0.0, @c02.axes[2][0], $tolerance )
892
+ assert_in_delta( 0.0, @c02.axes[2][1], $tolerance )
893
+ assert_in_delta( 2.0, @c02.axes[2][2], $tolerance )
894
+ assert_equal( 2, @c02.atoms.size )
895
+ # checking atom 0
896
+ assert_equal( 'Li' , @c02.atoms[0].element)
897
+ assert_equal( Vector3DInternal[0.0, 0.0, 0.0], @c02.atoms[0].position)
898
+ assert_equal( nil , @c02.atoms[0].name )
899
+ # checking atom 1
900
+ assert_equal( 'O' , @c02.atoms[1].element)
901
+ assert_equal( Vector3DInternal[ 0.2, 0.2, 0.2], @c02.atoms[1].position)
902
+ assert_equal( nil , @c02.atoms[1].name )
903
+
904
+ # y 軸反転
905
+ # [ [ ax, ay, az], [ 0, by, bz], [ 0, 0, cz] ]
906
+ # ↓ y 軸反転
907
+ # [ [ ax, ay, az], [ 0,-by,-bz], [ 0, 0, cz] ]
908
+ # ↓ b vector の y 成分が正になるようにする。
909
+ # すなわち z 軸回りに半回転し、全ての x, y 成分が反転する。
910
+ # [ [-ax,-ay, az], [ 0, by,-bz], [ 0, 0, cz] ]
911
+ t = @c02.inverse_axis( 1 )
912
+ assert_equal( Cell, t.class )
913
+ assert_in_delta( -2.0, t.axes[0][0], $tolerance )
914
+ assert_in_delta( -2.0, t.axes[0][1], $tolerance )
915
+ assert_in_delta( 2.0, t.axes[0][2], $tolerance )
916
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
917
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
918
+ assert_in_delta( -2.0, t.axes[1][2], $tolerance )
919
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
920
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
921
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
922
+ assert_equal( 2, t.atoms.size )
923
+ # checking atom 0
924
+ assert_equal( 'Li' , t.atoms[0].element)
925
+ assert_equal( Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
926
+ assert_equal( nil , t.atoms[0].name )
927
+ # checking atom 1
928
+ assert_equal( 'O' , t.atoms[1].element)
929
+ assert_equal( Vector3DInternal[ 0.2,-0.2, 0.2], t.atoms[1].position)
930
+ assert_equal( nil , t.atoms[1].name )
931
+
932
+ # z 軸反転
933
+ # [ [ ax, ay, az], [ 0, by, bz], [ 0, 0, cz] ]
934
+ # ↓ z 軸反転
935
+ # [ [ ax, ay, az], [ 0, by, bz], [ 0, 0,-cz] ]
936
+ # ↓ c vector の z 成分が正になるようにする。
937
+ # b vector の y 成分も正であることを保存する回転は、
938
+ # y 軸回りに半回転し、全ての x, z 成分が反転する。
939
+ # [ [-ax, ay,-az], [ 0, by,-bz], [ 0, 0, cz] ]
940
+ t = @c02.inverse_axis( 2 )
941
+ assert_equal( Cell, t.class )
942
+ assert_in_delta(-2.0, t.axes[0][0], $tolerance )
943
+ assert_in_delta( 2.0, t.axes[0][1], $tolerance )
944
+ assert_in_delta(-2.0, t.axes[0][2], $tolerance )
945
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
946
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
947
+ assert_in_delta(-2.0, t.axes[1][2], $tolerance )
948
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
949
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
950
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
951
+ assert_equal( 2, t.atoms.size )
952
+ # checking atom 0
953
+ assert_equal( 'Li' , t.atoms[0].element)
954
+ assert_equal( Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
955
+ assert_equal( nil , t.atoms[0].name )
956
+ # checking atom 1
957
+ assert_equal( 'O' , t.atoms[1].element)
958
+ assert_equal( Vector3DInternal[ 0.2, 0.2,-0.2], t.atoms[1].position)
959
+ assert_equal( nil , t.atoms[1].name )
960
+
961
+ end
962
+
963
+ def test_exchange_axes!
964
+ # b, c の交換。
965
+ @c08.exchange_axes!( [ 1, 2 ] )
966
+ t = @c08
967
+ assert_equal( Cell, t.class )
968
+ lc = t.axes.get_lattice_constants
969
+ assert_in_delta( 2.0 * Math::sqrt( 3.0 ) , lc[0], $tolerance )
970
+ assert_in_delta( 2.0 , lc[1], $tolerance )
971
+ assert_in_delta( 2.0 * Math::sqrt( 2.0 ) , lc[2], $tolerance )
972
+ assert_in_delta( 45.0000000000000, lc[3], $tolerance )
973
+ assert_in_delta( 35.2643896827547, lc[4], $tolerance )
974
+ assert_in_delta( 54.7356103172453, lc[5], $tolerance )
975
+ assert_equal( true, t.axes.lefthand? )
976
+ assert_equal( 2, t.atoms.size )
977
+ # checking atom 0
978
+ assert_equal( 'Li' , t.atoms[0].element)
979
+ assert_equal( Vector3DInternal[ 1.2, 5.6, 3.4], t.atoms[0].position)
980
+ assert_equal( 'atom0' , t.atoms[0].name )
981
+ assert_equal( [ false, false, true] , t.atoms[0].movable_flags )
982
+ # checking atom 1
983
+ assert_equal( 'O' , t.atoms[1].element)
984
+ assert_equal( Vector3DInternal[-1.2, -5.6, -3.4], t.atoms[1].position)
985
+ assert_equal( nil , t.atoms[1].name )
986
+ end
987
+
988
+ def test_exchange_axes
989
+ assert_raise( Cell::ArgumentError ){ @c02.exchange_axes( [ 0 ] ) }
990
+ assert_raise( Cell::ArgumentError ){ @c02.exchange_axes( [ 0, 1, 2] ) }
991
+ assert_raise( Cell::AxesRangeError ){ @c02.exchange_axes( [0, 3] ) }
992
+ assert_raise( Cell::AxesRangeError ){ @c02.exchange_axes( [-1, 2] ) }
993
+ assert_raise( Cell::SameAxesError ){ @c02.exchange_axes( [ 1,1] ) }
994
+
995
+ # b, c の交換。
996
+ t = @c08.exchange_axes( [ 1, 2 ] )
997
+ assert_equal( Cell, t.class )
998
+ lc = t.axes.get_lattice_constants
999
+ assert_in_delta( 2.0 * Math::sqrt( 3.0 ) , lc[0], $tolerance )
1000
+ assert_in_delta( 2.0 , lc[1], $tolerance )
1001
+ assert_in_delta( 2.0 * Math::sqrt( 2.0 ) , lc[2], $tolerance )
1002
+ assert_in_delta( 45.0000000000000, lc[3], $tolerance )
1003
+ assert_in_delta( 35.2643896827547, lc[4], $tolerance )
1004
+ assert_in_delta( 54.7356103172453, lc[5], $tolerance )
1005
+ assert_equal( true, t.axes.lefthand? )
1006
+ assert_equal( 2, t.atoms.size )
1007
+ # checking atom 0
1008
+ assert_equal( 'Li' , t.atoms[0].element)
1009
+ assert_equal( Vector3DInternal[ 1.2, 5.6, 3.4], t.atoms[0].position)
1010
+ assert_equal( 'atom0' , t.atoms[0].name )
1011
+ # checking atom 1
1012
+ assert_equal( 'O' , t.atoms[1].element)
1013
+ assert_equal( Vector3DInternal[-1.2, -5.6, -3.4], t.atoms[1].position)
1014
+ assert_equal( nil , t.atoms[1].name )
1015
+
1016
+ # b, c の交換によって非破壊であることを確認。
1017
+ t = @c08
1018
+ assert_equal( Cell, t.class )
1019
+ lc = t.axes.get_lattice_constants
1020
+ assert_in_delta( 2.0 * Math::sqrt( 3.0 ) , lc[0], $tolerance )
1021
+ assert_in_delta( 2.0 * Math::sqrt( 2.0 ) , lc[1], $tolerance )
1022
+ assert_in_delta( 2.0 , lc[2], $tolerance )
1023
+ assert_in_delta( 45.0000000000000, lc[3], $tolerance )
1024
+ assert_in_delta( 54.7356103172453, lc[4], $tolerance )
1025
+ assert_in_delta( 35.2643896827547, lc[5], $tolerance )
1026
+ assert_equal( true, t.axes.righthand? )
1027
+ assert_equal( 2, t.atoms.size )
1028
+ # checking atom 0
1029
+ assert_equal( 'Li' , t.atoms[0].element)
1030
+ assert_equal( Vector3DInternal[ 1.2, 3.4, 5.6], t.atoms[0].position)
1031
+ assert_equal( 'atom0' , t.atoms[0].name )
1032
+ # checking atom 1
1033
+ assert_equal( 'O' , t.atoms[1].element)
1034
+ assert_equal( Vector3DInternal[-1.2, -3.4, -5.6], t.atoms[1].position)
1035
+ assert_equal( nil , t.atoms[1].name )
1036
+
1037
+ end
1038
+
1039
+ def test_reflect!
1040
+ @c08.reflect!
1041
+ t = @c08
1042
+ assert_equal( Cell, t.class )
1043
+ lc = t.axes.get_lattice_constants
1044
+ assert_in_delta( 2.0 * Math::sqrt( 3.0 ) , lc[0], $tolerance )
1045
+ assert_in_delta( 2.0 * Math::sqrt( 2.0 ) , lc[1], $tolerance )
1046
+ assert_in_delta( 2.0 , lc[2], $tolerance )
1047
+ assert_in_delta( 45.0000000000000, lc[3], $tolerance )
1048
+ assert_in_delta( 54.7356103172453, lc[4], $tolerance )
1049
+ assert_in_delta( 35.2643896827547, lc[5], $tolerance )
1050
+ assert_equal( true, t.axes.lefthand? )
1051
+ assert_equal( 2, t.atoms.size )
1052
+ # checking atom 0
1053
+ assert_equal( 'Li' , t.atoms[0].element)
1054
+ assert_equal( Vector3DInternal[ 1.2, 3.4, 5.6], t.atoms[0].position)
1055
+ assert_equal( 'atom0' , t.atoms[0].name )
1056
+ # checking atom 1
1057
+ assert_equal( 'O' , t.atoms[1].element)
1058
+ assert_equal( Vector3DInternal[-1.2, -3.4, -5.6], t.atoms[1].position)
1059
+ assert_equal( nil , t.atoms[1].name )
1060
+ end
1061
+
1062
+ def test_reflect
1063
+ t = @c08.reflect
1064
+ assert_equal( Cell, t.class )
1065
+ lc = t.axes.get_lattice_constants
1066
+ assert_in_delta( 2.0 * Math::sqrt( 3.0 ) , lc[0], $tolerance )
1067
+ assert_in_delta( 2.0 * Math::sqrt( 2.0 ) , lc[1], $tolerance )
1068
+ assert_in_delta( 2.0 , lc[2], $tolerance )
1069
+ assert_in_delta( 45.0000000000000, lc[3], $tolerance )
1070
+ assert_in_delta( 54.7356103172453, lc[4], $tolerance )
1071
+ assert_in_delta( 35.2643896827547, lc[5], $tolerance )
1072
+ assert_equal( true, t.axes.lefthand? )
1073
+ assert_equal( 2, t.atoms.size )
1074
+ # checking atom 0
1075
+ assert_equal( 'Li' , t.atoms[0].element)
1076
+ assert_equal( Vector3DInternal[ 1.2, 3.4, 5.6], t.atoms[0].position)
1077
+ assert_equal( 'atom0' , t.atoms[0].name )
1078
+ # checking atom 1
1079
+ assert_equal( 'O' , t.atoms[1].element)
1080
+ assert_equal( Vector3DInternal[-1.2, -3.4, -5.6], t.atoms[1].position)
1081
+ assert_equal( nil , t.atoms[1].name )
1082
+
1083
+ # 非破壊であることを確認。
1084
+ t = @c08
1085
+ assert_equal( Cell, t.class )
1086
+ lc = t.axes.get_lattice_constants
1087
+ assert_in_delta( 2.0 * Math::sqrt( 3.0 ) , lc[0], $tolerance )
1088
+ assert_in_delta( 2.0 * Math::sqrt( 2.0 ) , lc[1], $tolerance )
1089
+ assert_in_delta( 2.0 , lc[2], $tolerance )
1090
+ assert_in_delta( 45.0000000000000, lc[3], $tolerance )
1091
+ assert_in_delta( 54.7356103172453, lc[4], $tolerance )
1092
+ assert_in_delta( 35.2643896827547, lc[5], $tolerance )
1093
+ assert_equal( true, t.axes.righthand? )
1094
+ assert_equal( 2, t.atoms.size )
1095
+ # checking atom 0
1096
+ assert_equal( 'Li' , t.atoms[0].element)
1097
+ assert_equal( Vector3DInternal[ 1.2, 3.4, 5.6], t.atoms[0].position)
1098
+ assert_equal( 'atom0' , t.atoms[0].name )
1099
+ # checking atom 1
1100
+ assert_equal( 'O' , t.atoms[1].element)
1101
+ assert_equal( Vector3DInternal[-1.2, -3.4, -5.6], t.atoms[1].position)
1102
+ assert_equal( nil , t.atoms[1].name )
1103
+ end
1104
+
1105
+ def test_operate
1106
+ # identity operation
1107
+ rotation = [
1108
+ [1, 0, 0],
1109
+ [0, 1, 0],
1110
+ [0, 0, 1],
1111
+ ]
1112
+ translation = [0.0, 0.0, 0.0]
1113
+ result = @c01.operate(rotation, translation)
1114
+ assert_in_delta( 0.0, result.atoms[0].position[0], $tolerance)
1115
+ assert_in_delta( 0.0, result.atoms[0].position[1], $tolerance)
1116
+ assert_in_delta( 0.0, result.atoms[0].position[2], $tolerance)
1117
+ assert_in_delta( 0.1, result.atoms[1].position[0], $tolerance)
1118
+ assert_in_delta( 0.2, result.atoms[1].position[1], $tolerance)
1119
+ assert_in_delta( 0.3, result.atoms[1].position[2], $tolerance)
1120
+
1121
+ # rotation
1122
+ rotation = [
1123
+ [1, 0, 0],
1124
+ [0, 1, 0],
1125
+ [0, 0,-1],
1126
+ ]
1127
+ translation = [0.0, 0.0, 0.0]
1128
+ result = @c01.operate(rotation, translation)
1129
+ assert_in_delta( 0.0, result.atoms[0].position[0], $tolerance)
1130
+ assert_in_delta( 0.0, result.atoms[0].position[1], $tolerance)
1131
+ assert_in_delta( 0.0, result.atoms[0].position[2], $tolerance)
1132
+ assert_in_delta( 0.1, result.atoms[1].position[0], $tolerance)
1133
+ assert_in_delta( 0.2, result.atoms[1].position[1], $tolerance)
1134
+ assert_in_delta(-0.3, result.atoms[1].position[2], $tolerance)
1135
+
1136
+ # translation
1137
+ rotation = [
1138
+ [1, 0, 0],
1139
+ [0, 1, 0],
1140
+ [0, 0, 1],
1141
+ ]
1142
+ translation = [0.1, 0.2, 0.3]
1143
+ result = @c01.operate(rotation, translation)
1144
+ assert_in_delta(0.1, result.atoms[0].position[0], $tolerance)
1145
+ assert_in_delta(0.2, result.atoms[0].position[1], $tolerance)
1146
+ assert_in_delta(0.3, result.atoms[0].position[2], $tolerance)
1147
+ assert_in_delta(0.2, result.atoms[1].position[0], $tolerance)
1148
+ assert_in_delta(0.4, result.atoms[1].position[1], $tolerance)
1149
+ assert_in_delta(0.6, result.atoms[1].position[2], $tolerance)
1150
+
1151
+ # rotation & translation
1152
+ rotation = [
1153
+ [1, 0, 0],
1154
+ [0, 1, 0],
1155
+ [0, 0,-1],
1156
+ ]
1157
+ translation = [0.1, 0.2, 0.3]
1158
+ result = @c01.operate(rotation, translation)
1159
+ assert_in_delta(0.1, result.atoms[0].position[0], $tolerance)
1160
+ assert_in_delta(0.2, result.atoms[0].position[1], $tolerance)
1161
+ assert_in_delta(0.3, result.atoms[0].position[2], $tolerance)
1162
+ assert_in_delta(0.2, result.atoms[1].position[0], $tolerance)
1163
+ assert_in_delta(0.4, result.atoms[1].position[1], $tolerance)
1164
+ assert_in_delta(0.0, result.atoms[1].position[2], $tolerance)
1165
+ end
1166
+
1167
+ end