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

Docs warning for charge in DielectricConstant #4263

Merged
merged 4 commits into from
Sep 2, 2023

Conversation

PicoCentauri
Copy link
Contributor

@PicoCentauri PicoCentauri commented Aug 28, 2023

Fixes #4262

Add a warning box to the documentation that only charge neutral systems can be handled by the current implementation.
See also #4249 for details on why this is important.

PR Checklist

  • Tests (we have a test for the error raise already.)?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

Developers certificate of origin


📚 Documentation preview 📚: https://mdanalysis--4263.org.readthedocs.build/en/4263/

@github-actions
Copy link

github-actions bot commented Aug 28, 2023

Linter Bot Results:

Hi @PicoCentauri! Thanks for making this PR. We linted your code and found the following:

There are currently no issues detected! 🎉

@codecov
Copy link

codecov bot commented Aug 28, 2023

Codecov Report

Patch coverage has no change and project coverage change: +0.01% 🎉

Comparison is base (e3354d1) 93.39% compared to head (a3d0bc6) 93.41%.

❗ Current head a3d0bc6 differs from pull request most recent head 1e5534c. Consider uploading reports for the commit 1e5534c to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4263      +/-   ##
===========================================
+ Coverage    93.39%   93.41%   +0.01%     
===========================================
  Files          170      183      +13     
  Lines        22224    23309    +1085     
  Branches      4065     4064       -1     
===========================================
+ Hits         20757    21775    +1018     
- Misses         951     1018      +67     
  Partials       516      516              
Files Changed Coverage Δ
package/MDAnalysis/analysis/dielectric.py 100.00% <ø> (ø)

... and 19 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -65,6 +65,10 @@ class DielectricConstant(AnalysisBase):
the usual case if electrostatics are handled with a Ewald summation
technique. See [Neumann1983]_ for details on the derivation.

.. warning::
Applying this class requires that no free charges, such as ions or
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a stupid question, if this is relying on an Ewald style summation, how well does it handle a system with a net charge?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, totally valid question. The answer will be a bit longer. sorry.

Ewald can handle systems with a net charge. You introduce a homogenous background charge that neutralizes the system, which will lead to an additional force an all atoms. This is unproblematic for homogenous systems but lead to severe artifacts in inhomogenous systems like membranes etc.

The equation we use here is derived for an Ewald boundary condition, meaning that the dielectric constant of sorrounding medium is a metal ($\varepsilon=\infty$). If you have other boundary conditions like when using reaction field or cutoff electrostatics the equation will change as described in the paper we cite. We use eq 26.4.3D because the derivation for an Ewald electrostatic leads to the same results as a reaction field with an dielectric constant of $\infty$.

Screenshot 2023-08-28 at 21 39 54

Now, why are charges a problem? The issue is that in the derivation you demand that Maxwell's equation for electric field

$$ \nabla \vec E = \frac{\rho}{\varepsilon_0} $$

where $\rho$ is the charge density is equal to zero: $\nabla \vec E = 0$. This means that no free charges are present. If you do not do this you will not end up with the equation we use.

Does this answer your question?

Copy link
Member

Choose a reason for hiding this comment

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

Do you think you could transfer this very insightful piece of writing to an issue for future reference. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes we sure. If people find it there.

@@ -65,6 +65,10 @@ class DielectricConstant(AnalysisBase):
the usual case if electrostatics are handled with a Ewald summation
technique. See [Neumann1983]_ for details on the derivation.

.. warning::
Applying this class requires that no free charges, such as ions or
Copy link
Member

Choose a reason for hiding this comment

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

Do you think you could transfer this very insightful piece of writing to an issue for future reference. :)

@@ -65,6 +65,10 @@ class DielectricConstant(AnalysisBase):
the usual case if electrostatics are handled with a Ewald summation
technique. See [Neumann1983]_ for details on the derivation.

.. warning::
Applying this class requires that no free charges, such as ions or
charged fragments, are present in the simulation.
Copy link
Member

Choose a reason for hiding this comment

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

@PicoCentauri perhaps I am misunderstanding but you can have no charged anything or is it that you need overall neutrality. Apologoies if silly q.

Copy link
Contributor Author

@PicoCentauri PicoCentauri Aug 29, 2023

Choose a reason for hiding this comment

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

Nono it is fine. This is really a bit tricky. There are even publications where people do this wrong.

As we do it in the assertion in the class' prepare function you need charge neutral molecules. In a classical MD world they can have of course have partial charges. In fact, they have to because otherwise the system's total dipole moment would be zero and with it the dielectric constant.

What you can not have are ions such as Na+ Cl- or other charged fragments i.e negative carboxylic acid groups COO- or positive amine groups H3N+.

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.

Im happy with the warning as is, once we resolve conflicts I think we can merge and address better documentation in #4262.

Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

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

LGTM. Apologies I jumped in here and fixed the changelog conflicts. (no need to wait for CI again, this is a docs change anyways)

@IAlibay IAlibay merged commit c2e6df9 into MDAnalysis:develop Sep 2, 2023
@PicoCentauri PicoCentauri deleted the dielectric_warn branch June 5, 2024 15:55
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.

[Docs] document limits of DielectricConstant
3 participants