Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions package/MDAnalysis/analysis/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,24 @@ def _single_frame(self):
backend=self.backend,
)

# Different people write code for different purposes. For my needs, the following two lines are sufficient:
# count, _ = np.histogram(dist, **self.rdf_settings)
# self.results.count[i][0, 0, :] += count

# The following is an optimized version based on the old logic.
bins = self.rdf_settings["bins"]
minv, maxv = (
self.rdf_settings["range"][0],
self.rdf_settings["range"][1],
)
# Calculate bin indices for each value in dist, similar to np.histogram's bin assignment.
bin_indices = (dist - minv) * bins / (maxv - minv)
bin_indices = bin_indices.astype(np.int64)

for j, (idx1, idx2) in enumerate(pairs):
count, _ = np.histogram(dist[j], **self.rdf_settings)
self.results.count[i][idx1, idx2, :] += count
if 0 <= bin_indices[j] < bins:
self.results.count[i][idx1, idx2, bin_indices[j]] += 1
# self.results.count[i][0, 0, bin_indices[j]] += 1 # this is necessary to calc rdf

if self.norm == "rdf":
self.volume_cum += self._ts.volume
Expand Down
Loading