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.
data/test/test_cell.rb CHANGED
@@ -1,1486 +1,1503 @@
1
+ #! /usr/bin/env ruby
1
2
  #! /usr/bin/ruby1.9 -W
2
3
 
3
4
  require "helper"
4
5
  require 'stringio'
5
6
 
6
7
  class CrystalCell::Cell
7
- public :symmetry_operations
8
+ public :symmetry_operations
8
9
  end
9
10
 
10
11
  class FooCell < CrystalCell::Cell; end
11
12
 
12
13
  class TC_Cell < Test::Unit::TestCase
13
- $tolerance = 10 ** (-10)
14
- $symprec = 1.0e-05
15
- $angle_tolerance = -1.0
16
-
17
- def setup
18
- # 原子のないセル。
19
- vectors00 = [[2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0]]
20
- axes00 = CrystalCell::LatticeAxes.new([[2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0]])
21
- @c00 = CrystalCell::Cell.new(axes00)
22
- @c00.comment = 'c00'
23
-
24
- # 元素の識別子を数字にしたもの。
25
- atoms = [
26
- CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0] ),
27
- CrystalCell::Atom.new( 1, [0.1, 0.2, 0.3] ),
28
- ]
29
- @c01 = CrystalCell::Cell.new(axes00, atoms)
30
- @c01.comment = 'c01'
31
-
32
- # Li と O を1つずつ入れたセル。
33
- # @c02 = CrystalCell::Cell.new( [ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0] ] )
34
- atoms = [
35
- CrystalCell::Atom.new( 'Li', [0.0, 0.0, 0.0] ),
36
- CrystalCell::Atom.new( 'O' , [0.2, 0.2, 0.2] ),
37
- ]
38
- @c02 = CrystalCell::Cell.new(vectors00, atoms)
39
- @c02.comment = 'c02'
40
-
41
- # 原子の順序を逆にしたもの。
42
- atoms = [
43
- CrystalCell::Atom.new( 'O' , [0.2, 0.2, 0.2] ),
44
- CrystalCell::Atom.new( 'Li', [0.0, 0.0, 0.0] ),
45
- ]
46
- @c03 = CrystalCell::Cell.new(vectors00, atoms)
47
- @c03.comment = 'c03'
48
-
49
- # 原子の順序がいりまじったもの
50
- atoms = [
51
- CrystalCell::Atom.new( 'Li', [0.0, 0.0, 0.0] ),
52
- CrystalCell::Atom.new( 'O' , [0.2, 0.2, 0.2] ),
53
- CrystalCell::Atom.new( 'Li', [0.1, 0.2, 0.3] ),
54
- ]
55
- @c04 = CrystalCell::Cell.new(vectors00, atoms)
56
- @c04.comment = 'c04'
57
-
58
- # 原子が不足しているもの。
59
- atoms = [
60
- CrystalCell::Atom.new( 'Li', [0.0, 0.0, 0.0] ),
61
- ]
62
- @c05 = CrystalCell::Cell.new(vectors00, atoms)
63
- @c05.comment = 'c05'
64
-
65
- # Selective dynamics をいれたもの。
66
- atoms = [
67
- CrystalCell::Atom.new( 'Li', [0.0, 0.0, 0.0], nil, [true, false, false ] ),
68
- CrystalCell::Atom.new( 'O' , [0.2, 0.2, 0.2] ),
69
- ]
70
- @c06 = CrystalCell::Cell.new(vectors00, atoms)
71
- @c06.comment = 'c06'
72
-
73
- # 元素の識別子を数字にしたもの。
74
- atoms = [
75
- CrystalCell::Atom.new( 0, Mageo::Vector3DInternal[0.0, 0.0, 0.0] ),
76
- CrystalCell::Atom.new( 1, Mageo::Vector3DInternal[0.2, 0.2, 0.2] ),
77
- ]
78
- @c07 = CrystalCell::Cell.new(vectors00, atoms)
79
- @c07.comment = 'c07'
80
-
81
- # セル外の座標の原子を追加。
82
- atoms = [
83
- CrystalCell::Atom.new( 'Li', [ 1.2, 3.4, 5.6], "atom0", [ false, false, true] ),
84
- CrystalCell::Atom.new( 'O', [-1.2, -3.4, -5.6] ),
85
- ]
86
- @c08 = CrystalCell::Cell.new(vectors00, atoms)
87
- @c08.comment = 'c08'
88
-
89
- #cubic
90
- axes = CrystalCell::LatticeAxes.new(
91
- [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
92
- )
93
- atoms = [
94
- CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0] )
95
- ]
96
- @c10 = CrystalCell::Cell.new( axes, atoms)
97
- @c10.comment = 'cubic'
98
-
99
- #hexagonal
100
- axes = CrystalCell::LatticeAxes.new(
101
- [
102
- [0.86602540378443864676, 0.5, 0.0],
103
- [0.0, 1.0, 0.0],
104
- [0.0, 0.0, 1.0],
105
- ]
106
- )
107
- atoms = [
108
- CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0] )
109
- ]
110
- @c11 = CrystalCell::Cell.new( axes, atoms)
111
- @c11.comment = 'hexagonal'
112
-
113
- #monoclinic
114
- axes = CrystalCell::LatticeAxes.new(
115
- [ [1.5, 1.4, 0.0],
116
- [0.0, 1.2, 0.0],
117
- [0.0, 0.0, 1.0],
118
- ]
119
- )
120
- atoms = [
121
- CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0]),
122
- #CrystalCell::Atom.new( 0, [0.1, 0.2, 0.3]),
123
- #CrystalCell::Atom.new( 0, [0.2, 0.3, 0.4]),
124
- ]
125
- @c12 = CrystalCell::Cell.new( axes, atoms)
126
- @c12.comment = 'monoclinic'
127
-
128
- #orthorhombic
129
- axes = CrystalCell::LatticeAxes.new(
130
- [
131
- [3.0, 0.0, 0.0],
132
- [0.0, 2.0, 0.0],
133
- [0.0, 0.0, 1.0],
134
- ]
135
- )
136
- atoms = [
137
- CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0])
138
- ]
139
- @c13 = CrystalCell::Cell.new( axes, atoms)
140
- @c13.comment = 'orthorhombic'
141
-
142
- #tetragonal
143
- axes = CrystalCell::LatticeAxes.new(
144
- [
145
- [2.0, 0.0, 0.0],
146
- [0.0, 2.0, 0.0],
147
- [0.0, 0.0, 1.0],
148
- ]
149
- )
150
- atoms = [
151
- CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0], )
152
- ]
153
- @c14 = CrystalCell::Cell.new( axes, atoms)
154
- @c14.comment = 'tetragonal'
155
-
156
- #tetragonal-b
157
- axes = CrystalCell::LatticeAxes.new(
158
- [
159
- [2.0, 0.0, 0.0],
160
- [0.0, 1.0, 0.0],
161
- [0.0, 0.0, 2.0],
162
- ]
163
- )
164
- atoms = [
165
- CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0], )
166
- ]
167
- @c14b = CrystalCell::Cell.new( axes, atoms)
168
- @c14b.comment = 'tetragonal-b'
169
-
170
- #triclinic
171
- axes = CrystalCell::LatticeAxes.new(
172
- [
173
- [1.5, 1.4, 1.3],
174
- [0.0, 1.2, 1.1],
175
- [0.0, 0.0, 1.0],
176
- ]
177
- )
178
- atoms = [
179
- CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0] ),
180
- CrystalCell::Atom.new( 0, [0.1, 0.2, 0.3] ),
181
- CrystalCell::Atom.new( 0, [0.2, 0.3, 0.4] ),
182
- ]
183
- @c15 = CrystalCell::Cell.new( axes, atoms)
184
- @c15.comment = 'triclinic'
185
-
186
- #trigonal
187
- axes = CrystalCell::LatticeAxes.new(
188
- [
189
- [0.86602540378443864676, 0.5, 0.0],
190
- [0.0, 1.0, 0.0],
191
- [0.0, 0.0, 1.0],
192
- ]
193
- )
194
- atoms = [
195
- CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0]),
196
- CrystalCell::Atom.new( 0, [0.333333333333333, 0.333333333333333, 0.333333333333333] ),
197
- ]
198
- @c16 = CrystalCell::Cell.new( axes, atoms)
199
- @c16.comment = 'trigonal'
14
+ $tolerance = 10 ** (-10)
15
+ $symprec = 1.0e-05
16
+ $angle_tolerance = -1.0
17
+
18
+ def setup
19
+ # 原子のないセル。
20
+ vectors00 = [[2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0]]
21
+ axes00 = CrystalCell::LatticeAxes.new([[2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0]])
22
+ @c00 = CrystalCell::Cell.new(axes00)
23
+ @c00.comment = 'c00'
24
+
25
+ # 元素の識別子を数字にしたもの。
26
+ atoms = [
27
+ CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0] ),
28
+ CrystalCell::Atom.new( 1, [0.1, 0.2, 0.3] ),
29
+ ]
30
+ @c01 = CrystalCell::Cell.new(axes00, atoms)
31
+ @c01.comment = 'c01'
32
+
33
+ # Li と O を1つずつ入れたセル。
34
+ # @c02 = CrystalCell::Cell.new( [ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0] ] )
35
+ atoms = [
36
+ CrystalCell::Atom.new( 'Li', [0.0, 0.0, 0.0] ),
37
+ CrystalCell::Atom.new( 'O' , [0.2, 0.2, 0.2] ),
38
+ ]
39
+ @c02 = CrystalCell::Cell.new(vectors00, atoms)
40
+ @c02.comment = 'c02'
41
+
42
+ # 原子の順序を逆にしたもの。
43
+ atoms = [
44
+ CrystalCell::Atom.new( 'O' , [0.2, 0.2, 0.2] ),
45
+ CrystalCell::Atom.new( 'Li', [0.0, 0.0, 0.0] ),
46
+ ]
47
+ @c03 = CrystalCell::Cell.new(vectors00, atoms)
48
+ @c03.comment = 'c03'
49
+
50
+ # 原子の順序がいりまじったもの
51
+ atoms = [
52
+ CrystalCell::Atom.new( 'Li', [0.0, 0.0, 0.0] ),
53
+ CrystalCell::Atom.new( 'O' , [0.2, 0.2, 0.2] ),
54
+ CrystalCell::Atom.new( 'Li', [0.1, 0.2, 0.3] ),
55
+ ]
56
+ @c04 = CrystalCell::Cell.new(vectors00, atoms)
57
+ @c04.comment = 'c04'
58
+
59
+ # 原子が不足しているもの。
60
+ atoms = [
61
+ CrystalCell::Atom.new( 'Li', [0.0, 0.0, 0.0] ),
62
+ ]
63
+ @c05 = CrystalCell::Cell.new(vectors00, atoms)
64
+ @c05.comment = 'c05'
65
+
66
+ # Selective dynamics をいれたもの。
67
+ atoms = [
68
+ CrystalCell::Atom.new( 'Li', [0.0, 0.0, 0.0], nil, [true, false, false ] ),
69
+ CrystalCell::Atom.new( 'O' , [0.2, 0.2, 0.2] ),
70
+ ]
71
+ @c06 = CrystalCell::Cell.new(vectors00, atoms)
72
+ @c06.comment = 'c06'
73
+
74
+ # 元素の識別子を数字にしたもの。
75
+ atoms = [
76
+ CrystalCell::Atom.new( 0, Mageo::Vector3DInternal[0.0, 0.0, 0.0] ),
77
+ CrystalCell::Atom.new( 1, Mageo::Vector3DInternal[0.2, 0.2, 0.2] ),
78
+ ]
79
+ @c07 = CrystalCell::Cell.new(vectors00, atoms)
80
+ @c07.comment = 'c07'
81
+
82
+ # セル外の座標の原子を追加。
83
+ atoms = [
84
+ CrystalCell::Atom.new( 'Li', [ 1.2, 3.4, 5.6], "atom0", [ false, false, true] ),
85
+ CrystalCell::Atom.new( 'O', [-1.2, -3.4, -5.6] ),
86
+ ]
87
+ @c08 = CrystalCell::Cell.new(vectors00, atoms)
88
+ @c08.comment = 'c08'
89
+
90
+ #cubic
91
+ axes = CrystalCell::LatticeAxes.new(
92
+ [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
93
+ )
94
+ atoms = [
95
+ CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0] )
96
+ ]
97
+ @c10 = CrystalCell::Cell.new( axes, atoms)
98
+ @c10.comment = 'cubic'
99
+
100
+ #hexagonal
101
+ axes = CrystalCell::LatticeAxes.new(
102
+ [
103
+ [0.86602540378443864676, 0.5, 0.0],
104
+ [0.0, 1.0, 0.0],
105
+ [0.0, 0.0, 1.0],
106
+ ]
107
+ )
108
+ atoms = [
109
+ CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0] )
110
+ ]
111
+ @c11 = CrystalCell::Cell.new( axes, atoms)
112
+ @c11.comment = 'hexagonal'
113
+
114
+ #monoclinic
115
+ axes = CrystalCell::LatticeAxes.new(
116
+ [ [1.5, 1.4, 0.0],
117
+ [0.0, 1.2, 0.0],
118
+ [0.0, 0.0, 1.0],
119
+ ]
120
+ )
121
+ atoms = [
122
+ CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0]),
123
+ #CrystalCell::Atom.new( 0, [0.1, 0.2, 0.3]),
124
+ #CrystalCell::Atom.new( 0, [0.2, 0.3, 0.4]),
125
+ ]
126
+ @c12 = CrystalCell::Cell.new( axes, atoms)
127
+ @c12.comment = 'monoclinic'
128
+
129
+ #orthorhombic
130
+ axes = CrystalCell::LatticeAxes.new(
131
+ [
132
+ [3.0, 0.0, 0.0],
133
+ [0.0, 2.0, 0.0],
134
+ [0.0, 0.0, 1.0],
135
+ ]
136
+ )
137
+ atoms = [
138
+ CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0])
139
+ ]
140
+ @c13 = CrystalCell::Cell.new( axes, atoms)
141
+ @c13.comment = 'orthorhombic'
142
+
143
+ #tetragonal
144
+ axes = CrystalCell::LatticeAxes.new(
145
+ [
146
+ [2.0, 0.0, 0.0],
147
+ [0.0, 2.0, 0.0],
148
+ [0.0, 0.0, 1.0],
149
+ ]
150
+ )
151
+ atoms = [
152
+ CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0], )
153
+ ]
154
+ @c14 = CrystalCell::Cell.new( axes, atoms)
155
+ @c14.comment = 'tetragonal'
156
+
157
+ #tetragonal-b
158
+ axes = CrystalCell::LatticeAxes.new(
159
+ [
160
+ [2.0, 0.0, 0.0],
161
+ [0.0, 1.0, 0.0],
162
+ [0.0, 0.0, 2.0],
163
+ ]
164
+ )
165
+ atoms = [
166
+ CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0], )
167
+ ]
168
+ @c14b = CrystalCell::Cell.new( axes, atoms)
169
+ @c14b.comment = 'tetragonal-b'
170
+
171
+ #triclinic
172
+ axes = CrystalCell::LatticeAxes.new(
173
+ [
174
+ [1.5, 1.4, 1.3],
175
+ [0.0, 1.2, 1.1],
176
+ [0.0, 0.0, 1.0],
177
+ ]
178
+ )
179
+ atoms = [
180
+ CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0] ),
181
+ CrystalCell::Atom.new( 0, [0.1, 0.2, 0.3] ),
182
+ CrystalCell::Atom.new( 0, [0.2, 0.3, 0.4] ),
183
+ ]
184
+ @c15 = CrystalCell::Cell.new( axes, atoms)
185
+ @c15.comment = 'triclinic'
186
+
187
+ #trigonal
188
+ axes = CrystalCell::LatticeAxes.new(
189
+ [
190
+ [0.86602540378443864676, 0.5, 0.0],
191
+ [0.0, 1.0, 0.0],
192
+ [0.0, 0.0, 1.0],
193
+ ]
194
+ )
195
+ atoms = [
196
+ CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0]),
197
+ CrystalCell::Atom.new( 0, [0.333333333333333, 0.333333333333333, 0.333333333333333] ),
198
+ ]
199
+ @c16 = CrystalCell::Cell.new( axes, atoms)
200
+ @c16.comment = 'trigonal'
201
+ end
202
+
203
+ def test_initialize
204
+ la = CrystalCell::LatticeAxes.new( [ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0] ] )
205
+ c10 = CrystalCell::Cell.new( la )
206
+ c10.comment = 'c00'
207
+ assert_equal( CrystalCell::Cell, c10.class )
208
+ assert_in_delta( 2.0, c10.axes[0][0], $tolerance )
209
+ assert_in_delta( 2.0, c10.axes[0][1], $tolerance )
210
+ assert_in_delta( 2.0, c10.axes[0][2], $tolerance )
211
+ assert_in_delta( 0.0, c10.axes[1][0], $tolerance )
212
+ assert_in_delta( 2.0, c10.axes[1][1], $tolerance )
213
+ assert_in_delta( 2.0, c10.axes[1][2], $tolerance )
214
+ assert_in_delta( 0.0, c10.axes[2][0], $tolerance )
215
+ assert_in_delta( 0.0, c10.axes[2][1], $tolerance )
216
+ assert_in_delta( 2.0, c10.axes[2][2], $tolerance )
217
+
218
+
219
+ end
220
+
221
+ def test_positions
222
+ assert_equal( [], @c00.positions)
223
+ assert_equal( [ Mageo::Vector3DInternal[0.0, 0.0, 0.0], Mageo::Vector3DInternal[0.2, 0.2, 0.2] ], @c02.positions )
224
+ assert_equal( [ Mageo::Vector3DInternal[0.0, 0.0, 0.0], Mageo::Vector3DInternal[0.1, 0.2, 0.3] ], @c01.positions )
225
+ end
226
+
227
+ def test_select_indices
228
+ assert_equal( [], @c00.select_indices{ |i| i.element == "" } )
229
+ assert_equal( [], @c00.select_indices{ |i| i.element == "Li" } )
230
+
231
+ assert_equal( [] , @c01.select_indices{ |i| i.element == "" } )
232
+ assert_equal( [] , @c01.select_indices{ |i| i.element == "Li" } )
233
+ #@c01.select_indices{ |i| p i.element }
234
+ assert_equal( [0], @c01.select_indices{ |i| i.element == 0 } )
235
+
236
+ assert_equal( [1], @c01.select_indices{ |i| i.element == 1 } )
237
+
238
+ assert_equal( [] , @c04.select_indices{ |i| i.element == "" } )
239
+ assert_equal( [0, 2], @c04.select_indices{ |i| i.element == "Li" } )
240
+ assert_equal( [1], @c04.select_indices{ |i| i.element == "O" } )
241
+ assert_equal( [ ], @c04.select_indices{ |i| i.element == 0 } )
242
+ assert_equal( [ ], @c04.select_indices{ |i| i.element == 1 } )
243
+
244
+ assert_equal( [1, 2], @c04.select_indices{ |i| i.position[0] > 0.05 } )
245
+ end
246
+
247
+ def test_atoms_in_supercell
248
+ t = @c02.atoms_in_supercell( 0, 0, 0, 0, 0, 1 )
249
+ assert_equal( 'Li', t[0].element )
250
+ assert_equal( 'Li', t[1].element )
251
+ assert_equal( 'O' , t[2].element )
252
+ assert_equal( 'O' , t[3].element )
253
+
254
+ assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t[0].position )
255
+ assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 1.0], t[1].position )
256
+ assert_equal( Mageo::Vector3DInternal[0.2, 0.2, 0.2], t[2].position )
257
+ assert_equal( Mageo::Vector3DInternal[0.2, 0.2, 1.2], t[3].position )
258
+
259
+ t = @c02.atoms_in_supercell(-1, 1,-1, 1,-1, 1 )
260
+ assert_equal( ['Li']*27 + ['O'] * 27 , t.map{|i| i.element} )
261
+ assert_equal( Mageo::Vector3DInternal[-1.0, -1.0, -1.0], t[ 0].position )
262
+ assert_equal( Mageo::Vector3DInternal[-1.0, -1.0, 0.0], t[ 1].position )
263
+ assert_equal( Mageo::Vector3DInternal[-1.0, -1.0, 1.0], t[ 2].position )
264
+ assert_equal( Mageo::Vector3DInternal[-1.0, 0.0, -1.0], t[ 3].position )
265
+ assert_equal( Mageo::Vector3DInternal[-1.0, 0.0, 0.0], t[ 4].position )
266
+ assert_equal( Mageo::Vector3DInternal[-1.0, 0.0, 1.0], t[ 5].position )
267
+ assert_equal( Mageo::Vector3DInternal[-1.0, 1.0, -1.0], t[ 6].position )
268
+ assert_equal( Mageo::Vector3DInternal[-1.0, 1.0, 0.0], t[ 7].position )
269
+ assert_equal( Mageo::Vector3DInternal[-1.0, 1.0, 1.0], t[ 8].position )
270
+ assert_equal( Mageo::Vector3DInternal[ 0.0, -1.0, -1.0], t[ 9].position )
271
+ assert_equal( Mageo::Vector3DInternal[ 0.0, -1.0, 0.0], t[10].position )
272
+ assert_equal( Mageo::Vector3DInternal[ 0.0, -1.0, 1.0], t[11].position )
273
+ assert_equal( Mageo::Vector3DInternal[ 0.0, 0.0, -1.0], t[12].position )
274
+ assert_equal( Mageo::Vector3DInternal[ 0.0, 0.0, 0.0], t[13].position )
275
+ assert_equal( Mageo::Vector3DInternal[ 0.0, 0.0, 1.0], t[14].position )
276
+ assert_equal( Mageo::Vector3DInternal[ 0.0, 1.0, -1.0], t[15].position )
277
+ assert_equal( Mageo::Vector3DInternal[ 0.0, 1.0, 0.0], t[16].position )
278
+ assert_equal( Mageo::Vector3DInternal[ 0.0, 1.0, 1.0], t[17].position )
279
+ assert_equal( Mageo::Vector3DInternal[ 1.0, -1.0, -1.0], t[18].position )
280
+ assert_equal( Mageo::Vector3DInternal[ 1.0, -1.0, 0.0], t[19].position )
281
+ assert_equal( Mageo::Vector3DInternal[ 1.0, -1.0, 1.0], t[20].position )
282
+ assert_equal( Mageo::Vector3DInternal[ 1.0, 0.0, -1.0], t[21].position )
283
+ assert_equal( Mageo::Vector3DInternal[ 1.0, 0.0, 0.0], t[22].position )
284
+ assert_equal( Mageo::Vector3DInternal[ 1.0, 0.0, 1.0], t[23].position )
285
+ assert_equal( Mageo::Vector3DInternal[ 1.0, 1.0, -1.0], t[24].position )
286
+ assert_equal( Mageo::Vector3DInternal[ 1.0, 1.0, 0.0], t[25].position )
287
+ assert_equal( Mageo::Vector3DInternal[ 1.0, 1.0, 1.0], t[26].position )
288
+ assert_equal( Mageo::Vector3DInternal[-0.8, -0.8, -0.8], t[27].position )
289
+ assert_equal( Mageo::Vector3DInternal[-0.8, -0.8, 0.2], t[28].position )
290
+ assert_equal( Mageo::Vector3DInternal[-0.8, -0.8, 1.2], t[29].position )
291
+ assert_equal( Mageo::Vector3DInternal[-0.8, 0.2, -0.8], t[30].position )
292
+ assert_equal( Mageo::Vector3DInternal[-0.8, 0.2, 0.2], t[31].position )
293
+ assert_equal( Mageo::Vector3DInternal[-0.8, 0.2, 1.2], t[32].position )
294
+ assert_equal( Mageo::Vector3DInternal[-0.8, 1.2, -0.8], t[33].position )
295
+ assert_equal( Mageo::Vector3DInternal[-0.8, 1.2, 0.2], t[34].position )
296
+ assert_equal( Mageo::Vector3DInternal[-0.8, 1.2, 1.2], t[35].position )
297
+ assert_equal( Mageo::Vector3DInternal[ 0.2, -0.8, -0.8], t[36].position )
298
+ assert_equal( Mageo::Vector3DInternal[ 0.2, -0.8, 0.2], t[37].position )
299
+ assert_equal( Mageo::Vector3DInternal[ 0.2, -0.8, 1.2], t[38].position )
300
+ assert_equal( Mageo::Vector3DInternal[ 0.2, 0.2, -0.8], t[39].position )
301
+ assert_equal( Mageo::Vector3DInternal[ 0.2, 0.2, 0.2], t[40].position )
302
+ assert_equal( Mageo::Vector3DInternal[ 0.2, 0.2, 1.2], t[41].position )
303
+ assert_equal( Mageo::Vector3DInternal[ 0.2, 1.2, -0.8], t[42].position )
304
+ assert_equal( Mageo::Vector3DInternal[ 0.2, 1.2, 0.2], t[43].position )
305
+ assert_equal( Mageo::Vector3DInternal[ 0.2, 1.2, 1.2], t[44].position )
306
+ assert_equal( Mageo::Vector3DInternal[ 1.2, -0.8, -0.8], t[45].position )
307
+ assert_equal( Mageo::Vector3DInternal[ 1.2, -0.8, 0.2], t[46].position )
308
+ assert_equal( Mageo::Vector3DInternal[ 1.2, -0.8, 1.2], t[47].position )
309
+ assert_equal( Mageo::Vector3DInternal[ 1.2, 0.2, -0.8], t[48].position )
310
+ assert_equal( Mageo::Vector3DInternal[ 1.2, 0.2, 0.2], t[49].position )
311
+ assert_equal( Mageo::Vector3DInternal[ 1.2, 0.2, 1.2], t[50].position )
312
+ assert_equal( Mageo::Vector3DInternal[ 1.2, 1.2, -0.8], t[51].position )
313
+ assert_equal( Mageo::Vector3DInternal[ 1.2, 1.2, 0.2], t[52].position )
314
+ assert_equal( Mageo::Vector3DInternal[ 1.2, 1.2, 1.2], t[53].position )
315
+ end
316
+
317
+ def test_elements
318
+ assert_equal( [], @c00.elements)
319
+ assert_equal( [ 'Li', 'O' ], @c02.elements )
320
+ assert_equal( [ 0, 1 ], @c01.elements )
321
+ end
322
+
323
+ def test_add_atom
324
+ assert_raise(ArgumentError){
325
+ @c00.add_atom('Li', [0.5, 0.5, 0.5] )
326
+ }
327
+
328
+ @c00.add_atom(CrystalCell::Atom.new( 'Li', [0.5, 0.5, 0.5] ))
329
+ assert_equal( 1 , @c00.atoms.size)
330
+ assert_equal( 'Li' , @c00.atoms[0].element)
331
+ assert_equal( Mageo::Vector3DInternal[0.5, 0.5, 0.5], @c00.atoms[0].position)
332
+ assert_equal( nil , @c00.atoms[0].name )
333
+
334
+ @c00.add_atom(CrystalCell::Atom.new( nil , [0.5, 0.5, 0.5], 'A' ))
335
+ assert_equal( 2 , @c00.atoms.size)
336
+ assert_equal( nil , @c00.atoms[1].element)
337
+ assert_equal( Mageo::Vector3DInternal[0.5, 0.5, 0.5], @c00.atoms[1].position)
338
+ assert_equal( 'A' , @c00.atoms[1].name )
339
+
340
+ @c02.add_atom(CrystalCell::Atom.new( 'Li', [0.5, 0.5, 0.5] ))
341
+ assert_equal( 3 , @c02.atoms.size)
342
+ assert_equal( 'Li' , @c02.atoms[0].element)
343
+ assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], @c02.atoms[0].position)
344
+ assert_equal( 'O' , @c02.atoms[1].element)
345
+ assert_equal( Mageo::Vector3DInternal[0.2, 0.2, 0.2], @c02.atoms[1].position)
346
+ assert_equal( 'Li' , @c02.atoms[2].element)
347
+ assert_equal( Mageo::Vector3DInternal[0.5, 0.5, 0.5], @c02.atoms[2].position)
348
+
349
+ @c01.add_atom(CrystalCell::Atom.new( 'Li', [0.5, 0.5, 0.5] ))
350
+ assert_equal( 3 , @c01.atoms.size)
351
+ assert_equal( 0 , @c01.atoms[0].element)
352
+ assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], @c01.atoms[0].position)
353
+ assert_equal( 1 , @c01.atoms[1].element)
354
+ assert_equal( Mageo::Vector3DInternal[0.1, 0.2, 0.3], @c01.atoms[1].position)
355
+ assert_equal( 'Li' , @c01.atoms[2].element)
356
+ assert_equal( Mageo::Vector3DInternal[0.5, 0.5, 0.5], @c01.atoms[2].position)
357
+
358
+ end
359
+
360
+ def test_delete_atom
361
+ # assert_raise(RuntimeError ) {@c00.delete_atom( 0 ) }
362
+ assert_equal(nil, @c00.delete_atom( 0 ) )
363
+ assert_equal([], @c00.positions )
364
+ assert_equal([], @c00.elements )
365
+
366
+ @c02.delete_atom( 0 )
367
+ assert_equal( [ Mageo::Vector3DInternal[0.2, 0.2, 0.2] ], @c02.positions)
368
+ assert_equal( [ 'O' ], @c02.elements )
369
+ @c02.delete_atom( 0 )
370
+ assert_equal( [], @c02.positions)
371
+ assert_equal( [], @c02.elements )
372
+
373
+ @c01.delete_atom( 0 )
374
+ assert_equal( [ Mageo::Vector3DInternal[0.1, 0.2, 0.3] ], @c01.positions)
375
+ assert_equal( [ 1 ], @c01.elements )
376
+ end
377
+
378
+ def test_set_elements
379
+ # 原子がないので変更されない。
380
+ @c00.set_elements( [] )
381
+ assert_equal( [], @c00.atoms )
382
+
383
+ # 0 -> 'Li、 1 -> 'O' に変更。
384
+ tmp = Marshal.load( Marshal.dump( @c01 ))
385
+ tmp.set_elements( [ 'Li', 'O' ] )
386
+ assert_equal( 'Li', tmp.atoms[0].element )
387
+ assert_equal( 'O', tmp.atoms[1].element )
388
+
389
+ # 0 -> 'Li, 片方だけ変更。
390
+ tmp = Marshal.load( Marshal.dump( @c01 ))
391
+ tmp.set_elements( [ 'Li' ] )
392
+ assert_equal( 'Li', tmp.atoms[0].element )
393
+ assert_equal( 1, tmp.atoms[1].element )
394
+
395
+ # 元々整数値以外にセットされているのでマッチせず変更されない。
396
+ tmp = Marshal.load( Marshal.dump( @c02 ))
397
+ tmp.set_elements( [ 'O', 'Li' ] )
398
+ assert_equal( 'Li', tmp.atoms[0].element )
399
+ assert_equal( 'O', tmp.atoms[1].element )
400
+
401
+ # Hash argument.
402
+ # 0 -> 'Li、 1 -> 'O' に変更。
403
+ tmp = Marshal.load( Marshal.dump( @c01 ))
404
+ tmp.set_elements( { 0 => 'Li', 1 => 'O' } )
405
+ assert_equal( 'Li', tmp.atoms[0].element )
406
+ assert_equal( 'O', tmp.atoms[1].element )
407
+
408
+ # 'Li' -> 'Na', 'O' -> 'S' に変更。
409
+ tmp = Marshal.load( Marshal.dump( @c02 ))
410
+ tmp.set_elements( { 'Li' => 'Na', 'O' => 'S' } )
411
+ assert_equal( 'Na', tmp.atoms[0].element )
412
+ assert_equal( 'S', tmp.atoms[1].element )
413
+
414
+ # 'Li' -> 'Na'、 片方だけ変更。
415
+ tmp = Marshal.load( Marshal.dump( @c02 ))
416
+ tmp.set_elements( { 'Li' => 'Na' } )
417
+ assert_equal( 'Na', tmp.atoms[0].element )
418
+ assert_equal( 'O', tmp.atoms[1].element )
419
+ end
420
+
421
+ def test_equal_lattice_in_delta?
422
+ assert_equal( true , @c00.equal_lattice_in_delta?(@c00, 0.001, 0.1) )
423
+ assert_equal( true , @c00.equal_lattice_in_delta?(@c02, 0.001, 0.1) )
424
+ assert_equal( true , @c00.equal_lattice_in_delta?(@c01, 0.001, 0.1) )
425
+ assert_equal( true , @c02.equal_lattice_in_delta?(@c00, 0.001, 0.1) )
426
+ assert_equal( true , @c02.equal_lattice_in_delta?(@c02, 0.001, 0.1) )
427
+ assert_equal( true , @c02.equal_lattice_in_delta?(@c01, 0.001, 0.1) )
428
+ assert_equal( true , @c01.equal_lattice_in_delta?(@c00, 0.001, 0.1) )
429
+ assert_equal( true , @c01.equal_lattice_in_delta?(@c02, 0.001, 0.1) )
430
+ assert_equal( true , @c01.equal_lattice_in_delta?(@c01, 0.001, 0.1) )
431
+
432
+ end
433
+
434
+ def test_equal_atoms_in_delta?
435
+ assert_equal( true , @c00.equal_atoms_in_delta?( @c00, 0.01 ) )
436
+ assert_equal( false, @c00.equal_atoms_in_delta?( @c02, 0.01 ) )
437
+ assert_equal( false, @c00.equal_atoms_in_delta?( @c01, 0.01 ) )
438
+ assert_equal( false, @c00.equal_atoms_in_delta?( @c03, 0.01 ) )
439
+ assert_equal( false, @c00.equal_atoms_in_delta?( @c04, 0.01 ) )
440
+ assert_equal( false, @c00.equal_atoms_in_delta?( @c05, 0.01 ) )
441
+ assert_equal( false, @c02.equal_atoms_in_delta?( @c00, 0.01 ) )
442
+ assert_equal( true , @c02.equal_atoms_in_delta?( @c02, 0.01 ) )
443
+ assert_equal( false, @c02.equal_atoms_in_delta?( @c01, 0.01 ) )
444
+ assert_equal( true , @c02.equal_atoms_in_delta?( @c03, 0.01 ) )
445
+ assert_equal( false, @c02.equal_atoms_in_delta?( @c04, 0.01 ) )
446
+ assert_equal( false, @c02.equal_atoms_in_delta?( @c05, 0.01 ) )
447
+ assert_equal( false, @c01.equal_atoms_in_delta?( @c00, 0.01 ) )
448
+ assert_equal( false, @c01.equal_atoms_in_delta?( @c02, 0.01 ) )
449
+ assert_equal( true , @c01.equal_atoms_in_delta?( @c01, 0.01 ) )
450
+ assert_equal( false, @c01.equal_atoms_in_delta?( @c03, 0.01 ) )
451
+ assert_equal( false, @c01.equal_atoms_in_delta?( @c04, 0.01 ) )
452
+ assert_equal( false, @c01.equal_atoms_in_delta?( @c05, 0.01 ) )
453
+ assert_equal( false, @c03.equal_atoms_in_delta?( @c00, 0.01 ) )
454
+ assert_equal( true , @c03.equal_atoms_in_delta?( @c02, 0.01 ) )
455
+ assert_equal( false, @c03.equal_atoms_in_delta?( @c01, 0.01 ) )
456
+ assert_equal( true , @c03.equal_atoms_in_delta?( @c03, 0.01 ) )
457
+ assert_equal( false, @c03.equal_atoms_in_delta?( @c04, 0.01 ) )
458
+ assert_equal( false, @c03.equal_atoms_in_delta?( @c05, 0.01 ) )
459
+ assert_equal( false, @c04.equal_atoms_in_delta?( @c00, 0.01 ) )
460
+ assert_equal( false, @c04.equal_atoms_in_delta?( @c02, 0.01 ) )
461
+ assert_equal( false, @c04.equal_atoms_in_delta?( @c01, 0.01 ) )
462
+ assert_equal( false, @c04.equal_atoms_in_delta?( @c03, 0.01 ) )
463
+ assert_equal( true , @c04.equal_atoms_in_delta?( @c04, 0.01 ) )
464
+ assert_equal( false, @c04.equal_atoms_in_delta?( @c05, 0.01 ) )
465
+ assert_equal( false, @c05.equal_atoms_in_delta?( @c00, 0.01 ) )
466
+ assert_equal( false, @c05.equal_atoms_in_delta?( @c02, 0.01 ) )
467
+ assert_equal( false, @c05.equal_atoms_in_delta?( @c01, 0.01 ) )
468
+ assert_equal( false, @c05.equal_atoms_in_delta?( @c03, 0.01 ) )
469
+ assert_equal( false, @c05.equal_atoms_in_delta?( @c04, 0.01 ) )
470
+ assert_equal( true , @c05.equal_atoms_in_delta?( @c05, 0.01 ) )
471
+ end
472
+
473
+ def test_equal_in_delta?
474
+ assert_equal(true , @c00.equal_in_delta?( @c00, 0.001, 0.1, 0.01 ) )
475
+ assert_equal(false, @c00.equal_in_delta?( @c01, 0.001, 0.1, 0.01 ) )
476
+ assert_equal(false, @c00.equal_in_delta?( @c02, 0.001, 0.1, 0.01 ) )
477
+ assert_equal(false, @c00.equal_in_delta?( @c03, 0.001, 0.1, 0.01 ) )
478
+ assert_equal(false, @c00.equal_in_delta?( @c04, 0.001, 0.1, 0.01 ) )
479
+ assert_equal(false, @c00.equal_in_delta?( @c05, 0.001, 0.1, 0.01 ) )
480
+
481
+ assert_equal(false, @c02.equal_in_delta?( @c00, 0.001, 0.1, 0.01 ) )
482
+ assert_equal(false, @c02.equal_in_delta?( @c01, 0.001, 0.1, 0.01 ) )
483
+ assert_equal(true , @c02.equal_in_delta?( @c02, 0.001, 0.1, 0.01 ) )
484
+ assert_equal(true , @c02.equal_in_delta?( @c03, 0.001, 0.1, 0.01 ) )
485
+ assert_equal(false, @c02.equal_in_delta?( @c04, 0.001, 0.1, 0.01 ) )
486
+ assert_equal(false, @c02.equal_in_delta?( @c05, 0.001, 0.1, 0.01 ) )
487
+
488
+ assert_equal(false, @c01.equal_in_delta?( @c00, 0.001, 0.1, 0.01 ) )
489
+ assert_equal(true , @c01.equal_in_delta?( @c01, 0.001, 0.1, 0.01 ) )
490
+ assert_equal(false, @c01.equal_in_delta?( @c02, 0.001, 0.1, 0.01 ) )
491
+ assert_equal(false, @c01.equal_in_delta?( @c03, 0.001, 0.1, 0.01 ) )
492
+ assert_equal(false, @c01.equal_in_delta?( @c04, 0.001, 0.1, 0.01 ) )
493
+ assert_equal(false, @c01.equal_in_delta?( @c05, 0.001, 0.1, 0.01 ) )
494
+
495
+ assert_equal(false, @c03.equal_in_delta?( @c00, 0.001, 0.1, 0.01 ) )
496
+ assert_equal(false, @c03.equal_in_delta?( @c01, 0.001, 0.1, 0.01 ) )
497
+ assert_equal(true , @c03.equal_in_delta?( @c02, 0.001, 0.1, 0.01 ) )
498
+ assert_equal(true , @c03.equal_in_delta?( @c03, 0.001, 0.1, 0.01 ) )
499
+ assert_equal(false, @c03.equal_in_delta?( @c04, 0.001, 0.1, 0.01 ) )
500
+ assert_equal(false, @c03.equal_in_delta?( @c05, 0.001, 0.1, 0.01 ) )
501
+
502
+ assert_equal(false, @c04.equal_in_delta?( @c00, 0.001, 0.1, 0.01 ) )
503
+ assert_equal(false, @c04.equal_in_delta?( @c01, 0.001, 0.1, 0.01 ) )
504
+ assert_equal(false, @c04.equal_in_delta?( @c02, 0.001, 0.1, 0.01 ) )
505
+ assert_equal(false, @c04.equal_in_delta?( @c03, 0.001, 0.1, 0.01 ) )
506
+ assert_equal(true , @c04.equal_in_delta?( @c04, 0.001, 0.1, 0.01 ) )
507
+ assert_equal(false, @c04.equal_in_delta?( @c05, 0.001, 0.1, 0.01 ) )
508
+
509
+ assert_equal(false, @c05.equal_in_delta?( @c00, 0.001, 0.1, 0.01 ) )
510
+ assert_equal(false, @c05.equal_in_delta?( @c01, 0.001, 0.1, 0.01 ) )
511
+ assert_equal(false, @c05.equal_in_delta?( @c02, 0.001, 0.1, 0.01 ) )
512
+ assert_equal(false, @c05.equal_in_delta?( @c03, 0.001, 0.1, 0.01 ) )
513
+ assert_equal(false, @c05.equal_in_delta?( @c04, 0.001, 0.1, 0.01 ) )
514
+ assert_equal(true , @c05.equal_in_delta?( @c05, 0.001, 0.1, 0.01 ) )
515
+ end
516
+
517
+ def test_equal
518
+ cell = CrystalCell::Cell.new( CrystalCell::LatticeAxes.new([ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0]]))
519
+ assert_equal( true , @c00 == cell )
520
+ assert_equal( false, @c01 == cell )
521
+
522
+ cell = CrystalCell::Cell.new( CrystalCell::LatticeAxes.new([ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0]]))
523
+ cell.add_atom(CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0] ))
524
+ cell.add_atom(CrystalCell::Atom.new( 1, [0.1, 0.2, 0.3] ))
525
+ assert_equal( false, @c00 == cell )
526
+ assert_equal( true , @c01 == cell )
527
+ end
528
+
529
+ def test_distance
530
+ assert_raise(CrystalCell::Cell::TypeError){@c00.distance([0,0,0], [1,1,1])}
531
+ assert_raise(CrystalCell::Cell::TypeError){@c00.distance([0,0,0], Mageo::Vector3DInternal[1,1,1])}
532
+ assert_raise(CrystalCell::Cell::TypeError){@c00.distance([0,0,0], Mageo::Vector3D[1,1,1])}
533
+
534
+ assert_in_delta(
535
+ Math::sqrt(0.56),
536
+ @c00.distance(Mageo::Vector3DInternal[0.0, 0.0, 0.0], Mageo::Vector3DInternal[0.1, 0.1, 0.1] ),
537
+ $tolerance
538
+ )
539
+ assert_in_delta( Math::sqrt( 1.6**2 + 3.4**2 + 5.4**2),
540
+ @c00.distance( Mageo::Vector3DInternal[0.0, 0.0, 0.0], Mageo::Vector3DInternal[0.8, 0.9, 1.0] ), $tolerance
541
+ )
542
+
543
+ assert_in_delta( Math::sqrt(0.56), @c00.distance( Mageo::Vector3DInternal[0.0, 0.0, 0.0], Mageo::Vector3DInternal[0.1, 0.1, 0.1] ), $tolerance )
544
+ assert_in_delta( Math::sqrt( 1.6**2 + 3.4**2 + 5.4**2),
545
+ @c00.distance( Mageo::Vector3DInternal[0.0, 0.0, 0.0], Mageo::Vector3DInternal[0.8, 0.9, 1.0] ), $tolerance
546
+ )
547
+ end
548
+
549
+ #def test_dump_poscar
550
+ # c00_str = [
551
+ # 'c00',
552
+ # '1.0',
553
+ # ' 2.00000000000000 2.00000000000000 2.00000000000000',
554
+ # ' 0.00000000000000 2.00000000000000 2.00000000000000',
555
+ # ' 0.00000000000000 0.00000000000000 2.00000000000000',
556
+ # ' ',
557
+ # '',
558
+ # 'Direct'
559
+ # ].join("\n")
560
+
561
+ # c01_str = [
562
+ # 'c01',
563
+ # '1.0',
564
+ # ' 2.00000000000000 2.00000000000000 2.00000000000000',
565
+ # ' 0.00000000000000 2.00000000000000 2.00000000000000',
566
+ # ' 0.00000000000000 0.00000000000000 2.00000000000000',
567
+ # ' 0 1',
568
+ # ' 1 1',
569
+ # 'Direct',
570
+ # ' 0.00000000000000 0.00000000000000 0.00000000000000',
571
+ # ' 0.10000000000000 0.20000000000000 0.30000000000000'
572
+ # ].join("\n")
573
+
574
+ # c02_str = [
575
+ # 'c02',
576
+ # '1.0',
577
+ # ' 2.00000000000000 2.00000000000000 2.00000000000000',
578
+ # ' 0.00000000000000 2.00000000000000 2.00000000000000',
579
+ # ' 0.00000000000000 0.00000000000000 2.00000000000000',
580
+ # ' Li O',
581
+ # ' 1 1',
582
+ # 'Direct',
583
+ # ' 0.00000000000000 0.00000000000000 0.00000000000000',
584
+ # ' 0.20000000000000 0.20000000000000 0.20000000000000'
585
+ # ].join("\n")
586
+
587
+ # c03_str = [
588
+ # 'c03',
589
+ # '1.0',
590
+ # ' 2.00000000000000 2.00000000000000 2.00000000000000',
591
+ # ' 0.00000000000000 2.00000000000000 2.00000000000000',
592
+ # ' 0.00000000000000 0.00000000000000 2.00000000000000',
593
+ # ' Li O',
594
+ # ' 1 1',
595
+ # 'Direct',
596
+ # ' 0.00000000000000 0.00000000000000 0.00000000000000',
597
+ # ' 0.20000000000000 0.20000000000000 0.20000000000000'
598
+ # ].join("\n")
599
+
600
+ # c04_str = [
601
+ # 'c04',
602
+ # '1.0',
603
+ # ' 2.00000000000000 2.00000000000000 2.00000000000000',
604
+ # ' 0.00000000000000 2.00000000000000 2.00000000000000',
605
+ # ' 0.00000000000000 0.00000000000000 2.00000000000000',
606
+ # ' Li O',
607
+ # ' 2 1',
608
+ # 'Direct',
609
+ # ' 0.00000000000000 0.00000000000000 0.00000000000000',
610
+ # ' 0.10000000000000 0.20000000000000 0.30000000000000',
611
+ # ' 0.20000000000000 0.20000000000000 0.20000000000000'
612
+ # ].join("\n")
613
+
614
+ # c05_str = [
615
+ # 'c05',
616
+ # '1.0',
617
+ # ' 2.00000000000000 2.00000000000000 2.00000000000000',
618
+ # ' 0.00000000000000 2.00000000000000 2.00000000000000',
619
+ # ' 0.00000000000000 0.00000000000000 2.00000000000000',
620
+ # ' Li',
621
+ # ' 1',
622
+ # 'Direct',
623
+ # ' 0.00000000000000 0.00000000000000 0.00000000000000'
624
+ # ].join("\n")
625
+
626
+ # c06_str = [
627
+ # 'c06',
628
+ # '1.0',
629
+ # ' 2.00000000000000 2.00000000000000 2.00000000000000',
630
+ # ' 0.00000000000000 2.00000000000000 2.00000000000000',
631
+ # ' 0.00000000000000 0.00000000000000 2.00000000000000',
632
+ # ' Li O',
633
+ # ' 1 1',
634
+ # 'Selective dynamics',
635
+ # 'Direct',
636
+ # ' 0.00000000000000 0.00000000000000 0.00000000000000 T F F',
637
+ # ' 0.20000000000000 0.20000000000000 0.20000000000000 T T T'
638
+ # ].join("\n")
639
+
640
+ # # Raise exception
641
+ # # assert_raise( RuntimeError ){ @c00.dump_poscar( [], io ) }
642
+ # assert_raise( RuntimeError ){ @c00.dump_poscar( [0] ) }
643
+ # assert_raise( RuntimeError ){ @c00.dump_poscar( [0, 1] ) }
644
+ # assert_raise( RuntimeError ){ @c00.dump_poscar( ['Li'] ) }
645
+ # assert_raise( RuntimeError ){ @c00.dump_poscar( ['Li', 'O'] ) }
646
+ # assert_raise( RuntimeError ){ @c02.dump_poscar( [] ) }
647
+ # assert_raise( RuntimeError ){ @c02.dump_poscar( [0] ) }
648
+ # assert_raise( RuntimeError ){ @c02.dump_poscar( [0, 1] ) }
649
+ # assert_raise( RuntimeError ){ @c02.dump_poscar( ['Li'] ) }
650
+ # assert_raise( RuntimeError ){ @c01.dump_poscar( [] ) }
651
+ # assert_raise( RuntimeError ){ @c01.dump_poscar( [0] ) }
652
+ # assert_raise( RuntimeError ){ @c01.dump_poscar( ['Li'] ) }
653
+ # assert_raise( RuntimeError ){ @c01.dump_poscar( ['Li', 'O'] ) }
654
+ # assert_raise( RuntimeError ){ @c04.dump_poscar( [] ) }
655
+ # assert_raise( RuntimeError ){ @c04.dump_poscar( [0] ) }
656
+ # assert_raise( RuntimeError ){ @c04.dump_poscar( [0, 1] ) }
657
+ # assert_raise( RuntimeError ){ @c04.dump_poscar( ['Li'] ) }
658
+ # assert_raise( RuntimeError ){ @c05.dump_poscar( [] ) }
659
+ # assert_raise( RuntimeError ){ @c05.dump_poscar( [0] ) }
660
+ # assert_raise( RuntimeError ){ @c05.dump_poscar( [0, 1] ) }
661
+ # assert_raise( RuntimeError ){ @c05.dump_poscar( ['Li', 'O'] ) }
662
+ # assert_raise( RuntimeError ){ @c03.dump_poscar( [] ) }
663
+ # assert_raise( RuntimeError ){ @c03.dump_poscar( [0] ) }
664
+ # assert_raise( RuntimeError ){ @c03.dump_poscar( [0, 1] ) }
665
+ # assert_raise( RuntimeError ){ @c03.dump_poscar( ['Li'] ) }
666
+
667
+ # #
668
+ # StringIO.new do |io|
669
+ # @c00.dump_poscar( [], io )
670
+ # assert_equal( c00_str, io.read )
671
+ # end
672
+
673
+ # StringIO.new do |io|
674
+ # @c01.dump_poscar( [ 0, 1 ], io )
675
+ # assert_equal( c01, io.read )
676
+ # end
677
+
678
+ # StringIO.new do |io|
679
+ # @c02.dump_poscar( [ 'Li', 'O' ], io )
680
+ # assert_equal( c02, io.read )
681
+ # end
682
+
683
+ # StringIO.new do |io|
684
+ # @c03.dump_poscar( [ 'Li', 'O' ], io )
685
+ # assert_equal( c03, io.read )
686
+ # end
687
+
688
+ # StringIO.new do |io|
689
+ # @c04.dump_poscar( [ 'Li', 'O' ], io )
690
+ # assert_equal( c04, io.read )
691
+ # end
692
+
693
+ # StringIO.new do |io|
694
+ # @c05.dump_poscar( [ 'Li', 'O' ], io )
695
+ # assert_equal( c05, io.read )
696
+ # end
697
+
698
+ # assert_equal( c00_str, @c00.dump_poscar( [ ], nil ) )
699
+ # assert_equal( c01_str, @c01.dump_poscar( [ 0 , 1 ], nil ) )
700
+ # assert_equal( c02_str, @c02.dump_poscar( [ 'Li', 'O' ], nil ) )
701
+ # assert_equal( c03_str, @c03.dump_poscar( [ 'Li', 'O' ], nil ) )
702
+ # assert_equal( c04_str, @c04.dump_poscar( [ 'Li', 'O' ], nil ) )
703
+ # assert_equal( c05_str, @c05.dump_poscar( [ 'Li' ], nil ) )
704
+
705
+ # assert_equal( c00_str, @c00.dump_poscar( [ ] ) )
706
+ # assert_equal( c01_str, @c01.dump_poscar( [ 0 , 1 ] ) )
707
+ # assert_equal( c02_str, @c02.dump_poscar( [ 'Li', 'O' ] ) )
708
+ # assert_equal( c03_str, @c03.dump_poscar( [ 'Li', 'O' ] ) )
709
+ # assert_equal( c04_str, @c04.dump_poscar( [ 'Li', 'O' ] ) )
710
+ # assert_equal( c05_str, @c05.dump_poscar( [ 'Li' ] ) )
711
+
712
+ # assert_equal( c06_str, @c06 .dump_poscar( [ 'Li', 'O' ] ) )
713
+
714
+ #end
715
+
716
+ def test_rotate
717
+ @c02.add_atom(CrystalCell::Atom.new( 'Li', [1.1, 1.2, 1.3] ))
718
+ assert_equal(
719
+ [ Mageo::Vector3DInternal[ 0.0, 0.0, 0.0 ],
720
+ Mageo::Vector3DInternal[ -0.2, -0.2, -0.2 ],
721
+ Mageo::Vector3DInternal[ -1.1, -1.2, -1.3 ]
722
+ ],
723
+ @c02.rotate( [[-1, 0, 0],[0, -1, 0],[0, 0, -1]] ).positions
724
+ )
725
+
726
+ # Check not destructed.
727
+ assert_equal(
728
+ [ Mageo::Vector3DInternal[ 0.0, 0.0, 0.0 ],
729
+ Mageo::Vector3DInternal[ 0.2, 0.2, 0.2 ],
730
+ Mageo::Vector3DInternal[ 1.1, 1.2, 1.3 ]
731
+ ],
732
+ @c02.positions
733
+ )
734
+ end
735
+
736
+ def test_rotate!
737
+ @c02.add_atom(CrystalCell::Atom.new( 'Li', [0.1, 0.2, 0.3] ))
738
+ @c02.rotate!( [[-1, 0, 0],[0, -1, 0],[0, 0, -1]] )
739
+ assert_equal(
740
+ [ Mageo::Vector3DInternal[ 0.0, 0.0, 0.0 ],
741
+ Mageo::Vector3DInternal[ -0.2, -0.2, -0.2 ],
742
+ Mageo::Vector3DInternal[ -0.1, -0.2, -0.3 ]
743
+ ],
744
+ @c02.positions
745
+ )
746
+ end
747
+
748
+ def test_translate
749
+ poss = @c02.translate( [1.1, 1.2, 1.3] ).positions
750
+ assert_in_delta( 1.1, poss[0][0], $tolerance )
751
+ assert_in_delta( 1.2, poss[0][1], $tolerance )
752
+ assert_in_delta( 1.3, poss[0][2], $tolerance )
753
+ assert_in_delta( 1.3, poss[1][0], $tolerance )
754
+ assert_in_delta( 1.4, poss[1][1], $tolerance )
755
+ assert_in_delta( 1.5, poss[1][2], $tolerance )
756
+
757
+ poss = @c02.translate( [-0.3,-0.3,-0.3] ).positions
758
+ assert_in_delta( -0.3, poss[0][0], $tolerance )
759
+ assert_in_delta( -0.3, poss[0][1], $tolerance )
760
+ assert_in_delta( -0.3, poss[0][2], $tolerance )
761
+ assert_in_delta( -0.1, poss[1][0], $tolerance )
762
+ assert_in_delta( -0.1, poss[1][1], $tolerance )
763
+ assert_in_delta( -0.1, poss[1][2], $tolerance )
764
+
765
+ # Check not destructed.
766
+ assert_equal(
767
+ [ Mageo::Vector3DInternal[ 0.0, 0.0, 0.0 ],
768
+ Mageo::Vector3DInternal[ 0.2, 0.2, 0.2 ]
769
+ ],
770
+ @c02.positions
771
+ )
772
+ end
773
+
774
+ def test_translate!
775
+ @c02.translate!( [1.1, 1.2, 1.3] )
776
+ poss = @c02.positions
777
+
778
+ assert_in_delta( 1.1, poss[0][0], $tolerance )
779
+ assert_in_delta( 1.2, poss[0][1], $tolerance )
780
+ assert_in_delta( 1.3, poss[0][2], $tolerance )
781
+ assert_in_delta( 1.3, poss[1][0], $tolerance )
782
+ assert_in_delta( 1.4, poss[1][1], $tolerance )
783
+ assert_in_delta( 1.5, poss[1][2], $tolerance )
784
+ end
785
+
786
+ def test_center_of_atoms
787
+ # No atom in the cell.
788
+ assert_raise( CrystalCell::Cell::NoAtomError ){ @c00.center_of_atoms }
789
+
790
+ assert_equal( Mageo::Vector3DInternal[0.05, 0.1, 0.15], @c01.center_of_atoms )
791
+ assert_equal( Mageo::Vector3DInternal[0.1, 0.1, 0.1], @c02.center_of_atoms )
792
+ assert_equal( Mageo::Vector3DInternal[0.1, 0.1, 0.1], @c03.center_of_atoms )
793
+ assert_equal( Mageo::Vector3DInternal[0.1, 4.0/30.0, 5.0/30.0], @c04.center_of_atoms )
794
+ assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], @c05.center_of_atoms )
795
+ assert_equal( Mageo::Vector3DInternal[0.1, 0.1, 0.1], @c06.center_of_atoms )
796
+ assert_equal( Mageo::Vector3DInternal[0.1, 0.1, 0.1], @c07.center_of_atoms )
797
+ end
798
+
799
+ def test_calc_volume
800
+ # @c00 = CrystalCell::Cell.new( [ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0] ] )
801
+ assert_in_delta( 8.00, @c00.calc_volume, $tolerance)
802
+
803
+ c10 = CrystalCell::Cell.new( [ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0] ] )
804
+ c11 = CrystalCell::Cell.new( [ [0.5, 0.5, 0.0], [0.5, 0.0, 0.5], [0.0, 0.5, 0.5] ] )
805
+ assert_in_delta( 1.00, c10.calc_volume, $tolerance)
806
+ assert_in_delta( 0.25, c11.calc_volume, $tolerance)
807
+ end
808
+
809
+ def test_cell_of_elements
810
+ t = @c04.cell_of_elements( [ 'Li' ] )
811
+ assert_equal( CrystalCell::Cell, t.class )
812
+ assert_in_delta( 2.0, t.axes[0][0], $tolerance )
813
+ assert_in_delta( 2.0, t.axes[0][1], $tolerance )
814
+ assert_in_delta( 2.0, t.axes[0][2], $tolerance )
815
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
816
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
817
+ assert_in_delta( 2.0, t.axes[1][2], $tolerance )
818
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
819
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
820
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
821
+ assert_equal( 2, t.atoms.size )
822
+ # checking atom 0
823
+ assert_equal( 'Li' , t.atoms[0].element)
824
+ assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
825
+ assert_equal( nil , t.atoms[0].name )
826
+ # checking atom 1
827
+ assert_equal( 'Li' , t.atoms[1].element)
828
+ assert_equal( Mageo::Vector3DInternal[0.1, 0.2, 0.3], t.atoms[1].position)
829
+ assert_equal( nil , t.atoms[1].name )
830
+
831
+ t = @c04.cell_of_elements( [ 'Li', 'O' ] )
832
+ assert_equal( CrystalCell::Cell, t.class )
833
+ assert_in_delta( 2.0, t.axes[0][0], $tolerance )
834
+ assert_in_delta( 2.0, t.axes[0][1], $tolerance )
835
+ assert_in_delta( 2.0, t.axes[0][2], $tolerance )
836
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
837
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
838
+ assert_in_delta( 2.0, t.axes[1][2], $tolerance )
839
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
840
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
841
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
842
+ assert_equal( 3, t.atoms.size )
843
+ # checking atom 0
844
+ assert_equal( 'Li' , t.atoms[0].element)
845
+ assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
846
+ assert_equal( nil , t.atoms[0].name )
847
+ # checking atom 1
848
+ assert_equal( 'O' , t.atoms[1].element)
849
+ assert_equal( Mageo::Vector3DInternal[0.2, 0.2, 0.2], t.atoms[1].position)
850
+ assert_equal( nil , t.atoms[1].name )
851
+ # checking atom 2
852
+ assert_equal( 'Li' , t.atoms[2].element)
853
+ assert_equal( Mageo::Vector3DInternal[0.1, 0.2, 0.3], t.atoms[2].position)
854
+ assert_equal( nil , t.atoms[2].name )
855
+
856
+ t = @c04.cell_of_elements( [ 'O' ] )
857
+ assert_equal( CrystalCell::Cell, t.class )
858
+ assert_in_delta( 2.0, t.axes[0][0], $tolerance )
859
+ assert_in_delta( 2.0, t.axes[0][1], $tolerance )
860
+ assert_in_delta( 2.0, t.axes[0][2], $tolerance )
861
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
862
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
863
+ assert_in_delta( 2.0, t.axes[1][2], $tolerance )
864
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
865
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
866
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
867
+ assert_equal( 1, t.atoms.size )
868
+ # checking atom 0
869
+ assert_equal( 'O' , t.atoms[0].element)
870
+ assert_equal( Mageo::Vector3DInternal[0.2, 0.2, 0.2], t.atoms[0].position)
871
+ assert_equal( nil , t.atoms[0].name )
872
+
873
+ t = @c04.cell_of_elements( [ 'F' ] )
874
+ assert_equal( CrystalCell::Cell, t.class )
875
+ assert_in_delta( 2.0, t.axes[0][0], $tolerance )
876
+ assert_in_delta( 2.0, t.axes[0][1], $tolerance )
877
+ assert_in_delta( 2.0, t.axes[0][2], $tolerance )
878
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
879
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
880
+ assert_in_delta( 2.0, t.axes[1][2], $tolerance )
881
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
882
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
883
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
884
+ assert_equal( 0, t.atoms.size )
885
+
886
+
887
+ # サブクラスで使用したときに、サブクラスで作られるか?
888
+ fc04 = FooCell.new( [ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0] ] )
889
+ fc04.add_atom(CrystalCell::Atom.new( 'Li', [0.0, 0.0, 0.0] ))
890
+ fc04.add_atom(CrystalCell::Atom.new( 'O' , [0.2, 0.2, 0.2] ))
891
+ fc04.add_atom(CrystalCell::Atom.new( 'Li', [0.1, 0.2, 0.3] ))
892
+ fc04.comment = 'fc04'
893
+ t = fc04.cell_of_elements( [ 'Li' ] )
894
+ assert_equal( FooCell, t.class )
895
+ assert_in_delta( 2.0, t.axes[0][0], $tolerance )
896
+ assert_in_delta( 2.0, t.axes[0][1], $tolerance )
897
+ assert_in_delta( 2.0, t.axes[0][2], $tolerance )
898
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
899
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
900
+ assert_in_delta( 2.0, t.axes[1][2], $tolerance )
901
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
902
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
903
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
904
+ assert_equal( 2, t.atoms.size )
905
+ # checking atom 0
906
+ assert_equal( 'Li' , t.atoms[0].element)
907
+ assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
908
+ assert_equal( nil , t.atoms[0].name )
909
+ # checking atom 1
910
+ assert_equal( 'Li' , t.atoms[1].element)
911
+ assert_equal( Mageo::Vector3DInternal[0.1, 0.2, 0.3], t.atoms[1].position)
912
+ assert_equal( nil , t.atoms[1].name )
913
+ end
914
+
915
+ def test_unite
916
+ ## 格子定数が違えば例外。将来的な feature.
917
+ #t = CrystalCell::Cell.new( [ [2.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 2.0] ] )
918
+ #t.add_atom(CrystalCell::Atom.new( 'Li', [0.0, 0.0, 0.0] ))
919
+ #t.comment = 't'
920
+ #assert_raise( CrystalCell::Cell::AxesMismatchError ){ @c05.unite( t ) }
921
+ t = CrystalCell::Cell.new( [ [2.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 2.0] ] )
922
+ t.add_atom(CrystalCell::Atom.new( 'Li', [0.0, 0.0, 0.0] ))
923
+ t.comment = 't'
924
+ assert_nothing_raised{ @c05.unite( t ) }
925
+
926
+ # unite
927
+ # 同じ座標のものがあっても気にせず統合する。
928
+ t = @c05.unite( @c06 )
929
+ assert_equal( CrystalCell::Cell, t.class )
930
+ assert_in_delta( 2.0, t.axes[0][0], $tolerance )
931
+ assert_in_delta( 2.0, t.axes[0][1], $tolerance )
932
+ assert_in_delta( 2.0, t.axes[0][2], $tolerance )
933
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
934
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
935
+ assert_in_delta( 2.0, t.axes[1][2], $tolerance )
936
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
937
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
938
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
939
+ assert_equal( 3, t.atoms.size )
940
+ # checking atom 0
941
+ assert_equal( 'Li' , t.atoms[0].element)
942
+ assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
943
+ assert_equal( nil , t.atoms[0].name )
944
+ # checking atom 1
945
+ assert_equal( 'Li' , t.atoms[1].element)
946
+ assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t.atoms[1].position)
947
+ assert_equal( nil , t.atoms[1].name )
948
+ # checking atom 2
949
+ assert_equal( 'O' , t.atoms[2].element)
950
+ assert_equal( Mageo::Vector3DInternal[0.2, 0.2, 0.2], t.atoms[2].position)
951
+ assert_equal( nil , t.atoms[2].name )
952
+ end
953
+
954
+ def test_inverse_axis!
955
+ @c02.inverse_axis!( 0 )
956
+ t = @c02
957
+ assert_equal( CrystalCell::Cell, t.class )
958
+ assert_in_delta(-2.0, t.axes[0][0], $tolerance )
959
+ assert_in_delta(-2.0, t.axes[0][1], $tolerance )
960
+ assert_in_delta(-2.0, t.axes[0][2], $tolerance )
961
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
962
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
963
+ assert_in_delta( 2.0, t.axes[1][2], $tolerance )
964
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
965
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
966
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
967
+ assert_equal( 2, t.atoms.size )
968
+ # checking atom 0
969
+ assert_equal( 'Li' , t.atoms[0].element)
970
+ assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
971
+ assert_equal( nil , t.atoms[0].name )
972
+ # checking atom 1
973
+ assert_equal( 'O' , t.atoms[1].element)
974
+ assert_equal( Mageo::Vector3DInternal[-0.2, 0.2, 0.2], t.atoms[1].position)
975
+ assert_equal( nil , t.atoms[1].name )
976
+ end
977
+
978
+ def test_inverse_axis
979
+ assert_raise( CrystalCell::Cell::AxesRangeError ){ @c02.inverse_axis( -1 ) }
980
+ assert_raise( CrystalCell::Cell::AxesRangeError ){ @c02.inverse_axis( 3 ) }
981
+
982
+ # x 軸反転
983
+ t = @c02.inverse_axis( 0 )
984
+ assert_equal( CrystalCell::Cell, t.class )
985
+ assert_in_delta( -2.0, t.axes[0][0], $tolerance )
986
+ assert_in_delta( -2.0, t.axes[0][1], $tolerance )
987
+ assert_in_delta( -2.0, t.axes[0][2], $tolerance )
988
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
989
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
990
+ assert_in_delta( 2.0, t.axes[1][2], $tolerance )
991
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
992
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
993
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
994
+ assert_equal( 2, t.atoms.size )
995
+ # checking atom 0
996
+ assert_equal( 'Li' , t.atoms[0].element)
997
+ assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
998
+ assert_equal( nil , t.atoms[0].name )
999
+ # checking atom 1
1000
+ assert_equal( 'O' , t.atoms[1].element)
1001
+ assert_equal( Mageo::Vector3DInternal[-0.2, 0.2, 0.2], t.atoms[1].position)
1002
+ assert_equal( nil , t.atoms[1].name )
1003
+ # checking non-destructive
1004
+ assert_equal( CrystalCell::Cell, t.class )
1005
+ assert_in_delta( 2.0, @c02.axes[0][0], $tolerance )
1006
+ assert_in_delta( 2.0, @c02.axes[0][1], $tolerance )
1007
+ assert_in_delta( 2.0, @c02.axes[0][2], $tolerance )
1008
+ assert_in_delta( 0.0, @c02.axes[1][0], $tolerance )
1009
+ assert_in_delta( 2.0, @c02.axes[1][1], $tolerance )
1010
+ assert_in_delta( 2.0, @c02.axes[1][2], $tolerance )
1011
+ assert_in_delta( 0.0, @c02.axes[2][0], $tolerance )
1012
+ assert_in_delta( 0.0, @c02.axes[2][1], $tolerance )
1013
+ assert_in_delta( 2.0, @c02.axes[2][2], $tolerance )
1014
+ assert_equal( 2, @c02.atoms.size )
1015
+ # checking atom 0
1016
+ assert_equal( 'Li' , @c02.atoms[0].element)
1017
+ assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], @c02.atoms[0].position)
1018
+ assert_equal( nil , @c02.atoms[0].name )
1019
+ # checking atom 1
1020
+ assert_equal( 'O' , @c02.atoms[1].element)
1021
+ assert_equal( Mageo::Vector3DInternal[ 0.2, 0.2, 0.2], @c02.atoms[1].position)
1022
+ assert_equal( nil , @c02.atoms[1].name )
1023
+
1024
+ # y 軸反転
1025
+ # [ [ ax, ay, az], [ 0, by, bz], [ 0, 0, cz] ]
1026
+ # ↓ y 軸反転
1027
+ # [ [ ax, ay, az], [ 0,-by,-bz], [ 0, 0, cz] ]
1028
+ # ↓ b vector の y 成分が正になるようにする。
1029
+ # すなわち z 軸回りに半回転し、全ての x, y 成分が反転する。
1030
+ # [ [-ax,-ay, az], [ 0, by,-bz], [ 0, 0, cz] ]
1031
+ t = @c02.inverse_axis( 1 )
1032
+ assert_equal( CrystalCell::Cell, t.class )
1033
+ assert_in_delta( -2.0, t.axes[0][0], $tolerance )
1034
+ assert_in_delta( -2.0, t.axes[0][1], $tolerance )
1035
+ assert_in_delta( 2.0, t.axes[0][2], $tolerance )
1036
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
1037
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
1038
+ assert_in_delta( -2.0, t.axes[1][2], $tolerance )
1039
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
1040
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
1041
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
1042
+ assert_equal( 2, t.atoms.size )
1043
+ # checking atom 0
1044
+ assert_equal( 'Li' , t.atoms[0].element)
1045
+ assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
1046
+ assert_equal( nil , t.atoms[0].name )
1047
+ # checking atom 1
1048
+ assert_equal( 'O' , t.atoms[1].element)
1049
+ assert_equal( Mageo::Vector3DInternal[ 0.2,-0.2, 0.2], t.atoms[1].position)
1050
+ assert_equal( nil , t.atoms[1].name )
1051
+
1052
+ # z 軸反転
1053
+ # [ [ ax, ay, az], [ 0, by, bz], [ 0, 0, cz] ]
1054
+ # ↓ z 軸反転
1055
+ # [ [ ax, ay, az], [ 0, by, bz], [ 0, 0,-cz] ]
1056
+ # ↓ c vector の z 成分が正になるようにする。
1057
+ # b vector の y 成分も正であることを保存する回転は、
1058
+ # y 軸回りに半回転し、全ての x, z 成分が反転する。
1059
+ # [ [-ax, ay,-az], [ 0, by,-bz], [ 0, 0, cz] ]
1060
+ t = @c02.inverse_axis( 2 )
1061
+ assert_equal( CrystalCell::Cell, t.class )
1062
+ assert_in_delta(-2.0, t.axes[0][0], $tolerance )
1063
+ assert_in_delta( 2.0, t.axes[0][1], $tolerance )
1064
+ assert_in_delta(-2.0, t.axes[0][2], $tolerance )
1065
+ assert_in_delta( 0.0, t.axes[1][0], $tolerance )
1066
+ assert_in_delta( 2.0, t.axes[1][1], $tolerance )
1067
+ assert_in_delta(-2.0, t.axes[1][2], $tolerance )
1068
+ assert_in_delta( 0.0, t.axes[2][0], $tolerance )
1069
+ assert_in_delta( 0.0, t.axes[2][1], $tolerance )
1070
+ assert_in_delta( 2.0, t.axes[2][2], $tolerance )
1071
+ assert_equal( 2, t.atoms.size )
1072
+ # checking atom 0
1073
+ assert_equal( 'Li' , t.atoms[0].element)
1074
+ assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
1075
+ assert_equal( nil , t.atoms[0].name )
1076
+ # checking atom 1
1077
+ assert_equal( 'O' , t.atoms[1].element)
1078
+ assert_equal( Mageo::Vector3DInternal[ 0.2, 0.2,-0.2], t.atoms[1].position)
1079
+ assert_equal( nil , t.atoms[1].name )
1080
+
1081
+ end
1082
+
1083
+ def test_exchange_axes!
1084
+ # b, c の交換。
1085
+ @c08.exchange_axes!( [ 1, 2 ] )
1086
+ t = @c08
1087
+ assert_equal( CrystalCell::Cell, t.class )
1088
+ lc = t.axes.get_lattice_constants
1089
+ assert_in_delta( 2.0 * Math::sqrt( 3.0 ) , lc[0], $tolerance )
1090
+ assert_in_delta( 2.0 , lc[1], $tolerance )
1091
+ assert_in_delta( 2.0 * Math::sqrt( 2.0 ) , lc[2], $tolerance )
1092
+ assert_in_delta( 45.0000000000000, lc[3], $tolerance )
1093
+ assert_in_delta( 35.2643896827547, lc[4], $tolerance )
1094
+ assert_in_delta( 54.7356103172453, lc[5], $tolerance )
1095
+ assert_equal( true, t.axes.lefthand? )
1096
+ assert_equal( 2, t.atoms.size )
1097
+ # checking atom 0
1098
+ assert_equal( 'Li' , t.atoms[0].element)
1099
+ assert_equal( Mageo::Vector3DInternal[ 1.2, 5.6, 3.4], t.atoms[0].position)
1100
+ assert_equal( 'atom0' , t.atoms[0].name )
1101
+ assert_equal( [ false, false, true] , t.atoms[0].movable_flags )
1102
+ # checking atom 1
1103
+ assert_equal( 'O' , t.atoms[1].element)
1104
+ assert_equal( Mageo::Vector3DInternal[-1.2, -5.6, -3.4], t.atoms[1].position)
1105
+ assert_equal( nil , t.atoms[1].name )
1106
+ end
1107
+
1108
+ def test_exchange_axes
1109
+ assert_raise( CrystalCell::Cell::ArgumentError ){ @c02.exchange_axes( [ 0 ] ) }
1110
+ assert_raise( CrystalCell::Cell::ArgumentError ){ @c02.exchange_axes( [ 0, 1, 2] ) }
1111
+ assert_raise( CrystalCell::Cell::AxesRangeError ){ @c02.exchange_axes( [0, 3] ) }
1112
+ assert_raise( CrystalCell::Cell::AxesRangeError ){ @c02.exchange_axes( [-1, 2] ) }
1113
+ assert_raise( CrystalCell::Cell::SameAxesError ){ @c02.exchange_axes( [ 1,1] ) }
1114
+
1115
+ # b, c の交換。
1116
+ t = @c08.exchange_axes( [ 1, 2 ] )
1117
+ assert_equal( CrystalCell::Cell, t.class )
1118
+ lc = t.axes.get_lattice_constants
1119
+ assert_in_delta( 2.0 * Math::sqrt( 3.0 ) , lc[0], $tolerance )
1120
+ assert_in_delta( 2.0 , lc[1], $tolerance )
1121
+ assert_in_delta( 2.0 * Math::sqrt( 2.0 ) , lc[2], $tolerance )
1122
+ assert_in_delta( 45.0000000000000, lc[3], $tolerance )
1123
+ assert_in_delta( 35.2643896827547, lc[4], $tolerance )
1124
+ assert_in_delta( 54.7356103172453, lc[5], $tolerance )
1125
+ assert_equal( true, t.axes.lefthand? )
1126
+ assert_equal( 2, t.atoms.size )
1127
+ # checking atom 0
1128
+ assert_equal( 'Li' , t.atoms[0].element)
1129
+ assert_equal( Mageo::Vector3DInternal[ 1.2, 5.6, 3.4], t.atoms[0].position)
1130
+ assert_equal( 'atom0' , t.atoms[0].name )
1131
+ # checking atom 1
1132
+ assert_equal( 'O' , t.atoms[1].element)
1133
+ assert_equal( Mageo::Vector3DInternal[-1.2, -5.6, -3.4], t.atoms[1].position)
1134
+ assert_equal( nil , t.atoms[1].name )
1135
+
1136
+ # b, c の交換によって非破壊であることを確認。
1137
+ t = @c08
1138
+ assert_equal( CrystalCell::Cell, t.class )
1139
+ lc = t.axes.get_lattice_constants
1140
+ assert_in_delta( 2.0 * Math::sqrt( 3.0 ) , lc[0], $tolerance )
1141
+ assert_in_delta( 2.0 * Math::sqrt( 2.0 ) , lc[1], $tolerance )
1142
+ assert_in_delta( 2.0 , lc[2], $tolerance )
1143
+ assert_in_delta( 45.0000000000000, lc[3], $tolerance )
1144
+ assert_in_delta( 54.7356103172453, lc[4], $tolerance )
1145
+ assert_in_delta( 35.2643896827547, lc[5], $tolerance )
1146
+ assert_equal( true, t.axes.righthand? )
1147
+ assert_equal( 2, t.atoms.size )
1148
+ # checking atom 0
1149
+ assert_equal( 'Li' , t.atoms[0].element)
1150
+ assert_equal( Mageo::Vector3DInternal[ 1.2, 3.4, 5.6], t.atoms[0].position)
1151
+ assert_equal( 'atom0' , t.atoms[0].name )
1152
+ # checking atom 1
1153
+ assert_equal( 'O' , t.atoms[1].element)
1154
+ assert_equal( Mageo::Vector3DInternal[-1.2, -3.4, -5.6], t.atoms[1].position)
1155
+ assert_equal( nil , t.atoms[1].name )
1156
+
1157
+ end
1158
+
1159
+ def test_reflect!
1160
+ @c08.reflect!
1161
+ t = @c08
1162
+ assert_equal( CrystalCell::Cell, t.class )
1163
+ lc = t.axes.get_lattice_constants
1164
+ assert_in_delta( 2.0 * Math::sqrt( 3.0 ) , lc[0], $tolerance )
1165
+ assert_in_delta( 2.0 * Math::sqrt( 2.0 ) , lc[1], $tolerance )
1166
+ assert_in_delta( 2.0 , lc[2], $tolerance )
1167
+ assert_in_delta( 45.0000000000000, lc[3], $tolerance )
1168
+ assert_in_delta( 54.7356103172453, lc[4], $tolerance )
1169
+ assert_in_delta( 35.2643896827547, lc[5], $tolerance )
1170
+ assert_equal( true, t.axes.lefthand? )
1171
+ assert_equal( 2, t.atoms.size )
1172
+ # checking atom 0
1173
+ assert_equal( 'Li' , t.atoms[0].element)
1174
+ assert_equal( Mageo::Vector3DInternal[ 1.2, 3.4, 5.6], t.atoms[0].position)
1175
+ assert_equal( 'atom0' , t.atoms[0].name )
1176
+ # checking atom 1
1177
+ assert_equal( 'O' , t.atoms[1].element)
1178
+ assert_equal( Mageo::Vector3DInternal[-1.2, -3.4, -5.6], t.atoms[1].position)
1179
+ assert_equal( nil , t.atoms[1].name )
1180
+ end
1181
+
1182
+ def test_reflect
1183
+ t = @c08.reflect
1184
+ assert_equal( CrystalCell::Cell, t.class )
1185
+ lc = t.axes.get_lattice_constants
1186
+ assert_in_delta( 2.0 * Math::sqrt( 3.0 ) , lc[0], $tolerance )
1187
+ assert_in_delta( 2.0 * Math::sqrt( 2.0 ) , lc[1], $tolerance )
1188
+ assert_in_delta( 2.0 , lc[2], $tolerance )
1189
+ assert_in_delta( 45.0000000000000, lc[3], $tolerance )
1190
+ assert_in_delta( 54.7356103172453, lc[4], $tolerance )
1191
+ assert_in_delta( 35.2643896827547, lc[5], $tolerance )
1192
+ assert_equal( true, t.axes.lefthand? )
1193
+ assert_equal( 2, t.atoms.size )
1194
+ # checking atom 0
1195
+ assert_equal( 'Li' , t.atoms[0].element)
1196
+ assert_equal( Mageo::Vector3DInternal[ 1.2, 3.4, 5.6], t.atoms[0].position)
1197
+ assert_equal( 'atom0' , t.atoms[0].name )
1198
+ # checking atom 1
1199
+ assert_equal( 'O' , t.atoms[1].element)
1200
+ assert_equal( Mageo::Vector3DInternal[-1.2, -3.4, -5.6], t.atoms[1].position)
1201
+ assert_equal( nil , t.atoms[1].name )
1202
+
1203
+ # 非破壊であることを確認。
1204
+ t = @c08
1205
+ assert_equal( CrystalCell::Cell, t.class )
1206
+ lc = t.axes.get_lattice_constants
1207
+ assert_in_delta( 2.0 * Math::sqrt( 3.0 ) , lc[0], $tolerance )
1208
+ assert_in_delta( 2.0 * Math::sqrt( 2.0 ) , lc[1], $tolerance )
1209
+ assert_in_delta( 2.0 , lc[2], $tolerance )
1210
+ assert_in_delta( 45.0000000000000, lc[3], $tolerance )
1211
+ assert_in_delta( 54.7356103172453, lc[4], $tolerance )
1212
+ assert_in_delta( 35.2643896827547, lc[5], $tolerance )
1213
+ assert_equal( true, t.axes.righthand? )
1214
+ assert_equal( 2, t.atoms.size )
1215
+ # checking atom 0
1216
+ assert_equal( 'Li' , t.atoms[0].element)
1217
+ assert_equal( Mageo::Vector3DInternal[ 1.2, 3.4, 5.6], t.atoms[0].position)
1218
+ assert_equal( 'atom0' , t.atoms[0].name )
1219
+ # checking atom 1
1220
+ assert_equal( 'O' , t.atoms[1].element)
1221
+ assert_equal( Mageo::Vector3DInternal[-1.2, -3.4, -5.6], t.atoms[1].position)
1222
+ assert_equal( nil , t.atoms[1].name )
1223
+ end
1224
+
1225
+ def test_operate
1226
+ # identity operation
1227
+ rotation = [
1228
+ [1, 0, 0],
1229
+ [0, 1, 0],
1230
+ [0, 0, 1],
1231
+ ]
1232
+ translation = [0.0, 0.0, 0.0]
1233
+ result = @c01.operate(rotation, translation)
1234
+ assert_in_delta( 0.0, result.atoms[0].position[0], $tolerance)
1235
+ assert_in_delta( 0.0, result.atoms[0].position[1], $tolerance)
1236
+ assert_in_delta( 0.0, result.atoms[0].position[2], $tolerance)
1237
+ assert_in_delta( 0.1, result.atoms[1].position[0], $tolerance)
1238
+ assert_in_delta( 0.2, result.atoms[1].position[1], $tolerance)
1239
+ assert_in_delta( 0.3, result.atoms[1].position[2], $tolerance)
1240
+
1241
+ # rotation
1242
+ rotation = [
1243
+ [1, 0, 0],
1244
+ [0, 1, 0],
1245
+ [0, 0,-1],
1246
+ ]
1247
+ translation = [0.0, 0.0, 0.0]
1248
+ result = @c01.operate(rotation, translation)
1249
+ assert_in_delta( 0.0, result.atoms[0].position[0], $tolerance)
1250
+ assert_in_delta( 0.0, result.atoms[0].position[1], $tolerance)
1251
+ assert_in_delta( 0.0, result.atoms[0].position[2], $tolerance)
1252
+ assert_in_delta( 0.1, result.atoms[1].position[0], $tolerance)
1253
+ assert_in_delta( 0.2, result.atoms[1].position[1], $tolerance)
1254
+ assert_in_delta(-0.3, result.atoms[1].position[2], $tolerance)
1255
+
1256
+ # translation
1257
+ rotation = [
1258
+ [1, 0, 0],
1259
+ [0, 1, 0],
1260
+ [0, 0, 1],
1261
+ ]
1262
+ translation = [0.1, 0.2, 0.3]
1263
+ result = @c01.operate(rotation, translation)
1264
+ assert_in_delta(0.1, result.atoms[0].position[0], $tolerance)
1265
+ assert_in_delta(0.2, result.atoms[0].position[1], $tolerance)
1266
+ assert_in_delta(0.3, result.atoms[0].position[2], $tolerance)
1267
+ assert_in_delta(0.2, result.atoms[1].position[0], $tolerance)
1268
+ assert_in_delta(0.4, result.atoms[1].position[1], $tolerance)
1269
+ assert_in_delta(0.6, result.atoms[1].position[2], $tolerance)
1270
+
1271
+ # rotation & translation
1272
+ rotation = [
1273
+ [1, 0, 0],
1274
+ [0, 1, 0],
1275
+ [0, 0,-1],
1276
+ ]
1277
+ translation = [0.1, 0.2, 0.3]
1278
+ result = @c01.operate(rotation, translation)
1279
+ assert_in_delta(0.1, result.atoms[0].position[0], $tolerance)
1280
+ assert_in_delta(0.2, result.atoms[0].position[1], $tolerance)
1281
+ assert_in_delta(0.3, result.atoms[0].position[2], $tolerance)
1282
+ assert_in_delta(0.2, result.atoms[1].position[0], $tolerance)
1283
+ assert_in_delta(0.4, result.atoms[1].position[1], $tolerance)
1284
+ assert_in_delta(0.0, result.atoms[1].position[2], $tolerance)
1285
+ end
1286
+
1287
+ def test_axis_independencies
1288
+ unless defined? Getspg
1289
+ puts
1290
+ puts "test_axis_independencies() is ignored because spglib is not installed."
1291
+ return
200
1292
  end
201
1293
 
202
- def test_initialize
203
- la = CrystalCell::LatticeAxes.new( [ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0] ] )
204
- c10 = CrystalCell::Cell.new( la )
205
- c10.comment = 'c00'
206
- assert_equal( CrystalCell::Cell, c10.class )
207
- assert_in_delta( 2.0, c10.axes[0][0], $tolerance )
208
- assert_in_delta( 2.0, c10.axes[0][1], $tolerance )
209
- assert_in_delta( 2.0, c10.axes[0][2], $tolerance )
210
- assert_in_delta( 0.0, c10.axes[1][0], $tolerance )
211
- assert_in_delta( 2.0, c10.axes[1][1], $tolerance )
212
- assert_in_delta( 2.0, c10.axes[1][2], $tolerance )
213
- assert_in_delta( 0.0, c10.axes[2][0], $tolerance )
214
- assert_in_delta( 0.0, c10.axes[2][1], $tolerance )
215
- assert_in_delta( 2.0, c10.axes[2][2], $tolerance )
216
-
217
-
218
- end
219
-
220
- def test_positions
221
- assert_equal( [], @c00.positions)
222
- assert_equal( [ Mageo::Vector3DInternal[0.0, 0.0, 0.0], Mageo::Vector3DInternal[0.2, 0.2, 0.2] ], @c02.positions )
223
- assert_equal( [ Mageo::Vector3DInternal[0.0, 0.0, 0.0], Mageo::Vector3DInternal[0.1, 0.2, 0.3] ], @c01.positions )
224
- end
225
-
226
- def test_select_indices
227
- assert_equal( [], @c00.select_indices{ |i| i.element == "" } )
228
- assert_equal( [], @c00.select_indices{ |i| i.element == "Li" } )
229
-
230
- assert_equal( [] , @c01.select_indices{ |i| i.element == "" } )
231
- assert_equal( [] , @c01.select_indices{ |i| i.element == "Li" } )
232
- #@c01.select_indices{ |i| p i.element }
233
- assert_equal( [0], @c01.select_indices{ |i| i.element == 0 } )
234
-
235
- assert_equal( [1], @c01.select_indices{ |i| i.element == 1 } )
236
-
237
- assert_equal( [] , @c04.select_indices{ |i| i.element == "" } )
238
- assert_equal( [0, 2], @c04.select_indices{ |i| i.element == "Li" } )
239
- assert_equal( [1], @c04.select_indices{ |i| i.element == "O" } )
240
- assert_equal( [ ], @c04.select_indices{ |i| i.element == 0 } )
241
- assert_equal( [ ], @c04.select_indices{ |i| i.element == 1 } )
242
-
243
- assert_equal( [1, 2], @c04.select_indices{ |i| i.position[0] > 0.05 } )
244
- end
245
-
246
- def test_atoms_in_supercell
247
- t = @c02.atoms_in_supercell( 0, 0, 0, 0, 0, 1 )
248
- assert_equal( 'Li', t[0].element )
249
- assert_equal( 'Li', t[1].element )
250
- assert_equal( 'O' , t[2].element )
251
- assert_equal( 'O' , t[3].element )
252
-
253
- assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t[0].position )
254
- assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 1.0], t[1].position )
255
- assert_equal( Mageo::Vector3DInternal[0.2, 0.2, 0.2], t[2].position )
256
- assert_equal( Mageo::Vector3DInternal[0.2, 0.2, 1.2], t[3].position )
257
-
258
- t = @c02.atoms_in_supercell(-1, 1,-1, 1,-1, 1 )
259
- assert_equal( ['Li']*27 + ['O'] * 27 , t.map{|i| i.element} )
260
- assert_equal( Mageo::Vector3DInternal[-1.0, -1.0, -1.0], t[ 0].position )
261
- assert_equal( Mageo::Vector3DInternal[-1.0, -1.0, 0.0], t[ 1].position )
262
- assert_equal( Mageo::Vector3DInternal[-1.0, -1.0, 1.0], t[ 2].position )
263
- assert_equal( Mageo::Vector3DInternal[-1.0, 0.0, -1.0], t[ 3].position )
264
- assert_equal( Mageo::Vector3DInternal[-1.0, 0.0, 0.0], t[ 4].position )
265
- assert_equal( Mageo::Vector3DInternal[-1.0, 0.0, 1.0], t[ 5].position )
266
- assert_equal( Mageo::Vector3DInternal[-1.0, 1.0, -1.0], t[ 6].position )
267
- assert_equal( Mageo::Vector3DInternal[-1.0, 1.0, 0.0], t[ 7].position )
268
- assert_equal( Mageo::Vector3DInternal[-1.0, 1.0, 1.0], t[ 8].position )
269
- assert_equal( Mageo::Vector3DInternal[ 0.0, -1.0, -1.0], t[ 9].position )
270
- assert_equal( Mageo::Vector3DInternal[ 0.0, -1.0, 0.0], t[10].position )
271
- assert_equal( Mageo::Vector3DInternal[ 0.0, -1.0, 1.0], t[11].position )
272
- assert_equal( Mageo::Vector3DInternal[ 0.0, 0.0, -1.0], t[12].position )
273
- assert_equal( Mageo::Vector3DInternal[ 0.0, 0.0, 0.0], t[13].position )
274
- assert_equal( Mageo::Vector3DInternal[ 0.0, 0.0, 1.0], t[14].position )
275
- assert_equal( Mageo::Vector3DInternal[ 0.0, 1.0, -1.0], t[15].position )
276
- assert_equal( Mageo::Vector3DInternal[ 0.0, 1.0, 0.0], t[16].position )
277
- assert_equal( Mageo::Vector3DInternal[ 0.0, 1.0, 1.0], t[17].position )
278
- assert_equal( Mageo::Vector3DInternal[ 1.0, -1.0, -1.0], t[18].position )
279
- assert_equal( Mageo::Vector3DInternal[ 1.0, -1.0, 0.0], t[19].position )
280
- assert_equal( Mageo::Vector3DInternal[ 1.0, -1.0, 1.0], t[20].position )
281
- assert_equal( Mageo::Vector3DInternal[ 1.0, 0.0, -1.0], t[21].position )
282
- assert_equal( Mageo::Vector3DInternal[ 1.0, 0.0, 0.0], t[22].position )
283
- assert_equal( Mageo::Vector3DInternal[ 1.0, 0.0, 1.0], t[23].position )
284
- assert_equal( Mageo::Vector3DInternal[ 1.0, 1.0, -1.0], t[24].position )
285
- assert_equal( Mageo::Vector3DInternal[ 1.0, 1.0, 0.0], t[25].position )
286
- assert_equal( Mageo::Vector3DInternal[ 1.0, 1.0, 1.0], t[26].position )
287
- assert_equal( Mageo::Vector3DInternal[-0.8, -0.8, -0.8], t[27].position )
288
- assert_equal( Mageo::Vector3DInternal[-0.8, -0.8, 0.2], t[28].position )
289
- assert_equal( Mageo::Vector3DInternal[-0.8, -0.8, 1.2], t[29].position )
290
- assert_equal( Mageo::Vector3DInternal[-0.8, 0.2, -0.8], t[30].position )
291
- assert_equal( Mageo::Vector3DInternal[-0.8, 0.2, 0.2], t[31].position )
292
- assert_equal( Mageo::Vector3DInternal[-0.8, 0.2, 1.2], t[32].position )
293
- assert_equal( Mageo::Vector3DInternal[-0.8, 1.2, -0.8], t[33].position )
294
- assert_equal( Mageo::Vector3DInternal[-0.8, 1.2, 0.2], t[34].position )
295
- assert_equal( Mageo::Vector3DInternal[-0.8, 1.2, 1.2], t[35].position )
296
- assert_equal( Mageo::Vector3DInternal[ 0.2, -0.8, -0.8], t[36].position )
297
- assert_equal( Mageo::Vector3DInternal[ 0.2, -0.8, 0.2], t[37].position )
298
- assert_equal( Mageo::Vector3DInternal[ 0.2, -0.8, 1.2], t[38].position )
299
- assert_equal( Mageo::Vector3DInternal[ 0.2, 0.2, -0.8], t[39].position )
300
- assert_equal( Mageo::Vector3DInternal[ 0.2, 0.2, 0.2], t[40].position )
301
- assert_equal( Mageo::Vector3DInternal[ 0.2, 0.2, 1.2], t[41].position )
302
- assert_equal( Mageo::Vector3DInternal[ 0.2, 1.2, -0.8], t[42].position )
303
- assert_equal( Mageo::Vector3DInternal[ 0.2, 1.2, 0.2], t[43].position )
304
- assert_equal( Mageo::Vector3DInternal[ 0.2, 1.2, 1.2], t[44].position )
305
- assert_equal( Mageo::Vector3DInternal[ 1.2, -0.8, -0.8], t[45].position )
306
- assert_equal( Mageo::Vector3DInternal[ 1.2, -0.8, 0.2], t[46].position )
307
- assert_equal( Mageo::Vector3DInternal[ 1.2, -0.8, 1.2], t[47].position )
308
- assert_equal( Mageo::Vector3DInternal[ 1.2, 0.2, -0.8], t[48].position )
309
- assert_equal( Mageo::Vector3DInternal[ 1.2, 0.2, 0.2], t[49].position )
310
- assert_equal( Mageo::Vector3DInternal[ 1.2, 0.2, 1.2], t[50].position )
311
- assert_equal( Mageo::Vector3DInternal[ 1.2, 1.2, -0.8], t[51].position )
312
- assert_equal( Mageo::Vector3DInternal[ 1.2, 1.2, 0.2], t[52].position )
313
- assert_equal( Mageo::Vector3DInternal[ 1.2, 1.2, 1.2], t[53].position )
1294
+ assert_equal([false, false, false],
1295
+ @c10 .axis_independencies($symprec, $angle_tolerance))
1296
+ assert_equal([false, false, true ],
1297
+ @c11 .axis_independencies($symprec, $angle_tolerance))
1298
+ assert_equal([true , true , true ],
1299
+ @c12 .axis_independencies($symprec, $angle_tolerance))
1300
+ assert_equal([true , true , true ],
1301
+ @c13 .axis_independencies($symprec, $angle_tolerance))
1302
+ assert_equal([false, false, true ],
1303
+ @c14 .axis_independencies($symprec, $angle_tolerance))
1304
+ assert_equal([false, true , false],
1305
+ @c14b.axis_independencies($symprec, $angle_tolerance))
1306
+ assert_equal([true , true , true ],
1307
+ @c15 .axis_independencies($symprec, $angle_tolerance))
1308
+ assert_equal([false, false, true ],
1309
+ @c16 .axis_independencies($symprec, $angle_tolerance))
1310
+ end
1311
+
1312
+ def test_symmetry_operations
1313
+ unless defined? Getspg
1314
+ puts
1315
+ puts "test_symmetry_operations() is ignored because spglib is not installed."
1316
+ return
314
1317
  end
315
1318
 
316
- def test_elements
317
- assert_equal( [], @c00.elements)
318
- assert_equal( [ 'Li', 'O' ], @c02.elements )
319
- assert_equal( [ 0, 1 ], @c01.elements )
1319
+ f13 = 1.0/3.0
1320
+
1321
+ #cubic/POSCAR #Pm-3m (221) / m-3m / -P 4 2 3 (517)
1322
+ corrects = [
1323
+ {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----01----
1324
+ {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----02----
1325
+ {:rotation => [[ 0, -1, 0], [ 1, 0, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----03----
1326
+ {:rotation => [[ 0, 1, 0], [-1, 0, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----04----
1327
+ {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----05----
1328
+ {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----06----
1329
+ {:rotation => [[ 0, 1, 0], [-1, 0, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----07----
1330
+ {:rotation => [[ 0, -1, 0], [ 1, 0, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----08----
1331
+ {:rotation => [[ 1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----09----
1332
+ {:rotation => [[-1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----10----
1333
+ {:rotation => [[ 0, -1, 0], [-1, 0, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----11----
1334
+ {:rotation => [[ 0, 1, 0], [ 1, 0, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----12----
1335
+ {:rotation => [[-1, 0, 0], [ 0, 1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----13----
1336
+ {:rotation => [[ 1, 0, 0], [ 0, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----14----
1337
+ {:rotation => [[ 0, 1, 0], [ 1, 0, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----15----
1338
+ {:rotation => [[ 0, -1, 0], [-1, 0, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----16----
1339
+ {:rotation => [[ 0, 0, 1], [ 1, 0, 0], [ 0, 1, 0]], :translation => [0.0, 0.0, 0.0]}, #----17----
1340
+ {:rotation => [[ 0, 0, -1], [-1, 0, 0], [ 0, -1, 0]], :translation => [0.0, 0.0, 0.0]}, #----18----
1341
+ {:rotation => [[ 0, 0, 1], [ 0, -1, 0], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----19----
1342
+ {:rotation => [[ 0, 0, -1], [ 0, 1, 0], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----20----
1343
+ {:rotation => [[ 0, 0, 1], [-1, 0, 0], [ 0, -1, 0]], :translation => [0.0, 0.0, 0.0]}, #----21----
1344
+ {:rotation => [[ 0, 0, -1], [ 1, 0, 0], [ 0, 1, 0]], :translation => [0.0, 0.0, 0.0]}, #----22----
1345
+ {:rotation => [[ 0, 0, 1], [ 0, 1, 0], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----23----
1346
+ {:rotation => [[ 0, 0, -1], [ 0, -1, 0], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----24----
1347
+ {:rotation => [[ 0, 0, -1], [ 1, 0, 0], [ 0, -1, 0]], :translation => [0.0, 0.0, 0.0]}, #----25----
1348
+ {:rotation => [[ 0, 0, 1], [-1, 0, 0], [ 0, 1, 0]], :translation => [0.0, 0.0, 0.0]}, #----26----
1349
+ {:rotation => [[ 0, 0, -1], [ 0, -1, 0], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----27----
1350
+ {:rotation => [[ 0, 0, 1], [ 0, 1, 0], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----28----
1351
+ {:rotation => [[ 0, 0, -1], [-1, 0, 0], [ 0, 1, 0]], :translation => [0.0, 0.0, 0.0]}, #----29----
1352
+ {:rotation => [[ 0, 0, 1], [ 1, 0, 0], [ 0, -1, 0]], :translation => [0.0, 0.0, 0.0]}, #----30----
1353
+ {:rotation => [[ 0, 0, -1], [ 0, 1, 0], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----31----
1354
+ {:rotation => [[ 0, 0, 1], [ 0, -1, 0], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----32----
1355
+ {:rotation => [[ 0, 1, 0], [ 0, 0, 1], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----33----
1356
+ {:rotation => [[ 0, -1, 0], [ 0, 0, -1], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----34----
1357
+ {:rotation => [[ 1, 0, 0], [ 0, 0, 1], [ 0, -1, 0]], :translation => [0.0, 0.0, 0.0]}, #----35----
1358
+ {:rotation => [[-1, 0, 0], [ 0, 0, -1], [ 0, 1, 0]], :translation => [0.0, 0.0, 0.0]}, #----36----
1359
+ {:rotation => [[ 0, -1, 0], [ 0, 0, 1], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----37----
1360
+ {:rotation => [[ 0, 1, 0], [ 0, 0, -1], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----38----
1361
+ {:rotation => [[-1, 0, 0], [ 0, 0, 1], [ 0, 1, 0]], :translation => [0.0, 0.0, 0.0]}, #----39----
1362
+ {:rotation => [[ 1, 0, 0], [ 0, 0, -1], [ 0, -1, 0]], :translation => [0.0, 0.0, 0.0]}, #----40----
1363
+ {:rotation => [[ 0, -1, 0], [ 0, 0, -1], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----41----
1364
+ {:rotation => [[ 0, 1, 0], [ 0, 0, 1], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----42----
1365
+ {:rotation => [[-1, 0, 0], [ 0, 0, -1], [ 0, -1, 0]], :translation => [0.0, 0.0, 0.0]}, #----43----
1366
+ {:rotation => [[ 1, 0, 0], [ 0, 0, 1], [ 0, 1, 0]], :translation => [0.0, 0.0, 0.0]}, #----44----
1367
+ {:rotation => [[ 0, 1, 0], [ 0, 0, -1], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----45----
1368
+ {:rotation => [[ 0, -1, 0], [ 0, 0, 1], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----46----
1369
+ {:rotation => [[ 1, 0, 0], [ 0, 0, -1], [ 0, 1, 0]], :translation => [0.0, 0.0, 0.0]}, #----47----
1370
+ {:rotation => [[-1, 0, 0], [ 0, 0, 1], [ 0, -1, 0]], :translation => [0.0, 0.0, 0.0]}, #----48----
1371
+ ]
1372
+
1373
+ results = @c10 .symmetry_operations($symprec, $angle_tolerance)
1374
+ assert_equal(corrects.size, results.size)
1375
+ corrects.size.times do |index|
1376
+ assert_equal(corrects[index], results[index])
320
1377
  end
321
1378
 
322
- def test_add_atom
323
- assert_raise(ArgumentError){
324
- @c00.add_atom('Li', [0.5, 0.5, 0.5] )
325
- }
326
-
327
- @c00.add_atom(CrystalCell::Atom.new( 'Li', [0.5, 0.5, 0.5] ))
328
- assert_equal( 1 , @c00.atoms.size)
329
- assert_equal( 'Li' , @c00.atoms[0].element)
330
- assert_equal( Mageo::Vector3DInternal[0.5, 0.5, 0.5], @c00.atoms[0].position)
331
- assert_equal( nil , @c00.atoms[0].name )
332
-
333
- @c00.add_atom(CrystalCell::Atom.new( nil , [0.5, 0.5, 0.5], 'A' ))
334
- assert_equal( 2 , @c00.atoms.size)
335
- assert_equal( nil , @c00.atoms[1].element)
336
- assert_equal( Mageo::Vector3DInternal[0.5, 0.5, 0.5], @c00.atoms[1].position)
337
- assert_equal( 'A' , @c00.atoms[1].name )
338
-
339
- @c02.add_atom(CrystalCell::Atom.new( 'Li', [0.5, 0.5, 0.5] ))
340
- assert_equal( 3 , @c02.atoms.size)
341
- assert_equal( 'Li' , @c02.atoms[0].element)
342
- assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], @c02.atoms[0].position)
343
- assert_equal( 'O' , @c02.atoms[1].element)
344
- assert_equal( Mageo::Vector3DInternal[0.2, 0.2, 0.2], @c02.atoms[1].position)
345
- assert_equal( 'Li' , @c02.atoms[2].element)
346
- assert_equal( Mageo::Vector3DInternal[0.5, 0.5, 0.5], @c02.atoms[2].position)
347
-
348
- @c01.add_atom(CrystalCell::Atom.new( 'Li', [0.5, 0.5, 0.5] ))
349
- assert_equal( 3 , @c01.atoms.size)
350
- assert_equal( 0 , @c01.atoms[0].element)
351
- assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], @c01.atoms[0].position)
352
- assert_equal( 1 , @c01.atoms[1].element)
353
- assert_equal( Mageo::Vector3DInternal[0.1, 0.2, 0.3], @c01.atoms[1].position)
354
- assert_equal( 'Li' , @c01.atoms[2].element)
355
- assert_equal( Mageo::Vector3DInternal[0.5, 0.5, 0.5], @c01.atoms[2].position)
356
-
357
- end
358
-
359
- def test_delete_atom
360
- # assert_raise(RuntimeError ) {@c00.delete_atom( 0 ) }
361
- assert_equal(nil, @c00.delete_atom( 0 ) )
362
- assert_equal([], @c00.positions )
363
- assert_equal([], @c00.elements )
364
-
365
- @c02.delete_atom( 0 )
366
- assert_equal( [ Mageo::Vector3DInternal[0.2, 0.2, 0.2] ], @c02.positions)
367
- assert_equal( [ 'O' ], @c02.elements )
368
- @c02.delete_atom( 0 )
369
- assert_equal( [], @c02.positions)
370
- assert_equal( [], @c02.elements )
371
-
372
- @c01.delete_atom( 0 )
373
- assert_equal( [ Mageo::Vector3DInternal[0.1, 0.2, 0.3] ], @c01.positions)
374
- assert_equal( [ 1 ], @c01.elements )
375
- end
376
-
377
- def test_set_elements
378
- # 原子がないので変更されない。
379
- @c00.set_elements( [] )
380
- assert_equal( [], @c00.atoms )
381
-
382
- # 0 -> 'Li、 1 -> 'O' に変更。
383
- tmp = Marshal.load( Marshal.dump( @c01 ))
384
- tmp.set_elements( [ 'Li', 'O' ] )
385
- assert_equal( 'Li', tmp.atoms[0].element )
386
- assert_equal( 'O', tmp.atoms[1].element )
387
-
388
- # 0 -> 'Li, 片方だけ変更。
389
- tmp = Marshal.load( Marshal.dump( @c01 ))
390
- tmp.set_elements( [ 'Li' ] )
391
- assert_equal( 'Li', tmp.atoms[0].element )
392
- assert_equal( 1, tmp.atoms[1].element )
393
-
394
- # 元々整数値以外にセットされているのでマッチせず変更されない。
395
- tmp = Marshal.load( Marshal.dump( @c02 ))
396
- tmp.set_elements( [ 'O', 'Li' ] )
397
- assert_equal( 'Li', tmp.atoms[0].element )
398
- assert_equal( 'O', tmp.atoms[1].element )
399
-
400
- # Hash argument.
401
- # 0 -> 'Li、 1 -> 'O' に変更。
402
- tmp = Marshal.load( Marshal.dump( @c01 ))
403
- tmp.set_elements( { 0 => 'Li', 1 => 'O' } )
404
- assert_equal( 'Li', tmp.atoms[0].element )
405
- assert_equal( 'O', tmp.atoms[1].element )
406
-
407
- # 'Li' -> 'Na', 'O' -> 'S' に変更。
408
- tmp = Marshal.load( Marshal.dump( @c02 ))
409
- tmp.set_elements( { 'Li' => 'Na', 'O' => 'S' } )
410
- assert_equal( 'Na', tmp.atoms[0].element )
411
- assert_equal( 'S', tmp.atoms[1].element )
412
-
413
- # 'Li' -> 'Na'、 片方だけ変更。
414
- tmp = Marshal.load( Marshal.dump( @c02 ))
415
- tmp.set_elements( { 'Li' => 'Na' } )
416
- assert_equal( 'Na', tmp.atoms[0].element )
417
- assert_equal( 'O', tmp.atoms[1].element )
418
- end
419
-
420
- def test_equal_lattice_in_delta?
421
- assert_equal( true , @c00.equal_lattice_in_delta?(@c00, 0.001, 0.1) )
422
- assert_equal( true , @c00.equal_lattice_in_delta?(@c02, 0.001, 0.1) )
423
- assert_equal( true , @c00.equal_lattice_in_delta?(@c01, 0.001, 0.1) )
424
- assert_equal( true , @c02.equal_lattice_in_delta?(@c00, 0.001, 0.1) )
425
- assert_equal( true , @c02.equal_lattice_in_delta?(@c02, 0.001, 0.1) )
426
- assert_equal( true , @c02.equal_lattice_in_delta?(@c01, 0.001, 0.1) )
427
- assert_equal( true , @c01.equal_lattice_in_delta?(@c00, 0.001, 0.1) )
428
- assert_equal( true , @c01.equal_lattice_in_delta?(@c02, 0.001, 0.1) )
429
- assert_equal( true , @c01.equal_lattice_in_delta?(@c01, 0.001, 0.1) )
430
-
431
- end
432
-
433
- def test_equal_atoms_in_delta?
434
- assert_equal( true , @c00.equal_atoms_in_delta?( @c00, 0.01 ) )
435
- assert_equal( false, @c00.equal_atoms_in_delta?( @c02, 0.01 ) )
436
- assert_equal( false, @c00.equal_atoms_in_delta?( @c01, 0.01 ) )
437
- assert_equal( false, @c00.equal_atoms_in_delta?( @c03, 0.01 ) )
438
- assert_equal( false, @c00.equal_atoms_in_delta?( @c04, 0.01 ) )
439
- assert_equal( false, @c00.equal_atoms_in_delta?( @c05, 0.01 ) )
440
- assert_equal( false, @c02.equal_atoms_in_delta?( @c00, 0.01 ) )
441
- assert_equal( true , @c02.equal_atoms_in_delta?( @c02, 0.01 ) )
442
- assert_equal( false, @c02.equal_atoms_in_delta?( @c01, 0.01 ) )
443
- assert_equal( true , @c02.equal_atoms_in_delta?( @c03, 0.01 ) )
444
- assert_equal( false, @c02.equal_atoms_in_delta?( @c04, 0.01 ) )
445
- assert_equal( false, @c02.equal_atoms_in_delta?( @c05, 0.01 ) )
446
- assert_equal( false, @c01.equal_atoms_in_delta?( @c00, 0.01 ) )
447
- assert_equal( false, @c01.equal_atoms_in_delta?( @c02, 0.01 ) )
448
- assert_equal( true , @c01.equal_atoms_in_delta?( @c01, 0.01 ) )
449
- assert_equal( false, @c01.equal_atoms_in_delta?( @c03, 0.01 ) )
450
- assert_equal( false, @c01.equal_atoms_in_delta?( @c04, 0.01 ) )
451
- assert_equal( false, @c01.equal_atoms_in_delta?( @c05, 0.01 ) )
452
- assert_equal( false, @c03.equal_atoms_in_delta?( @c00, 0.01 ) )
453
- assert_equal( true , @c03.equal_atoms_in_delta?( @c02, 0.01 ) )
454
- assert_equal( false, @c03.equal_atoms_in_delta?( @c01, 0.01 ) )
455
- assert_equal( true , @c03.equal_atoms_in_delta?( @c03, 0.01 ) )
456
- assert_equal( false, @c03.equal_atoms_in_delta?( @c04, 0.01 ) )
457
- assert_equal( false, @c03.equal_atoms_in_delta?( @c05, 0.01 ) )
458
- assert_equal( false, @c04.equal_atoms_in_delta?( @c00, 0.01 ) )
459
- assert_equal( false, @c04.equal_atoms_in_delta?( @c02, 0.01 ) )
460
- assert_equal( false, @c04.equal_atoms_in_delta?( @c01, 0.01 ) )
461
- assert_equal( false, @c04.equal_atoms_in_delta?( @c03, 0.01 ) )
462
- assert_equal( true , @c04.equal_atoms_in_delta?( @c04, 0.01 ) )
463
- assert_equal( false, @c04.equal_atoms_in_delta?( @c05, 0.01 ) )
464
- assert_equal( false, @c05.equal_atoms_in_delta?( @c00, 0.01 ) )
465
- assert_equal( false, @c05.equal_atoms_in_delta?( @c02, 0.01 ) )
466
- assert_equal( false, @c05.equal_atoms_in_delta?( @c01, 0.01 ) )
467
- assert_equal( false, @c05.equal_atoms_in_delta?( @c03, 0.01 ) )
468
- assert_equal( false, @c05.equal_atoms_in_delta?( @c04, 0.01 ) )
469
- assert_equal( true , @c05.equal_atoms_in_delta?( @c05, 0.01 ) )
470
- end
471
-
472
- def test_equal_in_delta?
473
- assert_equal(true , @c00.equal_in_delta?( @c00, 0.001, 0.1, 0.01 ) )
474
- assert_equal(false, @c00.equal_in_delta?( @c01, 0.001, 0.1, 0.01 ) )
475
- assert_equal(false, @c00.equal_in_delta?( @c02, 0.001, 0.1, 0.01 ) )
476
- assert_equal(false, @c00.equal_in_delta?( @c03, 0.001, 0.1, 0.01 ) )
477
- assert_equal(false, @c00.equal_in_delta?( @c04, 0.001, 0.1, 0.01 ) )
478
- assert_equal(false, @c00.equal_in_delta?( @c05, 0.001, 0.1, 0.01 ) )
479
-
480
- assert_equal(false, @c02.equal_in_delta?( @c00, 0.001, 0.1, 0.01 ) )
481
- assert_equal(false, @c02.equal_in_delta?( @c01, 0.001, 0.1, 0.01 ) )
482
- assert_equal(true , @c02.equal_in_delta?( @c02, 0.001, 0.1, 0.01 ) )
483
- assert_equal(true , @c02.equal_in_delta?( @c03, 0.001, 0.1, 0.01 ) )
484
- assert_equal(false, @c02.equal_in_delta?( @c04, 0.001, 0.1, 0.01 ) )
485
- assert_equal(false, @c02.equal_in_delta?( @c05, 0.001, 0.1, 0.01 ) )
486
-
487
- assert_equal(false, @c01.equal_in_delta?( @c00, 0.001, 0.1, 0.01 ) )
488
- assert_equal(true , @c01.equal_in_delta?( @c01, 0.001, 0.1, 0.01 ) )
489
- assert_equal(false, @c01.equal_in_delta?( @c02, 0.001, 0.1, 0.01 ) )
490
- assert_equal(false, @c01.equal_in_delta?( @c03, 0.001, 0.1, 0.01 ) )
491
- assert_equal(false, @c01.equal_in_delta?( @c04, 0.001, 0.1, 0.01 ) )
492
- assert_equal(false, @c01.equal_in_delta?( @c05, 0.001, 0.1, 0.01 ) )
493
-
494
- assert_equal(false, @c03.equal_in_delta?( @c00, 0.001, 0.1, 0.01 ) )
495
- assert_equal(false, @c03.equal_in_delta?( @c01, 0.001, 0.1, 0.01 ) )
496
- assert_equal(true , @c03.equal_in_delta?( @c02, 0.001, 0.1, 0.01 ) )
497
- assert_equal(true , @c03.equal_in_delta?( @c03, 0.001, 0.1, 0.01 ) )
498
- assert_equal(false, @c03.equal_in_delta?( @c04, 0.001, 0.1, 0.01 ) )
499
- assert_equal(false, @c03.equal_in_delta?( @c05, 0.001, 0.1, 0.01 ) )
500
-
501
- assert_equal(false, @c04.equal_in_delta?( @c00, 0.001, 0.1, 0.01 ) )
502
- assert_equal(false, @c04.equal_in_delta?( @c01, 0.001, 0.1, 0.01 ) )
503
- assert_equal(false, @c04.equal_in_delta?( @c02, 0.001, 0.1, 0.01 ) )
504
- assert_equal(false, @c04.equal_in_delta?( @c03, 0.001, 0.1, 0.01 ) )
505
- assert_equal(true , @c04.equal_in_delta?( @c04, 0.001, 0.1, 0.01 ) )
506
- assert_equal(false, @c04.equal_in_delta?( @c05, 0.001, 0.1, 0.01 ) )
507
-
508
- assert_equal(false, @c05.equal_in_delta?( @c00, 0.001, 0.1, 0.01 ) )
509
- assert_equal(false, @c05.equal_in_delta?( @c01, 0.001, 0.1, 0.01 ) )
510
- assert_equal(false, @c05.equal_in_delta?( @c02, 0.001, 0.1, 0.01 ) )
511
- assert_equal(false, @c05.equal_in_delta?( @c03, 0.001, 0.1, 0.01 ) )
512
- assert_equal(false, @c05.equal_in_delta?( @c04, 0.001, 0.1, 0.01 ) )
513
- assert_equal(true , @c05.equal_in_delta?( @c05, 0.001, 0.1, 0.01 ) )
514
- end
515
-
516
- def test_equal
517
- cell = CrystalCell::Cell.new( CrystalCell::LatticeAxes.new([ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0]]))
518
- assert_equal( true , @c00 == cell )
519
- assert_equal( false, @c01 == cell )
520
-
521
- cell = CrystalCell::Cell.new( CrystalCell::LatticeAxes.new([ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0]]))
522
- cell.add_atom(CrystalCell::Atom.new( 0, [0.0, 0.0, 0.0] ))
523
- cell.add_atom(CrystalCell::Atom.new( 1, [0.1, 0.2, 0.3] ))
524
- assert_equal( false, @c00 == cell )
525
- assert_equal( true , @c01 == cell )
526
- end
527
-
528
- def test_distance
529
- assert_raise(CrystalCell::Cell::TypeError){@c00.distance([0,0,0], [1,1,1])}
530
- assert_raise(CrystalCell::Cell::TypeError){@c00.distance([0,0,0], Mageo::Vector3DInternal[1,1,1])}
531
- assert_raise(CrystalCell::Cell::TypeError){@c00.distance([0,0,0], Mageo::Vector3D[1,1,1])}
532
-
533
- assert_in_delta(
534
- Math::sqrt(0.56),
535
- @c00.distance(Mageo::Vector3DInternal[0.0, 0.0, 0.0], Mageo::Vector3DInternal[0.1, 0.1, 0.1] ),
536
- $tolerance
537
- )
538
- assert_in_delta( Math::sqrt( 1.6**2 + 3.4**2 + 5.4**2),
539
- @c00.distance( Mageo::Vector3DInternal[0.0, 0.0, 0.0], Mageo::Vector3DInternal[0.8, 0.9, 1.0] ), $tolerance
540
- )
541
-
542
- assert_in_delta( Math::sqrt(0.56), @c00.distance( Mageo::Vector3DInternal[0.0, 0.0, 0.0], Mageo::Vector3DInternal[0.1, 0.1, 0.1] ), $tolerance )
543
- assert_in_delta( Math::sqrt( 1.6**2 + 3.4**2 + 5.4**2),
544
- @c00.distance( Mageo::Vector3DInternal[0.0, 0.0, 0.0], Mageo::Vector3DInternal[0.8, 0.9, 1.0] ), $tolerance
545
- )
546
- end
547
-
548
- def test_dump_poscar
549
- c00_str = [
550
- 'c00',
551
- '1.0',
552
- ' 2.00000000000000 2.00000000000000 2.00000000000000',
553
- ' 0.00000000000000 2.00000000000000 2.00000000000000',
554
- ' 0.00000000000000 0.00000000000000 2.00000000000000',
555
- ' ',
556
- '',
557
- 'Direct'
558
- ].join("\n")
559
-
560
- c01_str = [
561
- 'c01',
562
- '1.0',
563
- ' 2.00000000000000 2.00000000000000 2.00000000000000',
564
- ' 0.00000000000000 2.00000000000000 2.00000000000000',
565
- ' 0.00000000000000 0.00000000000000 2.00000000000000',
566
- ' 0 1',
567
- ' 1 1',
568
- 'Direct',
569
- ' 0.00000000000000 0.00000000000000 0.00000000000000',
570
- ' 0.10000000000000 0.20000000000000 0.30000000000000'
571
- ].join("\n")
572
-
573
- c02_str = [
574
- 'c02',
575
- '1.0',
576
- ' 2.00000000000000 2.00000000000000 2.00000000000000',
577
- ' 0.00000000000000 2.00000000000000 2.00000000000000',
578
- ' 0.00000000000000 0.00000000000000 2.00000000000000',
579
- ' Li O',
580
- ' 1 1',
581
- 'Direct',
582
- ' 0.00000000000000 0.00000000000000 0.00000000000000',
583
- ' 0.20000000000000 0.20000000000000 0.20000000000000'
584
- ].join("\n")
585
-
586
- c03_str = [
587
- 'c03',
588
- '1.0',
589
- ' 2.00000000000000 2.00000000000000 2.00000000000000',
590
- ' 0.00000000000000 2.00000000000000 2.00000000000000',
591
- ' 0.00000000000000 0.00000000000000 2.00000000000000',
592
- ' Li O',
593
- ' 1 1',
594
- 'Direct',
595
- ' 0.00000000000000 0.00000000000000 0.00000000000000',
596
- ' 0.20000000000000 0.20000000000000 0.20000000000000'
597
- ].join("\n")
598
-
599
- c04_str = [
600
- 'c04',
601
- '1.0',
602
- ' 2.00000000000000 2.00000000000000 2.00000000000000',
603
- ' 0.00000000000000 2.00000000000000 2.00000000000000',
604
- ' 0.00000000000000 0.00000000000000 2.00000000000000',
605
- ' Li O',
606
- ' 2 1',
607
- 'Direct',
608
- ' 0.00000000000000 0.00000000000000 0.00000000000000',
609
- ' 0.10000000000000 0.20000000000000 0.30000000000000',
610
- ' 0.20000000000000 0.20000000000000 0.20000000000000'
611
- ].join("\n")
612
-
613
- c05_str = [
614
- 'c05',
615
- '1.0',
616
- ' 2.00000000000000 2.00000000000000 2.00000000000000',
617
- ' 0.00000000000000 2.00000000000000 2.00000000000000',
618
- ' 0.00000000000000 0.00000000000000 2.00000000000000',
619
- ' Li',
620
- ' 1',
621
- 'Direct',
622
- ' 0.00000000000000 0.00000000000000 0.00000000000000'
623
- ].join("\n")
624
-
625
- c06_str = [
626
- 'c06',
627
- '1.0',
628
- ' 2.00000000000000 2.00000000000000 2.00000000000000',
629
- ' 0.00000000000000 2.00000000000000 2.00000000000000',
630
- ' 0.00000000000000 0.00000000000000 2.00000000000000',
631
- ' Li O',
632
- ' 1 1',
633
- 'Selective dynamics',
634
- 'Direct',
635
- ' 0.00000000000000 0.00000000000000 0.00000000000000 T F F',
636
- ' 0.20000000000000 0.20000000000000 0.20000000000000 T T T'
637
- ].join("\n")
638
-
639
- # Raise exception
640
- # assert_raise( RuntimeError ){ @c00.dump_poscar( [], io ) }
641
- assert_raise( RuntimeError ){ @c00.dump_poscar( [0] ) }
642
- assert_raise( RuntimeError ){ @c00.dump_poscar( [0, 1] ) }
643
- assert_raise( RuntimeError ){ @c00.dump_poscar( ['Li'] ) }
644
- assert_raise( RuntimeError ){ @c00.dump_poscar( ['Li', 'O'] ) }
645
- assert_raise( RuntimeError ){ @c02.dump_poscar( [] ) }
646
- assert_raise( RuntimeError ){ @c02.dump_poscar( [0] ) }
647
- assert_raise( RuntimeError ){ @c02.dump_poscar( [0, 1] ) }
648
- assert_raise( RuntimeError ){ @c02.dump_poscar( ['Li'] ) }
649
- assert_raise( RuntimeError ){ @c01.dump_poscar( [] ) }
650
- assert_raise( RuntimeError ){ @c01.dump_poscar( [0] ) }
651
- assert_raise( RuntimeError ){ @c01.dump_poscar( ['Li'] ) }
652
- assert_raise( RuntimeError ){ @c01.dump_poscar( ['Li', 'O'] ) }
653
- assert_raise( RuntimeError ){ @c04.dump_poscar( [] ) }
654
- assert_raise( RuntimeError ){ @c04.dump_poscar( [0] ) }
655
- assert_raise( RuntimeError ){ @c04.dump_poscar( [0, 1] ) }
656
- assert_raise( RuntimeError ){ @c04.dump_poscar( ['Li'] ) }
657
- assert_raise( RuntimeError ){ @c05.dump_poscar( [] ) }
658
- assert_raise( RuntimeError ){ @c05.dump_poscar( [0] ) }
659
- assert_raise( RuntimeError ){ @c05.dump_poscar( [0, 1] ) }
660
- assert_raise( RuntimeError ){ @c05.dump_poscar( ['Li', 'O'] ) }
661
- assert_raise( RuntimeError ){ @c03.dump_poscar( [] ) }
662
- assert_raise( RuntimeError ){ @c03.dump_poscar( [0] ) }
663
- assert_raise( RuntimeError ){ @c03.dump_poscar( [0, 1] ) }
664
- assert_raise( RuntimeError ){ @c03.dump_poscar( ['Li'] ) }
665
-
666
- #
667
- StringIO.new do |io|
668
- @c00.dump_poscar( [], io )
669
- assert_equal( c00_str, io.read )
670
- end
671
-
672
- StringIO.new do |io|
673
- @c01.dump_poscar( [ 0, 1 ], io )
674
- assert_equal( c01, io.read )
675
- end
676
-
677
- StringIO.new do |io|
678
- @c02.dump_poscar( [ 'Li', 'O' ], io )
679
- assert_equal( c02, io.read )
680
- end
681
-
682
- StringIO.new do |io|
683
- @c03.dump_poscar( [ 'Li', 'O' ], io )
684
- assert_equal( c03, io.read )
1379
+ #monoclinic/POSCAR #P2/m (10) / 2/m / -P 2y (57)
1380
+ corrects = [
1381
+ {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----01----
1382
+ {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----02----
1383
+ {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----03----
1384
+ {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----04----
1385
+ ]
1386
+ #pp @c12
1387
+ assert_equal(corrects, @c12 .symmetry_operations($symprec, $angle_tolerance)) #monoclinic
1388
+
1389
+ #orthorhombic/POSCAR #Pmmm (47) / mmm / -P 2 2 (227)
1390
+ corrects = [
1391
+ {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----01----
1392
+ {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----02----
1393
+ {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----03----
1394
+ {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----04----
1395
+ {:rotation => [[ 1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----05----
1396
+ {:rotation => [[-1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----06----
1397
+ {:rotation => [[-1, 0, 0], [ 0, 1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----07----
1398
+ {:rotation => [[ 1, 0, 0], [ 0, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----08----
1399
+ ]
1400
+ assert_equal(corrects, @c13 .symmetry_operations($symprec, $angle_tolerance)) #orthorhombic
1401
+
1402
+ #tetragonal-b/POSCAR #P4/mmm (123) / 4/mmm/ -P 4 2 (400)
1403
+ corrects = [
1404
+ {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----01----
1405
+ {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----02----
1406
+ {:rotation => [[ 0, 0, 1], [ 0, 1, 0], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----03----
1407
+ {:rotation => [[ 0, 0, -1], [ 0, -1, 0], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----04----
1408
+ {:rotation => [[-1, 0, 0], [ 0, 1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----05----
1409
+ {:rotation => [[ 1, 0, 0], [ 0, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----06----
1410
+ {:rotation => [[ 0, 0, -1], [ 0, 1, 0], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----07----
1411
+ {:rotation => [[ 0, 0, 1], [ 0, -1, 0], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----08----
1412
+ {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----09----
1413
+ {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----10----
1414
+ {:rotation => [[ 0, 0, -1], [ 0, -1, 0], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----11----
1415
+ {:rotation => [[ 0, 0, 1], [ 0, 1, 0], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----12----
1416
+ {:rotation => [[ 1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----13----
1417
+ {:rotation => [[-1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----14----
1418
+ {:rotation => [[ 0, 0, 1], [ 0, -1, 0], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----15----
1419
+ {:rotation => [[ 0, 0, -1], [ 0, 1, 0], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----16----
1420
+ ]
1421
+ assert_equal(corrects, @c14b .symmetry_operations($symprec, $angle_tolerance)) #tetragonal
1422
+
1423
+ #tetragonal/POSCAR #P4/mmm (123) / 4/mmm/ -P 4 2 (400)
1424
+ corrects = [
1425
+ {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----01----
1426
+ {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----02----
1427
+ {:rotation => [[ 0, -1, 0], [ 1, 0, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----03----
1428
+ {:rotation => [[ 0, 1, 0], [-1, 0, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----04----
1429
+ {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----05----
1430
+ {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----06----
1431
+ {:rotation => [[ 0, 1, 0], [-1, 0, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----07----
1432
+ {:rotation => [[ 0, -1, 0], [ 1, 0, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----08----
1433
+ {:rotation => [[ 1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----09----
1434
+ {:rotation => [[-1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----10----
1435
+ {:rotation => [[ 0, -1, 0], [-1, 0, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----11----
1436
+ {:rotation => [[ 0, 1, 0], [ 1, 0, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----12----
1437
+ {:rotation => [[-1, 0, 0], [ 0, 1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----13----
1438
+ {:rotation => [[ 1, 0, 0], [ 0, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----14----
1439
+ {:rotation => [[ 0, 1, 0], [ 1, 0, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----15----
1440
+ {:rotation => [[ 0, -1, 0], [-1, 0, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----16----
1441
+ ]
1442
+ assert_equal(corrects, @c14.symmetry_operations($symprec, $angle_tolerance)) #tetragonal-b
1443
+
1444
+ #triclinic/POSCAR #P1 (1) / 1 / P 1 (1)
1445
+ corrects = [
1446
+ {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----01----
1447
+ ]
1448
+ assert_equal(corrects, @c15 .symmetry_operations($symprec, $angle_tolerance)) #triclinic
1449
+
1450
+ #trigonal/POSCAR #P-3m1 (164) / -3m / -P 3 2= (456)
1451
+ corrects = [
1452
+ {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----01----
1453
+ {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [f13, f13, f13]}, #----02----
1454
+ {:rotation => [[-1, -1, 0], [ 1, 0, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 1.0]}, #----03----
1455
+ {:rotation => [[ 1, 1, 0], [-1, 0, 0], [ 0, 0, -1]], :translation => [f13, f13, f13]}, #----04----
1456
+ {:rotation => [[ 0, 1, 0], [-1, -1, 0], [ 0, 0, 1]], :translation => [1.0, 0.0, 1.0]}, #----05----
1457
+ {:rotation => [[ 0, -1, 0], [ 1, 1, 0], [ 0, 0, -1]], :translation => [f13, f13, f13]}, #----06----
1458
+ {:rotation => [[ 0, -1, 0], [-1, 0, 0], [ 0, 0, -1]], :translation => [f13, f13, f13]}, #----07----
1459
+ {:rotation => [[ 0, 1, 0], [ 1, 0, 0], [ 0, 0, 1]], :translation => [1.0, 0.0, 1.0]}, #----08----
1460
+ {:rotation => [[-1, 0, 0], [ 1, 1, 0], [ 0, 0, -1]], :translation => [f13, f13, f13]}, #----09----
1461
+ {:rotation => [[ 1, 0, 0], [-1, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 1.0]}, #----10----
1462
+ {:rotation => [[ 1, 1, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [f13, f13, f13]}, #----11----
1463
+ {:rotation => [[-1, -1, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 1.0]}, #----12----
1464
+ ]
1465
+ results = @c16.symmetry_operations($symprec, $angle_tolerance)
1466
+ corrects.size.times do |i|
1467
+ 3.times do |x|
1468
+ 3.times do |y|
1469
+ assert_in_delta(corrects[i][:rotation][x][y], results[i][:rotation][x][y], $tolerance)
685
1470
  end
686
-
687
- StringIO.new do |io|
688
- @c04.dump_poscar( [ 'Li', 'O' ], io )
689
- assert_equal( c04, io.read )
690
- end
691
-
692
- StringIO.new do |io|
693
- @c05.dump_poscar( [ 'Li', 'O' ], io )
694
- assert_equal( c05, io.read )
695
- end
696
-
697
- assert_equal( c00_str, @c00.dump_poscar( [ ], nil ) )
698
- assert_equal( c01_str, @c01.dump_poscar( [ 0 , 1 ], nil ) )
699
- assert_equal( c02_str, @c02.dump_poscar( [ 'Li', 'O' ], nil ) )
700
- assert_equal( c03_str, @c03.dump_poscar( [ 'Li', 'O' ], nil ) )
701
- assert_equal( c04_str, @c04.dump_poscar( [ 'Li', 'O' ], nil ) )
702
- assert_equal( c05_str, @c05.dump_poscar( [ 'Li' ], nil ) )
703
-
704
- assert_equal( c00_str, @c00.dump_poscar( [ ] ) )
705
- assert_equal( c01_str, @c01.dump_poscar( [ 0 , 1 ] ) )
706
- assert_equal( c02_str, @c02.dump_poscar( [ 'Li', 'O' ] ) )
707
- assert_equal( c03_str, @c03.dump_poscar( [ 'Li', 'O' ] ) )
708
- assert_equal( c04_str, @c04.dump_poscar( [ 'Li', 'O' ] ) )
709
- assert_equal( c05_str, @c05.dump_poscar( [ 'Li' ] ) )
710
-
711
- assert_equal( c06_str, @c06 .dump_poscar( [ 'Li', 'O' ] ) )
712
-
1471
+ end
1472
+ 3.times do |xyz|
1473
+ assert_in_delta(corrects[i][:translation][xyz], results[i][:translation][xyz], $tolerance)
1474
+ end
713
1475
  end
714
1476
 
715
- def test_rotate
716
- @c02.add_atom(CrystalCell::Atom.new( 'Li', [1.1, 1.2, 1.3] ))
717
- assert_equal(
718
- [ Mageo::Vector3DInternal[ 0.0, 0.0, 0.0 ],
719
- Mageo::Vector3DInternal[ -0.2, -0.2, -0.2 ],
720
- Mageo::Vector3DInternal[ -1.1, -1.2, -1.3 ]
721
- ],
722
- @c02.rotate( [[-1, 0, 0],[0, -1, 0],[0, 0, -1]] ).positions
723
- )
724
-
725
- # Check not destructed.
726
- assert_equal(
727
- [ Mageo::Vector3DInternal[ 0.0, 0.0, 0.0 ],
728
- Mageo::Vector3DInternal[ 0.2, 0.2, 0.2 ],
729
- Mageo::Vector3DInternal[ 1.1, 1.2, 1.3 ]
730
- ],
731
- @c02.positions
732
- )
733
- end
734
-
735
- def test_rotate!
736
- @c02.add_atom(CrystalCell::Atom.new( 'Li', [0.1, 0.2, 0.3] ))
737
- @c02.rotate!( [[-1, 0, 0],[0, -1, 0],[0, 0, -1]] )
738
- assert_equal(
739
- [ Mageo::Vector3DInternal[ 0.0, 0.0, 0.0 ],
740
- Mageo::Vector3DInternal[ -0.2, -0.2, -0.2 ],
741
- Mageo::Vector3DInternal[ -0.1, -0.2, -0.3 ]
742
- ],
743
- @c02.positions
744
- )
745
- end
746
-
747
- def test_translate
748
- poss = @c02.translate( [1.1, 1.2, 1.3] ).positions
749
- assert_in_delta( 1.1, poss[0][0], $tolerance )
750
- assert_in_delta( 1.2, poss[0][1], $tolerance )
751
- assert_in_delta( 1.3, poss[0][2], $tolerance )
752
- assert_in_delta( 1.3, poss[1][0], $tolerance )
753
- assert_in_delta( 1.4, poss[1][1], $tolerance )
754
- assert_in_delta( 1.5, poss[1][2], $tolerance )
755
-
756
- poss = @c02.translate( [-0.3,-0.3,-0.3] ).positions
757
- assert_in_delta( -0.3, poss[0][0], $tolerance )
758
- assert_in_delta( -0.3, poss[0][1], $tolerance )
759
- assert_in_delta( -0.3, poss[0][2], $tolerance )
760
- assert_in_delta( -0.1, poss[1][0], $tolerance )
761
- assert_in_delta( -0.1, poss[1][1], $tolerance )
762
- assert_in_delta( -0.1, poss[1][2], $tolerance )
763
-
764
- # Check not destructed.
765
- assert_equal(
766
- [ Mageo::Vector3DInternal[ 0.0, 0.0, 0.0 ],
767
- Mageo::Vector3DInternal[ 0.2, 0.2, 0.2 ]
768
- ],
769
- @c02.positions
770
- )
771
- end
772
-
773
- def test_translate!
774
- @c02.translate!( [1.1, 1.2, 1.3] )
775
- poss = @c02.positions
776
-
777
- assert_in_delta( 1.1, poss[0][0], $tolerance )
778
- assert_in_delta( 1.2, poss[0][1], $tolerance )
779
- assert_in_delta( 1.3, poss[0][2], $tolerance )
780
- assert_in_delta( 1.3, poss[1][0], $tolerance )
781
- assert_in_delta( 1.4, poss[1][1], $tolerance )
782
- assert_in_delta( 1.5, poss[1][2], $tolerance )
783
- end
784
-
785
- def test_center_of_atoms
786
- # No atom in the cell.
787
- assert_raise( CrystalCell::Cell::NoAtomError ){ @c00.center_of_atoms }
788
-
789
- assert_equal( Mageo::Vector3DInternal[0.05, 0.1, 0.15], @c01.center_of_atoms )
790
- assert_equal( Mageo::Vector3DInternal[0.1, 0.1, 0.1], @c02.center_of_atoms )
791
- assert_equal( Mageo::Vector3DInternal[0.1, 0.1, 0.1], @c03.center_of_atoms )
792
- assert_equal( Mageo::Vector3DInternal[0.1, 4.0/30.0, 5.0/30.0], @c04.center_of_atoms )
793
- assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], @c05.center_of_atoms )
794
- assert_equal( Mageo::Vector3DInternal[0.1, 0.1, 0.1], @c06.center_of_atoms )
795
- assert_equal( Mageo::Vector3DInternal[0.1, 0.1, 0.1], @c07.center_of_atoms )
796
- end
797
-
798
- def test_calc_volume
799
- # @c00 = CrystalCell::Cell.new( [ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0] ] )
800
- assert_in_delta( 8.00, @c00.calc_volume, $tolerance)
801
-
802
- c10 = CrystalCell::Cell.new( [ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0] ] )
803
- c11 = CrystalCell::Cell.new( [ [0.5, 0.5, 0.0], [0.5, 0.0, 0.5], [0.0, 0.5, 0.5] ] )
804
- assert_in_delta( 1.00, c10.calc_volume, $tolerance)
805
- assert_in_delta( 0.25, c11.calc_volume, $tolerance)
806
- end
807
-
808
- def test_cell_of_elements
809
- t = @c04.cell_of_elements( [ 'Li' ] )
810
- assert_equal( CrystalCell::Cell, t.class )
811
- assert_in_delta( 2.0, t.axes[0][0], $tolerance )
812
- assert_in_delta( 2.0, t.axes[0][1], $tolerance )
813
- assert_in_delta( 2.0, t.axes[0][2], $tolerance )
814
- assert_in_delta( 0.0, t.axes[1][0], $tolerance )
815
- assert_in_delta( 2.0, t.axes[1][1], $tolerance )
816
- assert_in_delta( 2.0, t.axes[1][2], $tolerance )
817
- assert_in_delta( 0.0, t.axes[2][0], $tolerance )
818
- assert_in_delta( 0.0, t.axes[2][1], $tolerance )
819
- assert_in_delta( 2.0, t.axes[2][2], $tolerance )
820
- assert_equal( 2, t.atoms.size )
821
- # checking atom 0
822
- assert_equal( 'Li' , t.atoms[0].element)
823
- assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
824
- assert_equal( nil , t.atoms[0].name )
825
- # checking atom 1
826
- assert_equal( 'Li' , t.atoms[1].element)
827
- assert_equal( Mageo::Vector3DInternal[0.1, 0.2, 0.3], t.atoms[1].position)
828
- assert_equal( nil , t.atoms[1].name )
829
-
830
- t = @c04.cell_of_elements( [ 'Li', 'O' ] )
831
- assert_equal( CrystalCell::Cell, t.class )
832
- assert_in_delta( 2.0, t.axes[0][0], $tolerance )
833
- assert_in_delta( 2.0, t.axes[0][1], $tolerance )
834
- assert_in_delta( 2.0, t.axes[0][2], $tolerance )
835
- assert_in_delta( 0.0, t.axes[1][0], $tolerance )
836
- assert_in_delta( 2.0, t.axes[1][1], $tolerance )
837
- assert_in_delta( 2.0, t.axes[1][2], $tolerance )
838
- assert_in_delta( 0.0, t.axes[2][0], $tolerance )
839
- assert_in_delta( 0.0, t.axes[2][1], $tolerance )
840
- assert_in_delta( 2.0, t.axes[2][2], $tolerance )
841
- assert_equal( 3, t.atoms.size )
842
- # checking atom 0
843
- assert_equal( 'Li' , t.atoms[0].element)
844
- assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
845
- assert_equal( nil , t.atoms[0].name )
846
- # checking atom 1
847
- assert_equal( 'O' , t.atoms[1].element)
848
- assert_equal( Mageo::Vector3DInternal[0.2, 0.2, 0.2], t.atoms[1].position)
849
- assert_equal( nil , t.atoms[1].name )
850
- # checking atom 2
851
- assert_equal( 'Li' , t.atoms[2].element)
852
- assert_equal( Mageo::Vector3DInternal[0.1, 0.2, 0.3], t.atoms[2].position)
853
- assert_equal( nil , t.atoms[2].name )
854
-
855
- t = @c04.cell_of_elements( [ 'O' ] )
856
- assert_equal( CrystalCell::Cell, t.class )
857
- assert_in_delta( 2.0, t.axes[0][0], $tolerance )
858
- assert_in_delta( 2.0, t.axes[0][1], $tolerance )
859
- assert_in_delta( 2.0, t.axes[0][2], $tolerance )
860
- assert_in_delta( 0.0, t.axes[1][0], $tolerance )
861
- assert_in_delta( 2.0, t.axes[1][1], $tolerance )
862
- assert_in_delta( 2.0, t.axes[1][2], $tolerance )
863
- assert_in_delta( 0.0, t.axes[2][0], $tolerance )
864
- assert_in_delta( 0.0, t.axes[2][1], $tolerance )
865
- assert_in_delta( 2.0, t.axes[2][2], $tolerance )
866
- assert_equal( 1, t.atoms.size )
867
- # checking atom 0
868
- assert_equal( 'O' , t.atoms[0].element)
869
- assert_equal( Mageo::Vector3DInternal[0.2, 0.2, 0.2], t.atoms[0].position)
870
- assert_equal( nil , t.atoms[0].name )
871
-
872
- t = @c04.cell_of_elements( [ 'F' ] )
873
- assert_equal( CrystalCell::Cell, t.class )
874
- assert_in_delta( 2.0, t.axes[0][0], $tolerance )
875
- assert_in_delta( 2.0, t.axes[0][1], $tolerance )
876
- assert_in_delta( 2.0, t.axes[0][2], $tolerance )
877
- assert_in_delta( 0.0, t.axes[1][0], $tolerance )
878
- assert_in_delta( 2.0, t.axes[1][1], $tolerance )
879
- assert_in_delta( 2.0, t.axes[1][2], $tolerance )
880
- assert_in_delta( 0.0, t.axes[2][0], $tolerance )
881
- assert_in_delta( 0.0, t.axes[2][1], $tolerance )
882
- assert_in_delta( 2.0, t.axes[2][2], $tolerance )
883
- assert_equal( 0, t.atoms.size )
884
-
885
-
886
- # サブクラスで使用したときに、サブクラスで作られるか?
887
- fc04 = FooCell.new( [ [2.0, 2.0, 2.0], [0.0, 2.0, 2.0], [0.0, 0.0, 2.0] ] )
888
- fc04.add_atom(CrystalCell::Atom.new( 'Li', [0.0, 0.0, 0.0] ))
889
- fc04.add_atom(CrystalCell::Atom.new( 'O' , [0.2, 0.2, 0.2] ))
890
- fc04.add_atom(CrystalCell::Atom.new( 'Li', [0.1, 0.2, 0.3] ))
891
- fc04.comment = 'fc04'
892
- t = fc04.cell_of_elements( [ 'Li' ] )
893
- assert_equal( FooCell, t.class )
894
- assert_in_delta( 2.0, t.axes[0][0], $tolerance )
895
- assert_in_delta( 2.0, t.axes[0][1], $tolerance )
896
- assert_in_delta( 2.0, t.axes[0][2], $tolerance )
897
- assert_in_delta( 0.0, t.axes[1][0], $tolerance )
898
- assert_in_delta( 2.0, t.axes[1][1], $tolerance )
899
- assert_in_delta( 2.0, t.axes[1][2], $tolerance )
900
- assert_in_delta( 0.0, t.axes[2][0], $tolerance )
901
- assert_in_delta( 0.0, t.axes[2][1], $tolerance )
902
- assert_in_delta( 2.0, t.axes[2][2], $tolerance )
903
- assert_equal( 2, t.atoms.size )
904
- # checking atom 0
905
- assert_equal( 'Li' , t.atoms[0].element)
906
- assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
907
- assert_equal( nil , t.atoms[0].name )
908
- # checking atom 1
909
- assert_equal( 'Li' , t.atoms[1].element)
910
- assert_equal( Mageo::Vector3DInternal[0.1, 0.2, 0.3], t.atoms[1].position)
911
- assert_equal( nil , t.atoms[1].name )
912
- end
913
-
914
- def test_unite
915
- ## 格子定数が違えば例外。将来的な feature.
916
- #t = CrystalCell::Cell.new( [ [2.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 2.0] ] )
917
- #t.add_atom(CrystalCell::Atom.new( 'Li', [0.0, 0.0, 0.0] ))
918
- #t.comment = 't'
919
- #assert_raise( CrystalCell::Cell::AxesMismatchError ){ @c05.unite( t ) }
920
- t = CrystalCell::Cell.new( [ [2.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 2.0] ] )
921
- t.add_atom(CrystalCell::Atom.new( 'Li', [0.0, 0.0, 0.0] ))
922
- t.comment = 't'
923
- assert_nothing_raised{ @c05.unite( t ) }
924
-
925
- # unite
926
- # 同じ座標のものがあっても気にせず統合する。
927
- t = @c05.unite( @c06 )
928
- assert_equal( CrystalCell::Cell, t.class )
929
- assert_in_delta( 2.0, t.axes[0][0], $tolerance )
930
- assert_in_delta( 2.0, t.axes[0][1], $tolerance )
931
- assert_in_delta( 2.0, t.axes[0][2], $tolerance )
932
- assert_in_delta( 0.0, t.axes[1][0], $tolerance )
933
- assert_in_delta( 2.0, t.axes[1][1], $tolerance )
934
- assert_in_delta( 2.0, t.axes[1][2], $tolerance )
935
- assert_in_delta( 0.0, t.axes[2][0], $tolerance )
936
- assert_in_delta( 0.0, t.axes[2][1], $tolerance )
937
- assert_in_delta( 2.0, t.axes[2][2], $tolerance )
938
- assert_equal( 3, t.atoms.size )
939
- # checking atom 0
940
- assert_equal( 'Li' , t.atoms[0].element)
941
- assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
942
- assert_equal( nil , t.atoms[0].name )
943
- # checking atom 1
944
- assert_equal( 'Li' , t.atoms[1].element)
945
- assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t.atoms[1].position)
946
- assert_equal( nil , t.atoms[1].name )
947
- # checking atom 2
948
- assert_equal( 'O' , t.atoms[2].element)
949
- assert_equal( Mageo::Vector3DInternal[0.2, 0.2, 0.2], t.atoms[2].position)
950
- assert_equal( nil , t.atoms[2].name )
951
- end
952
-
953
- def test_inverse_axis!
954
- @c02.inverse_axis!( 0 )
955
- t = @c02
956
- assert_equal( CrystalCell::Cell, t.class )
957
- assert_in_delta(-2.0, t.axes[0][0], $tolerance )
958
- assert_in_delta(-2.0, t.axes[0][1], $tolerance )
959
- assert_in_delta(-2.0, t.axes[0][2], $tolerance )
960
- assert_in_delta( 0.0, t.axes[1][0], $tolerance )
961
- assert_in_delta( 2.0, t.axes[1][1], $tolerance )
962
- assert_in_delta( 2.0, t.axes[1][2], $tolerance )
963
- assert_in_delta( 0.0, t.axes[2][0], $tolerance )
964
- assert_in_delta( 0.0, t.axes[2][1], $tolerance )
965
- assert_in_delta( 2.0, t.axes[2][2], $tolerance )
966
- assert_equal( 2, t.atoms.size )
967
- # checking atom 0
968
- assert_equal( 'Li' , t.atoms[0].element)
969
- assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
970
- assert_equal( nil , t.atoms[0].name )
971
- # checking atom 1
972
- assert_equal( 'O' , t.atoms[1].element)
973
- assert_equal( Mageo::Vector3DInternal[-0.2, 0.2, 0.2], t.atoms[1].position)
974
- assert_equal( nil , t.atoms[1].name )
975
- end
976
-
977
- def test_inverse_axis
978
- assert_raise( CrystalCell::Cell::AxesRangeError ){ @c02.inverse_axis( -1 ) }
979
- assert_raise( CrystalCell::Cell::AxesRangeError ){ @c02.inverse_axis( 3 ) }
980
-
981
- # x 軸反転
982
- t = @c02.inverse_axis( 0 )
983
- assert_equal( CrystalCell::Cell, t.class )
984
- assert_in_delta( -2.0, t.axes[0][0], $tolerance )
985
- assert_in_delta( -2.0, t.axes[0][1], $tolerance )
986
- assert_in_delta( -2.0, t.axes[0][2], $tolerance )
987
- assert_in_delta( 0.0, t.axes[1][0], $tolerance )
988
- assert_in_delta( 2.0, t.axes[1][1], $tolerance )
989
- assert_in_delta( 2.0, t.axes[1][2], $tolerance )
990
- assert_in_delta( 0.0, t.axes[2][0], $tolerance )
991
- assert_in_delta( 0.0, t.axes[2][1], $tolerance )
992
- assert_in_delta( 2.0, t.axes[2][2], $tolerance )
993
- assert_equal( 2, t.atoms.size )
994
- # checking atom 0
995
- assert_equal( 'Li' , t.atoms[0].element)
996
- assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
997
- assert_equal( nil , t.atoms[0].name )
998
- # checking atom 1
999
- assert_equal( 'O' , t.atoms[1].element)
1000
- assert_equal( Mageo::Vector3DInternal[-0.2, 0.2, 0.2], t.atoms[1].position)
1001
- assert_equal( nil , t.atoms[1].name )
1002
- # checking non-destructive
1003
- assert_equal( CrystalCell::Cell, t.class )
1004
- assert_in_delta( 2.0, @c02.axes[0][0], $tolerance )
1005
- assert_in_delta( 2.0, @c02.axes[0][1], $tolerance )
1006
- assert_in_delta( 2.0, @c02.axes[0][2], $tolerance )
1007
- assert_in_delta( 0.0, @c02.axes[1][0], $tolerance )
1008
- assert_in_delta( 2.0, @c02.axes[1][1], $tolerance )
1009
- assert_in_delta( 2.0, @c02.axes[1][2], $tolerance )
1010
- assert_in_delta( 0.0, @c02.axes[2][0], $tolerance )
1011
- assert_in_delta( 0.0, @c02.axes[2][1], $tolerance )
1012
- assert_in_delta( 2.0, @c02.axes[2][2], $tolerance )
1013
- assert_equal( 2, @c02.atoms.size )
1014
- # checking atom 0
1015
- assert_equal( 'Li' , @c02.atoms[0].element)
1016
- assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], @c02.atoms[0].position)
1017
- assert_equal( nil , @c02.atoms[0].name )
1018
- # checking atom 1
1019
- assert_equal( 'O' , @c02.atoms[1].element)
1020
- assert_equal( Mageo::Vector3DInternal[ 0.2, 0.2, 0.2], @c02.atoms[1].position)
1021
- assert_equal( nil , @c02.atoms[1].name )
1022
-
1023
- # y 軸反転
1024
- # [ [ ax, ay, az], [ 0, by, bz], [ 0, 0, cz] ]
1025
- # ↓ y 軸反転
1026
- # [ [ ax, ay, az], [ 0,-by,-bz], [ 0, 0, cz] ]
1027
- # ↓ b vector の y 成分が正になるようにする。
1028
- # すなわち z 軸回りに半回転し、全ての x, y 成分が反転する。
1029
- # [ [-ax,-ay, az], [ 0, by,-bz], [ 0, 0, cz] ]
1030
- t = @c02.inverse_axis( 1 )
1031
- assert_equal( CrystalCell::Cell, t.class )
1032
- assert_in_delta( -2.0, t.axes[0][0], $tolerance )
1033
- assert_in_delta( -2.0, t.axes[0][1], $tolerance )
1034
- assert_in_delta( 2.0, t.axes[0][2], $tolerance )
1035
- assert_in_delta( 0.0, t.axes[1][0], $tolerance )
1036
- assert_in_delta( 2.0, t.axes[1][1], $tolerance )
1037
- assert_in_delta( -2.0, t.axes[1][2], $tolerance )
1038
- assert_in_delta( 0.0, t.axes[2][0], $tolerance )
1039
- assert_in_delta( 0.0, t.axes[2][1], $tolerance )
1040
- assert_in_delta( 2.0, t.axes[2][2], $tolerance )
1041
- assert_equal( 2, t.atoms.size )
1042
- # checking atom 0
1043
- assert_equal( 'Li' , t.atoms[0].element)
1044
- assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
1045
- assert_equal( nil , t.atoms[0].name )
1046
- # checking atom 1
1047
- assert_equal( 'O' , t.atoms[1].element)
1048
- assert_equal( Mageo::Vector3DInternal[ 0.2,-0.2, 0.2], t.atoms[1].position)
1049
- assert_equal( nil , t.atoms[1].name )
1050
-
1051
- # z 軸反転
1052
- # [ [ ax, ay, az], [ 0, by, bz], [ 0, 0, cz] ]
1053
- # ↓ z 軸反転
1054
- # [ [ ax, ay, az], [ 0, by, bz], [ 0, 0,-cz] ]
1055
- # ↓ c vector の z 成分が正になるようにする。
1056
- # b vector の y 成分も正であることを保存する回転は、
1057
- # y 軸回りに半回転し、全ての x, z 成分が反転する。
1058
- # [ [-ax, ay,-az], [ 0, by,-bz], [ 0, 0, cz] ]
1059
- t = @c02.inverse_axis( 2 )
1060
- assert_equal( CrystalCell::Cell, t.class )
1061
- assert_in_delta(-2.0, t.axes[0][0], $tolerance )
1062
- assert_in_delta( 2.0, t.axes[0][1], $tolerance )
1063
- assert_in_delta(-2.0, t.axes[0][2], $tolerance )
1064
- assert_in_delta( 0.0, t.axes[1][0], $tolerance )
1065
- assert_in_delta( 2.0, t.axes[1][1], $tolerance )
1066
- assert_in_delta(-2.0, t.axes[1][2], $tolerance )
1067
- assert_in_delta( 0.0, t.axes[2][0], $tolerance )
1068
- assert_in_delta( 0.0, t.axes[2][1], $tolerance )
1069
- assert_in_delta( 2.0, t.axes[2][2], $tolerance )
1070
- assert_equal( 2, t.atoms.size )
1071
- # checking atom 0
1072
- assert_equal( 'Li' , t.atoms[0].element)
1073
- assert_equal( Mageo::Vector3DInternal[0.0, 0.0, 0.0], t.atoms[0].position)
1074
- assert_equal( nil , t.atoms[0].name )
1075
- # checking atom 1
1076
- assert_equal( 'O' , t.atoms[1].element)
1077
- assert_equal( Mageo::Vector3DInternal[ 0.2, 0.2,-0.2], t.atoms[1].position)
1078
- assert_equal( nil , t.atoms[1].name )
1079
-
1080
- end
1081
-
1082
- def test_exchange_axes!
1083
- # b, c の交換。
1084
- @c08.exchange_axes!( [ 1, 2 ] )
1085
- t = @c08
1086
- assert_equal( CrystalCell::Cell, t.class )
1087
- lc = t.axes.get_lattice_constants
1088
- assert_in_delta( 2.0 * Math::sqrt( 3.0 ) , lc[0], $tolerance )
1089
- assert_in_delta( 2.0 , lc[1], $tolerance )
1090
- assert_in_delta( 2.0 * Math::sqrt( 2.0 ) , lc[2], $tolerance )
1091
- assert_in_delta( 45.0000000000000, lc[3], $tolerance )
1092
- assert_in_delta( 35.2643896827547, lc[4], $tolerance )
1093
- assert_in_delta( 54.7356103172453, lc[5], $tolerance )
1094
- assert_equal( true, t.axes.lefthand? )
1095
- assert_equal( 2, t.atoms.size )
1096
- # checking atom 0
1097
- assert_equal( 'Li' , t.atoms[0].element)
1098
- assert_equal( Mageo::Vector3DInternal[ 1.2, 5.6, 3.4], t.atoms[0].position)
1099
- assert_equal( 'atom0' , t.atoms[0].name )
1100
- assert_equal( [ false, false, true] , t.atoms[0].movable_flags )
1101
- # checking atom 1
1102
- assert_equal( 'O' , t.atoms[1].element)
1103
- assert_equal( Mageo::Vector3DInternal[-1.2, -5.6, -3.4], t.atoms[1].position)
1104
- assert_equal( nil , t.atoms[1].name )
1105
- end
1106
-
1107
- def test_exchange_axes
1108
- assert_raise( CrystalCell::Cell::ArgumentError ){ @c02.exchange_axes( [ 0 ] ) }
1109
- assert_raise( CrystalCell::Cell::ArgumentError ){ @c02.exchange_axes( [ 0, 1, 2] ) }
1110
- assert_raise( CrystalCell::Cell::AxesRangeError ){ @c02.exchange_axes( [0, 3] ) }
1111
- assert_raise( CrystalCell::Cell::AxesRangeError ){ @c02.exchange_axes( [-1, 2] ) }
1112
- assert_raise( CrystalCell::Cell::SameAxesError ){ @c02.exchange_axes( [ 1,1] ) }
1113
-
1114
- # b, c の交換。
1115
- t = @c08.exchange_axes( [ 1, 2 ] )
1116
- assert_equal( CrystalCell::Cell, t.class )
1117
- lc = t.axes.get_lattice_constants
1118
- assert_in_delta( 2.0 * Math::sqrt( 3.0 ) , lc[0], $tolerance )
1119
- assert_in_delta( 2.0 , lc[1], $tolerance )
1120
- assert_in_delta( 2.0 * Math::sqrt( 2.0 ) , lc[2], $tolerance )
1121
- assert_in_delta( 45.0000000000000, lc[3], $tolerance )
1122
- assert_in_delta( 35.2643896827547, lc[4], $tolerance )
1123
- assert_in_delta( 54.7356103172453, lc[5], $tolerance )
1124
- assert_equal( true, t.axes.lefthand? )
1125
- assert_equal( 2, t.atoms.size )
1126
- # checking atom 0
1127
- assert_equal( 'Li' , t.atoms[0].element)
1128
- assert_equal( Mageo::Vector3DInternal[ 1.2, 5.6, 3.4], t.atoms[0].position)
1129
- assert_equal( 'atom0' , t.atoms[0].name )
1130
- # checking atom 1
1131
- assert_equal( 'O' , t.atoms[1].element)
1132
- assert_equal( Mageo::Vector3DInternal[-1.2, -5.6, -3.4], t.atoms[1].position)
1133
- assert_equal( nil , t.atoms[1].name )
1134
-
1135
- # b, c の交換によって非破壊であることを確認。
1136
- t = @c08
1137
- assert_equal( CrystalCell::Cell, t.class )
1138
- lc = t.axes.get_lattice_constants
1139
- assert_in_delta( 2.0 * Math::sqrt( 3.0 ) , lc[0], $tolerance )
1140
- assert_in_delta( 2.0 * Math::sqrt( 2.0 ) , lc[1], $tolerance )
1141
- assert_in_delta( 2.0 , lc[2], $tolerance )
1142
- assert_in_delta( 45.0000000000000, lc[3], $tolerance )
1143
- assert_in_delta( 54.7356103172453, lc[4], $tolerance )
1144
- assert_in_delta( 35.2643896827547, lc[5], $tolerance )
1145
- assert_equal( true, t.axes.righthand? )
1146
- assert_equal( 2, t.atoms.size )
1147
- # checking atom 0
1148
- assert_equal( 'Li' , t.atoms[0].element)
1149
- assert_equal( Mageo::Vector3DInternal[ 1.2, 3.4, 5.6], t.atoms[0].position)
1150
- assert_equal( 'atom0' , t.atoms[0].name )
1151
- # checking atom 1
1152
- assert_equal( 'O' , t.atoms[1].element)
1153
- assert_equal( Mageo::Vector3DInternal[-1.2, -3.4, -5.6], t.atoms[1].position)
1154
- assert_equal( nil , t.atoms[1].name )
1155
-
1156
- end
1157
-
1158
- def test_reflect!
1159
- @c08.reflect!
1160
- t = @c08
1161
- assert_equal( CrystalCell::Cell, t.class )
1162
- lc = t.axes.get_lattice_constants
1163
- assert_in_delta( 2.0 * Math::sqrt( 3.0 ) , lc[0], $tolerance )
1164
- assert_in_delta( 2.0 * Math::sqrt( 2.0 ) , lc[1], $tolerance )
1165
- assert_in_delta( 2.0 , lc[2], $tolerance )
1166
- assert_in_delta( 45.0000000000000, lc[3], $tolerance )
1167
- assert_in_delta( 54.7356103172453, lc[4], $tolerance )
1168
- assert_in_delta( 35.2643896827547, lc[5], $tolerance )
1169
- assert_equal( true, t.axes.lefthand? )
1170
- assert_equal( 2, t.atoms.size )
1171
- # checking atom 0
1172
- assert_equal( 'Li' , t.atoms[0].element)
1173
- assert_equal( Mageo::Vector3DInternal[ 1.2, 3.4, 5.6], t.atoms[0].position)
1174
- assert_equal( 'atom0' , t.atoms[0].name )
1175
- # checking atom 1
1176
- assert_equal( 'O' , t.atoms[1].element)
1177
- assert_equal( Mageo::Vector3DInternal[-1.2, -3.4, -5.6], t.atoms[1].position)
1178
- assert_equal( nil , t.atoms[1].name )
1179
- end
1180
-
1181
- def test_reflect
1182
- t = @c08.reflect
1183
- assert_equal( CrystalCell::Cell, t.class )
1184
- lc = t.axes.get_lattice_constants
1185
- assert_in_delta( 2.0 * Math::sqrt( 3.0 ) , lc[0], $tolerance )
1186
- assert_in_delta( 2.0 * Math::sqrt( 2.0 ) , lc[1], $tolerance )
1187
- assert_in_delta( 2.0 , lc[2], $tolerance )
1188
- assert_in_delta( 45.0000000000000, lc[3], $tolerance )
1189
- assert_in_delta( 54.7356103172453, lc[4], $tolerance )
1190
- assert_in_delta( 35.2643896827547, lc[5], $tolerance )
1191
- assert_equal( true, t.axes.lefthand? )
1192
- assert_equal( 2, t.atoms.size )
1193
- # checking atom 0
1194
- assert_equal( 'Li' , t.atoms[0].element)
1195
- assert_equal( Mageo::Vector3DInternal[ 1.2, 3.4, 5.6], t.atoms[0].position)
1196
- assert_equal( 'atom0' , t.atoms[0].name )
1197
- # checking atom 1
1198
- assert_equal( 'O' , t.atoms[1].element)
1199
- assert_equal( Mageo::Vector3DInternal[-1.2, -3.4, -5.6], t.atoms[1].position)
1200
- assert_equal( nil , t.atoms[1].name )
1201
-
1202
- # 非破壊であることを確認。
1203
- t = @c08
1204
- assert_equal( CrystalCell::Cell, t.class )
1205
- lc = t.axes.get_lattice_constants
1206
- assert_in_delta( 2.0 * Math::sqrt( 3.0 ) , lc[0], $tolerance )
1207
- assert_in_delta( 2.0 * Math::sqrt( 2.0 ) , lc[1], $tolerance )
1208
- assert_in_delta( 2.0 , lc[2], $tolerance )
1209
- assert_in_delta( 45.0000000000000, lc[3], $tolerance )
1210
- assert_in_delta( 54.7356103172453, lc[4], $tolerance )
1211
- assert_in_delta( 35.2643896827547, lc[5], $tolerance )
1212
- assert_equal( true, t.axes.righthand? )
1213
- assert_equal( 2, t.atoms.size )
1214
- # checking atom 0
1215
- assert_equal( 'Li' , t.atoms[0].element)
1216
- assert_equal( Mageo::Vector3DInternal[ 1.2, 3.4, 5.6], t.atoms[0].position)
1217
- assert_equal( 'atom0' , t.atoms[0].name )
1218
- # checking atom 1
1219
- assert_equal( 'O' , t.atoms[1].element)
1220
- assert_equal( Mageo::Vector3DInternal[-1.2, -3.4, -5.6], t.atoms[1].position)
1221
- assert_equal( nil , t.atoms[1].name )
1222
- end
1223
-
1224
- def test_operate
1225
- # identity operation
1226
- rotation = [
1227
- [1, 0, 0],
1228
- [0, 1, 0],
1229
- [0, 0, 1],
1230
- ]
1231
- translation = [0.0, 0.0, 0.0]
1232
- result = @c01.operate(rotation, translation)
1233
- assert_in_delta( 0.0, result.atoms[0].position[0], $tolerance)
1234
- assert_in_delta( 0.0, result.atoms[0].position[1], $tolerance)
1235
- assert_in_delta( 0.0, result.atoms[0].position[2], $tolerance)
1236
- assert_in_delta( 0.1, result.atoms[1].position[0], $tolerance)
1237
- assert_in_delta( 0.2, result.atoms[1].position[1], $tolerance)
1238
- assert_in_delta( 0.3, result.atoms[1].position[2], $tolerance)
1239
-
1240
- # rotation
1241
- rotation = [
1242
- [1, 0, 0],
1243
- [0, 1, 0],
1244
- [0, 0,-1],
1245
- ]
1246
- translation = [0.0, 0.0, 0.0]
1247
- result = @c01.operate(rotation, translation)
1248
- assert_in_delta( 0.0, result.atoms[0].position[0], $tolerance)
1249
- assert_in_delta( 0.0, result.atoms[0].position[1], $tolerance)
1250
- assert_in_delta( 0.0, result.atoms[0].position[2], $tolerance)
1251
- assert_in_delta( 0.1, result.atoms[1].position[0], $tolerance)
1252
- assert_in_delta( 0.2, result.atoms[1].position[1], $tolerance)
1253
- assert_in_delta(-0.3, result.atoms[1].position[2], $tolerance)
1254
-
1255
- # translation
1256
- rotation = [
1257
- [1, 0, 0],
1258
- [0, 1, 0],
1259
- [0, 0, 1],
1260
- ]
1261
- translation = [0.1, 0.2, 0.3]
1262
- result = @c01.operate(rotation, translation)
1263
- assert_in_delta(0.1, result.atoms[0].position[0], $tolerance)
1264
- assert_in_delta(0.2, result.atoms[0].position[1], $tolerance)
1265
- assert_in_delta(0.3, result.atoms[0].position[2], $tolerance)
1266
- assert_in_delta(0.2, result.atoms[1].position[0], $tolerance)
1267
- assert_in_delta(0.4, result.atoms[1].position[1], $tolerance)
1268
- assert_in_delta(0.6, result.atoms[1].position[2], $tolerance)
1269
-
1270
- # rotation & translation
1271
- rotation = [
1272
- [1, 0, 0],
1273
- [0, 1, 0],
1274
- [0, 0,-1],
1275
- ]
1276
- translation = [0.1, 0.2, 0.3]
1277
- result = @c01.operate(rotation, translation)
1278
- assert_in_delta(0.1, result.atoms[0].position[0], $tolerance)
1279
- assert_in_delta(0.2, result.atoms[0].position[1], $tolerance)
1280
- assert_in_delta(0.3, result.atoms[0].position[2], $tolerance)
1281
- assert_in_delta(0.2, result.atoms[1].position[0], $tolerance)
1282
- assert_in_delta(0.4, result.atoms[1].position[1], $tolerance)
1283
- assert_in_delta(0.0, result.atoms[1].position[2], $tolerance)
1284
- end
1285
-
1286
- def test_axis_independencies
1287
- unless defined? Getspg
1288
- puts
1289
- puts "test_axis_independencies() is ignored because spglib is not installed."
1290
- return
1291
- end
1292
-
1293
- assert_equal([false, false, false],
1294
- @c10 .axis_independencies($symprec, $angle_tolerance))
1295
- assert_equal([false, false, true ],
1296
- @c11 .axis_independencies($symprec, $angle_tolerance))
1297
- assert_equal([true , true , true ],
1298
- @c12 .axis_independencies($symprec, $angle_tolerance))
1299
- assert_equal([true , true , true ],
1300
- @c13 .axis_independencies($symprec, $angle_tolerance))
1301
- assert_equal([false, false, true ],
1302
- @c14 .axis_independencies($symprec, $angle_tolerance))
1303
- assert_equal([false, true , false],
1304
- @c14b.axis_independencies($symprec, $angle_tolerance))
1305
- assert_equal([true , true , true ],
1306
- @c15 .axis_independencies($symprec, $angle_tolerance))
1307
- assert_equal([false, false, true ],
1308
- @c16 .axis_independencies($symprec, $angle_tolerance))
1309
- end
1310
-
1311
- def test_symmetry_operations
1312
- unless defined? Getspg
1313
- puts
1314
- puts "test_symmetry_operations() is ignored because spglib is not installed."
1315
- return
1316
- end
1317
-
1318
- f13 = 1.0/3.0
1319
-
1320
- #cubic/POSCAR #Pm-3m (221) / m-3m / -P 4 2 3 (517)
1321
- corrects = [
1322
- {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----01----
1323
- {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----02----
1324
- {:rotation => [[ 0, -1, 0], [ 1, 0, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----03----
1325
- {:rotation => [[ 0, 1, 0], [-1, 0, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----04----
1326
- {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----05----
1327
- {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----06----
1328
- {:rotation => [[ 0, 1, 0], [-1, 0, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----07----
1329
- {:rotation => [[ 0, -1, 0], [ 1, 0, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----08----
1330
- {:rotation => [[ 1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----09----
1331
- {:rotation => [[-1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----10----
1332
- {:rotation => [[ 0, -1, 0], [-1, 0, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----11----
1333
- {:rotation => [[ 0, 1, 0], [ 1, 0, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----12----
1334
- {:rotation => [[-1, 0, 0], [ 0, 1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----13----
1335
- {:rotation => [[ 1, 0, 0], [ 0, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----14----
1336
- {:rotation => [[ 0, 1, 0], [ 1, 0, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----15----
1337
- {:rotation => [[ 0, -1, 0], [-1, 0, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----16----
1338
- {:rotation => [[ 0, 0, 1], [ 1, 0, 0], [ 0, 1, 0]], :translation => [0.0, 0.0, 0.0]}, #----17----
1339
- {:rotation => [[ 0, 0, -1], [-1, 0, 0], [ 0, -1, 0]], :translation => [0.0, 0.0, 0.0]}, #----18----
1340
- {:rotation => [[ 0, 0, 1], [ 0, -1, 0], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----19----
1341
- {:rotation => [[ 0, 0, -1], [ 0, 1, 0], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----20----
1342
- {:rotation => [[ 0, 0, 1], [-1, 0, 0], [ 0, -1, 0]], :translation => [0.0, 0.0, 0.0]}, #----21----
1343
- {:rotation => [[ 0, 0, -1], [ 1, 0, 0], [ 0, 1, 0]], :translation => [0.0, 0.0, 0.0]}, #----22----
1344
- {:rotation => [[ 0, 0, 1], [ 0, 1, 0], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----23----
1345
- {:rotation => [[ 0, 0, -1], [ 0, -1, 0], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----24----
1346
- {:rotation => [[ 0, 0, -1], [ 1, 0, 0], [ 0, -1, 0]], :translation => [0.0, 0.0, 0.0]}, #----25----
1347
- {:rotation => [[ 0, 0, 1], [-1, 0, 0], [ 0, 1, 0]], :translation => [0.0, 0.0, 0.0]}, #----26----
1348
- {:rotation => [[ 0, 0, -1], [ 0, -1, 0], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----27----
1349
- {:rotation => [[ 0, 0, 1], [ 0, 1, 0], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----28----
1350
- {:rotation => [[ 0, 0, -1], [-1, 0, 0], [ 0, 1, 0]], :translation => [0.0, 0.0, 0.0]}, #----29----
1351
- {:rotation => [[ 0, 0, 1], [ 1, 0, 0], [ 0, -1, 0]], :translation => [0.0, 0.0, 0.0]}, #----30----
1352
- {:rotation => [[ 0, 0, -1], [ 0, 1, 0], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----31----
1353
- {:rotation => [[ 0, 0, 1], [ 0, -1, 0], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----32----
1354
- {:rotation => [[ 0, 1, 0], [ 0, 0, 1], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----33----
1355
- {:rotation => [[ 0, -1, 0], [ 0, 0, -1], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----34----
1356
- {:rotation => [[ 1, 0, 0], [ 0, 0, 1], [ 0, -1, 0]], :translation => [0.0, 0.0, 0.0]}, #----35----
1357
- {:rotation => [[-1, 0, 0], [ 0, 0, -1], [ 0, 1, 0]], :translation => [0.0, 0.0, 0.0]}, #----36----
1358
- {:rotation => [[ 0, -1, 0], [ 0, 0, 1], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----37----
1359
- {:rotation => [[ 0, 1, 0], [ 0, 0, -1], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----38----
1360
- {:rotation => [[-1, 0, 0], [ 0, 0, 1], [ 0, 1, 0]], :translation => [0.0, 0.0, 0.0]}, #----39----
1361
- {:rotation => [[ 1, 0, 0], [ 0, 0, -1], [ 0, -1, 0]], :translation => [0.0, 0.0, 0.0]}, #----40----
1362
- {:rotation => [[ 0, -1, 0], [ 0, 0, -1], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----41----
1363
- {:rotation => [[ 0, 1, 0], [ 0, 0, 1], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----42----
1364
- {:rotation => [[-1, 0, 0], [ 0, 0, -1], [ 0, -1, 0]], :translation => [0.0, 0.0, 0.0]}, #----43----
1365
- {:rotation => [[ 1, 0, 0], [ 0, 0, 1], [ 0, 1, 0]], :translation => [0.0, 0.0, 0.0]}, #----44----
1366
- {:rotation => [[ 0, 1, 0], [ 0, 0, -1], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----45----
1367
- {:rotation => [[ 0, -1, 0], [ 0, 0, 1], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----46----
1368
- {:rotation => [[ 1, 0, 0], [ 0, 0, -1], [ 0, 1, 0]], :translation => [0.0, 0.0, 0.0]}, #----47----
1369
- {:rotation => [[-1, 0, 0], [ 0, 0, 1], [ 0, -1, 0]], :translation => [0.0, 0.0, 0.0]}, #----48----
1370
- ]
1371
-
1372
- results = @c10 .symmetry_operations($symprec, $angle_tolerance)
1373
- assert_equal(corrects.size, results.size)
1374
- corrects.size.times do |index|
1375
- assert_equal(corrects[index], results[index])
1376
- end
1377
-
1378
- #monoclinic/POSCAR #P2/m (10) / 2/m / -P 2y (57)
1379
- corrects = [
1380
- {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----01----
1381
- {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----02----
1382
- {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----03----
1383
- {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----04----
1384
- ]
1385
- #pp @c12
1386
- assert_equal(corrects, @c12 .symmetry_operations($symprec, $angle_tolerance)) #monoclinic
1387
-
1388
- #orthorhombic/POSCAR #Pmmm (47) / mmm / -P 2 2 (227)
1389
- corrects = [
1390
- {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----01----
1391
- {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----02----
1392
- {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----03----
1393
- {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----04----
1394
- {:rotation => [[ 1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----05----
1395
- {:rotation => [[-1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----06----
1396
- {:rotation => [[-1, 0, 0], [ 0, 1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----07----
1397
- {:rotation => [[ 1, 0, 0], [ 0, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----08----
1398
- ]
1399
- assert_equal(corrects, @c13 .symmetry_operations($symprec, $angle_tolerance)) #orthorhombic
1400
-
1401
- #tetragonal-b/POSCAR #P4/mmm (123) / 4/mmm/ -P 4 2 (400)
1402
- corrects = [
1403
- {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----01----
1404
- {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----02----
1405
- {:rotation => [[ 0, 0, 1], [ 0, 1, 0], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----03----
1406
- {:rotation => [[ 0, 0, -1], [ 0, -1, 0], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----04----
1407
- {:rotation => [[-1, 0, 0], [ 0, 1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----05----
1408
- {:rotation => [[ 1, 0, 0], [ 0, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----06----
1409
- {:rotation => [[ 0, 0, -1], [ 0, 1, 0], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----07----
1410
- {:rotation => [[ 0, 0, 1], [ 0, -1, 0], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----08----
1411
- {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----09----
1412
- {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----10----
1413
- {:rotation => [[ 0, 0, -1], [ 0, -1, 0], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----11----
1414
- {:rotation => [[ 0, 0, 1], [ 0, 1, 0], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----12----
1415
- {:rotation => [[ 1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----13----
1416
- {:rotation => [[-1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----14----
1417
- {:rotation => [[ 0, 0, 1], [ 0, -1, 0], [ 1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----15----
1418
- {:rotation => [[ 0, 0, -1], [ 0, 1, 0], [-1, 0, 0]], :translation => [0.0, 0.0, 0.0]}, #----16----
1419
- ]
1420
- assert_equal(corrects, @c14b .symmetry_operations($symprec, $angle_tolerance)) #tetragonal
1421
-
1422
- #tetragonal/POSCAR #P4/mmm (123) / 4/mmm/ -P 4 2 (400)
1423
- corrects = [
1424
- {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----01----
1425
- {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----02----
1426
- {:rotation => [[ 0, -1, 0], [ 1, 0, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----03----
1427
- {:rotation => [[ 0, 1, 0], [-1, 0, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----04----
1428
- {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----05----
1429
- {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----06----
1430
- {:rotation => [[ 0, 1, 0], [-1, 0, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----07----
1431
- {:rotation => [[ 0, -1, 0], [ 1, 0, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----08----
1432
- {:rotation => [[ 1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----09----
1433
- {:rotation => [[-1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----10----
1434
- {:rotation => [[ 0, -1, 0], [-1, 0, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----11----
1435
- {:rotation => [[ 0, 1, 0], [ 1, 0, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----12----
1436
- {:rotation => [[-1, 0, 0], [ 0, 1, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----13----
1437
- {:rotation => [[ 1, 0, 0], [ 0, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----14----
1438
- {:rotation => [[ 0, 1, 0], [ 1, 0, 0], [ 0, 0, -1]], :translation => [0.0, 0.0, 0.0]}, #----15----
1439
- {:rotation => [[ 0, -1, 0], [-1, 0, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----16----
1440
- ]
1441
- assert_equal(corrects, @c14.symmetry_operations($symprec, $angle_tolerance)) #tetragonal-b
1442
-
1443
- #triclinic/POSCAR #P1 (1) / 1 / P 1 (1)
1444
- corrects = [
1445
- {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----01----
1446
- ]
1447
- assert_equal(corrects, @c15 .symmetry_operations($symprec, $angle_tolerance)) #triclinic
1448
-
1449
- #trigonal/POSCAR #P-3m1 (164) / -3m / -P 3 2= (456)
1450
- corrects = [
1451
- {:rotation => [[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 0.0]}, #----01----
1452
- {:rotation => [[-1, 0, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [f13, f13, f13]}, #----02----
1453
- {:rotation => [[-1, -1, 0], [ 1, 0, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 1.0]}, #----03----
1454
- {:rotation => [[ 1, 1, 0], [-1, 0, 0], [ 0, 0, -1]], :translation => [f13, f13, f13]}, #----04----
1455
- {:rotation => [[ 0, 1, 0], [-1, -1, 0], [ 0, 0, 1]], :translation => [1.0, 0.0, 1.0]}, #----05----
1456
- {:rotation => [[ 0, -1, 0], [ 1, 1, 0], [ 0, 0, -1]], :translation => [f13, f13, f13]}, #----06----
1457
- {:rotation => [[ 0, -1, 0], [-1, 0, 0], [ 0, 0, -1]], :translation => [f13, f13, f13]}, #----07----
1458
- {:rotation => [[ 0, 1, 0], [ 1, 0, 0], [ 0, 0, 1]], :translation => [1.0, 0.0, 1.0]}, #----08----
1459
- {:rotation => [[-1, 0, 0], [ 1, 1, 0], [ 0, 0, -1]], :translation => [f13, f13, f13]}, #----09----
1460
- {:rotation => [[ 1, 0, 0], [-1, -1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 1.0]}, #----10----
1461
- {:rotation => [[ 1, 1, 0], [ 0, -1, 0], [ 0, 0, -1]], :translation => [f13, f13, f13]}, #----11----
1462
- {:rotation => [[-1, -1, 0], [ 0, 1, 0], [ 0, 0, 1]], :translation => [0.0, 0.0, 1.0]}, #----12----
1463
- ]
1464
- results = @c16.symmetry_operations($symprec, $angle_tolerance)
1465
- corrects.size.times do |index|
1466
- 3.times do |i|
1467
- 3.times do |j|
1468
- assert_in_delta(
1469
- corrects[index][:rotation][i][j] %1.0,
1470
- results[index][:rotation][i][j] %1.0,
1471
- $tolerance
1472
- )
1473
- end
1474
- end
1475
-
1476
- 3.times do |i|
1477
- assert_in_delta(
1478
- corrects[index][:translation][i] % 1.0,
1479
- results[index][:translation][i] %1.0,
1480
- $tolerance
1481
- )
1482
- end
1483
- end
1484
- end
1477
+ #corrects.size.times do |index|
1478
+ # 3.times do |i|
1479
+ # 3.times do |j|
1480
+ # assert_in_delta(
1481
+ # corrects[index][:rotation][i][j] %1.0,
1482
+ # results[index][:rotation][i][j] %1.0,
1483
+ # $tolerance
1484
+ # )
1485
+ # end
1486
+ # end
1487
+
1488
+ # 3.times do |i|
1489
+ # assert_in_delta(
1490
+ # corrects[index][:translation][i] % 1.0,
1491
+ # results[index][:translation][i] %1.0,
1492
+ # $tolerance
1493
+ # )
1494
+ # end
1495
+ #end
1496
+ end
1497
+
1498
+ def dump_povray
1499
+ #pp @c01
1500
+ ##TODO
1501
+ end
1485
1502
 
1486
1503
  end