// ************************************************************************** // // // BornAgain: simulate and fit reflection and scattering // //! @file Wrap/Swig/libBornAgainResample.i //! @brief SWIG interface file for libBornAgainResample //! //! Configuration is done in Resample/CMakeLists.txt //! //! @homepage http://apps.jcns.fz-juelich.de/BornAgain //! @license GNU General Public License v3 or higher (see COPYING) //! @copyright Forschungszentrum Jülich GmbH 2013 //! @authors Scientific Computing Group at MLZ Garching //! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke // // ************************************************************************** // %module(directors="1", moduleimport="import $module") "libBornAgainResample" %include "commons.i" %include "../../auto/Wrap/doxygenResample.i" %{ #include "Resample/Options/SimulationOptions.h" %} %include "Resample/Options/SimulationOptions.h" %include "ignoreBase.i" %include "ignoreSample.i" %import(module="libBornAgainFit") "" // Propagate python exceptions (from https://stackoverflow.com/questions/4811492) %feature("director:except") { if( $error != NULL ) { PyObject *ptype, *pvalue, *ptraceback; PyErr_Fetch( &ptype, &pvalue, &ptraceback ); PyErr_Restore( ptype, pvalue, ptraceback ); PyErr_Print(); Py_Exit(1); } } %{ #include "BAVersion.h" #include "Base/Vector/BasicVector3D.h" #include "Resample/Swig/MultiLayerFuncs.h" %} // The following goes verbatim from libBornAgainCore.i to libBornAgainCore_wrap.cxx. // Note that the order matters, as base classes must be included before derived classes. %include "fromBase.i" %include "fromParam.i" %import(module="libBornAgainSample") "Sample/Scattering/ISampleNode.h" %import(module="libBornAgainSample") "Sample/Scattering/IFormFactor.h" %import(module="libBornAgainSample") "Sample/Scattering/IBornFF.h" %include "BAVersion.h" %include "Resample/Swig/MultiLayerFuncs.h" %extend BasicVector3D<double> { BasicVector3D<double> __add__(const BasicVector3D<double>& rhs) const { return *($self) + rhs; } BasicVector3D<double> __mul__(double c) const { return c * *($self); } BasicVector3D<double> __rmul__(double c) const { return *($self) * c; } BasicVector3D<double> __neg__() const { return - *($self); } }; %pythoncode %{ def materialProfile(multilayer, n_points=400, z_min=None, z_max=None): """ Creates a material profile from the given multilayer. If no limits are given, it will provide sensible default values, considering the included particles and interface roughnesses. :param multilayer: bornagain.MultiLayer object :param n_points: number of points to generate :param z_min: starting value for z :param z_max: ending value for z :return: numpy arrays containing z positions and the complex material values in those positions """ def_z_min, def_z_max = defaultMaterialProfileLimits(multilayer) z_min = def_z_min if z_min is None else z_min z_max = def_z_max if z_max is None else z_max z_points = generateZValues(n_points, z_min, z_max) material_values = materialProfileSLD(multilayer, n_points, z_min, z_max) return (z_points, material_values) %}