-
Notifications
You must be signed in to change notification settings - Fork 134
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
Refactor: Unify the interfaces of Pulay terms of force and stress #5130
Conversation
The refactor of force or stress code should avoid the memory cost of |
You can delete those arrays in |
In PRs, try to fix the issues proposed by others, don‘t let others do anything to meet your demands. Nobody has the obligation to do something to meet your personal demands. You need to consider more for others. |
I didn't let others do anything to meet my demands. I'm meeting my demands by myself. |
b0113a1
to
208c057
Compare
Why need this change
To implement the analytical gradient of LR-TDDFT, we need to calculate:
where$(T+D^{Z})$ is a density matrix different from the ground-state (GS) one, and $\Lambda$ is a complicated energy density matrix different from the GS one.
However in the current code, the GS energy density matrix is hard-coded in
cal_fedm
, blocking me from implementing the feature.Additionally, I notice that if the energy density matrix is treated equally as the density matrix as the input argument, the Pulay terms of force can be abstracted to$\text{Tr}[D\frac{dH}{dr_x}]$ , and similarly $\frac{1}{\Omega}\text{Tr}[D\frac{dH}{dr_x}r_y]$ for stress, which can avoid a lot of duplicate code (
cal_fedm
,cal_ftvnl_dphi
andcal_fvnl_dphi
).What's changed
Unify
cal_fedm
,cal_ftvnl_dphi
andcal_fvnl_dphi
(both gamma-only and multi-k) into a new functioncal_pulay_fs
, where 3 overloads are provided:All of them above treat the (energy) density matrix as an input parameter, and the Hamiltonian term (any operator) is passed in the way according to the algorithm.