-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathreflectionprofile_ext.cpp
More file actions
124 lines (109 loc) · 4.67 KB
/
reflectionprofile_ext.cpp
File metadata and controls
124 lines (109 loc) · 4.67 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
/*****************************************************************************
*
* pyobjcryst
*
* File coded by: Vincent Favre-Nicolin
*
* See AUTHORS.txt for a list of people who contributed.
* See LICENSE.txt for license information.
*
******************************************************************************
*
* boost::python bindings to ObjCryst::ReflectionProfile.
*
* Changes from ObjCryst::ReflectionProfile
*
* Other Changes
*
*****************************************************************************/
#include <boost/python/class.hpp>
#include <boost/python/manage_new_object.hpp>
#include <boost/python/pure_virtual.hpp>
#undef B0
#include "helpers.hpp" // assignCrystVector helper for numpy/sequence inputs
#include <iostream>
#include <ObjCryst/ObjCryst/ReflectionProfile.h>
namespace bp = boost::python;
using namespace boost::python;
using namespace ObjCryst;
namespace
{
class ReflectionProfileWrap : public ReflectionProfile, public wrapper<ReflectionProfile>
{
public:
// Pure virtual functions
ReflectionProfile *CreateCopy() const
{
return this->get_override("CreateCopy")();
}
CrystVector_REAL GetProfile(
const CrystVector_REAL &x, const REAL xcenter,
const REAL h, const REAL k, const REAL l) const
{
bp::override f = this->get_override("GetProfile");
return f(x, xcenter, h, k, l);
}
REAL GetFullProfileWidth(
const REAL relativeIntensity, const REAL xcenter,
const REAL h, const REAL k, const REAL l)
{
bp::override f = this->get_override("GetFullProfileWidth");
return f(relativeIntensity, xcenter, h, k, l);
}
void XMLOutput(ostream &os, int indent) const
{
bp::override f = this->get_override("XMLOutput");
f(os, indent);
}
void XMLInput(istream &is, const XMLCrystTag &tag)
{
bp::override f = this->get_override("XMLInput");
f(is, tag);
}
};
// Accept python sequences/ndarrays for x and forward to the C++ API.
CrystVector_REAL _GetProfile(
const ReflectionProfile &rp, bp::object x, const REAL xcenter,
const REAL h, const REAL k, const REAL l)
{
CrystVector_REAL cvx;
assignCrystVector(cvx, x);
return rp.GetProfile(cvx, xcenter, h, k, l);
}
} // namespace
void wrap_reflectionprofile()
{
class_<ReflectionProfileWrap, bases<RefinableObj>, boost::noncopyable>(
"ReflectionProfile")
.def("CreateCopy",
pure_virtual(&ReflectionProfile::CreateCopy),
(return_value_policy<manage_new_object>()),
"Return a new ReflectionProfile instance copied from this one.")
// Two overloads for GetProfile:
// - Native CrystVector signature (for C++ callers / already-converted vectors).
// - Python-friendly wrapper that accepts sequences/ndarrays and converts them.
.def(
"GetProfile",
pure_virtual((CrystVector_REAL (ReflectionProfile::*)(const CrystVector_REAL &, REAL, REAL, REAL, REAL) const) & ReflectionProfile::GetProfile),
(bp::arg("x"), bp::arg("xcenter"), bp::arg("h"),
bp::arg("k"), bp::arg("l")),
"Compute the profile values at positions `x` for reflection (h, k, l) centered at `xcenter`.")
.def(
"GetProfile", &_GetProfile,
(bp::arg("x"), bp::arg("xcenter"), bp::arg("h"), bp::arg("k"),
bp::arg("l")),
"Compute the profile values at positions `x` (sequence/ndarray accepted) for reflection (h, k, l) centered at `xcenter`.")
.def("GetFullProfileWidth",
pure_virtual((REAL (ReflectionProfile::*)(const REAL, const REAL, const REAL, const REAL, const REAL) const) & ReflectionProfile::GetFullProfileWidth),
(bp::arg("relativeIntensity"), bp::arg("xcenter"),
bp::arg("h"), bp::arg("k"), bp::arg("l")),
"Return the full profile width at a given relative intensity for reflection (h, k, l) around `xcenter`.")
.def("XMLOutput",
pure_virtual((void (ReflectionProfile::*)(ostream &, int) const) & ReflectionProfile::XMLOutput),
(bp::arg("os"), bp::arg("indent")),
"Write this ReflectionProfile as XML to a file-like object. `indent` controls indentation depth.")
.def("XMLInput",
pure_virtual((void (ReflectionProfile::*)(istream &, const XMLCrystTag &))&ReflectionProfile::XMLInput),
(bp::arg("is"), bp::arg("tag")),
"Load ReflectionProfile parameters from an XML stream and tag.");
}