hexrd.rotations module

class hexrd.rotations.RotMatEuler(angles, axes_order, extrinsic=True, units='radians')[source]

Bases: object

property angles
property axes_order
property exponential_map

The matrix invariants of self.rmat as exponential map parameters

Returns

np.ndarray

The (3, ) array representing the exponential map parameters of the encoded rotation (self.rmat).

property extrinsic
property rmat

Return the rotation matrix.

As calculated from angles, axes_order, and convention.

Returns

numpy.ndarray

The (3, 3) proper orthogonal matrix according to the specification.

property units
hexrd.rotations.angleAxisOfRotMat(R)[source]

Extracts angle and axis invariants from rotation matrices.

Parameters

Rnumpy.ndarray

The (3, 3) or (n, 3, 3) array of rotation matrices. Note that these are assumed to be proper orthogonal.

Raises

RuntimeError

If R is not an shape is not (3, 3) or (n, 3, 3).

Returns

phinumpy.ndarray

The (n, ) array of rotation angles for the n input rotation matrices.

nnumpy.ndarray

The (3, n) array of unit rotation axes for the n input rotation matrices.

hexrd.rotations.angles_from_rmat_xyz(rmat)[source]

Calculate passive x-y-z Euler angles from a rotation matrix.

Parameters

rmatTYPE

DESCRIPTION.

Returns

rxTYPE

DESCRIPTION.

ryTYPE

DESCRIPTION.

rzTYPE

DESCRIPTION.

hexrd.rotations.angles_from_rmat_zxz(rmat)[source]

Calculate active z-x-z Euler angles from a rotation matrix.

Parameters

rmatTYPE

DESCRIPTION.

Returns

alphaTYPE

DESCRIPTION.

betaTYPE

DESCRIPTION.

gammaTYPE

DESCRIPTION.

hexrd.rotations.angularDifference(angList0, angList1, units='radians')

Do the proper (acute) angular difference in the context of a branch cut.

*) Default angular range in the code is [-pi, pi]

hexrd.rotations.angularDifference_opt(angList0, angList1, units='radians')[source]

Do the proper (acute) angular difference in the context of a branch cut.

*) Default angular range in the code is [-pi, pi]

hexrd.rotations.angularDifference_orig(angList0, angList1, units='radians')[source]

Do the proper (acute) angular difference in the context of a branch cut.

*) Default angular range in the code is [-pi, pi] *) … maybe more efficient not to vectorize?

hexrd.rotations.applySym(vec, qsym, csFlag=False, cullPM=False, tol=1.4901161193847656e-08)[source]

Apply symmetry group to a single 3-vector (columnar) argument.

csFlag : centrosymmetry flag cullPM : cull +/- flag

hexrd.rotations.arccosSafe(temp)[source]

Protect against numbers slightly larger than 1 in magnitude due to round-off

hexrd.rotations.discreteFiber(c, s, B=array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]), ndiv=120, invert=False, csym=None, ssym=None)[source]

Generate symmetrically reduced discrete orientation fiber.

Parameters

cTYPE

DESCRIPTION.

sTYPE

DESCRIPTION.

BTYPE, optional

DESCRIPTION. The default is I3.

ndivTYPE, optional

DESCRIPTION. The default is 120.

invertTYPE, optional

DESCRIPTION. The default is False.

csymTYPE, optional

DESCRIPTION. The default is None.

ssymTYPE, optional

DESCRIPTION. The default is None.

Raises

RuntimeError

DESCRIPTION.

Returns

retvalTYPE

DESCRIPTION.

hexrd.rotations.distanceToFiber(c, s, q, qsym, **kwargs)[source]

Calculate symmetrically reduced distance to orientation fiber.

Parameters

cTYPE

DESCRIPTION.

sTYPE

DESCRIPTION.

qTYPE

DESCRIPTION.

qsymTYPE

DESCRIPTION.

**kwargsTYPE

DESCRIPTION.

Raises

RuntimeError

DESCRIPTION.

Returns

dTYPE

DESCRIPTION.

hexrd.rotations.expMapOfQuat(quats)[source]

Return the exponential map parameters for an array of unit quaternions

Parameters

quatsarray_like

The (4, ) or (4, n) array of hstacked unit quaternions. The convention is [q0, q] where q0 is the scalar part and q is the vector part.

Returns

expmapsarray_like

The (3, ) or (3, n) array of exponential map parameters associated with the input quaternions.

hexrd.rotations.fixQuat(q)[source]

flip to positive q0 and normalize

hexrd.rotations.invertQuat(q)[source]

silly little routine for inverting a quaternion

hexrd.rotations.ltypeOfLaueGroup(tag)[source]

Yield lattice type of input tag.

Parameters

tagTYPE

DESCRIPTION.

Raises

RuntimeError

DESCRIPTION.

Returns

ltypeTYPE

DESCRIPTION.

hexrd.rotations.make_rmat_euler(tilt_angles, axes_order, extrinsic=True)[source]

Generate rotation matrix from Euler angles.

Parameters

tilt_anglesarray_like

The (3, ) list of Euler angles in RADIANS.

axes_orderstr

The axes order specification (case-insensitive). This must be one of the following: ‘xyz’, ‘zyx’

‘zxy’, ‘yxz’ ‘yzx’, ‘xzy’ ‘xyx’, ‘xzx’ ‘yxy’, ‘yzy’ ‘zxz’, ‘zyz’

extrinsicbool, optional

Flag denoting the convention. If True, the convention is extrinsic (passive); if False, the convention is instrinsic (active). The default is True.

Returns

numpy.ndarray

The (3, 3) rotation matrix corresponding to the input specification.

TODO: add kwarg for unit selection for tilt_angles TODO: input checks

hexrd.rotations.mapAngle(ang, *args, **kwargs)[source]

Utility routine to map an angle into a specified period

hexrd.rotations.misorientation(q1, q2, *args)[source]

sym is a tuple (crystal_symmetry, *sample_symmetry) generally coded.

!!! may split up special cases for no symmetry or crystal/sample only…

hexrd.rotations.printTestName(num, name)[source]
hexrd.rotations.quatAverage(q_in, qsym)[source]
hexrd.rotations.quatAverageCluster(q_in, qsym)[source]
hexrd.rotations.quatAverage_obj(xi_in, quats, qsym)[source]
hexrd.rotations.quatOfAngleAxis(angle, rotaxis)[source]

make an hstacked array of quaternions from arrays of angle/axis pairs

hexrd.rotations.quatOfExpMap(expMaps)[source]

Returns the unit quaternions associated with exponential map parameters.

Parameters

expMapsarray_like

The (3,) or (3, n) list of hstacked exponential map parameters to convert.

Returns

quatsarray_like

The (4,) or (4, n) array of unit quaternions.

Notes

  1. be aware that the output will always have non-negative q0; recall the antipodal symmetry of unit quaternions

hexrd.rotations.quatOfLaueGroup(tag)[source]

Return quaternion representation of requested symmetry group.

Parameters

tagstr

A case-insensitive string representing the Schoenflies symbol for the desired Laue group. The 14 available choices are:

Class Symbol N

Triclinic Ci (S2) 1 Monoclinic C2h 2 Orthorhombic D2h (Vh) 4 Tetragonal C4h 4

D4h 8

Trigonal C3i (S6) 3

D3d 6

Hexagonal C6h 6

D6h 12

Cubic Th 12

Oh 24

Raises

RuntimeError

For invalid symmetry group tag.

Returns

qsym(4, N) ndarray

the quaterions associated with each element of the chosen symmetry group having n elements (dep. on group – see INPUTS list above).

Notes

The conventions used for assigning a RHON basis, {x1, x2, x3}, to each point group are consistent with those published in Appendix B of [1]_.

References

[1] Nye, J. F., ``Physical Properties of Crystals: Their Representation by Tensors and Matrices’’, Oxford University Press, 1985. ISBN 0198511655

hexrd.rotations.quatOfRotMat(R)[source]
hexrd.rotations.quatProduct(q1, q2)[source]

Product of two unit quaternions.

qp = quatProduct(q2, q1)

q2, q1 are 4 x n, arrays whose columns are

quaternion parameters

qp is 4 x n, an array whose columns are the

quaternion parameters of the product; the first component of qp is nonnegative

If R(q) is the rotation corresponding to the quaternion parameters q, then

R(qp) = R(q2) R(q1)

hexrd.rotations.quatProductMatrix(quats, mult='right')[source]

Form 4 x 4 arrays to perform the quaternion product

USAGE

qmats = quatProductMatrix(quats, mult=’right’)

INPUTS
  1. quats is (4, n), a numpy ndarray array of n quaternions horizontally concatenated

  2. mult is a keyword arg, either ‘left’ or ‘right’, denoting the sense of the multiplication:

    quatProductMatrix(h, mult=’right’) * q
    q * h –> <
    quatProductMatrix(q, mult=’left’) * h
OUTPUTS
  1. qmats is (n, 4, 4), the left or right quaternion product operator

NOTES
*) This function is intended to replace a cross-product based

routine for products of quaternions with large arrays of quaternions (e.g. applying symmetries to a large set of orientations).

hexrd.rotations.rotMatOfExpMap(expMap)

Optimized version of rotMatOfExpMap

hexrd.rotations.rotMatOfExpMap_opt(expMap)[source]

Optimized version of rotMatOfExpMap

hexrd.rotations.rotMatOfExpMap_orig(expMap)[source]

Original rotMatOfExpMap, used for comparison to optimized version

hexrd.rotations.rotMatOfQuat(quat)[source]

Convert quaternions to rotation matrices.

Take an array of n quats (numpy ndarray, 4 x n) and generate an array of rotation matrices (n x 3 x 3)

Parameters

quatTYPE

DESCRIPTION.

Raises

RuntimeError

DESCRIPTION.

Returns

rmatTYPE

DESCRIPTION.

Notes

Uses the truncated series expansion for the exponential map; didvide-by-zero is checked using the global ‘cnst.epsf’

hexrd.rotations.testRotMatOfExpMap(numpts)[source]

Test rotation matrix from axial vector.

hexrd.rotations.toFundamentalRegion(q, crysSym='Oh', sampSym=None)[source]

Map quaternions to fundamental region.

Parameters

qTYPE

DESCRIPTION.

crysSymTYPE, optional

DESCRIPTION. The default is ‘Oh’.

sampSymTYPE, optional

DESCRIPTION. The default is None.

Raises

NotImplementedError

DESCRIPTION.

Returns

qrTYPE

DESCRIPTION.