Skip to content

New RDF method with flexible pair exclusions defined by an arbitrary bond depth. - #149

Merged
chrisjonesBSU merged 14 commits into
cmelab:mainfrom
chrisjonesBSU:rdf-exclude-bond-depth
Mar 12, 2026
Merged

New RDF method with flexible pair exclusions defined by an arbitrary bond depth.#149
chrisjonesBSU merged 14 commits into
cmelab:mainfrom
chrisjonesBSU:rdf-exclude-bond-depth

Conversation

@chrisjonesBSU

Copy link
Copy Markdown
Member

The current gsd_rdf method lets you exclude all pairs that belong to the same molecule. This was done initially to reduce huge signals in the RDF resulting from bonded neighbors. But, it's often too extreme of a correction, especially for polymers where you want to capture distances resulting from chains folding onto themselves. Instead, this new method lets you set bond exclusions based on bond depth (counted in steps down a bond graph). So, for a polymer, you might set an excluded depth to prevent pairs within a stiff region, but include pairs further down the chain.

I've tested it out with some simple single-chain trajectories, and it seems to be working exactly as intended. I'll try it on some bulk systems too.

Still left to do is make sure the normalization is being handled correctly.
Also, still need to get it working for excluding all bonded (to keep the old behavior).

@codecov

codecov Bot commented Mar 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.09091% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.29%. Comparing base (6a72164) to head (8fc3458).
⚠️ Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
cmeutils/structure.py 98.38% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #149      +/-   ##
==========================================
+ Coverage   96.24%   96.29%   +0.04%     
==========================================
  Files           8        8              
  Lines         773      810      +37     
==========================================
+ Hits          744      780      +36     
- Misses         29       30       +1     
Files with missing lines Coverage Δ
cmeutils/__init__.py 100.00% <100.00%> (ø)
cmeutils/geometry.py 97.56% <100.00%> (+0.63%) ⬆️
cmeutils/gsd_utils.py 91.66% <100.00%> (+1.19%) ⬆️
cmeutils/structure.py 99.55% <98.38%> (-0.45%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@chrisjonesBSU

Copy link
Copy Markdown
Member Author

I did some re-arranging. From structure.py I moved get_quarternions to geometry.py and get_centers to gsd_utils.py. I removed the all atom RDF function, since this new one can be used to find RDFs for all particles.

@chrisjonesBSU chrisjonesBSU linked an issue Mar 12, 2026 that may be closed by this pull request
@chrisjonesBSU

Copy link
Copy Markdown
Member Author

It seems to be working as intended on some test systems. Also, this solves a previous bug (that isn't posted anywhere, but has been discussed) where the g(r) values below the cutoff were affected by the choice of cutoff (e.g., g(r=2) was different when r_max was 3 than when r_max was 4)

excl_bond_depth r_cut_example

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the gsd_rdf function to support flexible pair exclusions based on bond graph depth, replacing the previous molecule-level exclude_bonded option. It also reorganizes code by moving get_quaternions to cmeutils/geometry.py, get_centers to cmeutils/gsd_utils.py, and removes the all_atom_rdf function (its functionality is subsumed by the updated gsd_rdf with A_name=None, B_name=None).

Changes:

  • Rewrote gsd_rdf with new exclude_bond_depth and exclude_all_bonded parameters, plus supporting functions get_excluded_pairs and filter_nlist that use networkx bond graphs.
  • Moved get_quaternions from structure.py to geometry.py and get_centers from structure.py to gsd_utils.py, updating tests and imports accordingly.
  • Added new test fixtures (AB_chain_gsd, LJ_gsd) and comprehensive tests for the new RDF exclusion logic.

Reviewed changes

Copilot reviewed 8 out of 10 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
cmeutils/structure.py Rewrote gsd_rdf with bond-depth exclusions; added get_excluded_pairs and filter_nlist; removed get_quaternions, get_centers, all_atom_rdf
cmeutils/gsd_utils.py Added snapshot_to_graph and moved get_centers here
cmeutils/geometry.py Moved get_quaternions here from structure.py
cmeutils/tests/test_structure.py Updated RDF tests for new API; moved get_quaternions/get_centers tests out
cmeutils/tests/test_gsd.py Added get_centers test
cmeutils/tests/test_geometry.py Added get_quaternions test
cmeutils/tests/base_test.py Added AB_chain_gsd and LJ_gsd fixtures
cmeutils/init.py Reformatted __all__ list
cmeutils/tests/assets/AB-traj.gsd New test asset for chain RDF tests

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread cmeutils/structure.py
Comment thread cmeutils/structure.py Outdated
Comment thread cmeutils/structure.py Outdated
Comment thread cmeutils/structure.py Outdated
Comment thread cmeutils/structure.py Outdated
Comment thread cmeutils/structure.py Outdated
Comment thread cmeutils/structure.py Outdated
Comment thread cmeutils/structure.py Outdated
@chrisjonesBSU

Copy link
Copy Markdown
Member Author

As of now, the normalization correction isn't accounting for updated bond graphs. We could compute single-frame RDFs and keep a list of normalization corrections (instead of using freud's accumulation). This would let us return standard deviations at each r value as well.

@chrisjonesBSU

Copy link
Copy Markdown
Member Author

I'm just going to remove the update_bond_graph option. It can be achieved by calling gsd_rdf in a for loop one frame at a time if needed (same with obtaining error bars for RDFs). I don't think wrapping it all up in this function is worth it at the moment.

@chrisjonesBSU
chrisjonesBSU merged commit 4b5f279 into cmelab:main Mar 12, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RDFs that ignore only certain pair types (e.g. 1-2, 1-3, 1-4)

2 participants