Skip to content

Commit

Permalink
reversed PBC = False; changed ball query to compute all distances and…
Browse files Browse the repository at this point in the history
… added support for partials with compute all distances
  • Loading branch information
DomFijan committed Sep 3, 2021
1 parent 2c87d99 commit 03dd664
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
8 changes: 4 additions & 4 deletions cpp/diffraction/StaticStructureFactorDebye.cc
Expand Up @@ -54,15 +54,15 @@ void StaticStructureFactorDebye::accumulate(const freud::locality::NeighborQuery
auto const min_box_length
= box.is2D() ? std::min(box_L.x, box_L.y) : std::min(box_L.x, std::min(box_L.y, box_L.z));
auto const r_max = std::nextafter(float(0.5) * min_box_length, float(0));
auto const qargs = freud::locality::QueryArgs::make_ball(r_max, 0.0, false);
auto points= neighbor_query->getPoints();
auto const n_points= neighbor_query->getNPoints();

// The minimum k value of validity is 4 * pi / L, where L is the smallest side length.
// This is equal to 2 * pi / r_max.
m_min_valid_k = std::min(m_min_valid_k, freud::constants::TWO_PI / r_max);

// This function requires a NeighborList object, so we always make one and store it locally.
auto const nlist = locality::makeDefaultNlist(neighbor_query, nullptr, query_points, n_query_points, qargs);
auto const& distances = nlist.getDistances();
auto distances = std::vector<float>(n_points * n_query_points);
box.computeAllDistances(points, n_points, query_points, n_query_points, distances.data());

auto const k_bin_centers = m_histogram.getBinCenters()[0];

Expand Down
7 changes: 0 additions & 7 deletions freud/diffraction.pyx
Expand Up @@ -130,14 +130,7 @@ cdef class StaticStructureFactorDebye(_Compute):
const float[:, ::1] l_query_points
unsigned int num_query_points

# This is identical to _preprocess_arguments except with no
# neighbors/qargs. The C++ class builds the largest allowed ball query
# (r_max = L/2).
nq = freud.locality.NeighborQuery.from_system(system)
# Debeye method needs PBC=False
new_box = nq.box
new_box.periodic = False
nq = freud.locality.NeighborQuery.from_system((new_box, nq.points))

if query_points is None:
query_points = nq.points
Expand Down
11 changes: 4 additions & 7 deletions tests/test_diffraction_StaticStructureFactorDebye.py
Expand Up @@ -26,19 +26,14 @@ def _validate_debye_method(system, bins, k_max, k_min):
Minimum :math:`k` value to include in the calculation.
"""
system = freud.locality.NeighborQuery.from_system(system)
new_box = system.box
new_box.periodic = False
system = freud.locality.NeighborQuery.from_system((new_box, system.points))
r_max = np.nextafter(np.min(system.box.L) * 0.5, 0, dtype=np.float32)
N = len(system.points)

Q = np.linspace(k_min, k_max, bins, endpoint=False)
Q += (k_max - k_min) / bins / 2
S = np.zeros_like(Q)

# Compute all pairwise distances
query_args = dict(mode="ball", r_max=r_max, exclude_ii=False)
distances = system.query(system.points, query_args).toNeighborList().distances
distances = system.box.compute_all_distances(system.points, system.points).flatten()

for i, q in enumerate(Q):
S[i] += np.sum(np.sinc(q * distances / np.pi)) / N
Expand Down Expand Up @@ -98,7 +93,9 @@ def test_partial_structure_factor_symmetry(self):
system = freud.AABBQuery.from_system((box, points))
A_points = system.points[: N // 3]
B_points = system.points[N // 3 :]
sf = freud.diffraction.StaticStructureFactorDebye(bins=100, k_max=10)
sf = freud.diffraction.StaticStructureFactorDebye(
bins=100, k_min=np.pi / L, k_max=30
)
sf.compute((system.box, B_points), query_points=A_points, N_total=N)
S_AB = sf.S_k
sf.compute((system.box, A_points), query_points=B_points, N_total=N)
Expand Down

0 comments on commit 03dd664

Please sign in to comment.