oILAB
Loading...
Searching...
No Matches
LatticeVectorBindings.h
Go to the documentation of this file.
1//
2// Created by Nikhil Chandra Admal on 7/3/25.
3//
4
5#ifndef OILAB_LATTICEVECTORBINDINGS_H
6#define OILAB_LATTICEVECTORBINDINGS_H
7
8#include <pybind11/pybind11.h>
9#include <pybind11/operators.h>
10#include <LatticeModule.h>
11#include <PyLatticeModule.h>
12#include <pybind11/numpy.h>
13#include <pybind11/eigen.h>
14
15namespace py = pybind11;
16
17namespace pyoilab{
18// Had to wrap the LatticeVector<dim> class due to Pybind11 issues with classes with
19// Eigen base classes
20 template<int dim>
25
26
27 using IntScalarType = long long int;
28 using MatrixDimD = Eigen::Matrix<double, dim, dim>;
29 using VectorDimD = Eigen::Matrix<double, dim, 1>;
30 using VectorDimI = Eigen::Matrix<IntScalarType, dim, 1>;
31 using MatrixDimI = Eigen::Matrix<IntScalarType, dim, dim>;
32 public:
34
35 PyLatticeVector(const Lattice& lattice) : lv(lattice) {}
36
37 PyLatticeVector(const VectorDimD& cartesianCoordinates, const Lattice& lattice) : lv(cartesianCoordinates,
38 lattice) {}
39
41 lattice) {}
42
44
46
48 return PyLatticeVector(lv.operator+(other.lv));
49 }
50
52 return PyLatticeVector(lv.operator-(other.lv));
53 }
54
56 lv.operator+=(other.lv);
57 return *this;
58 }
59
61 lv.operator-=(other.lv);
62 return *this;
63 }
64
66 return PyLatticeVector(lv.operator*(scalar));
67 }
68
70 return lv.cartesian();
71 }
72
74 return lv;
75 }
76
77 void integerCoordinates(const VectorDimI& input) {
78 lv << input;
79 }
80
82 return lv.dot(other.rlv);
83 }
84
85 template<int dm=dim>
86 typename std::enable_if<dm==2,PyReciprocalLatticeDirection>::type
87 cross(const PyLatticeVector<dim>& other) const
88 {
90 }
91
92 template<int dm=dim>
93 typename std::enable_if<dm==3,PyReciprocalLatticeDirection>::type
94 cross(const PyLatticeVector<dm>& other) const
95 {
97 }
98
99 template<int dm=dim>
100 typename std::enable_if<dm==2,PyReciprocalLatticeDirection>::type
101 cross() const
102 {
104 }
105 template<int dm=dim>
106 typename std::enable_if<dm==3,PyReciprocalLatticeDirection>::type
107 cross() const
108 {
110 }
111
112 };
113
114 template<int dim>
115 PyLatticeVector<dim> operator*(const long long int& scalar, const PyLatticeVector<dim>& L) {
116 return L * scalar;
117 }
118
119 template<int dim>
120 void bind_LatticeVector(py::module_& m) {
121 using Lattice = gbLAB::Lattice<dim>;
122 using LatticeVector = gbLAB::LatticeVector<dim>;
123 using IntScalarType = long long int;
124 using MatrixDimD = Eigen::Matrix<double, dim, dim>;
125 using VectorDimD = Eigen::Matrix<double, dim, 1>;
126 using VectorDimI = Eigen::Matrix<IntScalarType, dim, 1>;
127 using MatrixDimI = Eigen::Matrix<IntScalarType, dim, dim>;
130
131 py::class_<PyLatticeVector>(m, ("LatticeVector" + std::to_string(dim) + "D").c_str(),("LatticeVector" + std::to_string(dim) + "D class").c_str())
132 .def(py::init<const Lattice&>())
133 .def(py::init<const VectorDimD&, const Lattice&>())
134 .def(py::init<const VectorDimI&, const Lattice&>())
135 .def(py::init<const PyLatticeVector&>())
136 .def("lattice",[](const PyLatticeVector& self){
137 return self.lv.lattice;
138 },py::return_value_policy::reference_internal)
139 .def("cartesian", &PyLatticeVector::cartesian)
140 .def("integerCoordinates", static_cast<VectorDimI (PyLatticeVector::*)() const>(&PyLatticeVector::integerCoordinates),
141 "output the integer coordinates of the lattice vecctor")
142 .def("integerCoordinates", static_cast<void (PyLatticeVector::*)(const VectorDimI&)>(&PyLatticeVector::integerCoordinates),
143 "input the integer coordinates of the lattice vector")
144 .def("dot", &PyLatticeVector::dot,
145 "dot product with a reciprocal lattice vector")
146 .def(py::self + py::self)
147 .def(py::self - py::self)
148 .def("__mul__", [](const PyLatticeVector& self, const IntScalarType& scalar) {
149 return self * scalar;
150 }, py::is_operator())
151 .def("__rmul__", [](const PyLatticeVector& self, const IntScalarType& scalar) {
152 return scalar * self;
153 }, py::is_operator())
154 .def(py::self -= py::self)
155 .def(py::self += py::self)
156 .def("cross", static_cast<PyReciprocalLatticeDirection (PyLatticeVector::*)(const PyLatticeVector&) const> (&PyLatticeVector::cross))
157 .def("cross", static_cast<PyReciprocalLatticeDirection (PyLatticeVector::*)() const> (&PyLatticeVector::cross));
158 }
159}
160#endif //OILAB_LATTICEVECTORBINDINGS_H
Lattice class.
Definition Lattice.h:34
LatticeVector class.
VectorDimD cartesian() const
const Lattice< dim > & lattice
std::enable_if< dm==2, ReciprocalLatticeDirection< dm > >::type cross(const LatticeVector< dm > &other) const
IntScalarType dot(const ReciprocalLatticeVector< dim > &other) const
Eigen::Matrix< double, dim, dim > MatrixDimD
PyLatticeVector operator*(const IntScalarType &scalar) const
PyLatticeVector operator+(const PyLatticeVector &other) const
PyLatticeVector operator-(const PyLatticeVector &other) const
PyLatticeVector(const LatticeVector &lv)
std::enable_if< dm==3, PyReciprocalLatticeDirection >::type cross(const PyLatticeVector< dm > &other) const
PyLatticeVector(const VectorDimI &integerCoordinates, const Lattice &lattice)
PyLatticeVector(const Lattice &lattice)
PyLatticeVector operator+=(const PyLatticeVector &other)
IntScalarType dot(const PyReciprocalLatticeVector< dim > &other)
VectorDimI integerCoordinates() const
Eigen::Matrix< double, dim, 1 > VectorDimD
PyLatticeVector(const VectorDimD &cartesianCoordinates, const Lattice &lattice)
PyLatticeVector(const PyLatticeVector &)=default
Eigen::Matrix< IntScalarType, dim, dim > MatrixDimI
Eigen::Matrix< IntScalarType, dim, 1 > VectorDimI
PyLatticeVector operator-=(const PyLatticeVector &other)
PyReciprocalLatticeDirection< dim > PyReciprocalLatticeDirection
std::enable_if< dm==3, PyReciprocalLatticeDirection >::type cross() const
std::enable_if< dm==2, PyReciprocalLatticeDirection >::type cross() const
std::enable_if< dm==2, PyReciprocalLatticeDirection >::type cross(const PyLatticeVector< dim > &other) const
void integerCoordinates(const VectorDimI &input)
PyLatticeVector< dim > operator*(const long long int &scalar, const PyLatticeVector< dim > &L)
void bind_LatticeVector(py::module_ &m)