BioSimSpace
BioSimSpace copied to clipboard
Custom expression evaluation for steered Molecular Dynamics
The current sMD implementation allows to use RMSD, Distance and Torsion collective variables. I had a case where I had to use a custom function as one of my CVs (plumed docs). I think this is quite a niche case, but it could be a powerful way to add more flexibility to sMD protocols.
I have added a new CollectiveVariable.Expression
on branch feature-custom-smd
and also modified Process._plumed
to write out the PLUMED input file in a way that works with the custom expression. The key feature was defining the CVs that are part of the expression at the start of the PLUMED input file, but not adding them into the steering itself in the MOVINGRESTRAINT
part. I tried to write CollectiveVariable.Expression
to be consistent with BSS but of course make any changes that are needed. At the moment I have not modified the Metadynamics part (Process._plumed._createMetadynamicsConfig()
) but I can make the same changes if you are happt with what I did to the sMD (or simply make a custom expression not supported for it)
As an example, here is a notebook and associated data to illustrate how the code would be used to run sMD with a custom expression.
Thanks, this sounds great. I should be able to take a look through the code early next week and will get back to you with any comments / suggestions.
Thanks again for this, it will be a really useful feature.
I was wondering if we could assign a variable name to each collective variable to simplify the creation of expressions, e.g. if the user passes two CVs, then the expression should use something like cv0
and cv1
to refer to them. (We could just document how the user should refer to the CVs.) If they need components, they can use, e.g, cv0.x
. Components could be extracted using an appropriate regex, following which we make sure that the corresponding CV is set to use components, etc. This would mean that the user only needed to provide an expression (which is validated), rather than also needing to (potentially) provide vars and args.
I was also wondering how bounds are handled for the CUSTOM
CV? Are these taken from the bounds of the CVs used to build the expression, or is it also possible to set separate bounds for the CUSTOM
CV itself? At present the other CVs have some self-consistency checks to make sure that the bounds are valid, but this might be complicated for the CustomExpression
.
At the moment I have not modified the Metadynamics part (Process._plumed._createMetadynamicsConfig()) but I can make the same changes if you are happt with what I did to the sMD.
I'd be happy for you to add the same functionality for the regular metadynamics configuration writer too. It's definitely a feature that will be of general use.
So would the variable names be cv0, cv1, ...
in the order they appear in when the CV objects are being passed? And the expression would then be validated and corrected for writing into the plumed input?
E.g. if the user passes something like CollectiveVariable.Expression([var0, var1], "cv0.x-cv1.x")
(where var0
and var1
are CollectiveVariable.Distance
), then we would validate the expression to get
ARG=d1.x,d2.x
VAR=cv0,cv1
FUNC=cv0-cv1