diff --git a/freud/CMakeLists.txt b/freud/CMakeLists.txt index 86a97011f..e78725232 100644 --- a/freud/CMakeLists.txt +++ b/freud/CMakeLists.txt @@ -159,19 +159,17 @@ target_set_install_rpath(_box) # environment nanobind_add_module( - _environment - environment/module-environment.cc - environment/export-AngularSeparationNeighbor.cc - environment/export-AngularSeparationGlobal.cc - environment/export-LocalBondProjection.cc - environment/export-LocalDescriptors.cc - environment/export-BondOrder.cc - environment/export-MatchEnv.cc -) + _environment + environment/module-environment.cc + environment/export-AngularSeparationNeighbor.cc + environment/export-AngularSeparationGlobal.cc + environment/export-LocalBondProjection.cc + environment/export-LocalDescriptors.cc + environment/export-BondOrder.cc + environment/export-MatchEnv.cc) target_link_libraries(_environment PUBLIC freud TBB::tbb) target_set_install_rpath(_environment) - # locality nanobind_add_module( _locality diff --git a/freud/environment.py b/freud/environment.py index 7d0b63b10..b5ef19028 100644 --- a/freud/environment.py +++ b/freud/environment.py @@ -59,15 +59,18 @@ class attribute. orientations ((:math:`N_{points}`, 4) :class:`numpy.ndarray`): Orientations associated with system points that are used to calculate bonds. - query_points ((:math:`N_{query\_points}`, 3) :class:`numpy.ndarray`, optional): + query_points ((:math:`N_{query\_points}`, 3) :class:`numpy.ndarray`, + optional): Query points used to calculate the correlation function. Uses the system's points if :code:`None` (Default value = :code:`None`). - query_orientations ((:math:`N_{query\_points}`, 4) :class:`numpy.ndarray`, optional): + query_orientations ((:math:`N_{query\_points}`, 4) :class:`numpy.ndarray`, + optional): Query orientations used to calculate bonds. Uses :code:`orientations` if :code:`None`. (Default value = :code:`None`). - equiv_orientations ((:math:`N_{equiv}`, 4) :class:`numpy.ndarray`, optional): + equiv_orientations ((:math:`N_{equiv}`, 4) :class:`numpy.ndarray`, + optional): The set of all equivalent quaternions that map the particle to itself (the elements of its rotational symmetry group). Important: :code:`equiv_orientations` must include both @@ -303,11 +306,13 @@ def compute( Orientations associated with system points that are used to calculate bonds. Uses identity quaternions if :code:`None` (Default value = :code:`None`). - query_points ((:math:`N_{query\_points}`, 3) :class:`numpy.ndarray`, optional): + query_points ((:math:`N_{query\_points}`, 3) :class:`numpy.ndarray`, + optional): Query points used to calculate the correlation function. Uses the system's points if :code:`None` (Default value = :code:`None`). - query_orientations ((:math:`N_{query\_points}`, 4) :class:`numpy.ndarray`, optional): + query_orientations ((:math:`N_{query\_points}`, 4) :class:`numpy.ndarray`, + optional): Query orientations used to calculate bonds. Uses :code:`orientations` if :code:`None`. (Default value = :code:`None`). @@ -408,21 +413,29 @@ class LocalDescriptors(_PairCompute): environments (Default value = :code:`'neighborhood'`). """ - known_modes = {'neighborhood': freud._environment.LocalNeighborhood, - 'global': freud._environment.Global, - 'particle_local': freud._environment.ParticleLocal} + known_modes = { + "neighborhood": freud._environment.LocalNeighborhood, + "global": freud._environment.Global, + "particle_local": freud._environment.ParticleLocal, + } - def __init__(self, l_max, negative_m=True, mode='neighborhood'): + def __init__(self, l_max, negative_m=True, mode="neighborhood"): try: l_mode = self.known_modes[mode] except KeyError: - msg = f'Unknown LocalDescriptors orientation mode: {mode}' + msg = f"Unknown LocalDescriptors orientation mode: {mode}" raise ValueError(msg) from None self._cpp_obj = freud._environment.LocalDescriptors(l_max, negative_m, l_mode) - def compute(self, system, query_points=None, orientations=None, - neighbors=None, max_num_neighbors=0): + def compute( + self, + system, + query_points=None, + orientations=None, + neighbors=None, + max_num_neighbors=0, + ): r"""Calculates the local descriptors of bonds from a set of source points to a set of destination points. @@ -448,20 +461,22 @@ def compute(self, system, query_points=None, orientations=None, particle for the given neighbor-finding algorithm. Uses all neighbors if set to 0 (Default value = 0). """ # noqa: E501 - nq, nlist, qargs, query_points, num_query_points = \ - self._preprocess_arguments(system, query_points, neighbors) + nq, nlist, qargs, query_points, num_query_points = self._preprocess_arguments( + system, query_points, neighbors + ) # The l_orientations_ptr is only used for 'particle_local' mode. - if self.mode == 'particle_local': + if self.mode == "particle_local": if orientations is None: msg = ( - 'Orientations must be given to orient LocalDescriptors ' - 'with particles\' orientations' + "Orientations must be given to orient LocalDescriptors " + "with particles' orientations" ) raise RuntimeError(msg) orientations = freud.util._convert_array( - orientations, shape=(nq.points.shape[0], 4)) + orientations, shape=(nq.points.shape[0], 4) + ) self._cpp_obj.compute( nq._cpp_obj, @@ -470,7 +485,7 @@ def compute(self, system, query_points=None, orientations=None, orientations, nlist._cpp_obj, qargs._cpp_obj, - max_num_neighbors + max_num_neighbors, ) return self @@ -523,8 +538,10 @@ def mode(self): return None def __repr__(self): - return (f"freud.environment.{type(self).__name__}(l_max={self.l_max}, " - f"negative_m={self.negative_m}, mode='{self.mode}')") + return ( + f"freud.environment.{type(self).__name__}(l_max={self.l_max}, " + f"negative_m={self.negative_m}, mode='{self.mode}')" + ) def _minimize_RMSD(box, ref_points, points, registration=False): @@ -559,17 +576,14 @@ def _minimize_RMSD(box, ref_points, points, registration=False): if nRef1 != nRef2: msg = ( "The number of vectors in ref_points must MATCH" - "the number of vectors in points" + "the number of vectors in points" ) raise ValueError(msg) min_rmsd = -1 - results_map = \ - freud._environment.minimizeRMSD( - b._cpp_obj, - ref_points, - points, - nRef1, min_rmsd, registration) + results_map = freud._environment.minimizeRMSD( + b._cpp_obj, ref_points, points, nRef1, min_rmsd, registration + ) return [min_rmsd, np.asarray(points), results_map] @@ -608,7 +622,7 @@ def _is_similar_motif(box, ref_points, points, threshold, registration=False): nRef1 = ref_points.shape[0] nRef2 = points.shape[0] - threshold_sq = threshold*threshold + threshold_sq = threshold * threshold if nRef1 != nRef2: msg = ( @@ -618,17 +632,13 @@ def _is_similar_motif(box, ref_points, points, threshold, registration=False): raise ValueError(msg) vec_map = freud._environment.isSimilar( - b._cpp_obj, - ref_points, - points, - nRef1, - threshold_sq, - registration) + b._cpp_obj, ref_points, points, nRef1, threshold_sq, registration + ) return [np.asarray(points), vec_map] class _MatchEnv(_PairCompute): - r"""Parent for environment matching methods. """ + r"""Parent for environment matching methods.""" def __init__(self, *args, **kwargs): # Abstract class @@ -642,7 +652,7 @@ def point_environments(self): return [np.asarray(env) for env in envs] def __repr__(self): - return (f"freud.environment.{type(self).__name__}()") + return f"freud.environment.{type(self).__name__}()" class EnvironmentCluster(_MatchEnv): @@ -653,8 +663,14 @@ class EnvironmentCluster(_MatchEnv): def __init__(self): self._cpp_obj = freud._environment.EnvironmentCluster() - def compute(self, system, threshold, cluster_neighbors=None, - env_neighbors=None, registration=False): + def compute( + self, + system, + threshold, + cluster_neighbors=None, + env_neighbors=None, + registration=False, + ): r"""Determine clusters of particles with matching environments. An environment is defined by the bond vectors between a particle and its @@ -762,8 +778,9 @@ def compute(self, system, threshold, cluster_neighbors=None, option incurs a significant performance penalty. (Default value = :code:`False`) """ # noqa: E501 - nq, nlist, qargs, l_query_points, num_query_points = \ - self._preprocess_arguments(system, neighbors=cluster_neighbors) + nq, nlist, qargs, l_query_points, num_query_points = self._preprocess_arguments( + system, neighbors=cluster_neighbors + ) if env_neighbors is None: env_neighbors = cluster_neighbors @@ -776,7 +793,8 @@ def compute(self, system, threshold, cluster_neighbors=None, env_nlist._cpp_obj, env_qargs._cpp_obj, threshold, - registration) + registration, + ) return self @_Compute._computed_property @@ -809,17 +827,20 @@ def plot(self, ax=None): (:class:`matplotlib.axes.Axes`): Axis with the plot. """ import freud.plot + try: values, counts = np.unique(self.cluster_idx, return_counts=True) except ValueError: return None else: return freud.plot.clusters_plot( - values, counts, num_clusters_to_plot=10, ax=ax) + values, counts, num_clusters_to_plot=10, ax=ax + ) def _repr_png_(self): try: import freud.plot + return freud.plot._ax_to_bytes(self.plot()) except (AttributeError, ImportError): return None @@ -839,8 +860,7 @@ class EnvironmentMotifMatch(_MatchEnv): def __init__(self): self._cpp_obj = freud._environment.EnvironmentMotifMatch() - def compute(self, system, motif, threshold, env_neighbors=None, - registration=False): + def compute(self, system, motif, threshold, env_neighbors=None, registration=False): r"""Determine which particles have local environments matching the given environment motif. @@ -875,8 +895,9 @@ def compute(self, system, motif, threshold, env_neighbors=None, it minimizes the RMSD between the two sets (Default value = False). """ - nq, nlist, qargs, l_query_points, num_query_points = \ - self._preprocess_arguments(system, neighbors=env_neighbors) + nq, nlist, qargs, l_query_points, num_query_points = self._preprocess_arguments( + system, neighbors=env_neighbors + ) motif = freud.util._convert_array(motif, shape=(None, 3)) if (motif == 0).all(axis=1).any(): @@ -884,7 +905,7 @@ def compute(self, system, motif, threshold, env_neighbors=None, "Attempting to match a motif containing the zero " "vector is likely to result in zero matches.", RuntimeWarning, - stacklevel=2 + stacklevel=2, ) nRef = motif.shape[0] @@ -895,7 +916,8 @@ def compute(self, system, motif, threshold, env_neighbors=None, motif, nRef, threshold, - registration) + registration, + ) return self @_Compute._computed_property @@ -922,8 +944,7 @@ class _EnvironmentRMSDMinimizer(_MatchEnv): def __init__(self): self._cpp_obj = freud._environment.EnvironmentRMSDMinimizer() - def compute(self, system, motif, neighbors=None, - registration=False): + def compute(self, system, motif, neighbors=None, registration=False): r"""Rotate (if registration=True) and permute the environments of all particles to minimize their RMSD with respect to the motif provided by motif. @@ -950,19 +971,16 @@ def compute(self, system, motif, neighbors=None, Vector of minimal RMSD values, one value per particle. """ - nq, nlist, qargs, l_query_points, num_query_points = \ - self._preprocess_arguments(system, neighbors=neighbors) + nq, nlist, qargs, l_query_points, num_query_points = self._preprocess_arguments( + system, neighbors=neighbors + ) motif = freud.util._convert_array(motif, shape=(None, 3)) nRef = motif.shape[0] self._cpp_obj.compute( - nq._cpp_obj, - nlist._cpp_obj, - qargs._cpp_obj, - motif, - nRef, - registration) + nq._cpp_obj, nlist._cpp_obj, qargs._cpp_obj, motif, nRef, registration + ) return self @_Compute._computed_property @@ -973,17 +991,23 @@ def rmsds(self): class LocalBondProjection(_PairCompute): - r"""Calculates the maximal projection of nearest neighbor bonds for each - particle onto some set of reference vectors, defined in the particles' - local reference frame. - """ + r"""Calculates the maximal projection of nearest neighbor bonds for each + particle onto some set of reference vectors, defined in the particles' + local reference frame. + """ - def __init__(self): + def __init__(self): self._cpp_obj = freud._environment.LocalBondProjection() - def compute(self, system, orientations, proj_vecs, - query_points=None, equiv_orientations=np.array([[1, 0, 0, 0]]), - neighbors=None): + def compute( + self, + system, + orientations, + proj_vecs, + query_points=None, + equiv_orientations=np.array([[1, 0, 0, 0]]), + neighbors=None, + ): r"""Calculates the maximal projections of nearest neighbor bonds (between :code:`points` and :code:`query_points`) onto the set of reference vectors :code:`proj_vecs`, defined in the local reference @@ -1022,14 +1046,15 @@ def compute(self, system, orientations, proj_vecs, `_ (Default value: None). """ # noqa: E501 - nq, nlist, qargs, query_points, num_query_points = \ - self._preprocess_arguments(system, query_points, neighbors) + nq, nlist, qargs, query_points, num_query_points = self._preprocess_arguments( + system, query_points, neighbors + ) - orientations = freud.util._convert_array( - orientations, shape=(None, 4)) + orientations = freud.util._convert_array(orientations, shape=(None, 4)) equiv_orientations = freud.util._convert_array( - equiv_orientations, shape=(None, 4)) + equiv_orientations, shape=(None, 4) + ) proj_vecs = freud.util._convert_array(proj_vecs, shape=(None, 3)) self._cpp_obj.compute( @@ -1043,29 +1068,28 @@ def compute(self, system, orientations, proj_vecs, ) return self - @_Compute._computed_property - def nlist(self): + @_Compute._computed_property + def nlist(self): """:class:`freud.locality.NeighborList`: The neighbor list from the last compute.""" nlist = freud.locality._nlist_from_cnlist(self._cpp_obj.getNList()) nlist._compute = self return nlist - @_Compute._computed_property - def projections(self): + @_Compute._computed_property + def projections(self): """:math:`\\left(N_{bonds}, N_{projection\\_vecs} \\right)` :class:`numpy.ndarray`: The projection of each bond between query particles and their neighbors onto each of the projection vectors.""" # noqa: E501 return self._cpp_obj.getProjections().toNumpyArray() - @_Compute._computed_property - def normed_projections(self): + @_Compute._computed_property + def normed_projections(self): """:math:`\\left(N_{bonds}, N_{projection\\_vecs} \\right)` :class:`numpy.ndarray`: The projection of each bond between query particles and their neighbors onto each of the projection vectors, normalized by the length of the bond.""" # noqa: E501 return self._cpp_obj.getNormedProjections().toNumpyArray() - def __repr__(self): - return (f"freud.environment.{type(self).__name__}()") - + def __repr__(self): + return f"freud.environment.{type(self).__name__}()" diff --git a/freud/environment/AngularSeparation.cc b/freud/environment/AngularSeparation.cc index 1d36fa7fe..db3ff8ab9 100644 --- a/freud/environment/AngularSeparation.cc +++ b/freud/environment/AngularSeparation.cc @@ -49,12 +49,13 @@ float computeMinSeparationAngle(const quat& ref_q, const quat& q, return min_angle; } -void AngularSeparationNeighbor::compute(const std::shared_ptr nq, const quat* orientations, - const vec3* query_points, +void AngularSeparationNeighbor::compute(const std::shared_ptr nq, + const quat* orientations, const vec3* query_points, const quat* query_orientations, unsigned int n_query_points, const quat* equiv_orientations, unsigned int n_equiv_orientations, - const std::shared_ptr nlist, const locality::QueryArgs& qargs) + const std::shared_ptr nlist, + const locality::QueryArgs& qargs) { // This function requires a NeighborList object, so we always make one and store it locally. diff --git a/freud/environment/AngularSeparation.h b/freud/environment/AngularSeparation.h index ff921debd..8a5aa2c9a 100644 --- a/freud/environment/AngularSeparation.h +++ b/freud/environment/AngularSeparation.h @@ -80,7 +80,7 @@ class AngularSeparationNeighbor private: std::shared_ptr> m_angles; //!< neighbor angle array computed - std::shared_ptr m_nlist; //!< The NeighborList used in the last call to compute. + std::shared_ptr m_nlist; //!< The NeighborList used in the last call to compute. }; }; }; // end namespace freud::environment diff --git a/freud/environment/LocalBondProjection.cc b/freud/environment/LocalBondProjection.cc index b6bec3871..4efa887b8 100644 --- a/freud/environment/LocalBondProjection.cc +++ b/freud/environment/LocalBondProjection.cc @@ -46,11 +46,13 @@ float computeMaxProjection(const vec3& proj_vec, const vec3& local return max_proj; } -void LocalBondProjection::compute(const std::shared_ptr nq, const quat* orientations, - const vec3* query_points, unsigned int n_query_points, - const vec3* proj_vecs, unsigned int n_proj, - const quat* equiv_orientations, unsigned int n_equiv_orientations, - const std::shared_ptr nlist, const locality::QueryArgs& qargs) +void LocalBondProjection::compute(const std::shared_ptr nq, + const quat* orientations, const vec3* query_points, + unsigned int n_query_points, const vec3* proj_vecs, + unsigned int n_proj, const quat* equiv_orientations, + unsigned int n_equiv_orientations, + const std::shared_ptr nlist, + const locality::QueryArgs& qargs) { // This function requires a NeighborList object, so we always make one and store it locally. m_nlist = locality::makeDefaultNlist(nq, nlist, query_points, n_query_points, qargs); @@ -59,25 +61,27 @@ void LocalBondProjection::compute(const std::shared_ptr const unsigned int tot_num_neigh = m_nlist->getNumBonds(); const auto& neighbors = m_nlist->getNeighbors(); - m_local_bond_proj = std::make_shared>(std::vector {tot_num_neigh, n_proj}); - m_local_bond_proj_norm = std::make_shared>(std::vector {tot_num_neigh, n_proj}); + m_local_bond_proj + = std::make_shared>(std::vector {tot_num_neigh, n_proj}); + m_local_bond_proj_norm + = std::make_shared>(std::vector {tot_num_neigh, n_proj}); // compute the order parameter util::forLoopWrapper(0, n_query_points, [&](size_t begin, size_t end) { size_t bond(m_nlist->find_first_index(begin)); for (size_t i = begin; i < end; ++i) { - for (; bond < tot_num_neigh && (* neighbors)(bond, 0) == i; ++bond) + for (; bond < tot_num_neigh && (*neighbors)(bond, 0) == i; ++bond) { - const size_t j( (* neighbors)(bond, 1)); + const size_t j((*neighbors)(bond, 1)); // compute bond vector between the two particles - vec3 local_bond((* m_nlist->getVectors())(bond)); + vec3 local_bond((*m_nlist->getVectors())(bond)); // rotate bond vector into the local frame of particle p local_bond = rotate(conj(orientations[j]), local_bond); // store the length of this local bond - float local_bond_len = (* m_nlist->getDistances())(bond); + float local_bond_len = (*m_nlist->getDistances())(bond); for (unsigned int k = 0; k < n_proj; k++) { diff --git a/freud/environment/LocalBondProjection.h b/freud/environment/LocalBondProjection.h index 01e4ab198..e663281e1 100644 --- a/freud/environment/LocalBondProjection.h +++ b/freud/environment/LocalBondProjection.h @@ -35,7 +35,8 @@ class LocalBondProjection void compute(const std::shared_ptr nq, const quat* orientations, const vec3* query_points, unsigned int n_query_points, const vec3* proj_vecs, unsigned int n_proj, const quat* equiv_orientations, - unsigned int n_equiv_orientations, const std::shared_ptr nlist, + unsigned int n_equiv_orientations, + const std::shared_ptr nlist, const locality::QueryArgs& qargs); //! Get a reference to the last computed maximal local bond projection array @@ -59,8 +60,9 @@ class LocalBondProjection private: std::shared_ptr m_nlist; //!< The NeighborList used in the last call to compute. - std::shared_ptr> m_local_bond_proj; //!< Local bond projection array computed - std::shared_ptr> m_local_bond_proj_norm; //!< Normalized local bond projection array computed + std::shared_ptr> m_local_bond_proj; //!< Local bond projection array computed + std::shared_ptr> + m_local_bond_proj_norm; //!< Normalized local bond projection array computed }; }; }; // end namespace freud::environment diff --git a/freud/environment/LocalDescriptors.cc b/freud/environment/LocalDescriptors.cc index df9d11010..1349b0901 100644 --- a/freud/environment/LocalDescriptors.cc +++ b/freud/environment/LocalDescriptors.cc @@ -19,12 +19,10 @@ LocalDescriptors::LocalDescriptors(unsigned int l_max, bool negative_m, {} void LocalDescriptors::compute(const std::shared_ptr nq, - const vec3* query_points, - unsigned int n_query_points, + const vec3* query_points, unsigned int n_query_points, const quat* orientations, const std::shared_ptr nlist, - const locality::QueryArgs& qargs, - unsigned int max_num_neighbors) + const locality::QueryArgs& qargs, unsigned int max_num_neighbors) { // This function requires a NeighborList object, so we always make one and store it locally. m_nlist = locality::makeDefaultNlist(nq, nlist, query_points, n_query_points, qargs); @@ -34,7 +32,7 @@ void LocalDescriptors::compute(const std::shared_ptr nq max_num_neighbors = std::numeric_limits::max(); } m_sphArray = std::make_shared>>( - std::vector{m_nlist->getNumBonds(), getSphWidth()}); + std::vector {m_nlist->getNumBonds(), getSphWidth()}); util::forLoopWrapper(0, nq->getNPoints(), [&](size_t begin, size_t end) { fsph::PointSPHEvaluator sph_eval(m_l_max); @@ -55,7 +53,7 @@ void LocalDescriptors::compute(const std::shared_ptr nq && (*m_nlist->getNeighbors())(bond_copy, 0) == i && neighbor_count < max_num_neighbors; ++bond_copy, ++neighbor_count) { - const vec3 r_ij((* m_nlist->getVectors())(bond_copy)); + const vec3 r_ij((*m_nlist->getVectors())(bond_copy)); const float r_sq(dot(r_ij, r_ij)); for (size_t ii(0); ii < 3; ++ii) @@ -107,8 +105,8 @@ void LocalDescriptors::compute(const std::shared_ptr nq ++bond, ++neighbor_count) { const unsigned int sphCount(bond * getSphWidth()); - const vec3 r_ij((* m_nlist->getVectors())(bond)); - const float magR((* m_nlist->getDistances())(bond)); + const vec3 r_ij((*m_nlist->getVectors())(bond)); + const float magR((*m_nlist->getDistances())(bond)); const vec3 bond_ij(dot(rotation_0, r_ij), dot(rotation_1, r_ij), dot(rotation_2, r_ij)); diff --git a/freud/environment/LocalDescriptors.h b/freud/environment/LocalDescriptors.h index 5bf19b050..7021b14c9 100644 --- a/freud/environment/LocalDescriptors.h +++ b/freud/environment/LocalDescriptors.h @@ -52,12 +52,9 @@ class LocalDescriptors //! Compute the local neighborhood descriptors given some //! positions and the number of particles - void compute(const std::shared_ptr nq, - const vec3* query_points, - unsigned int n_query_points, - const quat* orientations, - const std::shared_ptr nlist, - const locality::QueryArgs& qargs, + void compute(const std::shared_ptr nq, const vec3* query_points, + unsigned int n_query_points, const quat* orientations, + const std::shared_ptr nlist, const locality::QueryArgs& qargs, unsigned int max_num_neighbor); //! Get a reference to the last computed spherical harmonic array @@ -89,11 +86,11 @@ class LocalDescriptors } private: - unsigned int m_l_max; //!< Maximum spherical harmonic l to calculate - bool m_negative_m; //!< true if we should compute Ylm for negative m - unsigned int m_nSphs; //!< Last number of bond spherical harmonics computed - std::shared_ptr m_nlist; //!< The NeighborList used in the last call to compute. - LocalDescriptorOrientation m_orientation; //!< The orientation mode to compute with. + unsigned int m_l_max; //!< Maximum spherical harmonic l to calculate + bool m_negative_m; //!< true if we should compute Ylm for negative m + unsigned int m_nSphs; //!< Last number of bond spherical harmonics computed + std::shared_ptr m_nlist; //!< The NeighborList used in the last call to compute. + LocalDescriptorOrientation m_orientation; //!< The orientation mode to compute with. //! Spherical harmonics for each neighbor std::shared_ptr>> m_sphArray; diff --git a/freud/environment/MatchEnv.cc b/freud/environment/MatchEnv.cc index aace88506..f41b1fbf3 100644 --- a/freud/environment/MatchEnv.cc +++ b/freud/environment/MatchEnv.cc @@ -488,8 +488,8 @@ MatchEnv::~MatchEnv() = default; EnvironmentCluster::~EnvironmentCluster() = default; -Environment MatchEnv::buildEnv(const std::shared_ptr& nlist, size_t num_bonds, size_t& bond, - unsigned int i, unsigned int env_ind) +Environment MatchEnv::buildEnv(const std::shared_ptr& nlist, size_t num_bonds, + size_t& bond, unsigned int i, unsigned int env_ind) { Environment ei = Environment(); // set the environment index equal to the particle index @@ -510,7 +510,8 @@ Environment MatchEnv::buildEnv(const std::shared_ptr& nq, - const std::shared_ptr& nlist_arg, locality::QueryArgs qargs, + const std::shared_ptr& nlist_arg, + locality::QueryArgs qargs, const std::shared_ptr& env_nlist_arg, locality::QueryArgs env_qargs, float threshold, bool registration) { @@ -636,9 +637,9 @@ unsigned int EnvironmentCluster::populateEnv(EnvDisjointSet dj) * EnvironmentMotifMatch * *************************/ void EnvironmentMotifMatch::compute(const std::shared_ptr& nq, - const std::shared_ptr& nlist_arg, locality::QueryArgs qargs, - const vec3* motif, unsigned int motif_size, float threshold, - bool registration) + const std::shared_ptr& nlist_arg, + locality::QueryArgs qargs, const vec3* motif, + unsigned int motif_size, float threshold, bool registration) { std::shared_ptr nlist = locality::makeDefaultNlist(nq, nlist_arg, nq->getPoints(), nq->getNPoints(), qargs); diff --git a/freud/environment/MatchEnv.h b/freud/environment/MatchEnv.h index 03a1cbbef..9973e48a4 100644 --- a/freud/environment/MatchEnv.h +++ b/freud/environment/MatchEnv.h @@ -204,8 +204,8 @@ class MatchEnv //! Construct and return a local environment surrounding the particle indexed by i. Set the environment //! index to env_ind. - static Environment buildEnv(const std::shared_ptr& nlist, size_t num_bonds, size_t& bond, - unsigned int i, unsigned int env_ind); + static Environment buildEnv(const std::shared_ptr& nlist, size_t num_bonds, + size_t& bond, unsigned int i, unsigned int env_ind); //! Returns the entire Np by m_num_neighbors by 3 matrix of all environments for all particles const std::vector>>& getPointEnvironments() @@ -263,8 +263,9 @@ class EnvironmentCluster : public MatchEnv * orient the second set of vectors such that it * minimizes the RMSD between the two sets */ - void compute(const std::shared_ptr& nq, const std::shared_ptr& nlist_arg, - locality::QueryArgs qargs, const std::shared_ptr& env_nlist_arg, + void compute(const std::shared_ptr& nq, + const std::shared_ptr& nlist_arg, locality::QueryArgs qargs, + const std::shared_ptr& env_nlist_arg, locality::QueryArgs env_qargs, float threshold, bool registration = false); //! Get a reference to the particles, indexed into clusters according to their matching local environments @@ -303,8 +304,9 @@ class EnvironmentCluster : public MatchEnv */ unsigned int populateEnv(EnvDisjointSet dj); - unsigned int m_num_clusters {0}; //!< Last number of local environments computed - std::shared_ptr> m_env_index; //!< Cluster index determined for each particle + unsigned int m_num_clusters {0}; //!< Last number of local environments computed + std::shared_ptr> + m_env_index; //!< Cluster index determined for each particle std::vector>> m_cluster_environments; //!< Dictionary of (cluster id, vectors) pairs }; @@ -350,9 +352,10 @@ class EnvironmentMotifMatch : public MatchEnv * orient the second set of vectors such that it * minimizes the RMSD between the two sets */ - void compute(const std::shared_ptr& nq, const std::shared_ptr& nlist_arg, - locality::QueryArgs qargs, const vec3* motif, unsigned int motif_size, - float threshold, bool registration = false); + void compute(const std::shared_ptr& nq, + const std::shared_ptr& nlist_arg, locality::QueryArgs qargs, + const vec3* motif, unsigned int motif_size, float threshold, + bool registration = false); //! Return the array indicating whether each particle matched the motif or not. const std::shared_ptr>& getMatches() @@ -412,9 +415,9 @@ class EnvironmentRMSDMinimizer : public MatchEnv * orient the second set of vectors such that it * minimizes the RMSD between the two sets */ - void compute(const std::shared_ptr& nq, const std::shared_ptr& nlist_arg, - locality::QueryArgs qargs, const vec3* motif, unsigned int motif_size, - bool registration = false); + void compute(const std::shared_ptr& nq, + const std::shared_ptr& nlist_arg, locality::QueryArgs qargs, + const vec3* motif, unsigned int motif_size, bool registration = false); //! Return the array indicating whether or not a successful mapping was found between each particle and //! the provided motif. diff --git a/freud/environment/export-AngularSeparationGlobal.cc b/freud/environment/export-AngularSeparationGlobal.cc index ab984cc33..efb712a93 100644 --- a/freud/environment/export-AngularSeparationGlobal.cc +++ b/freud/environment/export-AngularSeparationGlobal.cc @@ -9,7 +9,6 @@ #include "AngularSeparation.h" - namespace nb = nanobind; namespace freud { namespace environment { @@ -18,21 +17,22 @@ template using nb_array = nanobind::ndarray; namespace wrap { -void compute(const std::shared_ptr& angular_separation, - const nb_array>& global_orientations, +void compute(const std::shared_ptr& angular_separation, + const nb_array>& global_orientations, const nb_array>& orientations, const nb_array>& equiv_orientations) - { +{ unsigned int const n_global = global_orientations.shape(0); unsigned int const n_points = orientations.shape(0); unsigned int const n_equiv_orientations = equiv_orientations.shape(0); auto* global_orientations_data = reinterpret_cast*>(global_orientations.data()); auto* orientations_data = reinterpret_cast*>(orientations.data()); auto* equiv_orientations_data = reinterpret_cast*>(equiv_orientations.data()); - angular_separation->compute(global_orientations_data, n_global, orientations_data, n_points, equiv_orientations_data, n_equiv_orientations); - } + angular_separation->compute(global_orientations_data, n_global, orientations_data, n_points, + equiv_orientations_data, n_equiv_orientations); +} -}; +}; // namespace wrap namespace detail { @@ -41,9 +41,9 @@ void export_AngularSeparationGlobal(nb::module_& module) nb::class_(module, "AngularSeparationGlobal") .def(nb::init<>()) .def("getAngles", &AngularSeparationGlobal::getAngles) - .def("compute", &wrap::compute, nb::arg("global_orientations"), nb::arg("orientations"), + .def("compute", &wrap::compute, nb::arg("global_orientations"), nb::arg("orientations"), nb::arg("equiv_orientations")); } -}; }; // namespace detail -}; // namespace freud::locality +}; // namespace detail +}; }; // namespace freud::environment diff --git a/freud/environment/export-AngularSeparationNeighbor.cc b/freud/environment/export-AngularSeparationNeighbor.cc index 1a1697ae8..1f3d91b06 100644 --- a/freud/environment/export-AngularSeparationNeighbor.cc +++ b/freud/environment/export-AngularSeparationNeighbor.cc @@ -19,26 +19,24 @@ using nb_array = nanobind::ndarray& angular_separation, - std::shared_ptr nq, - nb_array>& orientations, - nb_array>& query_points, - nb_array>& query_orientations, - nb_array>& equiv_orientations, - std::shared_ptr nlist, - const locality::QueryArgs& qargs -) - { +void compute(std::shared_ptr& angular_separation, + std::shared_ptr nq, + nb_array>& orientations, + nb_array>& query_points, + nb_array>& query_orientations, + nb_array>& equiv_orientations, + std::shared_ptr nlist, const locality::QueryArgs& qargs) +{ auto* orientations_data = reinterpret_cast*>(orientations.data()); auto* query_points_data = reinterpret_cast*>(query_points.data()); auto* query_orientations_data = reinterpret_cast*>(query_orientations.data()); auto* equiv_orientations_data = reinterpret_cast*>(equiv_orientations.data()); unsigned int n_equiv_orientations = equiv_orientations.shape(0); unsigned int n_query_points = query_orientations.shape(0); - angular_separation->compute(nq, orientations_data, query_points_data, query_orientations_data, n_query_points, equiv_orientations_data, n_equiv_orientations, nlist, qargs); - } -}; + angular_separation->compute(nq, orientations_data, query_points_data, query_orientations_data, + n_query_points, equiv_orientations_data, n_equiv_orientations, nlist, qargs); +} +}; // namespace wrap namespace detail { @@ -48,12 +46,11 @@ void export_AngularSeparationNeighbor(nb::module_& module) .def(nb::init<>()) .def("getNList", &AngularSeparationNeighbor::getNList) .def("getAngles", &AngularSeparationNeighbor::getAngles) - .def("compute", &wrap::compute, nb::arg("nq"), nb::arg("orientations"), - nb::arg("query_points"), nb::arg("query_orientations"), - nb::arg("equiv_orientations"), nb::arg("nlist").none(), + .def("compute", &wrap::compute, nb::arg("nq"), nb::arg("orientations"), nb::arg("query_points"), + nb::arg("query_orientations"), nb::arg("equiv_orientations"), nb::arg("nlist").none(), nb::arg("qargs")); } }; // namespace detail -}; }; // namespace freud::locality +}; }; // namespace freud::environment diff --git a/freud/environment/export-LocalBondProjection.cc b/freud/environment/export-LocalBondProjection.cc index 993928a21..73f196d86 100644 --- a/freud/environment/export-LocalBondProjection.cc +++ b/freud/environment/export-LocalBondProjection.cc @@ -9,7 +9,6 @@ #include "LocalBondProjection.h" - namespace nb = nanobind; namespace freud { namespace environment { @@ -19,17 +18,14 @@ using nb_array = nanobind::ndarray& local_bond_projection, - std::shared_ptr nq, - nb_array>& orientations, - nb_array>& query_points, - nb_array>& projected_vectors, - nb_array>& equiv_orientations, - std::shared_ptr nlist, - const locality::QueryArgs& qargs -) - { +void compute(std::shared_ptr& local_bond_projection, + std::shared_ptr nq, + nb_array>& orientations, + nb_array>& query_points, + nb_array>& projected_vectors, + nb_array>& equiv_orientations, + std::shared_ptr nlist, const locality::QueryArgs& qargs) +{ auto* orientations_data = reinterpret_cast*>(orientations.data()); auto* query_points_data = reinterpret_cast*>(query_points.data()); auto* proj_vectors_data = reinterpret_cast*>(projected_vectors.data()); @@ -37,10 +33,12 @@ void compute( unsigned int n_proj_vec = projected_vectors.shape(0); unsigned int n_query_points = query_points.shape(0); unsigned int n_equiv_orientations = equiv_orientations.shape(0); - local_bond_projection->compute(nq, orientations_data, query_points_data, n_query_points, proj_vectors_data, n_proj_vec, equiv_orientations_data, n_equiv_orientations, nlist, qargs); - } + local_bond_projection->compute(nq, orientations_data, query_points_data, n_query_points, + proj_vectors_data, n_proj_vec, equiv_orientations_data, + n_equiv_orientations, nlist, qargs); +} -}; +}; // namespace wrap namespace detail { @@ -51,11 +49,10 @@ void export_LocalBondProjection(nb::module_& module) .def("getNList", &LocalBondProjection::getNList) .def("getProjections", &LocalBondProjection::getProjections) .def("getNormedProjections", &LocalBondProjection::getNormedProjections) - .def("compute", &wrap::compute, nb::arg("nq"), nb::arg("orientations"), - nb::arg("query_points"), nb::arg("projected_vectors"), - nb::arg("equiv_orientations"), nb::arg("nlist").none(), + .def("compute", &wrap::compute, nb::arg("nq"), nb::arg("orientations"), nb::arg("query_points"), + nb::arg("projected_vectors"), nb::arg("equiv_orientations"), nb::arg("nlist").none(), nb::arg("qargs")); } -}; }; // namespace detail -}; // namespace freud::locality +}; // namespace detail +}; }; // namespace freud::environment diff --git a/freud/environment/export-LocalDescriptors.cc b/freud/environment/export-LocalDescriptors.cc index 15b56d2ff..b4871baaf 100644 --- a/freud/environment/export-LocalDescriptors.cc +++ b/freud/environment/export-LocalDescriptors.cc @@ -9,7 +9,6 @@ #include "LocalDescriptors.h" - namespace nb = nanobind; namespace freud { namespace environment { @@ -18,28 +17,25 @@ template using nb_array = nanobind::ndarray; namespace wrap { -void compute(const std::shared_ptr& local_descriptors, +void compute(const std::shared_ptr& local_descriptors, std::shared_ptr nq, - const nb_array>& query_points, - const unsigned int n_query_points, + const nb_array>& query_points, const unsigned int n_query_points, const nb_array>& orientations, - std::shared_ptr nlist, - const locality::QueryArgs& qargs, - const unsigned int max_num_neighbors -) - { + std::shared_ptr nlist, const locality::QueryArgs& qargs, + const unsigned int max_num_neighbors) +{ auto* query_points_data = reinterpret_cast*>(query_points.data()); auto* orientations_data = reinterpret_cast*>(orientations.data()); - local_descriptors->compute(nq, query_points_data, n_query_points, orientations_data, nlist, qargs, max_num_neighbors); - } + local_descriptors->compute(nq, query_points_data, n_query_points, orientations_data, nlist, qargs, + max_num_neighbors); +} -}; +}; // namespace wrap namespace detail { void export_LocalDescriptors(nb::module_& module) { - nb::enum_(module, "LocalDescriptorOrientation") .value("LocalNeighborhood", LocalDescriptorOrientation::LocalNeighborhood) .value("Global", LocalDescriptorOrientation::Global) @@ -54,11 +50,10 @@ void export_LocalDescriptors(nb::module_& module) .def("getLMax", &LocalDescriptors::getLMax) .def("getNegativeM", &LocalDescriptors::getNegativeM) .def("getMode", &LocalDescriptors::getMode) - .def("compute", &wrap::compute,nb::arg("nq"), - nb::arg("query_points"), nb::arg("n_query_points"), nb::arg("orientations").none(), - nb::arg("nlist").none(), - nb::arg("qargs"), nb::arg("max_num_neighbors")); + .def("compute", &wrap::compute, nb::arg("nq"), nb::arg("query_points"), nb::arg("n_query_points"), + nb::arg("orientations").none(), nb::arg("nlist").none(), nb::arg("qargs"), + nb::arg("max_num_neighbors")); } -}; }; // namespace detail -}; // namespace freud::locality +}; // namespace detail +}; }; // namespace freud::environment