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

Zero rotation nematic #1184

Merged
merged 8 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to
* The ``neighbors`` argument to ``env_neighbors`` for ``EnvironmentMotifMatch`` class.
* The ``neighbors`` argument to ``cluster_neighbors`` for ``EnvironmentCluster`` class.
* `freud.order.Nematic` uses orientation vectors instead of quaternions and a nematic director.
* `freud.order.Nematic` raises a warning when the zero is vector passed.
* Remove zero-padding from arrays in `freud.environment.EnvironmentCluster` and `freud.environment.EnvironmentMotifMatch` and replace with ragged lists of NumPy arrays.

### Removed
Expand Down
1 change: 1 addition & 0 deletions doc/source/reference/credits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ Kody Takada
Alain Kadar

* Introduced mass dependence for ``ClusterProperties`` class, inertia tensor and radius of gyration.
* Added check for passing zero vector to ``Nematic`` class.

Melody Zhang

Expand Down
6 changes: 5 additions & 1 deletion freud/order.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,15 @@ cdef class Nematic(_Compute):
Orientation vectors for which to calculate the order parameter.
""" # noqa: E501
if orientations.shape[1] == 4:
raise ValueError('In freud versions >=3.0.0, Nematic.compute() takes'
raise ValueError('In freud versions >=3.0.0, Nematic.compute() takes '
'3d orientation vectors instead of 4d quaternions.')
orientations = freud.util._convert_array(
orientations, shape=(None, 3))

if len(np.where(~orientations.any(axis=1))[0])!=0:
warnings.warn('Including zero vector in the orientations array '
'may lead to undefined behavior.',
UserWarning)
cdef const float[:, ::1] l_orientations = orientations
cdef unsigned int num_particles = l_orientations.shape[0]

Expand Down
19 changes: 19 additions & 0 deletions tests/test_order_Nematic.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ def test_imperfect(self):
npt.assert_allclose(op_perp.nematic_tensor, np.diag([-0.5, 1, -0.5]), atol=1e-1)
assert not np.all(op_perp.nematic_tensor == np.diag([-0.5, 1, -0.5]))

def test_warning(self):
"""Test that supplying a zero orientation vector raises a warning."""
N = 10000
np.random.seed(0)
u = [1, 0, 0]

# Generate orientations close to the u
orientations = np.random.normal(
np.repeat(np.expand_dims(u, axis=0), repeats=N, axis=0), 0.1
)

# Change first orientation to zero vector
orientations[0] = np.array([0, 0, 0])

op = freud.order.Nematic()

with pytest.warns(UserWarning):
op.compute(orientations)

def test_repr(self):
op = freud.order.Nematic()
assert str(op) == str(eval(repr(op)))