Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cb9bcfc
updated cpp version and replaced boost smart pointer usages
SYMSCAE Jun 24, 2026
a77b086
added nanobind source to build system
SYMSCAE Jun 24, 2026
107ea7c
ran docformatter
SYMSCAE Jun 24, 2026
330e612
update precommit deps
SYMSCAE Jun 25, 2026
70778b9
fix docformatter conflicts
SYMSCAE Jun 26, 2026
790eff8
Merge pull request #87 from SYMSCAE/precommit-deps
sbillinge Jun 26, 2026
5094a2a
Merge branch 'main' into nanobind-deps
SYMSCAE Jun 26, 2026
63006a8
news
SYMSCAE Jun 26, 2026
71ddfd5
migrated syntax for srreal_converters and srreal_validators
SYMSCAE Jun 24, 2026
50e706b
migrated syntax for srreal_ext and srreal_registry
SYMSCAE Jun 24, 2026
eebb59d
reworked pickling and migrated syntax for wrap_AtomicStructureAdapter
SYMSCAE Jun 25, 2026
49430b4
migrated bindings for AtomRadiiTable, Attributes, BaseBondGenerator a…
SYMSCAE Jun 25, 2026
774b475
migrated bindings for BVParametersTable, BVSCalculator, EventTicker a…
SYMSCAE Jun 25, 2026
3920040
migrated bindings for ObjCrystAdapters, OverlapCalculator, PairQuanti…
SYMSCAE Jun 25, 2026
0066c2b
migrated bindings for PDFCalculators and PDFenvelope
SYMSCAE Jun 25, 2026
7f55adb
migrated bindings for PeakProfile, PeakWidthModel and ScatteringFacto…
SYMSCAE Jun 25, 2026
9fe4a79
migrated bindings for StructureAdapter and StructureDifference
SYMSCAE Jun 25, 2026
25c1e74
fix build
SYMSCAE Jun 25, 2026
ee7ef63
restore default constructors
SYMSCAE Jun 26, 2026
a56ab24
corrected code behaviors
SYMSCAE Jun 26, 2026
c4f74cd
restore PDFCalculator behavior
SYMSCAE Jun 26, 2026
334cfcd
reworked pickling system
SYMSCAE Jun 26, 2026
72deaae
fix tests
SYMSCAE Jun 26, 2026
711a416
ran docformatter
SYMSCAE Jul 7, 2026
8ef7657
cleanup boost imports
SYMSCAE Jul 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
migrated bindings for PeakProfile, PeakWidthModel and ScatteringFacto…
…rTable
  • Loading branch information
SYMSCAE committed Jul 7, 2026
commit 7f55adbee43b4ed11e537cc1581ff11f15a42352
111 changes: 66 additions & 45 deletions src/extensions/wrap_PeakProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
*
*****************************************************************************/

#include <boost/python/class.hpp>
#include <boost/python/def.hpp>
#include <boost/python/copy_const_reference.hpp>
#include <boost/python/register_ptr_to_python.hpp>
#include <nanobind/nanobind.h>
#include <nanobind/trampoline.h>

#include <string>

Expand All @@ -35,8 +33,6 @@
namespace srrealmodule {
namespace nswrap_PeakProfile {

using namespace boost;
using namespace boost::python;
using namespace diffpy::srreal;

// docstrings ----------------------------------------------------------------
Expand Down Expand Up @@ -110,61 +106,84 @@ The profile is also rescaled to keep the integrated area of 1.\n\
// Support for override of PeakProfile methods from Python.

class PeakProfileWrap :
public PeakProfile,
public wrapper_srreal<PeakProfile>
public PeakProfile
{
public:

NB_TRAMPOLINE(PeakProfile, 7);

// HasClassRegistry methods

PeakProfilePtr create() const
PeakProfilePtr create() const override
{
object rv = this->get_pure_virtual_override("create")();
nb::gil_scoped_acquire gil;
nb::detail::ticket ticket(nb_trampoline, "create", true);

if (!ticket.key.is_valid())
{
throw nb::type_error(
"pure virtual method PeakProfile.create() called"
);
}

nb::object rv = nb_trampoline.base().attr(ticket.key)();
return mconfigurator.fetch(rv);
}

PeakProfilePtr clone() const
PeakProfilePtr clone() const override
{
return this->get_pure_virtual_override("clone")();
NB_OVERRIDE_PURE(clone);
}


const std::string& type() const
const std::string& type() const override
{
python::object tp = this->get_pure_virtual_override("type")();
mtype = python::extract<std::string>(tp);
nb::gil_scoped_acquire gil;
nb::detail::ticket ticket(nb_trampoline, "type", true);

if (!ticket.key.is_valid())
{
throw nb::type_error(
"pure virtual method PeakProfile.type() called"
);
}

nb::object tp = nb_trampoline.base().attr(ticket.key)();
mtype = nb::cast<std::string>(tp);
return mtype;
}

// own methods

double operator()(double x, double fwhm) const
double operator()(double x, double fwhm) const override
{
return this->get_pure_virtual_override("__call__")(x, fwhm);
NB_OVERRIDE_PURE_NAME("__call__", operator(), x, fwhm);
}

double xboundlo(double fwhm) const
double xboundlo(double fwhm) const override
{
return this->get_pure_virtual_override("xboundlo")(fwhm);
NB_OVERRIDE_PURE(xboundlo, fwhm);
}

double xboundhi(double fwhm) const
double xboundhi(double fwhm) const override
{
return this->get_pure_virtual_override("xboundhi")(fwhm);
NB_OVERRIDE_PURE(xboundhi, fwhm);
}

// Support for ticker override from Python.

diffpy::eventticker::EventTicker& ticker() const
diffpy::eventticker::EventTicker& ticker() const override
{
using diffpy::eventticker::EventTicker;
override f = this->get_override("ticker");
if (f)
nb::gil_scoped_acquire gil;
nb::detail::ticket ticket(nb_trampoline, "ticker", false);

if (ticket.key.is_valid())
{
// avoid "dangling reference error" when used from C++
python::object ptic = f();
return python::extract<EventTicker&>(ptic);
nb::object ptic = nb_trampoline.base().attr(ticket.key)();
return nb::cast<EventTicker&>(ptic);
}

return this->default_ticker();
}

Expand All @@ -177,7 +196,7 @@ class PeakProfileWrap :

// HasClassRegistry method

void setupRegisteredObject(PeakProfilePtr p) const
void setupRegisteredObject(PeakProfilePtr p) const override
{
mconfigurator.setup(p);
}
Expand All @@ -202,40 +221,42 @@ class PeakProfileWrap :

// Wrapper definition --------------------------------------------------------

void wrap_PeakProfile()
void wrap_PeakProfile(nb::module_& m)
{
using namespace nswrap_PeakProfile;
using diffpy::Attributes;
namespace bp = boost::python;

class_<PeakProfileWrap, bases<Attributes>, noncopyable>
peakprofile("PeakProfile", doc_PeakProfile);
nb::class_<PeakProfile, Attributes, PeakProfileWrap>
peakprofile(m, "PeakProfile", nb::dynamic_attr(), doc_PeakProfile);
wrap_registry_methods(peakprofile)
.def(nb::init<>())
.def("__call__", &PeakProfile::operator(),
(bp::arg("x"), bp::arg("fwhm")), doc_PeakProfile___call__)
nb::arg("x"), nb::arg("fwhm"), doc_PeakProfile___call__)
.def("xboundlo", &PeakProfile::xboundlo,
bp::arg("fwhm"), doc_PeakProfile_xboundlo)
nb::arg("fwhm"), doc_PeakProfile_xboundlo)
.def("xboundhi", &PeakProfile::xboundhi,
bp::arg("fwhm"), doc_PeakProfile_xboundhi)
nb::arg("fwhm"), doc_PeakProfile_xboundhi)
.def("ticker",
&PeakProfile::ticker,
&PeakProfileWrap::default_ticker,
return_internal_reference<>(),
nb::rv_policy::reference_internal,
doc_PeakProfile_ticker)
.def_pickle(SerializationPickleSuite<PeakProfile,DICT_PICKLE>())
;

register_ptr_to_python<PeakProfilePtr>();
SerializationPickleSuite<PeakProfile, DICT_PICKLE>::bind(peakprofile);

class_<GaussianProfile, bases<PeakProfile> >(
"GaussianProfile", doc_GaussianProfile)
.def_pickle(SerializationPickleSuite<GaussianProfile>())
nb::class_<GaussianProfile, PeakProfile> gaussianprofile(m,
"GaussianProfile", doc_GaussianProfile);
gaussianprofile
.def(nb::init<>())
;
SerializationPickleSuite<GaussianProfile, DICT_IGNORE>::bind(gaussianprofile);

class_<CroppedGaussianProfile, bases<GaussianProfile> >(
"CroppedGaussianProfile", doc_CroppedGaussianProfile)
.def_pickle(SerializationPickleSuite<CroppedGaussianProfile>())
nb::class_<CroppedGaussianProfile, GaussianProfile> croppedgaussianprofile(m,
"CroppedGaussianProfile", doc_CroppedGaussianProfile);
croppedgaussianprofile
.def(nb::init<>())
;
SerializationPickleSuite<CroppedGaussianProfile, DICT_IGNORE>::bind(croppedgaussianprofile);

}

Expand Down
Loading