-
Notifications
You must be signed in to change notification settings - Fork 57
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
Collect atomic gradients for combination cvcs #247
Conversation
jhenin
commented
Apr 11, 2019
- delegate work of colvar::collect_cvc_gradients(), which was very intrusive, to cvc::get_gradients()
- overload virtual get_gradients() in CVCs such as dihedPC
- enables gradient display for dihedPC in VMD dashboard
- could be extended to other "special" CVCs
- in the process fix destructor bug that lead to segfault (double delete)
- delegate work of colvar::collect_cvc_gradients(), which was very intrusive, to cvc::get_gradients() - overload virtual get_gradients() in CVCs such as dihedPC - enables gradient display for dihedPC in VMD dashboard - could be extended to other "special" CVCs - in the process fix destructor bug that lead to segfault (double delete)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly OK as is. Let me know if you prefer to let me deal with alpha_angles
, and what do you think about the computer-accessor split.
src/colvarcomp.h
Outdated
@@ -163,6 +163,10 @@ class colvar::cvc | |||
/// \brief Calculate finite-difference gradients alongside the analytical ones, for each Cartesian component | |||
virtual void debug_gradients(); | |||
|
|||
/// \brief Calculate atomic gradients and add them to the corresponding item in gradient vector | |||
/// May be overridden by CVCs that do not store their gradients in the classic way, see dihedPC | |||
virtual void get_gradients(std::vector<int> const &atom_ids, std::vector<cvm::rvector> &atomic_gradients); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally agree with the move to colvar::cvc
.
The name get_gradients()
just sounds a bit like a pure accessor. How about splitting it into collect_gradients()
and get_gradients()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is, there is no data structure to hold the gradients at the CVC level. I think that should be the case eventually, or something similar (as part of #61 ), but in the meantime I didn't see a solution to split these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is true, but even if the gradients aren't stored yet in the CVC object, they can still be an argument to both functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, the results of the gradient calculation cannot be stored anywhere but in the atomic_gradients
vector. If collect_gradients
does that, then there is nothing left for an accessor to do. Actually, I think that is the case, so let me rename this to collect_gradients
.
src/colvarcomp.h
Outdated
@@ -1148,6 +1152,8 @@ class colvar::dihedPC | |||
virtual ~dihedPC(); | |||
void calc_value(); | |||
void calc_gradients(); | |||
/// Re-implementation of cvc::get_gradients() to carry over atomic gradients of sub-cvcs | |||
void get_gradients(std::vector<int> const &atom_ids, std::vector<cvm::rvector> &atomic_gradients); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about colvar::alpha_angles
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually writing this raised the question of addressing this situation in a more generic way: a CVC that combines several sub-CVCs. I didn't move forward yet because I see a few obstacles to handling that in an elegant way, e.g.: (1) the precise mathematical combination will be specific to each combination CVC, and (2) the dependency system is not designed to handle this kind of "horizontal" dependency (CVC to another CVC), although that could probably be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems a bit of work to derive a general template function for only two exceptions. With one already covered, it's mostly a matter of who deals with the other one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That matter is now settled :-)
In passing, remove bug-causing destructor ~h_bond()
// fit gradients are in the unrotated (simulation) frame | ||
atomic_gradients[a] += coeff * fg.fit_gradients[k]; | ||
} | ||
for (size_t k = 0; k < ag.size(); k++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Realized treating all the atom group rotation cases was unnecessary for these sub-CVCs!
Forgot to merge this, thanks. I updated the version strings in 9fab4ab |