FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
diffpy.pdfgui/tests/test_fitstructure.py at main · diffpy/diffpy.pdfgui · GitHub
diffpy
diffpy.pdfgui
Repository navigation
Code
Issues
24
(24)
Pull requests
2
(2)
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
diffpy.pdfgui
/
tests
/
test_fitstructure.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
295 lines (259 loc) · 9.26 KB
Breadcrumbs
diffpy.pdfgui
/
tests
/
test_fitstructure.py
Copy path
File metadata and controls
295 lines (259 loc) · 9.26 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/usr/bin/env python
"""Unit tests for class FitStructure."""
import
unittest
from
testutils
import
datafile
from
diffpy
.
pdfgui
.
control
.
constraint
import
Constraint
from
diffpy
.
pdfgui
.
control
.
controlerrors
import
ControlTypeError
from
diffpy
.
pdfgui
.
control
.
fitstructure
import
FitStructure
from
diffpy
.
pdfgui
.
control
.
pdfstructure
import
PDFStructure
from
diffpy
.
structure
import
Structure
# ----------------------------------------------------------------------------
class
TestFitStructure
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
stru
=
FitStructure
(
"noname"
)
return
def
tearDown
(
self
):
return
def
test___init__
(
self
):
"""Check FitStructure.__init__()"""
stru
=
self
.
stru
self
.
assertEqual
(
"noname"
,
stru
.
name
)
self
.
assertEqual
(
"all-all"
,
stru
.
selected_pairs
)
return
# def test__update_custom_spacegroup(self):
# """check FitStructure._update_custom_spacegroup()
# """
# return
# def test_read(self):
# """check FitStructure.read()
# """
# return
# def test_readStr(self):
# """check FitStructure.readStr()
# """
# return
def
test___getattr__
(
self
):
"""Check FitStructure.__getattr__()"""
stru
=
self
.
stru
self
.
assertTrue
(
stru
is
stru
.
initial
)
self
.
assertRaises
(
AttributeError
,
eval
,
"stru.notdefined"
,
locals
())
return
def
test__getStrId
(
self
):
"""Check FitStructure._getStrId()"""
stru
=
self
.
stru
self
.
assertEqual
(
"p_noname"
,
stru
.
_getStrId
())
return
# def test_clearRefined(self):
# """check FitStructure.clearRefined()
# """
# return
# def test_obtainRefined(self):
# """check FitStructure.obtainRefined()
# """
# return
def
test_findParameters
(
self
):
"""Check FitStructure.findParameters()"""
stru
=
self
.
stru
stru
.
read
(
datafile
(
"Ni.stru"
),
format
=
"pdffit"
)
for
a
in
stru
.
initial
:
a
.
Uiso
=
0.00126651
stru
.
constraints
[
"lat(4)"
]
=
Constraint
(
"@1"
)
stru
.
constraints
[
"y(2)"
]
=
Constraint
(
"@3 + 0.4"
)
stru
.
constraints
[
"u11(3)"
]
=
Constraint
(
"@7 * 3.0"
)
pd
=
stru
.
findParameters
()
self
.
assertEqual
([
1
,
3
,
7
],
sorted
(
pd
.
keys
()))
self
.
assertEqual
(
90
,
pd
[
1
].
initialValue
())
self
.
assertEqual
(
0.5
-
0.4
,
pd
[
3
].
initialValue
())
self
.
assertEqual
(
0.00126651
/
3.0
,
pd
[
7
].
initialValue
())
return
def
test_applyParameters
(
self
):
"""Check FitStructure.applyParameters()"""
stru
=
self
.
stru
stru
.
read
(
datafile
(
"Ni.stru"
),
format
=
"pdffit"
)
for
a
in
stru
.
initial
:
a
.
Uiso
=
0.00126651
stru
.
constraints
[
"lat(4)"
]
=
Constraint
(
"@1"
)
stru
.
constraints
[
"u11(3)"
]
=
Constraint
(
"@7 * 3.0"
)
pd
=
stru
.
findParameters
()
# adjust Parameter instances in pd
pd
[
1
].
setInitial
(
99
)
pd
[
7
].
setInitial
(
0.5
)
stru
.
applyParameters
(
pd
)
self
.
assertEqual
(
99
,
stru
.
lattice
.
alpha
)
self
.
assertEqual
(
1.5
,
stru
[
2
].
U11
)
# pd values can be floats
pd
[
1
]
=
89
stru
.
applyParameters
(
pd
)
self
.
assertEqual
(
89
,
stru
.
lattice
.
alpha
)
return
def
test_changeParameterIndex
(
self
):
"""Check FitStructure.changeParameterIndex()"""
stru
=
self
.
stru
stru
.
constraints
[
"pscale"
]
=
Constraint
(
"@7+3"
)
stru
.
changeParameterIndex
(
7
,
13
)
self
.
assertEqual
(
"@13+3"
,
stru
.
constraints
[
"pscale"
].
formula
)
stru
.
changeParameterIndex
(
2
,
19
)
self
.
assertEqual
(
"@13+3"
,
stru
.
constraints
[
"pscale"
].
formula
)
return
# tested in insertAtoms and deleteAtoms
# def test__popAtomConstraints(self):
# """check FitStructure._popAtomConstraints()
# """
# return
# def test__restoreAtomConstraints(self):
# """check FitStructure._restoreAtomConstraints()
# """
# return
def
test_insertAtoms
(
self
):
"""Check FitStructure.insertAtoms()"""
from
diffpy
.
structure
import
Atom
stru
=
self
.
stru
stru
.
read
(
datafile
(
"Ni.stru"
),
format
=
"pdffit"
)
cns
=
Constraint
(
"@1"
)
stru
.
constraints
[
"x(2)"
]
=
cns
stru
.
insertAtoms
(
0
, [
Atom
(
"Na"
, (
0
,
0
,
0
))])
self
.
assertEqual
(
5
,
len
(
stru
))
self
.
assertEqual
(
1
,
len
(
stru
.
constraints
))
self
.
assertTrue
(
cns
is
stru
.
constraints
[
"x(3)"
])
stru
.
insertAtoms
(
5
, [
Atom
(
"Cl"
, (
0
,
0
,
0
))])
self
.
assertTrue
([
"x(3)"
]
==
list
(
stru
.
constraints
.
keys
()))
return
def
test_deleteAtoms
(
self
):
"""Check FitStructure.deleteAtoms()"""
stru
=
self
.
stru
stru
.
read
(
datafile
(
"Ni.stru"
),
format
=
"pdffit"
)
cns
=
Constraint
(
"@1"
)
stru
.
constraints
[
"x(2)"
]
=
cns
stru
.
deleteAtoms
([
3
])
self
.
assertEqual
([
"x(2)"
],
list
(
stru
.
constraints
.
keys
()))
self
.
assertTrue
(
cns
is
next
(
iter
(
stru
.
constraints
.
values
())))
stru
.
deleteAtoms
([
0
])
self
.
assertEqual
([
"x(1)"
],
list
(
stru
.
constraints
.
keys
()))
self
.
assertTrue
(
cns
is
next
(
iter
(
stru
.
constraints
.
values
())))
stru
.
deleteAtoms
([
0
])
self
.
assertEqual
({},
stru
.
constraints
)
return
# def test_expandSuperCell(self):
# """check FitStructure.expandSuperCell()
# """
# return
#
#
# def test_isSpaceGroupPossible(self):
# """check FitStructure.isSpaceGroupPossible()
# """
# return
#
#
# def test_getSpaceGroupList(self):
# """check FitStructure.getSpaceGroupList()
# """
# return
#
#
# def test_getSpaceGroup(self):
# """check FitStructure.getSpaceGroup()
# """
# return
#
#
# def test_expandAsymmetricUnit(self):
# """check FitStructure.expandAsymmetricUnit()
# """
# return
#
#
# def test_applySymmetryConstraints(self):
# """check FitStructure.applySymmetryConstraints()
# """
# return
#
#
# def test_setSelectedPairs(self):
# """check FitStructure.setSelectedPairs()
# """
# return
#
#
# def test_getSelectedPairs(self):
# """check FitStructure.getSelectedPairs()
# """
# return
def
test_getPairSelectionFlags
(
self
):
"""Check FitStructure.getPairSelectionFlags()"""
cdse
=
self
.
stru
cdse
.
read
(
datafile
(
"CdSe_bulk_wur.stru"
),
format
=
"pdffit"
)
self
.
assertEqual
(
"all-all"
,
cdse
.
getSelectedPairs
())
psf
=
cdse
.
getPairSelectionFlags
()
self
.
assertEqual
(
4
*
[
True
],
psf
[
"firstflags"
])
self
.
assertEqual
(
4
*
[
True
],
psf
[
"secondflags"
])
psf
=
cdse
.
getPairSelectionFlags
(
"Cd-Cd"
)
self
.
assertEqual
(
2
*
[
True
]
+
2
*
[
False
],
psf
[
"firstflags"
])
self
.
assertEqual
(
psf
[
"firstflags"
],
psf
[
"secondflags"
])
psf
=
cdse
.
getPairSelectionFlags
(
"all-all, !Cd-"
)
self
.
assertEqual
(
2
*
[
False
]
+
2
*
[
True
],
psf
[
"firstflags"
])
self
.
assertEqual
(
4
*
[
True
],
psf
[
"secondflags"
])
psf
=
cdse
.
getPairSelectionFlags
(
"all-all, -!Cd"
)
self
.
assertEqual
(
4
*
[
True
],
psf
[
"firstflags"
])
self
.
assertEqual
(
2
*
[
False
]
+
2
*
[
True
],
psf
[
"secondflags"
])
psf
=
cdse
.
getPairSelectionFlags
(
"Cd-3:4"
)
self
.
assertEqual
(
2
*
[
True
]
+
2
*
[
False
],
psf
[
"firstflags"
])
self
.
assertEqual
(
2
*
[
False
]
+
2
*
[
True
],
psf
[
"secondflags"
])
psf
=
cdse
.
getPairSelectionFlags
(
"all-all, !Se-!Se"
)
self
.
assertEqual
(
2
*
[
True
]
+
2
*
[
False
],
psf
[
"firstflags"
])
self
.
assertEqual
(
2
*
[
True
]
+
2
*
[
False
],
psf
[
"secondflags"
])
psf
=
cdse
.
getPairSelectionFlags
(
"all-all, !Se-, -!Se"
)
self
.
assertEqual
(
2
*
[
True
]
+
2
*
[
False
],
psf
[
"firstflags"
])
self
.
assertEqual
(
2
*
[
True
]
+
2
*
[
False
],
psf
[
"secondflags"
])
psf
=
cdse
.
getPairSelectionFlags
(
"1-all"
)
self
.
assertEqual
([
True
]
+
3
*
[
False
],
psf
[
"firstflags"
])
self
.
assertEqual
(
4
*
[
True
],
psf
[
"secondflags"
])
return
# def test_applyPairSelection(self):
# """check FitStructure.applyPairSelection()
# """
# return
def
test_copy
(
self
):
"""Check FitStructure.copy()"""
stru2
=
self
.
stru
.
copy
()
self
.
assertEqual
(
"noname"
,
stru2
.
name
)
stru3
=
Structure
()
self
.
assertRaises
(
ControlTypeError
,
stru2
.
copy
,
stru3
)
self
.
stru
.
refined
=
PDFStructure
(
"refined-name"
)
stru4
=
self
.
stru
.
copy
()
self
.
assertIsNot
(
self
.
stru
.
refined
,
stru4
.
refined
)
self
.
assertEqual
(
"refined-name"
,
stru4
.
refined
.
name
)
return
# def test_load(self):
# """check FitStructure.load()
# """
# return
#
#
# def test_save(self):
# """check FitStructure.save()
# """
# return
#
#
# def test_getYNames(self):
# """check FitStructure.getYNames()
# """
# return
#
#
# def test_getXNames(self):
# """check FitStructure.getXNames()
# """
# return
#
#
# def test_getData(self):
# """check FitStructure.getData()
# """
# return
# End of class TestFitStructure
# ----------------------------------------------------------------------------
if
__name__
==
"__main__"
:
unittest
.
main
()
# End of file
Back
|
FazBrowse Home
|
New Git URL