Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Aug 28, 2024
1 parent bcba7c8 commit 587fd88
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 51 deletions.
3 changes: 2 additions & 1 deletion cpp/pmft/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
nanobind_add_module(_pmft ${freud_nanobind_linking} module-pmft.cc export-PMFTXY.cc export-PMFTXYZ.cc)
nanobind_add_module(_pmft ${freud_nanobind_linking} module-pmft.cc
export-PMFTXY.cc export-PMFTXYZ.cc)
target_link_libraries(_pmft PUBLIC libfreud)

target_set_install_rpath(_pmft)
Expand Down
2 changes: 1 addition & 1 deletion cpp/pmft/PMFTXYZ.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void PMFTXYZ::reduce()
// reallocate the data arrays so we don't overwrite copies of the data the user may have made
m_pcf_array = std::make_shared<util::ManagedArray<float>>(m_pcf_array->shape());
m_histogram = BondHistogram(m_histogram.getAxes());

float inv_num_dens = m_box.getVolume() / (float) m_n_query_points;
float norm_factor
= (float) 1.0 / ((float) m_frame_counter * (float) m_n_points * (float) m_num_equiv_orientations);
Expand Down
9 changes: 5 additions & 4 deletions cpp/pmft/PMFTXYZ.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ class PMFTXYZ : public PMFT
/*! Compute the PCF for the passed in set of points. The function will be added to previous values
of the pcf
*/
void accumulate(std::shared_ptr<locality::NeighborQuery> neighbor_query, const quat<float>* query_orientations,
const vec3<float>* query_points, unsigned int n_query_points,
const quat<float>* equiv_orientations, unsigned int num_equiv_orientations,
std::shared_ptr<locality::NeighborList> nlist, const freud::locality::QueryArgs& qargs);
void accumulate(std::shared_ptr<locality::NeighborQuery> neighbor_query,
const quat<float>* query_orientations, const vec3<float>* query_points,
unsigned int n_query_points, const quat<float>* equiv_orientations,
unsigned int num_equiv_orientations, std::shared_ptr<locality::NeighborList> nlist,
const freud::locality::QueryArgs& qargs);

//! Reset the PMFT
/*! Override the parent method to also reset the number of equivalent orientations.
Expand Down
14 changes: 8 additions & 6 deletions cpp/pmft/export-PMFTXYZ.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ using nb_array = nanobind::ndarray<T, shape, nanobind::device::cpu, nanobind::c_
namespace wrap {

void accumulateXYZ(std::shared_ptr<PMFTXYZ> self, std::shared_ptr<locality::NeighborQuery> nq,
nb_array<float, nanobind::shape<-1, 4>> query_orientations,
nb_array<float, nanobind::shape<-1, 3>> query_points,
nb_array<float, nanobind::shape<-1, 4>> equivalent_orientations,
std::shared_ptr<locality::NeighborList> nlist, const locality::QueryArgs& qargs)
nb_array<float, nanobind::shape<-1, 4>> query_orientations,
nb_array<float, nanobind::shape<-1, 3>> query_points,
nb_array<float, nanobind::shape<-1, 4>> equivalent_orientations,
std::shared_ptr<locality::NeighborList> nlist, const locality::QueryArgs& qargs)
{
unsigned int num_query_points = query_points.shape(0);
auto* query_orientations_data = reinterpret_cast<quat<float>*>(query_orientations.data());
auto* query_points_data = reinterpret_cast<vec3<float>*>(query_points.data());
auto* equivalent_orientations_data = reinterpret_cast<quat<float>*>(equivalent_orientations.data());
unsigned int num_equivalent_orientations = equivalent_orientations.shape(0);
self->accumulate(nq, query_orientations_data, query_points_data, num_query_points, equivalent_orientations_data, num_equivalent_orientations, nlist, qargs);
self->accumulate(nq, query_orientations_data, query_points_data, num_query_points,
equivalent_orientations_data, num_equivalent_orientations, nlist, qargs);
}

}; // namespace wrap
Expand All @@ -37,7 +38,8 @@ void export_PMFTXYZ(nanobind::module_& m)
nanobind::class_<PMFTXYZ, PMFT>(m, "PMFTXYZ")
.def(nanobind::init<float, float, float, unsigned int, unsigned int, unsigned int>())
.def("accumulate", &wrap::accumulateXYZ, nanobind::arg("nq"), nanobind::arg("query_orientations"),
nanobind::arg("query_points"), nanobind::arg("equiv_orientations"), nanobind::arg("nlist").none(), nanobind::arg("qargs"));
nanobind::arg("query_points"), nanobind::arg("equiv_orientations"),
nanobind::arg("nlist").none(), nanobind::arg("qargs"));
}

} // namespace detail
Expand Down
4 changes: 2 additions & 2 deletions cpp/pmft/module-pmft.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#include <nanobind/nanobind.h>

namespace freud::pmft::detail {

void export_PMFT(nanobind::module_& m);
void export_PMFTXY(nanobind::module_& m);
void export_PMFTXYZ(nanobind::module_& m);
}
} // namespace freud::pmft::detail

using namespace freud::pmft::detail;

Expand Down
79 changes: 42 additions & 37 deletions freud/pmft.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,12 @@ def __init__(self, x_max, y_max, z_max, bins, shiftvec=[0, 0, 0]):
n_x = n_y = n_z = bins

self._cpp_obj = freud._pmft.PMFTXYZ(
x_max, y_max, z_max, n_x, n_y, n_z,
x_max,
y_max,
z_max,
n_x,
n_y,
n_z,
)
self.shiftvec = np.array(shiftvec, dtype=np.float32)
self.r_max = np.sqrt(x_max**2 + y_max**2 + z_max**2)
Expand All @@ -496,42 +501,42 @@ def compute(
):
r"""Calculates the PMFT.
.. note::
The orientations of the system points are irrelevant for this
calculation because that dimension is integrated out. The provided
``query_orientations`` are therefore always associated with
``query_points`` (which are equal to the system points if no
``query_points`` are explicitly provided.
Args:
system:
Any object that is a valid argument to
:class:`freud.locality.NeighborQuery.from_system`.
query_orientations ((:math:`N_{points}`, 4) :class:`numpy.ndarray`):
Query orientations associated with query points that are used
to calculate bonds.
query_points ((:math:`N_{query\_points}`, 3) :class:`numpy.ndarray`, optional):
Query points used to calculate the PMFT. Uses the system's
points if :code:`None` (Default value = :code:`None`).
equiv_orientations ((:math:`N_{faces}`, 4) :class:`numpy.ndarray`, optional):
Orientations to be treated as equivalent to account for
symmetry of the points. For instance, if the
:code:`query_points` are rectangular prisms with the long axis
& corresponding to the x-axis, then a point at :math:`(1, 0, 0)`
and a point at :math:`(-1, 0, 0)` are symmetrically equivalent
and can be counted towards both the positive and negative bins.
If not supplied by user or :code:`None`, a unit quaternion will
be used (Default value = :code:`None`).
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).
reset (bool):
Whether to erase the previously computed values before adding
the new computation; if False, will accumulate data (Default
value: True).
.. note::
The orientations of the system points are irrelevant for this
calculation because that dimension is integrated out. The provided
``query_orientations`` are therefore always associated with
``query_points`` (which are equal to the system points if no
``query_points`` are explicitly provided.
Args:
system:
Any object that is a valid argument to
:class:`freud.locality.NeighborQuery.from_system`.
query_orientations ((:math:`N_{points}`, 4) :class:`numpy.ndarray`):
Query orientations associated with query points that are used
to calculate bonds.
query_points ((:math:`N_{query\_points}`, 3) :class:`numpy.ndarray`, optional):
Query points used to calculate the PMFT. Uses the system's
points if :code:`None` (Default value = :code:`None`).
equiv_orientations ((:math:`N_{faces}`, 4) :class:`numpy.ndarray`, optional):
Orientations to be treated as equivalent to account for
symmetry of the points. For instance, if the
:code:`query_points` are rectangular prisms with the long axis
& corresponding to the x-axis, then a point at :math:`(1, 0, 0)`
and a point at :math:`(-1, 0, 0)` are symmetrically equivalent
and can be counted towards both the positive and negative bins.
If not supplied by user or :code:`None`, a unit quaternion will
be used (Default value = :code:`None`).
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).
reset (bool):
Whether to erase the previously computed values before adding
the new computation; if False, will accumulate data (Default
value: True).
""" # noqa: E501
if reset:
self._reset()
Expand Down

0 comments on commit 587fd88

Please sign in to comment.