This PR contains several improvements to colvar::cvc and its derived classes, including substantial simplification of the code and some fixes where the previous implementation was incorrect (distanceVec metrics) or less robust (period).
There is now only one type of CVC constructor, which takes no arguments: this removes the need to maintain two different types of constructor. init(conf) now initializes an object from the configuration string, by modifying existing defaults.
Default values for plain old data are set right where the member is declared in the header, at long last! :-)
(Fix) The distanceVec metric functions are now consistent with the documentation.
There is no longer a need to explicitly derive the metric functions: the base class assumes a scalar-valued function, and only special cases are overridden. A ton of duplicated functions were removed with this.
period can now be set only for those CVCs that allow it: that includes distanceZ as well all periodic angles (only where someone needs something else than 360°).
std::shared_ptr is now used to collect the CVC objects inside the colvar level. I have not yet touched the arrays of CVC pointers inside complex CVC objects (e.g. the protein CVCs or the combination ones) because those will be modified anyway in upcoming work.
Other possible improvements that were out of scope to do:
Because all CVCs have now a derived init() function, it would be theoretically possible to call that from colvar::update_cvc_config(), i.e. the backend for the modifycvcs scripting command. Currently, the base class method cvc::init() is still called, because not all the derived ones are idempotent yet.
Atom groups could now be tracked much better with smart pointers, allowing them to be shared to save data/computation (this is done in #644).
colvarcomp.h could be split up to reduce interdependencies.
Feature objects could definitely use some smart-pointer love, too.
This PR contains several improvements to
colvar::cvc
and its derived classes, including substantial simplification of the code and some fixes where the previous implementation was incorrect (distanceVec
metrics) or less robust (period
).init(conf)
now initializes an object from the configuration string, by modifying existing defaults.distanceVec
metric functions are now consistent with the documentation.period
can now be set only for those CVCs that allow it: that includesdistanceZ
as well all periodic angles (only where someone needs something else than 360°).std::shared_ptr
is now used to collect the CVC objects inside the colvar level. I have not yet touched the arrays of CVC pointers inside complex CVC objects (e.g. the protein CVCs or the combination ones) because those will be modified anyway in upcoming work.Other possible improvements that were out of scope to do:
init()
function, it would be theoretically possible to call that fromcolvar::update_cvc_config()
, i.e. the backend for themodifycvcs
scripting command. Currently, the base class methodcvc::init()
is still called, because not all the derived ones are idempotent yet.colvarcomp.h
could be split up to reduce interdependencies.