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

AttributeError: AtomGroup has no attribute charges #2536

Closed
laurapulido opened this issue Feb 18, 2020 · 13 comments
Closed

AttributeError: AtomGroup has no attribute charges #2536

laurapulido opened this issue Feb 18, 2020 · 13 comments
Labels
more information needed Please reply to requests for information or the issue will be closed. question

Comments

@laurapulido
Copy link

laurapulido commented Feb 18, 2020

I'm trying to use the potential_profile.py code available in the examples folder. After loading the topology and trajectory, I want to get the charges of all atoms in the system using the command universe.atoms.charges, but I get the following error:

AttributeError                            Traceback (most recent call last)
<ipython-input-26-a04736538ca1> in <module>
----> 1 universe.atoms.charges

/Applications/miniconda3/envs/MDAnalysis_Mdtraj/lib/python3.7/site-packages/MDAnalysis/core/groups.py in __getattr__(self, attr)
   2276                 pass
   2277         raise AttributeError("{cls} has no attribute {attr}".format(
-> 2278             cls=self.__class__.__name__, attr=attr))
   2279 
   2280     def __reduce__(self):

AttributeError: AtomGroup has no attribute charges
Actual behavior

What happened instead. Add as much detail as you can. Include (copy and paste) stack traces and any output.

Thank you for your help

@orbeckst
Copy link
Member

Does your topology file contain charges? The .charges attribute is only created if you have charges.

How did you load your Universe, i.e., what input files do you have?

@orbeckst orbeckst added more information needed Please reply to requests for information or the issue will be closed. question labels Feb 18, 2020
@richardjgowers
Copy link
Member

So on a dev level, maybe this message should grab some debug info from Universe (filenames) to make the message clearer?

@zemanj
Copy link
Member

zemanj commented Feb 18, 2020

So on a dev level, maybe this message should grab some debug info from Universe (filenames) to make the message clearer?

Yeah that will save some headaches. 👍

@zemanj
Copy link
Member

zemanj commented Feb 18, 2020

@richardjgowers BTW what is the rationale behind this whole AtomGroup argument injection machinery besides uncluttering tab completion?
IMHO raising exceptions due to missing TopologyAttrs should be the responsibility of Topology.
The fact that missing transplanted properties/methods raise unhelpful AttributeErrors has the potential to confuse users and has already led to some dirty workarounds on the dev side, see e.g. in *Group.wrap() and *Group.unwrap() (and there's more of that kind elsewhere).

@richardjgowers
Copy link
Member

richardjgowers commented Feb 18, 2020 via email

@zemanj
Copy link
Member

zemanj commented Feb 18, 2020

Here’s an example of where we catch an error and do better: https://github.com/MDAnalysis/mdanalysis/blob/develop/package/MDAnalysis/core/groups.py#L2218

I see your point, but keep in mind that this solution means we have to do the bookkeeping manually.
Also, the error mesage "<attr> not available; this requires Bonds" could be improved, especially because the error is often not triggered by the user trying to directly access some AtomGroup attribute but rather when trying to run some method such as unwrap().
Maybe the error message could be generalized to something like "The attribute/method you are trying to access is not available because your topology <insert topology filename if possible> doesn't contain information about <insert corresponding TopologyAttr>."

All that said, maybe we should include more attributes by default, ie charge, mass, name. I’ve been thinking of making AtomGroup a cython class, which ties in with this...

I'm all in favor of this. However, if we have attributes like masses and charges by default, shouldn't that also apply to related methods such as center_of_mass(), total_charge(), etc?

@richardjgowers
Copy link
Member

Yeah so associated methods would get included in with the mandatory attributes. One thing that would get a lot faster would be AG.center_of_mass() because it would be all C(++).

@zemanj
Copy link
Member

zemanj commented Feb 18, 2020

@laurapulido To give you a quick answer: The most likely reason for the error you are seeing is that the topology file format you used to construct your Universe doesn't contain charge information.
Unfortunately, the error message is not very clear about this.

I would appreciate it if you could tell us whether my (and @orbeckst's) guess is right (or wrong).

@laurapulido
Copy link
Author

Thank you for all your answers. I checked the topology file and I found that it doesn't have charges.

Thank you

@zemanj
Copy link
Member

zemanj commented Feb 20, 2020

Thanks @laurapulido for reporting back!
@richardjgowers @orbeckst Should we close this and open a new issue regarding improving the error handling/message?

@orbeckst
Copy link
Member

orbeckst commented Feb 20, 2020 via email

@orbeckst
Copy link
Member

@zemanj – you have been put in charge for closing this issue and opening a new one :-)

@zemanj
Copy link
Member

zemanj commented Feb 28, 2020

Superseded by #2565, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more information needed Please reply to requests for information or the issue will be closed. question
Projects
None yet
Development

No branches or pull requests

4 participants