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 "../Lattices/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 using IntScalarType = long long int;
27 using MatrixDimD = Eigen::Matrix<double, dim, dim>;
28 using VectorDimD = Eigen::Matrix<double, dim, 1>;
29 using VectorDimI = Eigen::Matrix<IntScalarType, dim, 1>;
30 using MatrixDimI = Eigen::Matrix<IntScalarType, dim, dim>;
31 public:
33
34 PyLatticeVector(const Lattice& lattice) : lv(lattice) {}
35
36 PyLatticeVector(const VectorDimD& cartesianCoordinates, const Lattice& lattice) : lv(cartesianCoordinates,
37 lattice) {}
38
40 lattice) {}
41
43
45
47 return PyLatticeVector(lv.operator+(other.lv));
48 }
49
51 return PyLatticeVector(lv.operator-(other.lv));
52 }
53
55 lv.operator+=(other.lv);
56 return *this;
57 }
58
60 lv.operator-=(other.lv);
61 return *this;
62 }
63
65 return PyLatticeVector(lv.operator*(scalar));
66 }
67
69 return lv.cartesian();
70 }
71
73 return lv;
74 }
75
76 void integerCoordinates(const VectorDimI& input) {
77 lv << input;
78 }
79
81 return lv.dot(other.rlv);
82 }
83
84 template<int dm=dim>
85 typename std::enable_if<dm==2,PyReciprocalLatticeDirection>::type
86 cross(const PyLatticeVector<dim>& other) const
87 {
89 }
90
91 template<int dm=dim>
92 typename std::enable_if<dm==3,PyReciprocalLatticeDirection>::type
93 cross(const PyLatticeVector<dm>& other) const
94 {
96 }
97
98 template<int dm=dim>
99 typename std::enable_if<dm==2,PyReciprocalLatticeDirection>::type
100 cross() const
101 {
103 }
104 template<int dm=dim>
105 typename std::enable_if<dm==3,PyReciprocalLatticeDirection>::type
106 cross() const
107 {
109 }
110
111 };
112
113 template<int dim>
114 PyLatticeVector<dim> operator*(const long long int& scalar, const PyLatticeVector<dim>& L) {
115 return L * scalar;
116 }
117
118 template<int dim>
119 void bind_LatticeVector(py::module_& m) {
120 using Lattice = oILAB::Lattice<dim>;
121 using LatticeVector = oILAB::LatticeVector<dim>;
122 using IntScalarType = long long int;
123 using MatrixDimD = Eigen::Matrix<double, dim, dim>;
124 using VectorDimD = Eigen::Matrix<double, dim, 1>;
125 using VectorDimI = Eigen::Matrix<IntScalarType, dim, 1>;
126 using MatrixDimI = Eigen::Matrix<IntScalarType, dim, dim>;
129
130 py::class_<PyLatticeVector>(
131 m, ("LatticeVector" + std::to_string(dim) + "D").c_str(),
132 ("LatticeVector" + std::to_string(dim) + "D class").c_str())
133 .def(py::init<const Lattice &>())
134 .def(py::init<const VectorDimD &, const Lattice &>())
135 .def(py::init<const VectorDimI &, const Lattice &>())
136 .def(py::init<const PyLatticeVector &>())
137 .def(
138 "lattice",
139 [](const PyLatticeVector &self) { return self.lv.lattice; },
140 py::return_value_policy::reference_internal)
141 .def("cartesian", &PyLatticeVector::cartesian)
142 .def("integerCoordinates",
143 static_cast<VectorDimI (PyLatticeVector::*)() const>(
145 "output the integer coordinates of the lattice vecctor")
146 .def("integerCoordinates",
147 static_cast<void (PyLatticeVector::*)(const VectorDimI &)>(
149 "input the integer coordinates of the lattice vector")
150 .def("dot", &PyLatticeVector::dot,
151 "dot product with a reciprocal lattice vector")
152 .def(py::self + py::self)
153 .def(py::self - py::self)
154 .def(
155 "__mul__",
156 [](const PyLatticeVector &self, const IntScalarType &scalar) {
157 return self * scalar;
158 },
159 py::is_operator())
160 .def(
161 "__rmul__",
162 [](const PyLatticeVector &self, const IntScalarType &scalar) {
163 return scalar * self;
164 },
165 py::is_operator())
166 .def(py::self -= py::self)
167 .def(py::self += py::self)
168 .def("cross",
170 const PyLatticeVector &) const>(&PyLatticeVector::cross))
171 .def("cross",
173 const>(&PyLatticeVector::cross));
174 }
175}
176#endif //OILAB_LATTICEVECTORBINDINGS_H
Lattice class.
Definition Lattice.h:31
LatticeVector class.
const Lattice< dim > & lattice
IntScalarType dot(const ReciprocalLatticeVector< dim > &other) const
std::enable_if< dm==2, ReciprocalLatticeDirection< dm > >::type cross(const LatticeVector< dm > &other) const
VectorDimD cartesian() 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)