Define collective variables in the Python language.
A Python module named in the IMPORT
keyword is first imported. The function passed as the FUNCTION
keyword is called at each time step. It is assumed to receive a numpy array of shape (N,1)
, N being the number of arguments passed at the ARG
keyword. See also CUSTOM.
The function should return two values: a scalar (the CV value), and its gradient with respect to each coordinate (an array of the same shape as the input). Not returning the gradient will prevent biasing from working (with warnings).
Automatic differentiation and transparent compilation (including to GPU) can be performed via Google's JAX library: see PYTHONCV.
The following example mimics the one in CUSTOM.
dAB: DISTANCEMETAD ARG=diff WIDTH=0.1 HEIGHT=0.5 BIASFACTOR=10 PACE=100ATOMS=10,12 dAC: DISTANCEthe pair of atom that we are calculating the distance between.ATOMS=10,15 diff: PYTHONFUNCTIONthe pair of atom that we are calculating the distance between.ARG=dAB,dACcould not find this keywordIMPORT=pythonfunctioncould not find this keywordFUNCTION=diffcould not find this keywordPERIODIC=NOcould not find this keyword
The file pythonfunction.py
should contain something as follows.
Use PYTHONCV if you are dealing with atom coordinates directly.
Please see PYTHONCV for installation and automatic differentiation.
See CUSTOM for a non-Python equivalent.