Skip to content

MDAnalysis.analysis.align.alignto won't reindex the atomgroup as is documented #2977

@xiki-tempula

Description

@xiki-tempula

Expected behavior

In the doc (https://docs.mdanalysis.org/1.0.0/documentation_pages/analysis/align.html#MDAnalysis.analysis.align.alignto), it is said:

Warning

The atom order for mobile and reference is only preserved when select is either “all” or None. In any other case, a new selection will be made that will sort the resulting AtomGroup by index and therefore destroy the correspondence between the two groups. It is safest not to mix ordered AtomGroups with selection strings.

So I would imagine that is select keyword is used, the atomgroup will be sorted by index before passing for alignment, which is not the case.

Actual behavior

The atom group won't be sorted even when the select is used.

Code to reproduce the behavior

>>> from MDAnalysisTests.datafiles import PDB_helix
>>> from MDAnalysis.analysis.align import alignto
>>> u = mda.Universe(PDB_helix)
>>> mobile = u.atoms[:4]
>>> mobile.ids
array([1, 2, 3, 4])
>>> mobile.ix
array([0, 1, 2, 3])
>>> ref = sum([u.atoms[3], u.atoms[2], u.atoms[1], u.atoms[0]])
>>> ref.ids
array([4, 3, 2, 1])
>>> ref.ix
array([3, 2, 1, 0])
>>> alignto(mobile, ref, select='bynum 1-4')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "~/GitHub/mdanalysis/package/MDAnalysis/analysis/align.py", line 492, in alignto
    match_atoms=match_atoms)
  File "~/GitHub/mdanalysis/package/MDAnalysis/analysis/align.py", line 1367, in get_matching_atoms
    raise SelectionError(errmsg)
MDAnalysis.exceptions.SelectionError: Inconsistent selections, masses differ by more than 0.1; mis-matching atoms are shown above.
>>> alignto(mobile, ref, select='bynum 1-3')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "~/GitHub/mdanalysis/package/MDAnalysis/analysis/align.py", line 492, in alignto
    match_atoms=match_atoms)
  File "~/GitHub/mdanalysis/package/MDAnalysis/analysis/align.py", line 1367, in get_matching_atoms
    raise SelectionError(errmsg)
MDAnalysis.exceptions.SelectionError: Inconsistent selections, masses differ by more than 0.1; mis-matching atoms are shown above.

So mobile and ref are essentially the same things with a different order. Using the select should sort them and thus, give them the same order, which is not the case. Related to #2976

Current version of MDAnalysis

  • Which version are you using? 2.0.0-dev0
  • Which version of Python (python -V)? 3.6
  • Which operating system? osx

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions