Skip to content

Commit

Permalink
export cubatic
Browse files Browse the repository at this point in the history
  • Loading branch information
janbridley committed Oct 26, 2024
1 parent b55deaf commit f59ce23
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 32 deletions.
8 changes: 5 additions & 3 deletions freud/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ add_library(
order
order/ContinuousCoordination.h
order/ContinuousCoordination.cc
# order/Cubatic.cc
# order/Cubatic.h
order/Cubatic.cc
order/Cubatic.h
# order/HexaticTranslational.cc
# order/HexaticTranslational.h
order/Nematic.cc
Expand Down Expand Up @@ -176,7 +176,9 @@ target_set_install_rpath(_locality)
# order
nanobind_add_module(_order order/module-order.cc order/export-Nematic.cc
order/export-RotationalAutocorrelation.cc order/export-Steinhardt.cc
order/export-SolidLiquid.cc order/export-ContinuousCoordination.cc)
order/export-SolidLiquid.cc order/export-ContinuousCoordination.cc
order/export-Cubatic.cc
)
target_link_libraries(_order PUBLIC freud)
target_set_install_rpath(_order)

Expand Down
49 changes: 21 additions & 28 deletions freud/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,37 +41,30 @@
# _always_ do that, or you will have segfaults
# np.import_array()

print("ADFHAFGJAKFHAJ")
class Cubatic(_Compute):
r"""Compute the cubatic order parameter :cite:`Haji_Akbari_2015` for a system of
particles using simulated annealing instead of Newton-Raphson root finding.
# cdef class Cubatic(_Compute):
# r"""Compute the cubatic order parameter :cite:`Haji_Akbari_2015` for a system of
# particles using simulated annealing instead of Newton-Raphson root finding.

# Args:
# t_initial (float):
# Starting temperature.
# t_final (float):
# Final temperature.
# scale (float):
# Scaling factor to reduce temperature.
# n_replicates (unsigned int, optional):
# Number of replicate simulated annealing runs.
# (Default value = :code:`1`).
# seed (unsigned int, optional):
# Random seed to use in calculations. If :code:`None`, system time is used.
# (Default value = :code:`None`).
# """ # noqa: E501
# cdef freud._order.Cubatic * thisptr

# def __cinit__(self, t_initial, t_final, scale, n_replicates=1, seed=None):
# if seed is None:
# seed = int(time.time())
Args:
t_initial (float):
Starting temperature.
t_final (float):
Final temperature.
scale (float):
Scaling factor to reduce temperature.
n_replicates (unsigned int, optional):
Number of replicate simulated annealing runs.
(Default value = :code:`1`).
seed (unsigned int, optional):
Random seed to use in calculations. If :code:`None`, system time is used.
(Default value = :code:`None`).
"""

# self.thisptr = new freud._order.Cubatic(
# t_initial, t_final, scale, n_replicates, seed)
def __init__(self, t_initial, t_final, scale, n_replicates=1, seed=None):
if seed is None:
seed = int(time.time())

# def __dealloc__(self):
# del self.thisptr
self._cpp_obj = freud._order.Cubatic(t_initial, t_final, scale, n_replicates, seed)

# def compute(self, orientations):
# r"""Calculates the per-particle and global order parameter.
Expand Down
52 changes: 52 additions & 0 deletions freud/order/export-Cubatic.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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.

#include <memory>
#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 "Cubatic.h"
#include "VectorMath.h"

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 computeCubatic(const std::shared_ptr<Cubatic>& self,
const nb_array<float, nanobind::shape<-1, 4>>& orientations)
{
unsigned int const num_orientations = orientations.shape(0);
auto* orientations_data = reinterpret_cast<quat<float>*>(orientations.data());

self->compute(orientations_data, num_orientations);
}

// nanobind::tuple getNematicDirector(const std::shared_ptr<Cubatic>& self)
// {
// vec3<float> nem_d_cpp = self->getNematicDirector();
// return nanobind::make_tuple(nem_d_cpp.x, nem_d_cpp.y, nem_d_cpp.z);
// }
}; // namespace wrap

namespace detail {

void export_Nematic(nanobind::module_& m)
{
nanobind::class_<Cubatic>(m, "Cubatic")
.def(nanobind::init<float, float, float, unsigned int, unsigned int>())
.def("compute", &wrap::computeCubatic, nanobind::arg("orientations"))
// .def("getNematicOrderParameter", &Nematic::getNematicOrderParameter)
// .def("getNematicDirector", &wrap::getNematicDirector)
// .def("getParticleTensor", &Nematic::getParticleTensor)
// .def("getNematicTensor", &Nematic::getNematicTensor);
}

} // namespace detail

}; }; // namespace freud::order
3 changes: 2 additions & 1 deletion freud/order/module-order.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ void export_RotationalAutocorrelation(nanobind::module_& m);
void export_Steinhardt(nanobind::module_& m);
void export_SolidLiquid(nanobind::module_& m);
void export_ContinuousCoordination(nanobind::module_& m);
void export_Cubatic(nanobind::module_& m);
} // namespace freud::order::detail

using namespace freud::order::detail;
Expand All @@ -20,5 +21,5 @@ NB_MODULE(_order, module) // NOLINT(misc-use-anonymous-namespace): caused by nan
export_RotationalAutocorrelation(module);
export_Steinhardt(module);
export_SolidLiquid(module);
export_ContinuousCoordination(module);
export_Cubatic(module);
}

0 comments on commit f59ce23

Please sign in to comment.