When you use need to pass many arguments to a PLUMED action, being them components of a few collective variables or also multiple collective variables, you might find it convenient to use regular expressions.
Regular expressions are enclosed in round braces and must not contain spaces (the components names have no spaces indeed, so why use them?).
As an example the command:
d1: DISTANCE ATOMSthe pair of atom that we are calculating the distance between. =1,2 COMPONENTS( default=off ) calculate the x, y and z components of the distance separately and store them as label.x, PRINT ARGcompulsory keyword the labels of the values that you would like to print to the file =(d1\.[xy]) STRIDEcompulsory keyword ( default=1 ) the frequency with which the quantities of interest should be output =100 FILEthe name of the file on which to output these quantities =colvar FMTthe format that should be used to output real numbers =%8.4f
will cause both the d1.x and d1.y components of the DISTANCE action to be printed.
Notice that selection does not happen in alphabetic order, nor in the order in which [xy]
are listed, but rather in the order in which the two variables have been created by PLUMED. Also notice that the .
character must be escaped as \.
in order to interpret it as a literal .
. An un-escaped dot is a wildcard which is matched by any character, So as an example
d1: DISTANCE ATOMSthe pair of atom that we are calculating the distance between. =1,2 COMPONENTS( default=off ) calculate the x, y and z components of the distance separately and store them as label.x, dxy: DISTANCE ATOMSthe pair of atom that we are calculating the distance between. =1,3 # this will match d1.x,d1.y,dxy PRINT ARGcompulsory keyword the labels of the values that you would like to print to the file =(d1.[xy]) STRIDEcompulsory keyword ( default=1 ) the frequency with which the quantities of interest should be output =100 FILEthe name of the file on which to output these quantities =colvar FMTthe format that should be used to output real numbers =%8.4f # while this will match d1.x,d1.y only PRINT ARGcompulsory keyword the labels of the values that you would like to print to the file =(d1\.[xy]) STRIDEcompulsory keyword ( default=1 ) the frequency with which the quantities of interest should be output =100 FILEthe name of the file on which to output these quantities =colvar FMTthe format that should be used to output real numbers =%8.4f
You can concatenate more than one regular expression by using comma separated regular expressions. The resulting matches will be concatenated:
t1: TORSION ATOMSthe four atoms involved in the torsional angle =5,7,9,15 t2: TORSION ATOMSthe four atoms involved in the torsional angle =7,9,15,17 d1: DISTANCE ATOMSthe pair of atom that we are calculating the distance between. =7,17 COMPONENTS( default=off ) calculate the x, y and z components of the distance separately and store them as label.x, # The first expression matches d1.x and d1.y # The second expression matches t1 and t2 PRINT ARGcompulsory keyword the labels of the values that you would like to print to the file =(d1\.[xy]),(t[0-9]) STRIDEcompulsory keyword ( default=1 ) the frequency with which the quantities of interest should be output =100 FILEthe name of the file on which to output these quantities =colvar FMTthe format that should be used to output real numbers =%8.4f # Thus this is the same as ARG=d1.x,d1.y,t1,t2
Be aware that if you have overlapping selections they will be duplicated. As an alternative you could use the "or" operator |
:
t1: TORSION ATOMSthe four atoms involved in the torsional angle =5,7,9,15 t2: TORSION ATOMSthe four atoms involved in the torsional angle =7,9,15,17 d1: DISTANCE ATOMSthe pair of atom that we are calculating the distance between. =7,17 COMPONENTS( default=off ) calculate the x, y and z components of the distance separately and store them as label.x, # Here is a single regular expression PRINT ARGcompulsory keyword the labels of the values that you would like to print to the file =(d1\.[xy]|t[0-9]) STRIDEcompulsory keyword ( default=1 ) the frequency with which the quantities of interest should be output =100 FILEthe name of the file on which to output these quantities =colvar FMTthe format that should be used to output real numbers =%8.4f # Thus this is the same as ARG=t1,t2,d1.x,d1.y
this selects the same set of arguments as the previous example.
()
and only available when PLUMED has been compiled with the regex library, with the capability of PLUMED to use *
as a wildcard in arguments:
d1: DISTANCE ATOMSthe pair of atom that we are calculating the distance between. =1,2 COMPONENTS( default=off ) calculate the x, y and z components of the distance separately and store them as label.x, # this is a regular expression that selects all components of d1 # i.e. d1.x d1.y and d1.z PRINT ARGcompulsory keyword the labels of the values that you would like to print to the file =(d1\..*) STRIDEcompulsory keyword ( default=1 ) the frequency with which the quantities of interest should be output =100 FILEthe name of the file on which to output these quantities =colvar_reg FMTthe format that should be used to output real numbers =%8.4f # this is a wildcard that selects all the components of d1 as well PRINT ARGcompulsory keyword the labels of the values that you would like to print to the file =d1.* STRIDEcompulsory keyword ( default=1 ) the frequency with which the quantities of interest should be output =100 FILEthe name of the file on which to output these quantities =colvar_wild FMTthe format that should be used to output real numbers =%8.4fRegular expressions are way more flexible than wildcards!
You can check the log to see whether or not your regular expression is picking the set of components you desire.
For more information on regular expressions visit http://www.regular-expressions.info/reference.html.