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

Surface forces (after rebasing #488) #497

Merged
merged 106 commits into from
Nov 27, 2024

Conversation

ilfreddy
Copy link
Contributor

@ilfreddy ilfreddy commented Nov 8, 2024

Taken from PR #488 from @moritzgubler and rebased with the AZORA functionality which has just been merged in master.

Rest of the description verbatim from #488

This is my implementation of the idea I had of calculating forces with surface integrals.

It works quite well and the forces are more accurate. Also, mrchem struggles to compute forces when the world precision is 1e-7 or smaller. Then it requires a lot of memory (more than 32 GB for a H2 molecule). This is not the case with my approach . Geometry optimizations seem to be reliable if the stopping criterion is chosen 10 * world_prec.

I have already put all the parameters into the parser, so it is quite simple to test and run my code (look for the section "- name: Forces" in the template.yaml input parser file).

It works with lda and gga functionals and for both closed and open shell systems.
At the moment, there is one thing that might be improved in the future:

The exact exchange stress is not computed. Therefore forces can not be computed for exact exchange. It shouldn't be too complicated to implement, but in a quick search I did not find a reference that derives it.

@ilfreddy ilfreddy changed the title Surface forces Surface forces (after rebasing #488) Nov 9, 2024
Copy link

codecov bot commented Nov 9, 2024

Codecov Report

Attention: Patch coverage is 27.86561% with 1095 lines in your changes missing coverage. Please review.

Project coverage is 65.53%. Comparing base (764eb22) to head (dc430cf).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/surface_forces/xcStress.cpp 38.93% 80 Missing ⚠️
src/surface_forces/detail/lebedev_utils.cpp 38.31% 66 Missing ⚠️
src/surface_forces/LebedevData.cpp 13.33% 65 Missing ⚠️
src/surface_forces/detail/Lebedev_021_0170.hpp 0.00% 33 Missing ⚠️
src/surface_forces/detail/Lebedev_023_0194.hpp 0.00% 33 Missing ⚠️
src/surface_forces/detail/Lebedev_027_0266.hpp 0.00% 33 Missing ⚠️
src/surface_forces/detail/Lebedev_047_0770.hpp 0.00% 33 Missing ⚠️
src/surface_forces/detail/Lebedev_059_1202.hpp 0.00% 33 Missing ⚠️
src/surface_forces/detail/Lebedev_071_1730.hpp 0.00% 33 Missing ⚠️
src/surface_forces/detail/Lebedev_083_2354.hpp 0.00% 33 Missing ⚠️
... and 29 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #497      +/-   ##
==========================================
- Coverage   69.16%   65.53%   -3.64%     
==========================================
  Files         202      241      +39     
  Lines       15646    17141    +1495     
==========================================
+ Hits        10822    11233     +411     
- Misses       4824     5908    +1084     

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

@moritzgubler
Copy link
Contributor

moritzgubler commented Nov 19, 2024

@ilfreddy I have found two minor bugs that I would like to fix:

  1. change the default value of the parameter radius_factor from 0.6 to 0.5.
  2. Force calculation fails when only a single atom is present in the system (The force is of course zero but it should nevertheless work). This is because the radius of the integration sphere (0.5 times the bond length) is not defined. The fix would be in the distanceToNearestNeighbour function which must return 1.0 or any other positive value when only a single particle is considered.

Should I create a pull request for this branch?

@ilfreddy
Copy link
Contributor Author

@moritzgubler I think I have fixed what you asked. Could you check and the fixes, and then review the whole PR? Thereafter we can most likely merge it into master (assuming no test fails this time).

@ilfreddy
Copy link
Contributor Author

@moritzgubler the test fails with the new default, so I explicitly used 0.6 in the test. Although the gradient should in principle be the same, I assume this is a low prec calculation with an SCF which is not converged either. I therefore assume it is not granted the computed gradient makes physical sense at this stage.

@moritzgubler
Copy link
Contributor

In order to reduce testing time, I did not converge the SCF in the test (I basically copied the test from the Hellmann Feynman forces). The resulting forces do not make physical sense and even depend on the shape of the surface integral but I think this is ok for testing.

@ilfreddy
Copy link
Contributor Author

If you are OK with my fixes and you can review the whole PR, I believe this gan go now, unless @stigrj wants to have a look first.

Copy link
Contributor

@robertodr robertodr left a comment

Choose a reason for hiding this comment

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

Thanks @moritzgubler!

Comment on lines 482 to 486
:radius_factor: Sets the radius of the surface used in the computation of forces. The radius is given by this factor times the distance to the neariest neighbour. Must be between 0.1 and 0.9. This should rarely need to be changed. Different values can change the accuracy of the forces.

**Type** ``float``

**Default** ``0.6``
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't you change that to 0.5?

Comment on lines 48 to 49
LEBVEDEV_SOURCE_DIR="${LEBVEDEV_SOURCE_DIR}"
LEBVEDEV_INSTALL_DIR="${LEBVEDEV_INSTALL_DIR}"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can delete these lines

src/driver.cpp Outdated
@@ -57,6 +57,7 @@
#include "qmoperators/one_electron/NuclearOperator.h"
#include "qmoperators/one_electron/ZoraOperator.h"
#include "qmoperators/one_electron/AZoraPotential.h"
#include "qmoperators/one_electron/NablaOperator.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not needed

src/driver.cpp Outdated
Comment on lines 89 to 90
#include <fstream>
#include <filesystem>
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not needed


Forces {
method = 'surface_integrals'
radius_factor = 0.6
Copy link
Contributor

Choose a reason for hiding this comment

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

when the radius_factor is set here, the test should still work when the default is changed to 0.5

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed it does. With the added bonus that we test setting a non-default value 😄

stigrj and others added 2 commits November 26, 2024 16:51
Default value updated in the manual
Comment on lines 440 to 444
- name: radius_factor
type: float
default: 0.6
docstring: |
Sets the radius of the surface used in the computation of forces.
Copy link
Contributor

Choose a reason for hiding this comment

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

Here, the default is also not 0.5 did you run the parameter update script?

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 fixed that too now :-) Thanks for pointing that out!

@ilfreddy
Copy link
Contributor Author

If @moritzgubler and @stigrj are happy this one can finally go for my part.

@moritzgubler
Copy link
Contributor

The changes look good to me.

@ilfreddy ilfreddy merged commit ae09736 into MRChemSoft:master Nov 27, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants