Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2014-2020 The plumed team 3 : (see the PEOPLE file at the root of the distribution for a list of names) 4 : 5 : See http://www.plumed.org for more information. 6 : 7 : This file is part of plumed, version 2. 8 : 9 : plumed is free software: you can redistribute it and/or modify 10 : it under the terms of the GNU Lesser General Public License as published by 11 : the Free Software Foundation, either version 3 of the License, or 12 : (at your option) any later version. 13 : 14 : plumed is distributed in the hope that it will be useful, 15 : but WITHOUT ANY WARRANTY; without even the implied warranty of 16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 : GNU Lesser General Public License for more details. 18 : 19 : You should have received a copy of the GNU Lesser General Public License 20 : along with plumed. If not, see <http://www.gnu.org/licenses/>. 21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ 22 : #include "core/ActionShortcut.h" 23 : #include "core/ActionRegister.h" 24 : #include "multicolvar/MultiColvarShortcuts.h" 25 : 26 : //+PLUMEDOC CONCOMP CLUSTER_PROPERTIES 27 : /* 28 : Calculate properties of the distribution of some quantities that are part of a connected component 29 : 30 : __This shortcut action is present to ensure that inputs for older PLUMED versions remain compatible. We STRONGLY 31 : encourage you to use the newer (and simpler) syntax for clustering calculations__ Look at the documentation for 32 : CLUSTER_WEIGHTS and the expanded version of the input below to see how this new input syntax operates. 33 : 34 : This collective variable was developed for looking at nucleation phenomena, where you are 35 : interested in using studying the behavior of atoms in small aggregates or nuclei. In these sorts of 36 : problems you might be interested in the degree the atoms in a nucleus have adopted their crystalline 37 : structure or (in the case of heterogeneous nucleation of a solute from a solvent) you might be 38 : interested in how many atoms are present in the largest cluster. 39 : 40 : The input below calculates the coordination numbers of atoms 1-100 and then computes the an adjacency 41 : matrix whose elements measures whether atoms $i$ and $j$ are within 0.55 nm of each other. The action 42 : labelled dfs then treats the elements of this matrix as zero or ones and thus thinks of the matrix as defining 43 : a graph. This dfs action then finds the largest connected component in this graph. The sum of the coordination 44 : numbers for the atoms in this largest connected component are then computed and this quantity is output to a colvar 45 : file. 46 : 47 : ```plumed 48 : lq: COORDINATIONNUMBER SPECIES=1-100 SWITCH={CUBIC D_0=0.45 D_MAX=0.55} 49 : cm: CONTACT_MATRIX GROUP=lq SWITCH={CUBIC D_0=0.45 D_MAX=0.55} 50 : dfs: DFSCLUSTERING ARG=cm 51 : clust1: CLUSTER_PROPERTIES ARG=lq CLUSTERS=dfs CLUSTER=1 SUM 52 : PRINT ARG=clust1.sum FILE=colvar 53 : ``` 54 : 55 : */ 56 : //+ENDPLUMEDOC 57 : 58 : namespace PLMD { 59 : namespace clusters { 60 : 61 : class ClusterProperties : public ActionShortcut { 62 : public: 63 : static void registerKeywords(Keywords& keys); 64 : explicit ClusterProperties(const ActionOptions&); 65 : }; 66 : 67 : PLUMED_REGISTER_ACTION(ClusterProperties,"CLUSTER_PROPERTIES") 68 : 69 54 : void ClusterProperties::registerKeywords(Keywords& keys) { 70 54 : ActionShortcut::registerKeywords( keys ); 71 54 : keys.add("compulsory","ARG","calculate the sum of the arguments calculated by this action for the cluster"); 72 54 : keys.add("compulsory","CLUSTERS","the label of the action that does the clustering"); 73 54 : keys.add("compulsory","CLUSTER","1","which cluster would you like to look at 1 is the largest cluster, 2 is the second largest, 3 is the the third largest and so on."); 74 108 : keys.setValueDescription("vector","a vector that is one if the atom is part of the cluster or interest and zero otherwise"); 75 54 : multicolvar::MultiColvarShortcuts::shortcutKeywords( keys ); 76 54 : keys.needsAction("CLUSTER_WEIGHTS"); 77 54 : } 78 : 79 20 : ClusterProperties::ClusterProperties(const ActionOptions& ao): 80 : Action(ao), 81 20 : ActionShortcut(ao) { 82 : // Read the property we are interested in 83 : std::string argstr; 84 40 : parse("ARG",argstr); 85 : // Read in the shortcut keywords 86 : std::map<std::string,std::string> keymap; 87 20 : multicolvar::MultiColvarShortcuts::readShortcutKeywords( keymap, this ); 88 : // Create a cluster weights object 89 40 : readInputLine( getShortcutLabel() + ": CLUSTER_WEIGHTS " + convertInputLineToString() ); 90 : // Now do the multicolvar bit 91 20 : multicolvar::MultiColvarShortcuts::expandFunctions( getShortcutLabel(), argstr, getShortcutLabel(), keymap, this ); 92 20 : } 93 : 94 : } 95 : }