Skip to content

Commit

Permalink
Initial SolidLiquid python layer
Browse files Browse the repository at this point in the history
  • Loading branch information
janbridley committed Oct 25, 2024
1 parent 39a9e14 commit 7b66c2b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 79 deletions.
116 changes: 52 additions & 64 deletions freud/order.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) 2010-2024 The Regents of the University of Michigan
# This file is from the freud project, released under the BSD 3-Clause License.
# This file is from the freud project, released under the BSD 3-Clause License->
# ruff: noqa: E741
r"""
The :class:`freud.order` module contains functions which compute order
Expand Down Expand Up @@ -669,80 +669,68 @@ def _repr_png_(self):
return None


# cdef class SolidLiquid(_PairCompute):
# r"""Identifies solid-like clusters using dot products of :math:`q_{lm}`.
class SolidLiquid(_PairCompute):
r"""Identifies solid-like clusters using dot products of :math:`q_{lm}`.
# The solid-liquid order parameter :cite:`Wolde:1995aa,Filion_2010` uses a
# Steinhardt-like approach to identify solid-like particles. First, a bond
# parameter :math:`q_l(i, j)` is computed for each neighbor bond.
The solid-liquid order parameter :cite:`Wolde:1995aa,Filion_2010` uses a
Steinhardt-like approach to identify solid-like particles. First, a bond
parameter :math:`q_l(i, j)` is computed for each neighbor bond.
# If :code:`normalize_q` is true (default), the bond parameter is given by
# :math:`q_l(i, j) = \frac{\sum \limits_{m=-l}^{l} \text{Re}~q_{lm}(i) q_{lm}^*(j)}
# {\sqrt{\sum \limits_{m=-l}^{l} \lvert q_{lm}(i) \rvert^2}
# \sqrt{\sum \limits_{m=-l}^{l} \lvert q_{lm}(j) \rvert^2}}`
If :code:`normalize_q` is true (default), the bond parameter is given by
:math:`q_l(i, j) = \frac{\sum \limits_{m=-l}^{l} \text{Re}~q_{lm}(i) q_{lm}^*(j)}
{\sqrt{\sum \limits_{m=-l}^{l} \lvert q_{lm}(i) \rvert^2}
\sqrt{\sum \limits_{m=-l}^{l} \lvert q_{lm}(j) \rvert^2}}`
# If :code:`normalize_q` is false, then the denominator of the above
# expression is left out.
If :code:`normalize_q` is false, then the denominator of the above
expression is left out.
# Next, the bonds are filtered to keep only "solid-like" bonds with
# :math:`q_l(i, j)` above a cutoff value :math:`q_{threshold}`.
Next, the bonds are filtered to keep only "solid-like" bonds with
:math:`q_l(i, j)` above a cutoff value :math:`q_{threshold}`.
# If a particle has more than :math:`S_{threshold}` solid-like bonds, then
# the particle is considered solid-like. Finally, solid-like particles are
# clustered.
If a particle has more than :math:`S_{threshold}` solid-like bonds, then
the particle is considered solid-like. Finally, solid-like particles are
clustered.
# Args:
# l (unsigned int):
# Spherical harmonic quantum number l.
# q_threshold (float):
# Value of dot product threshold when evaluating
# :math:`q_l(i, j)` to determine if a bond is solid-like. For
# :math:`l=6`, 0.7 is generally good for FCC or BCC structures
# :cite:`Filion_2010`.
# solid_threshold (unsigned int):
# Minimum required number of adjacent solid-like bonds for a particle
# to be considered solid-like for clustering. For :math:`l=6`, 6-8
# is generally good for FCC or BCC structures.
# normalize_q (bool):
# Whether to normalize the dot product (Default value =
# :code:`True`).
# """ # noqa: E501
# cdef freud._order.SolidLiquid * thisptr
Args:
l (unsigned int):
Spherical harmonic quantum number l.
q_threshold (float):
Value of dot product threshold when evaluating
:math:`q_l(i, j)` to determine if a bond is solid-like. For
:math:`l=6`, 0.7 is generally good for FCC or BCC structures
:cite:`Filion_2010`.
solid_threshold (unsigned int):
Minimum required number of adjacent solid-like bonds for a particle
to be considered solid-like for clustering. For :math:`l=6`, 6-8
is generally good for FCC or BCC structures.
normalize_q (bool):
Whether to normalize the dot product (Default value =
:code:`True`).
"""

# def __cinit__(self, l, q_threshold, solid_threshold, normalize_q=True):
# self.thisptr = new freud._order.SolidLiquid(
# l, q_threshold, solid_threshold, normalize_q)
def __init__(self, l, q_threshold, solid_threshold, normalize_q=True):
self._cpp_obj = freud._order.SolidLiquid(l, q_threshold, solid_threshold, normalize_q)

# def __dealloc__(self):
# del self.thisptr

# def compute(self, system, neighbors=None):
# r"""Compute the order parameter.
def compute(self, system, neighbors=None):
r"""Compute the order parameter.
# Args:
# system:
# Any object that is a valid argument to
# :class:`freud.locality.NeighborQuery.from_system`.
# neighbors (:class:`freud.locality.NeighborList` or dict, optional):
# Either a :class:`NeighborList <freud.locality.NeighborList>` of
# neighbor pairs to use in the calculation, or a dictionary of
# `query arguments
# <https://freud.readthedocs.io/en/stable/topics/querying.html>`_
# (Default value: None).
# """
# cdef:
# freud.locality.NeighborQuery nq
# freud.locality.NeighborList nlist
# freud.locality._QueryArgs qargs
# const float[:, ::1] l_query_points
# unsigned int num_query_points
Args:
system:
Any object that is a valid argument to
:class:`freud.locality.NeighborQuery.from_system`.
neighbors (:class:`freud.locality.NeighborList` or dict, optional):
Either a :class:`NeighborList <freud.locality.NeighborList>` of
neighbor pairs to use in the calculation, or a dictionary of
`query arguments
<https://freud.readthedocs.io/en/stable/topics/querying.html>`_
(Default value: None).
"""

# nq, nlist, qargs, l_query_points, num_query_points = \
# self._preprocess_arguments(system, neighbors=neighbors)
# self.thisptr.compute(nlist.get_ptr(),
# nq.get_ptr(),
# dereference(qargs.thisptr))
# return self
nq, nlist, qargs, l_query_points, num_query_points = \
self._preprocess_arguments(system, neighbors=neighbors)
self._cpp_obj.compute(nlist._cpp_obj, nq._cpp_obj, qargs._cpp_obj)
return self

# @property
# def l(self): # noqa: E743
Expand Down
3 changes: 1 addition & 2 deletions freud/order/export-SolidLiquid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <nanobind/nanobind.h>
#include <nanobind/ndarray.h>
#include <nanobind/stl/shared_ptr.h> // NOLINT(misc-include-cleaner): used implicitly
// #include <nanobind/stl/tuple.h> // NOLINT(misc-include-cleaner): used implicitly
#include <utility>

// #include "ManagedArray.h"
Expand All @@ -23,7 +22,7 @@ void export_SolidLiquid(nanobind::module_& m)
{
nanobind::class_<SolidLiquid>(m, "SolidLiquid")
.def(nanobind::init<unsigned int, float, unsigned int, bool>())
// .def("getRAArray", &RotationalAutocorrelation::getRAArray)
.def("compute", &SolidLiquid::compute, nanobind::arg("nlist").none(), nanobind::arg("points"), nanobind::arg("qargs"))
;
}

Expand Down
13 changes: 0 additions & 13 deletions freud/order/export-Steinhardt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ namespace freud { namespace order {
template<typename T, typename shape>
using nb_array = nanobind::ndarray<T, shape, nanobind::device::cpu, nanobind::c_contig>;

namespace wrap {

// void computeNematic(const std::shared_ptr<Nematic>& self,
// const nb_array<float, nanobind::shape<-1,3>>& orientations)
// {
// unsigned int const num_orientations = orientations.shape(0);
// auto* orientations_data = reinterpret_cast<vec3<float>*>(orientations.data());

// self->compute(orientations_data, num_orientations);
// }

}; // namespace wrap

namespace detail {

void export_Steinhardt(nanobind::module_& m)
Expand Down

0 comments on commit 7b66c2b

Please sign in to comment.