<commit_before>/*! \file
 *
 * \brief Python exports for the molecule library
 * \author <NAME> (<EMAIL>)
 */ 


#include <boost/python/module.hpp>
#include <boost/python/class.hpp>
#include <boost/python/def.hpp>
#include <boost/python/copy_const_reference.hpp>
#include <boost/python/to_python_converter.hpp>
#include <boost/python/tuple.hpp>

#include "bpmodule/python_helper/Convert.hpp"
#include "bpmodule/molecule/AtomicInfo.hpp"
#include "bpmodule/molecule/Molecule.hpp"

using namespace boost::python;
using bpmodule::python_helper::CppToPyExport;
using bpmodule::python_helper::ConvertToCpp;

namespace bpmodule {
namespace molecule {
namespace export_python {


// A bit of a hack
// Since we want isotopes to be a data member, and not a function,
// Python won't use the to_python_converter. So we use add_property
// instead and create a little wrapper function
std::vector<IsotopeData> AtomicDataIsotopes_(AtomicData & ad) { return ad.isotopes; }



// Molecule::AddAtom wrapper
void Molecule_AddAtomWrapper(Molecule & mol, int Z, const boost::python::tuple & xyz)
{
    //! \todo check for tuple of length 3
    double x = ConvertToCpp<double>(xyz[0]);
    double y = ConvertToCpp<double>(xyz[1]);
    double z = ConvertToCpp<double>(xyz[2]);
    return mol.AddAtom(Z, {x, y, z});
}




BOOST_PYTHON_MODULE(molecule)
{
    class_<IsotopeData>("IsotopeData", no_init)
    .def_readonly("isonum", &IsotopeData::isonum)
    .def_readonly("mass", &IsotopeData::mass)
    .def_readonly("mass_low", &IsotopeData::mass_low)
    .def_readonly("mass_high", &IsotopeData::mass_high)
    .def_readonly("abund", &IsotopeData::abund)
    .def_readonly("abund_low", &IsotopeData::abund_low)
    .def_readonly("abund_high", &IsotopeData::abund_high)
    ;

    // A vector of isotopes
    to_python_converter<std::vector<IsotopeData>, CppToPyExport<std::vector<IsotopeData>>>();


    class_<AtomicData>("AtomicData", no_init)
    .def_readonly("Z", &AtomicData::Z)
    .def_readonly("sym", &AtomicData::sym)
    .def_readonly("name", &AtomicData::name)
    .def_readonly("mass", &AtomicData::mass)
    .def_readonly("mass_low", &AtomicData::mass_low)
    .def_readonly("mass_high", &AtomicData::mass_high)
    .add_property("isotopes", AtomicDataIsotopes_)
    ;


    // Free functions
    def("AtomicInfoFromZ", AtomicInfoFromZ, return_value_policy<copy_const_reference>());
    def("AtomicInfoFromSym", AtomicInfoFromSym, return_value_policy<copy_const_reference>());
    def("IsotopeInfoFromZ", IsotopeInfoFromZ, return_value_policy<copy_const_reference>());
    def("IsotopeInfoFromSym", IsotopeInfoFromSym, return_value_policy<copy_const_reference>());
    def("MostCommonIsotopeFromZ", MostCommonIsotopeFromZ);
    def("MostCommonIsotopeFromSym", MostCommonIsotopeFromSym);

    def("AtomicMassFromZ", AtomicMassFromZ);
    def("AtomicMassFromSym", AtomicMassFromSym);
    def("IsotopeMassFromZ", IsotopeMassFromZ);
    def("IsotopeMassFromSym", IsotopeMassFromSym);
    def("AtomicSymFromZ", AtomicSymFromZ);
    def("AtomicZNumberFromSym", AtomicZNumberFromSym);
    def("AtomicNameFromZ", AtomicNameFromZ);
    def("AtomicNameFromSym", AtomicNameFromSym);


    // Atom structure
    class_<Atom>("Atom", no_init)
    .def_readwrite("id", &Atom::id)
    .def_readwrite("z", &Atom::z)
    .def_readwrite("isonum", &Atom::isonum)
    .def_readwrite("mass", &Atom::mass)
    .def_readwrite("xyz", &Atom::xyz)
    ;

    // Molecule class
    class_<Molecule>("Molecule", init<>())
    .def("AddAtom", Molecule_AddAtomWrapper)
    .def("GetAtom", &Molecule::GetAtom)
    .def("NAtoms", &Molecule::NAtoms)
    ;


}


} // close namespace export_python
} // close namespace molecule 
} // close namespace bpmodule
<commit_msg>Fix some molecule exports<commit_after>/*! \file
 *
 * \brief Python exports for the molecule library
 * \author <NAME> (<EMAIL>)
 */ 


#include <boost/python/module.hpp>
#include <boost/python/class.hpp>
#include <boost/python/def.hpp>
#include <boost/python/copy_const_reference.hpp>
#include <boost/python/to_python_converter.hpp>

#include "bpmodule/python_helper/Convert.hpp"
#include "bpmodule/molecule/AtomicInfo.hpp"
#include "bpmodule/molecule/Molecule.hpp"

using namespace boost::python;
using bpmodule::python_helper::CppToPyExport;
using bpmodule::python_helper::ConvertToCpp;

namespace bpmodule {
namespace molecule {
namespace export_python {


// A bit of a hack
// Since we want isotopes to be a data member, and not a function,
// Python won't use the to_python_converter. So we use add_property
// instead and create a little wrapper function
std::vector<IsotopeData> AtomicDataIsotopes_(const AtomicData & ad) { return ad.isotopes; }

// Ditto for atom XYZ
std::array<double, 3> AtomXYZ_(const Atom & a) { return a.xyz; }



// Molecule::AddAtom wrapper
void Molecule_AddAtomWrapper(Molecule & mol, int Z, const boost::python::list & xyz)
{
    //! \todo check for list of length 3
    double x = ConvertToCpp<double>(xyz[0]);
    double y = ConvertToCpp<double>(xyz[1]);
    double z = ConvertToCpp<double>(xyz[2]);
    return mol.AddAtom(Z, {x, y, z});
}




BOOST_PYTHON_MODULE(molecule)
{
    class_<IsotopeData>("IsotopeData", no_init)
    .def_readonly("isonum", &IsotopeData::isonum)
    .def_readonly("mass", &IsotopeData::mass)
    .def_readonly("mass_low", &IsotopeData::mass_low)
    .def_readonly("mass_high", &IsotopeData::mass_high)
    .def_readonly("abund", &IsotopeData::abund)
    .def_readonly("abund_low", &IsotopeData::abund_low)
    .def_readonly("abund_high", &IsotopeData::abund_high)
    ;

    // A vector of isotopes
    to_python_converter<std::vector<IsotopeData>, CppToPyExport<std::vector<IsotopeData>>>();


    class_<AtomicData>("AtomicData", no_init)
    .def_readonly("Z", &AtomicData::Z)
    .def_readonly("sym", &AtomicData::sym)
    .def_readonly("name", &AtomicData::name)
    .def_readonly("mass", &AtomicData::mass)
    .def_readonly("mass_low", &AtomicData::mass_low)
    .def_readonly("mass_high", &AtomicData::mass_high)
    .add_property("isotopes", AtomicDataIsotopes_)
    ;


    // Free functions
    def("AtomicInfoFromZ", AtomicInfoFromZ, return_value_policy<copy_const_reference>());
    def("AtomicInfoFromSym", AtomicInfoFromSym, return_value_policy<copy_const_reference>());
    def("IsotopeInfoFromZ", IsotopeInfoFromZ, return_value_policy<copy_const_reference>());
    def("IsotopeInfoFromSym", IsotopeInfoFromSym, return_value_policy<copy_const_reference>());
    def("MostCommonIsotopeFromZ", MostCommonIsotopeFromZ);
    def("MostCommonIsotopeFromSym", MostCommonIsotopeFromSym);

    def("AtomicMassFromZ", AtomicMassFromZ);
    def("AtomicMassFromSym", AtomicMassFromSym);
    def("IsotopeMassFromZ", IsotopeMassFromZ);
    def("IsotopeMassFromSym", IsotopeMassFromSym);
    def("AtomicSymFromZ", AtomicSymFromZ);
    def("AtomicZNumberFromSym", AtomicZNumberFromSym);
    def("AtomicNameFromZ", AtomicNameFromZ);
    def("AtomicNameFromSym", AtomicNameFromSym);


    // Atom structure
    class_<Atom>("Atom", no_init)
    .def_readwrite("id", &Atom::id)
    .def_readwrite("z", &Atom::z)
    .def_readwrite("isonum", &Atom::isonum)
    .def_readwrite("mass", &Atom::mass)
    .add_property("xyz", AtomXYZ_)
    ;

    // Molecule class
    class_<Molecule>("Molecule", init<>())
    .def("AddAtom", Molecule_AddAtomWrapper)
    .def("GetAtom", &Molecule::GetAtom)
    .def("NAtoms", &Molecule::NAtoms)
    ;


}


} // close namespace export_python
} // close namespace molecule 
} // close namespace bpmodule

{'fraction_non_alphanumeric': 0.1427812458493824, 'fraction_numerical': 0.0011953778722273874, 'mean_word_length': 5.26977518734388, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2239640', 'n_tokens_mistral': 2738, 'n_tokens_neox': 2599, 'n_words': 451}