Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper error message and suggestion for AlignTraj on trajectory without mass #2469

Closed
xiki-tempula opened this issue Jan 26, 2020 · 9 comments · Fixed by #2614
Closed

Proper error message and suggestion for AlignTraj on trajectory without mass #2469

xiki-tempula opened this issue Jan 26, 2020 · 9 comments · Fixed by #2614

Comments

@xiki-tempula
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Coarse-grain trajectory has no assigned mass but it still makes sense to use the AlignTraj. Thus, if one were to run.

u = mda.Universe(gro)
protein = u.select_atoms('bynum 1-518')
traj = mda.Universe(xtc, xtc)
AlignTraj(traj, protein, select='bynum 1-518', in_memory=True)

He will get

  File "pa.py", line 13, in plot
    AlignTraj(traj, protein, select='bynum 1-518', in_memory=True)
  File "/Users//GitHub/mdanalysis/package/MDAnalysis/analysis/align.py", line 668, in __init__
    strict=strict, match_atoms=match_atoms)
  File "/Users//GitHub/mdanalysis/package/MDAnalysis/analysis/align.py", line 1187, in get_matching_atoms
    mass_mismatches = (np.absolute(ag1.masses - ag2.masses) > tol_mass)
  File "/Users//GitHub/mdanalysis/package/MDAnalysis/core/groups.py", line 2294, in __getattr__
    cls=self.__class__.__name__, attr=attr))
AttributeError: AtomGroup has no attribute masses

I felt that there should be certain options to disable the check on mass if the weight is not set to mass.

Say if one run

AlignTraj(traj, protein, select='bynum 1-518', in_memory=True, weights=None)

Then the AlignTraj should work without checking for mass.

@richardjgowers
Copy link
Member

richardjgowers commented Jan 26, 2020 via email

@xiki-tempula
Copy link
Contributor Author

@richardjgowers Yes, I'm currently solving it by adding the mass. But I felt that since the AlignTraj doesn't require mass information in this case, it doesn't make sense by force the mass attribute to be present,

@lilyminium
Copy link
Member

lilyminium commented Jan 27, 2020

Try setting match_atoms=False. The only reason it checks masses is to try to enforce that the reference and mobile atoms are in the same order.

Edit: although I think that's only in the develop branch. And possibly it should be off by default anyway.

@xiki-tempula
Copy link
Contributor Author

@lilyminium Thanks. It seems to be working. It might be a good idea to document it.

@richardjgowers
Copy link
Member

I think this just needs a doc fix rather than a behaviour change. The case where all atoms are similar mass (so don't required weighting) is very niche, and I can see more people (with dissimilar masses) getting burnt by weighting being ignored when masses aren't available.

@richardjgowers richardjgowers changed the title Create an option for the AlignTraj to work on trajectory without mass Proper error message and suggestion ~~Create an option~~ for the AlignTraj to work on trajectory without mass Jan 28, 2020
@richardjgowers richardjgowers changed the title Proper error message and suggestion ~~Create an option~~ for the AlignTraj to work on trajectory without mass Proper error message and suggestion for AlignTraj on trajectory without mass Jan 28, 2020
@lilyminium
Copy link
Member

@richardjgowers weights=None by default in AlignTraj, so it doesn't weight alignment without explicitly turning it on. In this case it's dying because get_matching_atoms looks for 'mismatching' atoms by checking if any one pair has a difference higher than tol_mass. If you want to keep match_atoms=True by default then you could just change this line

to if match_atoms and hasattr(ag1, 'masses') and hasattr(ag2, 'masses')

@siddharthjain1611
Copy link
Member

@lilyminium I'm making the changes suggested by you hope these try to solve the problem of mismatching.

@siddharthjain1611 siddharthjain1611 mentioned this issue Mar 6, 2020
4 tasks
@siddharthjain1611
Copy link
Member

@lilyminium If could please spare some time to review my PR and suggest the changes required.

siddharthjain1611 added a commit to siddharthjain1611/mdanalysis that referenced this issue Mar 11, 2020
@siddharthjain1611 siddharthjain1611 mentioned this issue Mar 11, 2020
4 tasks
siddharthjain1611 added a commit to siddharthjain1611/mdanalysis that referenced this issue Mar 11, 2020
@lilyminium
Copy link
Member

@xiki-tempula actually I'm surprised your topology didn't have masses, because I thought that was a mandatory attribute that would be guessed if not given.

PicoCentauri pushed a commit to siddharthjain1611/mdanalysis that referenced this issue Mar 21, 2020
PicoCentauri pushed a commit to siddharthjain1611/mdanalysis that referenced this issue Mar 21, 2020
lilyminium pushed a commit that referenced this issue Mar 28, 2020
* Fixes issue #2469
* raise SelectionWarning if AlignTraj is called with match_atoms=True and masses are not present
* fit_translation and fit_trans_rot now raise TypeErrors (originally ValueErrors) for getting weights from atoms without masses
* get_weights now raises ValueError if weights is given as incorrect value (originally TypeError)

Co-authored-by: Philip Loche <ploche@physik.fu-berlin.de>
Co-authored-by: Oliver Beckstein <orbeckst@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants