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

Collect atomic gradients for combination cvcs #247

Merged
merged 3 commits into from
Apr 16, 2019
Merged

Conversation

jhenin
Copy link
Member

@jhenin 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)
@jhenin jhenin requested a review from giacomofiorin April 11, 2019 17:26
Copy link
Member

@giacomofiorin giacomofiorin left a 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);
Copy link
Member

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()?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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);
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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 :-)

// 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++) {
Copy link
Member Author

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!

@jhenin jhenin merged commit 42a5ec6 into master Apr 16, 2019
@giacomofiorin
Copy link
Member

Forgot to merge this, thanks. I updated the version strings in 9fab4ab

@giacomofiorin giacomofiorin deleted the collect_cvc_gradients branch April 17, 2019 12:46
jhenin added a commit that referenced this pull request Dec 16, 2019
Eerily similar to #286 and #247

I wonder if we could use a more general mechanism to avoid these dangling references.
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.

2 participants