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

u.select_atoms(...).bonds should return only bonds with atoms *inside* of the selection #2821

Closed
cbouy opened this issue Jul 3, 2020 · 7 comments · Fixed by #3200
Closed
Assignees
Milestone

Comments

@cbouy
Copy link
Member

cbouy commented Jul 3, 2020

No necessarily a bug, but I think it's worth mentioning:
When making a selection, should the resulting bonds only contain bonds where both atoms are in the selection, or should it return all bonds where at least one atom of the atomgroup is part of the bond ?

The current behavior is to return all bonds where at least one atom of the atomgroup is part of the bond

Code to reproduce the behavior

>>> import MDAnalysis as mda
>>> from rdkit import Chem

>>> mol = Chem.MolFromSequence("GAG")
>>> u = mda.Universe(mol)
>>> u.select_atoms("resid 2").indices
array([4, 5, 6, 7, 8])

>>> u.select_atoms("resid 2").bonds.indices
array([[2, 4],
       [4, 5],
       [5, 6],
       [5, 8],
       [6, 7],
       [6, 9]], dtype=int32)

image

Should it return only the green bonds, or should it return the green bonds and the yellow ones (between atoms 2-4 and 6-9) as well ?
The current behavior is green+yellow.

Current version of MDAnalysis

  • Which version are you using? (run python -c "import MDAnalysis as mda; print(mda.__version__)")
    2.0.0-dev0
  • Which version of Python (python -V)?
    Python 3.6.10
  • Which operating system?
    Ubuntu 18.04.4 LTS through a VM (WSL2)
@cbouy cbouy mentioned this issue Jul 3, 2020
7 tasks
@lilyminium
Copy link
Member

Try atomgroup_intersection(strict=True) -- not sure if there's a quicker way to do this. Maybe turning bonds etc into functions (ag.bonds(strict=True)) instead of properties would be easier.

ag = u.select_atoms('protein')
bonds = ag.bonds.atomgroup_intersection(ag, strict=True)

@cbouy
Copy link
Member Author

cbouy commented Jul 3, 2020

Great, thank you! Yes it looks a bit heavy to be honest, but I wouldn't expect users to use this everyday so...
I'm not sure if changing to ag.bonds() is a good idea, tbh as a new user I wouldn't expect bonds to be a method, it's a bit confusing. Maybe adding a get_bonds() with parameters could work ?

@lilyminium
Copy link
Member

lilyminium commented Jul 3, 2020 via email

@richardjgowers
Copy link
Member

richardjgowers commented Jul 3, 2020 via email

@orbeckst
Copy link
Member

orbeckst commented Jul 3, 2020

I agree:

personally would expect .bonds to only be the ones inside the atomgroup,

Well, you can go wild for 2.0... just raise an issue to change it. Probably applies to angles, dihedrals, etc as well.

Having an way to get bonded information with the outside world when you need it would be good. If it's an expert-level thing then maybe we don't need getters for everything, just a generic ag.get_bonded_type("bonds", outside=True) or similar might do it. You can then make it work for "atoms", "angles", "dihedrals", .... It would return different types, depending on the argument, which is perhaps not desirable, but still better than a proliferation of ag.get_X() that confuses users when they also have ag.X.

@orbeckst
Copy link
Member

orbeckst commented Jul 3, 2020

just raise an issue to change it

... or we can just decide that this is the issue where we decide to change it ;-). Then it should be consistent. though, and apply to all bonded attributes.

@orbeckst
Copy link
Member

I don't see any opposing views to the change so I am removing the proposal tag and rename the issue appropriately.

@orbeckst orbeckst removed the proposal label Jul 12, 2020
@orbeckst orbeckst added this to the 2.0 milestone Jul 12, 2020
@orbeckst orbeckst changed the title u.select_atoms(...).bonds returns bonds with atoms outside of the selection u.select_atoms(...).bonds should return only bonds with atoms *inside* of the selection Jul 12, 2020
@IAlibay IAlibay mentioned this issue Mar 14, 2021
9 tasks
@lilyminium lilyminium mentioned this issue Mar 14, 2021
4 tasks
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.

4 participants