-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #4315. Finish off geometry exports
This required a const to be added to a member of Matrix and similarly to OrientedLattice.
- Loading branch information
1 parent
37b5f6e
commit 199d27c
Showing
12 changed files
with
238 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
Code/Mantid/Framework/PythonInterface/mantid/geometry/src/OrientedLattice.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "MantidGeometry/Crystal/OrientedLattice.h" | ||
#include "MantidPythonInterface/kernel/NumpyConverters.h" | ||
#include <boost/python/class.hpp> | ||
|
||
using Mantid::Geometry::OrientedLattice; | ||
using Mantid::Geometry::UnitCell; | ||
using Mantid::Geometry::angDegrees; | ||
using namespace boost::python; | ||
|
||
namespace //<unnamed> | ||
{ | ||
using namespace Mantid::PythonInterface; | ||
|
||
/// Return the U matrix as a 2D numpy array | ||
PyObject * getU(OrientedLattice &self) | ||
{ | ||
return Numpy::wrapWithReadOnlyNumpy(self.getU()); | ||
} | ||
|
||
/// Set the U vector via a numpy array | ||
void setU(OrientedLattice & self, PyObject *data) | ||
{ | ||
self.setU(Numpy::createDoubleMatrix(data)); | ||
} | ||
|
||
/// Return the U matrix as a 2D numpy array | ||
PyObject * getUB(OrientedLattice &self) | ||
{ | ||
return Numpy::wrapWithReadOnlyNumpy(self.getUB()); | ||
} | ||
|
||
/// Set the U vector via a numpy array | ||
void setUB(OrientedLattice & self, PyObject *data) | ||
{ | ||
self.setUB(Numpy::createDoubleMatrix(data)); | ||
} | ||
|
||
/// Set the U matrix from 2 Python objects representing a V3D type. This can be a V3D object, a list | ||
/// or a numpy array. If the arrays are used they must be of length 3 | ||
void setUFromVectors(OrientedLattice & self, PyObject * vec1, PyObject *vec2) | ||
{ | ||
self.setUFromVectors(Numpy::createV3D(vec1), Numpy::createV3D(vec2)); | ||
} | ||
|
||
} | ||
|
||
void export_OrientedLattice() | ||
{ | ||
class_<OrientedLattice, bases<UnitCell> >("OrientedLattice", init< >()) | ||
.def( init< OrientedLattice const & >(( arg("other") )) ) | ||
.def( init< double, double, double >(( arg("_a"), arg("_b"), arg("_c") )) ) | ||
.def( init< double, double, double, double, double, double, | ||
optional< int > >(( arg("_a"), arg("_b"), arg("_c"), arg("_alpha"), arg("_beta"), arg("_gamma"), arg("Unit")=(int)(angDegrees) )) ) | ||
.def( init<UnitCell>( arg("uc") ) ) | ||
.def( "getuVector", (&OrientedLattice::getuVector)) | ||
.def( "getvVector", (&OrientedLattice::getvVector)) | ||
.def( "getU", &getU ) | ||
.def( "setU", &setU ) | ||
.def( "getUB",&getUB ) | ||
.def( "setUB",&setUB ) | ||
.def( "setUFromVectors", &setUFromVectors) | ||
|
||
; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
Code/Mantid/Framework/PythonInterface/test/python/OrientedLatticeTest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import unittest | ||
from mantid.geometry import OrientedLattice, UnitCell | ||
from mantid.kernel import V3D | ||
import numpy as np | ||
|
||
class OrientedLatticeTest(unittest.TestCase): | ||
|
||
def test_OrientedLattice_is_subclass_of_UnitCell(self): | ||
self.assertTrue(issubclass(OrientedLattice, UnitCell)) | ||
|
||
def test_simple_values(self): | ||
u1 = OrientedLattice() | ||
self.assertEquals(u1.a1(),1) | ||
self.assertEquals(u1.alpha(),90) | ||
|
||
u2 = OrientedLattice(3,4,5) | ||
self.assertAlmostEqual(u2.b1(),1./3.,10) | ||
self.assertAlmostEqual(u2.alphastar(),90,10) | ||
u3 = u2; | ||
self.assertAlmostEqual(u3.volume(),1./u2.recVolume(),10) | ||
u2.seta(3); | ||
self.assertAlmostEqual(u2.a(),3,10) | ||
|
||
def test_setu_matrix_from_vectors(self): | ||
def run_test(v1, v2): | ||
cell = OrientedLattice() | ||
try: | ||
cell.setUFromVectors(v1, v2) | ||
except RuntimeError: | ||
self.fail("The unit transformation should not raise an error") | ||
rot = cell.getUB(); | ||
expected = np.array([(0,1.,0.), (0.,0.,1.), (1.,0.,0.)]) | ||
np.testing.assert_array_almost_equal(expected, rot, 8) | ||
|
||
# Set from V3Ds | ||
run_test(V3D(1,0,0),V3D(0,1,0)) | ||
# Set from Python lists | ||
run_test([1,0,0],[0,1,0]) | ||
# Set from numpy arrays | ||
run_test(np.array([1,0,0]),np.array([0,1,0])) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.