Skip to content

Commit a26df04

Browse files
authored
BUG: combine cmaps when merging Universes (#5415)
- Fixes #3672 - add cmaps to the connection attributes that Merge() should remap and merge (avoids TypeError) - add regression test - update CHANGELOG - update AUTHORS
1 parent c1b821b commit a26df04

4 files changed

Lines changed: 27 additions & 2 deletions

File tree

package/AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ Chronological list of authors
281281
- Shubham Mittal
282282
- Charity Grey
283283
- Sai Udayagiri
284+
- Apoorva Verma
284285

285286
External code
286287
-------------

package/CHANGELOG

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ The rules for this file:
1717
??/??/?? IAlibay, orbeckst, marinegor, tylerjereddy, ljwoods2, marinegor,
1818
spyke7, talagayev, tanii1125, BradyAJohnston, hejamu, jeremyleung521,
1919
harshitgajjela-droid, kunjsinha, aygarwal, jauy123, Dreamstick9,
20-
ollyfutur, Amarendra22, charity-g, ParthUppal523
20+
ollyfutur, Amarendra22, charity-g, ParthUppal523, apoorva-01
2121

2222
* 2.11.0
2323

2424
Fixes
25+
* `Merge()` no longer raises a TypeError on Universes that have a `cmaps`
26+
attribute; cmaps are now combined like the other connection attributes
27+
(bonds, angles, dihedrals, impropers) (Issue #3672).
2528
* The `principal_axes` method in :class:`Masses` now uses
2629
`np.linalg.eigh` instead of `np.linalg.eig`, improving numerical
2730
stability. This may lead to slightly different results from previous

package/MDAnalysis/core/universe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2162,7 +2162,7 @@ def Merge(*args):
21622162
common_attrs = set.intersection(
21632163
*[set(dir(ag.universe._topology)) for ag in args]
21642164
)
2165-
tops = set(["bonds", "angles", "dihedrals", "impropers"])
2165+
tops = set(["bonds", "angles", "dihedrals", "impropers", "cmaps"])
21662166

21672167
attrs = []
21682168

testsuite/MDAnalysisTests/utils/test_modelling.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,24 @@ def test_merge_without_topology(self, u):
329329
assert len(u_merge.atoms.angles) == 0
330330
assert len(u_merge.atoms.dihedrals) == 0
331331
assert len(u_merge.atoms.impropers) == 0
332+
333+
def test_merge_with_cmaps(self, u):
334+
# cmaps are a connection attribute like bonds/angles, so Merge() must
335+
# route them through the connection path rather than treating them as a
336+
# plain array (Issue #3672).
337+
u.add_TopologyAttr(
338+
"cmaps", [[0, 1, 2, 3, 4], [100, 101, 102, 103, 104]]
339+
)
340+
341+
ag1 = u.atoms[:20]
342+
ag2 = u.atoms[100:110]
343+
u_merge = MDAnalysis.Merge(ag1, ag2)
344+
345+
# Both cmaps lie entirely within their atomgroup, so both survive and
346+
# are renumbered against the merged universe (ag2 is offset by len(ag1)).
347+
assert hasattr(u_merge.atoms, "cmaps")
348+
assert len(u_merge.atoms.cmaps) == 2
349+
merged = sorted(
350+
tuple(int(i) for i in c.indices) for c in u_merge.atoms.cmaps
351+
)
352+
assert merged == [(0, 1, 2, 3, 4), (20, 21, 22, 23, 24)]

0 commit comments

Comments
 (0)