13
13
******************************************************************************
14
14
*
15
15
* boost::python bindings to ObjCryst::DiffractionDataSingleCrystal.
16
- *
16
+ * Changes from ObjCryst::DiffractionDataSingleCrystal
17
+ * - SetHklIobs takes float(64) H, K, L arrays rather than long integers - easier
18
+ * because passing numpy int array seesm complicated, and more practical anyway
19
+ * since GetH() GetK() GetL() functions from ScatteringData natively use floats.
17
20
*****************************************************************************/
18
21
19
22
#include < boost/python/class.hpp>
20
23
#include < boost/python/def.hpp>
21
24
#include < boost/python/copy_const_reference.hpp>
22
25
#include < boost/python/manage_new_object.hpp>
26
+ #include < boost/python/stl_iterator.hpp>
23
27
#undef B0
24
28
25
29
#include < string>
@@ -67,6 +71,71 @@ DiffractionDataSingleCrystal* _CreateSingleCrystalDataFromCIF(bp::object input,
67
71
return d;
68
72
}
69
73
74
+ void setdiffractiondatasinglecrystal_iobs (DiffractionDataSingleCrystal& diff, bp::object iobs)
75
+ {
76
+ CrystVector_REAL iiobs;
77
+ assignCrystVector (iiobs, iobs);
78
+ if (iiobs.size () != diff.GetIobs ().size ())
79
+ throw ObjCryst::ObjCrystException (" DiffractionDataSingleCrystal::SetIobs(): "
80
+ " number of elements does not match the previous Iobs list. "
81
+ " Use SetHklIobs if you want to change the number of reflections." );
82
+ MuteObjCrystUserInfo muzzle;
83
+ diff.SetIobs (iiobs);
84
+ }
85
+
86
+ void setdiffractiondatasinglecrystal_sigma (DiffractionDataSingleCrystal& diff, bp::object sigma)
87
+ {
88
+ CrystVector_REAL ssigma;
89
+ assignCrystVector (ssigma, sigma);
90
+ if (ssigma.size () != diff.GetIobs ().size ())
91
+ throw ObjCryst::ObjCrystException (" DiffractionDataSingleCrystal::SetSigma(): "
92
+ " number of elements does not match the Iobs list. "
93
+ " Use SetHklIobs if you want to change the number of reflections." );
94
+ MuteObjCrystUserInfo muzzle;
95
+ diff.SetSigma (ssigma);
96
+ }
97
+
98
+ // TODO: For SetHklIobs we should pass directly an integer array but that seems difficult-passed numpy arrays
99
+ // are always interpreted as doubles (?). It's more practical this way.
100
+ void assignCrystVector (CrystVector<long >& cv, bp::object obj)
101
+ {
102
+ bp::stl_input_iterator<double > begin (obj), end;
103
+ std::list<double > values (begin, end);
104
+ cv.resize (values.size ());
105
+ std::list<double >::const_iterator vv = values.begin ();
106
+ long * dst = cv.data ();
107
+ for (; vv != values.end (); ++vv, ++dst) *dst = lround (*vv);
108
+ }
109
+
110
+ void setdiffractiondatasinglecrystal_hkliobs (DiffractionDataSingleCrystal& diff,
111
+ bp::object h,bp::object k, bp::object l,
112
+ bp::object iobs, bp::object sigma)
113
+ {
114
+ CrystVector<long > hh;
115
+ assignCrystVector (hh, h);
116
+ CrystVector<long > kk;
117
+ assignCrystVector (kk, k);
118
+ CrystVector<long > ll;
119
+ assignCrystVector (ll, l);
120
+ CrystVector_REAL iiobs;
121
+ assignCrystVector (iiobs, iobs);
122
+ CrystVector_REAL ssigma;
123
+ assignCrystVector (ssigma, sigma);
124
+
125
+ if (hh.size () != kk.size ())
126
+ throw ObjCryst::ObjCrystException (" DiffractionDataSingleCrystal::SetHklIobs(): h and k array sizes differ" );
127
+ if (hh.size () != ll.size ())
128
+ throw ObjCryst::ObjCrystException (" DiffractionDataSingleCrystal::SetHklIobs(): h and l array sizes differ" );
129
+ if (hh.size () != iiobs.size ())
130
+ throw ObjCryst::ObjCrystException (" DiffractionDataSingleCrystal::SetHklIobs(): h and iobs array sizes differ" );
131
+ if (hh.size () != ssigma.size ())
132
+ throw ObjCryst::ObjCrystException (" DiffractionDataSingleCrystal::SetHklIobs(): h and sigma array sizes differ" );
133
+
134
+ MuteObjCrystUserInfo muzzle;
135
+ diff.SetHklIobs (hh, kk, ll, iiobs, ssigma);
136
+ }
137
+
138
+
70
139
} // namespace
71
140
72
141
void wrap_diffractiondatasinglecrystal ()
@@ -83,10 +152,24 @@ void wrap_diffractiondatasinglecrystal()
83
152
return_value_policy<copy_const_reference>())
84
153
.def (" GetIobs" , &DiffractionDataSingleCrystal::GetIobs,
85
154
return_value_policy<copy_const_reference>())
86
- // FIXME ... add SetIobs, SetSigma ....
155
+ .def (" GetSigma" , &DiffractionDataSingleCrystal::GetSigma,
156
+ return_value_policy<copy_const_reference>())
157
+ .def (" SetIobs" ,
158
+ &setdiffractiondatasinglecrystal_iobs,
159
+ bp::arg (" iobs" ))
160
+ .def (" SetSigma" ,
161
+ &setdiffractiondatasinglecrystal_sigma,
162
+ bp::arg (" sigma" ))
163
+ .def (" SetHklIobs" ,
164
+ &setdiffractiondatasinglecrystal_hkliobs,
165
+ (bp::arg (" h" ),bp::arg (" k" ),bp::arg (" l" ), bp::arg (" iobs" ), bp::arg (" sigma" )))
87
166
.def (" SetIobsToIcalc" , &DiffractionDataSingleCrystal::SetIobsToIcalc)
88
167
.def (" GetRw" , &DiffractionDataSingleCrystal::GetRw)
89
168
.def (" GetR" , &DiffractionDataSingleCrystal::GetR)
169
+ .def (" GetChi2" , &DiffractionDataSingleCrystal::GetChi2)
170
+ .def (" FitScaleFactorForRw" , &DiffractionDataSingleCrystal::FitScaleFactorForRw)
171
+ .def (" FitScaleFactorForR" , &DiffractionDataSingleCrystal::FitScaleFactorForR)
172
+ // TODO: These functions should print a limited number of reflections - problems otherwise
90
173
.def (" PrintObsData" , &DiffractionDataSingleCrystal::PrintObsData)
91
174
.def (" PrintObsCalcData" , &DiffractionDataSingleCrystal::PrintObsCalcData)
92
175
.def (" SetUseOnlyLowAngleData" , &DiffractionDataSingleCrystal::SetUseOnlyLowAngleData)
0 commit comments