Skip to content

Commit

Permalink
Export states list to Python
Browse files Browse the repository at this point in the history
  • Loading branch information
mducle committed Apr 23, 2020
1 parent 13e323d commit b53bba3
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/include/ic1ion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class ic1ion : public cfpars {
std::vector< std::vector<double> > calculate_moments(RowMatrixXcd ev);
std::vector<double> calculate_boltzmann( // Calculates the Boltzmann factor exp(-E/kT)
VectorXd en, double T);
std::vector<fstates_t> get_states();

}; // class ic1ion

Expand Down
1 change: 1 addition & 0 deletions src/libmcphase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(LIBMCPHASE_PYTHON_SOURCES
pycfpars.cpp
pycf1ion.cpp
pyic1ion.cpp
pyicstates.cpp
)
target_sources(${LIBMCPHASE_PYTHON_MODULE} PRIVATE ${LIBMCPHASE_PYTHON_SOURCES})
target_link_libraries(${LIBMCPHASE_PYTHON_MODULE} PUBLIC ${LIBMCPHASE_CXX_LIBRARIES})
Expand Down
2 changes: 2 additions & 0 deletions src/libmcphase/libmcphase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ namespace py = pybind11;
void wrap_cfpars(py::module &);
void wrap_cf1ion(py::module &);
void wrap_ic1ion(py::module &);
void wrap_icstates(py::module &);

PYBIND11_MODULE(libmcphase, m) {
m.doc() = "Python bindings for libMcPhase";

wrap_cfpars(m);
wrap_cf1ion(m);
wrap_ic1ion(m);
wrap_icstates(m);
}


3 changes: 2 additions & 1 deletion src/libmcphase/pyic1ion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ void wrap_ic1ion(py::module &m) {
.def("magnetisation", [](ic1ion &self, std::vector<double> H, std::vector<double> Hdir, double T, std::string unit) { return self.magnetisation(H, Hdir, T,
set_enum(unit, mag_unit_names, "Invalid magnetic unit, must be one of: 'bohr', 'cgs', or 'SI'")); })
.def("susceptibility", [](ic1ion &self, std::vector<double> T, std::vector<double> Hdir, std::string unit) { return self.susceptibility(T, Hdir,
set_enum(unit, mag_unit_names, "Invalid magnetic unit, must be one of: 'bohr', 'cgs', or 'SI'")); });
set_enum(unit, mag_unit_names, "Invalid magnetic unit, must be one of: 'bohr', 'cgs', or 'SI'")); })
.def("get_states", &ic1ion::get_states, "Gets the list of states for this ion configuration");
}


49 changes: 49 additions & 0 deletions src/libmcphase/pyicstates.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* pyicstates.cpp
*
* Python bindings for the fstates class of libMcPhase
*
* (C) 2020 Duc Le - [email protected]
* This program is licensed under the GNU General Purpose License, version 3. Please see the LICENSE file
*/

#include "ic_states.hpp"
#include <pybind11/pybind11.h>

namespace py = pybind11;
using namespace libMcPhase;

void wrap_icstates(py::module &m) {

py::class_<fstates_t> pyicstate(m, "ic_state");

py::enum_<orbital>(pyicstate, "orbital")
.value("S", orbital::S)
.value("P", orbital::P)
.value("D", orbital::D)
.value("F", orbital::F)
.value("Fp", orbital::Fp)
.value("G", orbital::G)
.value("Gp", orbital::Gp)
.value("H", orbital::H)
.value("Hp", orbital::Hp)
.value("I", orbital::I)
.value("Ip", orbital::Ip)
.value("K", orbital::K)
.value("Kp", orbital::Kp)
.value("L", orbital::L)
.value("Lp", orbital::Lp)
.value("M", orbital::M)
.value("N", orbital::N)
.value("O", orbital::O)
.value("Q", orbital::Q)
.export_values();

pyicstate
.def_property_readonly("S2", [](const fstates_t &self){ return self.S2; }, "Twice the total spin momentum")
.def_property_readonly("L", [](const fstates_t &self){ return (int)abs(self.L); }, "The orbital momentum")
.def_property_readonly("id", [](const fstates_t &self){ return self.id; }, "id string")
.def_property_readonly("J2", [](const fstates_t &self){ return self.J2; }, "Twice the total momentum")
.def_property_readonly("mJ2", [](const fstates_t &self){ return self.mJ2; }, "Twice the total azimuth momentum");
}


8 changes: 8 additions & 0 deletions src/singleion/ic1ion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ void ic1ion::set_name(const std::string &ionname) {
m_ham_calc = false;
m_ev_calc = false;
m_tensorops.clear();
m_conf = fconf(m_n, 1, m_l);
}

void ic1ion::set_coulomb(const std::vector<double> val, ic1ion::CoulombType type) {
Expand Down Expand Up @@ -168,6 +169,13 @@ void ic1ion::set_spinorbit(double val, ic1ion::SpinOrbType type) {
}
}

std::vector<fstates_t> ic1ion::get_states() {
if (m_conf.states.empty()) {
m_conf = fconf(m_n, 1, m_l);
}
return m_conf.states;
}

// --------------------------------------------------------------------------------------------------------------- //
// Constructors for the ic1ion class
// --------------------------------------------------------------------------------------------------------------- //
Expand Down

0 comments on commit b53bba3

Please sign in to comment.