oILAB
Loading...
Searching...
No Matches
ReciprocalLatticeVectorBindings.h
Go to the documentation of this file.
1//
2// Created by Nikhil Chandra Admal on 7/3/25.
3//
4
5#ifndef OILAB_RECIPROCALLATTICEVECTORBINDINGS_H
6#define OILAB_RECIPROCALLATTICEVECTORBINDINGS_H
7
8#include <pybind11/pybind11.h>
9#include <pybind11/operators.h>
10#include <pybind11/numpy.h>
11#include <pybind11/eigen.h>
12
13#include <LatticeModule.h>
14#include <PyLatticeModule.h>
15
16namespace py = pybind11;
17
18namespace pyoilab {
19// Had to wrap the ReciprocalLatticeVector<dim> class due to Pybind11 issues with classes with
20// Eigen base classes
21 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 PyReciprocalLatticeVector(const Lattice &lattice) : rlv(lattice) {}
35
36 PyReciprocalLatticeVector(const VectorDimD &cartesianCoordinates, const Lattice &lattice) : rlv(
37 cartesianCoordinates,
38 lattice) {}
39
43
45
47
49 return PyReciprocalLatticeVector(rlv.operator+(other.rlv));
50 }
51
53 return PyReciprocalLatticeVector(rlv.operator-(other.rlv));
54 }
55
57 rlv.operator+=(other.rlv);
58 return *this;
59 }
60
62 rlv.operator-=(other.rlv);
63 return *this;
64 }
65
67 return PyReciprocalLatticeVector(rlv.operator*(scalar));
68 }
69
71 return rlv.cartesian();
72 }
73
75 return rlv;
76 }
77
79 return rlv.dot(other.lv);
80 }
81
85
89
93
94 template<int dm=dim>
95 typename std::enable_if<dm==2,PyLatticeDirection<dm>>::type
97 return PyLatticeDirection(rlv.cross(other.rlv));
98 }
99 template<int dm=dim>
100 typename std::enable_if<dm==3,PyLatticeDirection<dm>>::type
102 return PyLatticeDirection(rlv.cross(other.rlv));
103 }
104 };
105
106 template<int dim>
108 return L * scalar;
109 }
110
111
112 template<int dim>
113 void bind_ReciprocalLatticeVector(py::module_ &m) {
114 using Lattice = gbLAB::Lattice<dim>;
115 using LatticeVector = gbLAB::LatticeVector<dim>;
116 using ReciprocalLatticeVector = gbLAB::ReciprocalLatticeVector<dim>;
117 using IntScalarType = long long int;
118 using MatrixDimD = Eigen::Matrix<double, dim, dim>;
119 using VectorDimD = Eigen::Matrix<double, dim, 1>;
120 using VectorDimI = Eigen::Matrix<IntScalarType, dim, 1>;
121 using MatrixDimI = Eigen::Matrix<IntScalarType, dim, dim>;
123
124 py::class_<PyReciprocalLatticeVector>(m, ("ReciprocalLatticeVector" + std::to_string(dim) + "D").c_str())
125 .def(py::init<const Lattice &>())
126 .def(py::init<const VectorDimD&, const Lattice&>())
127 .def(py::init<const VectorDimI&, const Lattice&>())
128 .def(py::init<const PyReciprocalLatticeVector&>())
129 .def("cartesian", &PyReciprocalLatticeVector::cartesian)
130 .def("integerCoordinates", &PyReciprocalLatticeVector::integerCoordinates)
131 .def(py::self + py::self)
132 .def(py::self - py::self)
133 .def("__mul__", [](const PyReciprocalLatticeVector& self, const IntScalarType& scalar) {
134 return self * scalar;
135 }, py::is_operator())
136 .def("__rmul__", [](const PyReciprocalLatticeVector& self, const IntScalarType& scalar) {
137 return scalar * self;
138 }, py::is_operator())
139 .def(py::self -= py::self)
140 .def(py::self += py::self)
142 // note that cross is a template member function
143 .def("cross",&PyReciprocalLatticeVector::template cross<dim>);
144 }
145
146}
147#endif //OILAB_RECIPROCALLATTICEVECTORBINDINGS_H
Lattice class.
Definition Lattice.h:34
LatticeVector class.
IntScalarType dot(const LatticeVector< dim > &other) const
std::enable_if< dm==2, LatticeDirection< dim > >::type cross(const ReciprocalLatticeVector< dim > &other) const
IntScalarType closestPlaneIndexOfPoint(const VectorDimD &P) const
IntScalarType planeIndexOfPoint(const VectorDimD &P) const
PyReciprocalLatticeVector operator+(const PyReciprocalLatticeVector &other) const
IntScalarType closestPlaneIndexOfPoint(const VectorDimD &p) const
PyReciprocalLatticeVector operator+=(const PyReciprocalLatticeVector &other)
IntScalarType dot(const PyLatticeVector< dim > &other) const
PyReciprocalLatticeVector operator-=(const PyReciprocalLatticeVector &other)
std::enable_if< dm==2, PyLatticeDirection< dm > >::type cross(const PyReciprocalLatticeVector< dm > &other)
PyReciprocalLatticeVector(const PyReciprocalLatticeVector &)=default
std::enable_if< dm==3, PyLatticeDirection< dm > >::type cross(const PyReciprocalLatticeVector< dm > &other)
PyReciprocalLatticeVector(const ReciprocalLatticeVector &rlv)
PyReciprocalLatticeVector operator*(const IntScalarType &scalar) const
PyReciprocalLatticeVector(const VectorDimI &integerCoordinates, const Lattice &lattice)
IntScalarType planeIndexOfPoint(const VectorDimD &p)
Eigen::Matrix< IntScalarType, dim, 1 > VectorDimI
PyReciprocalLatticeVector operator-(const PyReciprocalLatticeVector &other) const
PyReciprocalLatticeVector(const VectorDimD &cartesianCoordinates, const Lattice &lattice)
Eigen::Matrix< IntScalarType, dim, dim > MatrixDimI
Eigen::Matrix< double, dim, dim > MatrixDimD
IntScalarType planeIndexOfPoint(const gbLAB::LatticeVector< dim > &p) const
void bind_ReciprocalLatticeVector(py::module_ &m)
PyLatticeVector< dim > operator*(const long long int &scalar, const PyLatticeVector< dim > &L)