Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2015-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 : 25 : //+PLUMEDOC CONCOMP CLUSTER_NATOMS 26 : /* 27 : Calculate the number of atoms in the cluster of interest 28 : 29 : An example input that determines the number of atoms in the second largest cluster that is identified by 30 : analysing the connected components of a [CONTACT_MATRIX](CONTACT_MATRIX.md) using [DFSCLUSTERING](DFSCLUSTERING.md) is shown below: 31 : 32 : ```plumed 33 : # Calculate a contact matrix between the first 100 atoms in the configuration 34 : cm: CONTACT_MATRIX GROUP=1-100 SWITCH={CUBIC D_0=0.45 D_MAX=0.55} 35 : # Find the connected components from the contact matrix 36 : dfs: DFSCLUSTERING ARG=cm 37 : # And determine the size of the second largest cluster that was identified 38 : c1: CLUSTER_NATOMS CLUSTERS=dfs CLUSTER=2 39 : PRINT ARG=c1 FILE=colvar 40 : ``` 41 : 42 : __The output from this action is NOT differentiable__ 43 : 44 : */ 45 : //+ENDPLUMEDOC 46 : 47 : namespace PLMD { 48 : namespace clusters { 49 : 50 : class ClusterNatoms : public ActionShortcut { 51 : public: 52 : static void registerKeywords(Keywords& keys); 53 : explicit ClusterNatoms(const ActionOptions&); 54 : }; 55 : 56 : PLUMED_REGISTER_ACTION(ClusterNatoms,"CLUSTER_NATOMS") 57 : 58 4 : void ClusterNatoms::registerKeywords(Keywords& keys) { 59 4 : ActionShortcut::registerKeywords( keys ); 60 4 : keys.add("compulsory","CLUSTERS","the label of the action that does the clustering"); 61 4 : 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."); 62 8 : keys.setValueDescription("scalar","the number of atoms in the cluster"); 63 4 : keys.needsAction("CLUSTER_WEIGHTS"); 64 4 : keys.needsAction("SUM"); 65 4 : } 66 : 67 2 : ClusterNatoms::ClusterNatoms(const ActionOptions& ao): 68 : Action(ao), 69 2 : ActionShortcut(ao) { 70 : // Create a cluster weights object 71 4 : readInputLine( getShortcutLabel() + "_weights: CLUSTER_WEIGHTS " + convertInputLineToString() ); 72 : // Add all the weights together (weights are 1 or 0) 73 4 : readInputLine( getShortcutLabel() + ": SUM ARG=" + getShortcutLabel() + "_weights PERIODIC=NO"); 74 2 : } 75 : 76 : } 77 : }