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

Add dipole and quadrupole caclulation in AtomGroup #3842

Merged
merged 23 commits into from
Jan 24, 2023

Conversation

jaclark5
Copy link
Contributor

Fixes #3841

Changes made in this Pull Request:

  • Added dipole and quadrupole moments to AtomGroup topology methods

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

@codecov
Copy link

codecov bot commented Sep 21, 2022

Codecov Report

Base: 93.50% // Head: 93.52% // Increases project coverage by +0.02% 🎉

Coverage data is based on head (f3ee76f) compared to base (363037a).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3842      +/-   ##
===========================================
+ Coverage    93.50%   93.52%   +0.02%     
===========================================
  Files          190      190              
  Lines        24943    25028      +85     
  Branches      3523     3542      +19     
===========================================
+ Hits         23322    23407      +85     
  Misses        1100     1100              
  Partials       521      521              
Impacted Files Coverage Δ
package/MDAnalysis/core/topologyattrs.py 96.09% <100.00%> (+0.29%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jaclark5, another awesome contribution that is coming along super nicely. I think this would be a well used and useful addition. 🥇

This is mostly a review for style rather than scientific correctness, I will try and circle back for a more detailed look ASAP.

One thing that would be great is if you could make some test cases that are easy to reason about, eg dipole/quadruplepole moments that should be zero by virtue of equally separated charges, or moments that should all be a certain value etc etc.

package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
testsuite/MDAnalysisTests/core/test_accumulate.py Outdated Show resolved Hide resolved
Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, this looks quite useful. I'd advocate for extending it to also return dipolevector and quadrupoletensors instead of just scalar moments. Otherwise see various comments on notation. Sorry, did not have time to look at code in depth.

package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
@jaclark5
Copy link
Contributor Author

Thanks, I do think returning the quadrupole moment is something that must happen. Most people calculate the quadrupole moment with just the diagonal elements and it's only Gray and Gubbins that specify this method of calculating it will all information in the tensor. Additionally, the quadrupole moment can not be easily adjusted for it's origin and is very origin dependent. All these factors are a lot to handle for a user. I'm willing to add two additional dipole_vector, and quadrupole_tensor though (and then change the definition of dipole_moment)

Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great, see my comments. :)

@@ -27,6 +27,7 @@ dependencies:
- tqdm>=4.43.0
- sphinxcontrib-bibtex
- sphinx_rtd_theme
- pyyaml>=3.02
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaclark5 what is this addition for exactly? I might have missed it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new citation method won't compile without this constraint.

package/CHANGELOG Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Show resolved Hide resolved
@@ -15,6 +15,7 @@ numpy>=1.20.0
packaging
parmed
pytest
pyyaml>=3.02
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the pyyaml addition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this constraint to all files that check for the sphinx installation since this constraint allows the citations to be compiled.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im surprised the docs arn't working normally...

Perhaps fix the CHANGELOG conflicts and re-trigger CI and I'll have a look.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So to be clear, you want me to remove this change and then run the CI so you can see the error? I'm 90% sure that the failure in #3905 is this same failure, so I could also add this change to that PR to show that it's resolved.

Copy link
Contributor Author

@jaclark5 jaclark5 Dec 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hmacdope I tried to look through my browsing history to find the site where I found the answer, but I didn't find it. I thiiiink I took a shot in the dark based on this statement (https://avocado-framework.readthedocs.io/en/latest/releases/44_0.html?highlight=pyyaml#documentation) and it worked.

Here is the link to the check-logs for this PR where you see the same errors that are now presenting in #3905, illustrating that the issue is consistent between the two.https://github.com/MDAnalysis/mdanalysis/actions/runs/3159210367/jobs/5142154816

Also I did give a heads up about this to the citation work that is under development in Oct as seen here:
MDAnalysis/UserGuide#212

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I'm coming here a bit blind to this whole issue, but why requirements.txt? Is this for an issue with running things locally?

Re: CI, as far as I'm aware either uses optional deps defined in the github action or the environment.yaml file under maintainer.

Copy link
Contributor Author

@jaclark5 jaclark5 Dec 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was for an issue with compiling the docs with CI, and I can't remember if I had the same issue locally. Although it appears that this is not longer an issue since the other PR with the same issue compiled the docs in CI (#3905). There must have been a change somewhere within the past week that resolved it in a different way.

I'll remove the commits that added these dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok in theory I should be able to remove the two commits involved in this thread (first to add the dependencies and then to remove them). However, I keep making a mess, could I get some advice?

  1. git rebase -i HEAD~30, this shows a list of all previous commits from both me and the develop branch.
  2. At the commits of interest, I change "pick" to "drop" and then save and quit in vi
  3. A conflict in the CHANGELOG appears (like always) and asks me to change it. If I do, git adds the change to someone else's commit, so instead I type git rebase --skip a million times and the conflict is eventually resolved down the line.
  4. I can then force push these changes to GitHub, however, all commits from the development branch now show up on this PR with the label "@soandso authored, @jaclark5 committed". I don't like this so then I reflog locally to undo everything and force push that.

Is there something I should be doing differently?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually squash merge PRs, so history doesn't usually end up being an issue, would this fix things here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, if you mean that squashing the commits will cancel out the two that I want to remove, then yes :). Ok I think this is good to go then if I've addressed all of @hmacdope's concerns (I think I have).

Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaclark5 I have a bunch of small nit-picks on the formatting and style.

  • PEP8 — please leave space after comma, no space after assignment in argument list
  • when boldfacing variable names as vectors, please do not boldface subscripts
  • please be clear about semantics of equations and just say in words what operations mean because not everyone is using the same symbols for operations

I really like the PR, I just don't want to have to come back to it later and fix up little things. Thank you!

package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for addressing my nit-picks. I added a bunch of final text fixes and I'll commit them myself in a moment and when all passes and I didn't break the docs then I'll approve.

package/MDAnalysis/core/topologyattrs.py Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Show resolved Hide resolved
@orbeckst
Copy link
Member

Sorry, I broke the docs somewhere...

Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks super good just one or two nitpicks. One last annoying request, could we have a toy test with 0 dipole and quadrupole by virtue of symmetry? Would be easy to reason about.

package/CHANGELOG Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
@jaclark5
Copy link
Contributor Author

Hey I'll get to these @hmacdope, but I did add a case with exactly zero dipole and quadrupole, namely methane in the tests. Does that not satisfy your intention? Otherwise, I'm going to need a better idea of what you expect.

@hmacdope
Copy link
Member

hmacdope commented Dec 19, 2022

Hey I'll get to these @hmacdope, but I did add a case with exactly zero dipole and quadrupole, namely methane in the tests. Does that not satisfy your intention? Otherwise, I'm going to need a better idea of what you expect.

No spot on. All good from my end! Just update for new CHANGELOG. I'll approve now when changelog is fixed, and merge in a few days if no other comments from @MDAnalysis/coredevs.

@hmacdope hmacdope self-requested a review December 19, 2022 05:20
package/MDAnalysis/core/topologyattrs.py Outdated Show resolved Hide resolved
Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to approve here as my comments have been addressed. See @IAlibay's outstanding review.

@hmacdope
Copy link
Member

Actually I'm going to block here on CI issues, @jaclark5 can you reproduce these locally?

Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the great contribution.

@IAlibay
Copy link
Member

IAlibay commented Jan 19, 2023

Went ahead and merged - should be good to merge once CI is green

@jaclark5
Copy link
Contributor Author

The error is: testsuite/MDAnalysisTests/datafiles.py:288:89: E501 line too long (89 > 88 characters) [flake8]

This line isn't part of this contribution, but should I fix it anyway?

@IAlibay
Copy link
Member

IAlibay commented Jan 20, 2023

The error is: testsuite/MDAnalysisTests/datafiles.py:288:89: E501 line too long (89 > 88 characters) [flake8]

This line isn't part of this contribution, but should I fix it anyway?

Nope, you can ignore that, datafiles is one of those we don't care about re: PEP8. Darken doesn't know not to look at certain files (I think we can set up an file with some excludes, we probably should do that eventually).

@IAlibay
Copy link
Member

IAlibay commented Jan 20, 2023

I'm just going to cycle CI again since we just merged a bunch of stuff, if that returns green I think it's good to go.

@hmacdope hmacdope merged commit d73523f into MDAnalysis:develop Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AtomGroup Dipole and Quadrupole Moment
4 participants