Skip to content

Commit 66e7e5c

Browse files
BHM-Boborbeckst
andauthored
GNMAnalysis fixes #4924 (#4961)
* fix #4924 * fix-bug: package/MDAnalysis/analysis/gnm.py: closeContactGNMAnalysis: generate_kirchoff: fix residue_index_map generate to avoid use all atoms when select is 'name CA' * docs(AUTHORS): add BHM-Bob G to the list of authors * test(gnm): add test case for 'name CA' selection in closeContactGNMAnalysis * Add test case to verify correct behavior when selecting 'name CA' atoms * Ensure that all residues are included in the analysis, fixing the issue where only residues 0-14 were used * Validate the results against expected eigenvalues and Kirchhoff matrix * test(gnm): reformat test_closeContactGNMAnalysis_select_CA for better readability - Improved code formatting and line breaks for better readability * test(gnm): Update the test to use a higher precision (decimal=17) for eigenvalue comparison * docs(changelog): Add fix for bug in `analysis/gnm.py` in `closeContactGNMAnalysis` * test(gnm): relax precision in CloseContactGNMAnalysis eigenvalue test - Lowered precision in eigenvalue comparison to accommodate platform-specific results - Added comment about platform-specific results to explain the change in expected values * test(gnm): fit linters / black --------- Co-authored-by: Oliver Beckstein <[email protected]>
1 parent 35d9d2e commit 66e7e5c

File tree

4 files changed

+50
-6
lines changed

4 files changed

+50
-6
lines changed

package/AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ Chronological list of authors
250250
- Joshua Raphael Uy
251251
- Namir Oues
252252
- Lexi Xu
253+
- BHM-Bob G
253254

254255
External code
255256
-------------

package/CHANGELOG

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ The rules for this file:
1414

1515

1616
-------------------------------------------------------------------------------
17-
??/??/?? IAlibay, orbeckst
17+
??/??/?? IAlibay, orbeckst, BHM-Bob
1818

1919

2020
* 2.10.0
2121

2222
Fixes
23+
* Fixes bug in `analysis/gnm.py`: `closeContactGNMAnalysis`: correct the
24+
`residue_index_map` generation when selection is not `protein`.
25+
(Issue #4924, PR #4961)
2326

2427
Enhancements
2528

package/MDAnalysis/analysis/gnm.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,11 +458,7 @@ def __init__(
458458
def generate_kirchoff(self):
459459
nresidues = self.ca.n_residues
460460
positions = self.ca.positions
461-
residue_index_map = [
462-
resnum
463-
for [resnum, residue] in enumerate(self.ca.residues)
464-
for atom in residue.atoms
465-
]
461+
residue_index_map = self.ca.resindices.copy()
466462
matrix = np.zeros((nresidues, nresidues), dtype=np.float64)
467463
cutoffsq = self.cutoff**2
468464

testsuite/MDAnalysisTests/analysis/test_gnm.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,47 @@ def test_closeContactGNMAnalysis_weights_None(universe, client_GNMAnalysis):
175175
]
176176
)
177177
# fmt: on
178+
179+
180+
def test_closeContactGNMAnalysis_select_CA(universe, client_GNMAnalysis):
181+
# Issue #4924 fix the bug of CA selection
182+
gnm = mda.analysis.gnm.closeContactGNMAnalysis(
183+
universe, "name CA", weights=None
184+
)
185+
gnm.run(stop=2, **client_GNMAnalysis)
186+
result = gnm.results
187+
assert len(result.times) == 2
188+
assert_almost_equal(gnm.results.times, (0, 100), decimal=4)
189+
# without Issue #4924 fix, eigenvalues are [3.20010632e-16, 4.27574601e-16]
190+
# but use big totolerance to make sure PASS in each platform
191+
assert_almost_equal(
192+
gnm.results.eigenvalues,
193+
[3.57984776e-16, 3.53892581e-16],
194+
)
195+
gen = gnm.generate_kirchoff()
196+
# without Issue #4924 fix, gnm only use 0~14 residues for this data
197+
assert np.abs(gen[15]).sum() > 0
198+
# fmt: off
199+
assert_almost_equal(
200+
gen[0],
201+
[
202+
1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
203+
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
204+
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,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