Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix k-value/k-vector units for non-cubic systems #793

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@
"MDAnalysis": ("https://docs.mdanalysis.org/stable", None),
"ovito": ("https://www.ovito.org/docs/current/python/", None),
"pytest": ("https://docs.pytest.org/en/stable", None),
"rowan": ("https://rowan.readthedocs.io/en/stable/", None),
}

autodoc_default_options = {
Expand Down
23 changes: 21 additions & 2 deletions freud/diffraction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ cdef class DiffractionPattern(_Compute):
roll_shift -= 0.5 / zoom

box_matrix = box.to_matrix()
ss = np.max(box_matrix) * inv_shear
ss = np.max(box_matrix[:, 0:2]) * inv_shear

shift_matrix = np.array(
[[1, 0, -roll],
Expand Down Expand Up @@ -217,6 +217,23 @@ cdef class DiffractionPattern(_Compute):
Whether to erase the previously computed values before adding
the new computations; if False, will accumulate data (Default
value: True).

For a target view axis in Cartesian coordinates, `rowan
<https://rowan.readthedocs.io/en/latest/index.html>`__ provides
:py:func:`rowan.vector_vector_rotation`, a function that will return
the necessary quaternion for rotating the default view orientation to
the desired axis.

Example::

>>> import rowan
>>> import numpy as np
>>> default_view_axis = np.array([0, 0, 1])
>>> desired_view_axis = np.array([1, 1, 1])
>>> view_orientation = rowan.vector_vector_rotation(
... default_view_axis, desired_view_axis
... )

"""
if reset:
self._diffraction = np.zeros((self.output_size, self.output_size))
Expand Down Expand Up @@ -277,7 +294,9 @@ cdef class DiffractionPattern(_Compute):

# Cache the view orientation and box matrix scale factor for
# lazy evaluation of k-values and k-vectors
self._box_matrix_scale_factor = np.max(system.box.to_matrix())
self._box_matrix_scale_factor = np.max(
rowan.rotate(view_orientation, system.box.to_matrix())[:, 0:2]
)
self._view_orientation = view_orientation
self._k_scale_factor = 2 * np.pi * self.output_size / (self._box_matrix_scale_factor * zoom)
self._k_values_cached = False
Expand Down
Loading