-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathwrap_OverlapCalculator.cpp
More file actions
292 lines (243 loc) · 9.52 KB
/
wrap_OverlapCalculator.cpp
File metadata and controls
292 lines (243 loc) · 9.52 KB
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
/*****************************************************************************
*
* diffpy.srreal by DANSE Diffraction group
* Simon J. L. Billinge
* (c) 2011 The Trustees of Columbia University
* in the City of New York. All rights reserved.
*
* File coded by: Pavol Juhas
*
* See AUTHORS.txt for a list of people who contributed.
* See LICENSE_DANSE.txt for license information.
*
******************************************************************************
*
* Bindings to the OverlapCalculator class.
*
*****************************************************************************/
#include <boost/python/class.hpp>
#include <diffpy/srreal/OverlapCalculator.hpp>
#include "srreal_converters.hpp"
#include "srreal_pickling.hpp"
namespace srrealmodule {
namespace nswrap_OverlapCalculator {
using namespace boost::python;
using namespace diffpy::srreal;
// docstrings ----------------------------------------------------------------
const char* doc_OverlapCalculator = "\
Calculate the overlap of atom radii and coordination numbers at each site.\n\
";
const char* doc_OverlapCalculator_overlaps = "\
Magnitudes of all non-zero atom radii overlaps in the structure.\n\
";
const char* doc_OverlapCalculator_distances = "\
Distances of all overlapping atom pairs in the structure.\n\
";
const char* doc_OverlapCalculator_directions = "\
Directions from the first to the second atom in the overlapping pairs.\n\
Returns an Nx3 array.\n\
";
const char* doc_OverlapCalculator_sites0 = "\
Indices of all first sites of the overlapping pairs.\n\
";
const char* doc_OverlapCalculator_sites1 = "\
Indices of all second sites of the overlapping pairs.\n\
";
const char* doc_OverlapCalculator_types0 = "\
List of atom symbols of all first sites of the overlapping pairs.\n\
";
const char* doc_OverlapCalculator_types1 = "\
List of atom symbols of all second sites of the overlapping pairs.\n\
";
const char* doc_OverlapCalculator_sitesquareoverlaps = "\
Sum of squared overlaps per each site in the structure.\n\
";
const char* doc_OverlapCalculator_totalsquareoverlap = "\
Total sum of squared overlaps in the structure adjusted\n\
for site multiplicities and occupancies.\n\
";
const char* doc_OverlapCalculator_meansquareoverlap = "\
Total square overlap per one atom in the structure.\n\
";
const char* doc_OverlapCalculator_flipDiffTotal = "\
Calculate change of the totalsquareoverlap after flipping the atom types\n\
at the i and j sites.\n\
\n\
i -- zero-based index of the first site\n\
j -- zero-based index of the second site\n\
\n\
Return float.\n\
";
const char* doc_OverlapCalculator_flipDiffMean = "\
Calculate change of the meansquareoverlap after flipping the atom types\n\
at the i and j sites.\n\
\n\
i -- zero-based index of the first site\n\
j -- zero-based index of the second site\n\
\n\
Return float.\n\
";
const char* doc_OverlapCalculator_gradients = "\
Gradients of the totalsquareoverlap per each site in the structure.\n\
Returns an Nx3 array.\n\
";
const char* doc_OverlapCalculator_getNeighborSites = "\
Get indices of all sites that neighbor with the specified site,\n\
either directly or as periodic or symmetry images. Atoms are\n\
assumed neighbors if they have non-zero overlap.\n\
\n\
i -- zero-based index of the evaluated site\n\
\n\
Return a set of integer indices, this may include i.\n\
";
const char* doc_OverlapCalculator_coordinations = "\
Return coordination numbers per each site in the structure.\n\
These may be non-integer if there are sites with partial occupancies.\n\
";
const char* doc_OverlapCalculator_coordinationByTypes = "\
Evaluate neighbor types and their occupancies at the specified site.\n\
\n\
i -- zero-based index of the evaluated site\n\
\n\
Return a dictionary where the keys are atom type strings and the values\n\
their total occupancies.\n\
";
const char* doc_OverlapCalculator_neighborhoods = "\
Return all sets of connected site indices in the structure.\n\
Sites are assumed in the same neighborhood if they have overlapping\n\
neighbors or can be connected through neighbor links. There are no\n\
overlapping pairs between sites from different neighborhoods.\n\
\n\
Return a list of site indices sets.\n\
";
const char* doc_OverlapCalculator_atomradiitable = "\
AtomRadiiTable object used for radius lookup.\n\
";
// wrappers ------------------------------------------------------------------
DECLARE_PYARRAY_METHOD_WRAPPER(overlaps, overlaps_asarray)
DECLARE_PYARRAY_METHOD_WRAPPER(siteSquareOverlaps, siteSquareOverlaps_asarray)
DECLARE_PYARRAY_METHOD_WRAPPER(gradients, gradients_asarray)
DECLARE_PYARRAY_METHOD_WRAPPER(coordinations, coordinations_asarray)
DECLARE_PYDICT_METHOD_WRAPPER1(coordinationByTypes, coordinationByTypes_asdict)
DECLARE_PYLISTSET_METHOD_WRAPPER(neighborhoods, neighborhoods_aslistset)
AtomRadiiTablePtr getatomradiitable(OverlapCalculator& obj)
{
return obj.getAtomRadiiTable();
}
DECLARE_BYTYPE_SETTER_WRAPPER(setAtomRadiiTable, setatomradiitable)
double flip_diff_total(const OverlapCalculator& obj, object i, object j)
{
int i1 = extractint(i);
int j1 = extractint(j);
return obj.flipDiffTotal(i1, j1);
}
double flip_diff_mean(const OverlapCalculator& obj, object i, object j)
{
int i1 = extractint(i);
int j1 = extractint(j);
return obj.flipDiffMean(i1, j1);
}
object get_neighbor_sites(const OverlapCalculator& obj, object i)
{
int i1 = extractint(i);
object rv = convertToPythonSet(obj.getNeighborSites(i1));
return rv;
}
class OverlapCalculatorPickleSuite :
public PairQuantityPickleSuite<OverlapCalculator>
{
private:
typedef PairQuantityPickleSuite<OverlapCalculator> Super;
public:
static boost::python::tuple getstate(boost::python::object obj)
{
namespace bp = boost::python;
bp::object tb = obj.attr("atomradiitable");
bp::tuple rv = bp::make_tuple(
Super::getstate(obj),
resolve_state_object<AtomRadiiTable>(tb)
);
return rv;
}
static void setstate(
boost::python::object obj, boost::python::tuple state)
{
namespace bp = boost::python;
ensure_tuple_length(state, 2);
// restore the state using boost serialization
bp::tuple st0 = bp::extract<bp::tuple>(state[0]);
Super::setstate(obj, st0);
// atomradiitable is present only when restoring Python class
assign_state_object(obj.attr("atomradiitable"), state[1]);
}
};
} // namespace nswrap_OverlapCalculator
// Wrapper definition --------------------------------------------------------
void wrap_OverlapCalculator()
{
using namespace nswrap_OverlapCalculator;
class_<OverlapCalculator, bases<PairQuantity> >("OverlapCalculator",
doc_OverlapCalculator)
.add_property("overlaps",
overlaps_asarray<OverlapCalculator>,
doc_OverlapCalculator_overlaps)
.add_property("distances",
distances_asarray<OverlapCalculator>,
doc_OverlapCalculator_distances)
.add_property("directions",
directions_asarray<OverlapCalculator>,
doc_OverlapCalculator_directions)
.add_property("sites0",
sites0_asarray<OverlapCalculator>,
doc_OverlapCalculator_sites0)
.add_property("sites1",
sites1_asarray<OverlapCalculator>,
doc_OverlapCalculator_sites1)
.add_property("types0",
types0_aschararray<OverlapCalculator>,
doc_OverlapCalculator_types0)
.add_property("types1",
types1_aschararray<OverlapCalculator>,
doc_OverlapCalculator_types1)
.add_property("sitesquareoverlaps",
siteSquareOverlaps_asarray<OverlapCalculator>,
doc_OverlapCalculator_sitesquareoverlaps)
.add_property("totalsquareoverlap",
&OverlapCalculator::totalSquareOverlap,
doc_OverlapCalculator_totalsquareoverlap)
.add_property("meansquareoverlap",
&OverlapCalculator::meanSquareOverlap,
doc_OverlapCalculator_meansquareoverlap)
.def("flipDiffTotal",
flip_diff_total,
(arg("i"), arg("j")),
doc_OverlapCalculator_flipDiffTotal)
.def("flipDiffMean",
flip_diff_mean,
doc_OverlapCalculator_flipDiffMean)
.add_property("gradients",
gradients_asarray<OverlapCalculator>,
doc_OverlapCalculator_gradients)
.def("getNeighborSites",
get_neighbor_sites,
arg("i"),
doc_OverlapCalculator_getNeighborSites)
.add_property("coordinations",
coordinations_asarray<OverlapCalculator>,
doc_OverlapCalculator_coordinations)
.def("coordinationByTypes",
coordinationByTypes_asdict<OverlapCalculator,int>,
arg("i"),
doc_OverlapCalculator_coordinationByTypes)
.add_property("neighborhoods",
neighborhoods_aslistset<OverlapCalculator>,
doc_OverlapCalculator_neighborhoods)
.add_property("atomradiitable",
getatomradiitable,
setatomradiitable<OverlapCalculator,AtomRadiiTable>,
doc_OverlapCalculator_atomradiitable)
.def_pickle(OverlapCalculatorPickleSuite())
;
}
} // namespace srrealmodule
// End of file