LCOV - code coverage report
Current view: top level - clusters - ClusterDiameter.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 17 17 100.0 %
Date: 2024-10-18 14:00:25 Functions: 2 3 66.7 %

          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_DIAMETER
      26             : /*
      27             : Print out the diameter of one of the connected components
      28             : 
      29             : As discussed in the section of the manual on \ref contactmatrix a useful tool for developing complex collective variables is the notion of the
      30             : so called adjacency matrix.  An adjacency matrix is an \f$N \times N\f$ matrix in which the \f$i\f$th, \f$j\f$th element tells you whether
      31             : or not the \f$i\f$th and \f$j\f$th atoms/molecules from a set of \f$N\f$ atoms/molecules are adjacent or not.  When analyzing these matrix
      32             : we can treat them as a graph and find connected components using some clustering algorithm.  This action is used in tandem with this form of analysis
      33             : to output the largest of the distances between the pairs of atoms that are connected together in a particular connected component.  It is important to
      34             : note that the quantity that is output by this action cannot be differentiated.  As such it cannot be used as a collective variable in a biased simulation.
      35             : 
      36             : \par Examples
      37             : 
      38             : The following input uses PLUMED to calculate a adjacency matrix that connects a pair of atoms if they both have a coordination number that is greater
      39             : than 2.0 and if they are within 6.0 nm of each other.  Depth first search clustering is used to find the connected components in this matrix.  The distance
      40             : between every pair of atoms that are within the largest of the clusters found is then calculated and the largest of these distances is output to a file named
      41             : colvar.
      42             : 
      43             : \plumedfile
      44             : # Calculate coordination numbers
      45             : c1: COORDINATIONNUMBER SPECIES=1-512 SWITCH={EXP D_0=4.0 R_0=0.5 D_MAX=6.0}
      46             : # Select coordination numbers that are more than 2.0
      47             : cf: MFILTER_MORE DATA=c1 SWITCH={RATIONAL D_0=2.0 R_0=0.1} LOWMEM
      48             : # Build a contact matrix
      49             : mat: CONTACT_MATRIX ATOMS=cf SWITCH={EXP D_0=4.0 R_0=0.5 D_MAX=6.0}
      50             : # Find largest cluster
      51             : dfs: DFSCLUSTERING MATRIX=mat
      52             : clust1: CLUSTER_PROPERTIES CLUSTERS=dfs CLUSTER=1
      53             : dia: CLUSTER_DIAMETER CLUSTERS=dfs CLUSTER=1
      54             : PRINT ARG=dia FILE=colvar
      55             : \endplumedfile
      56             : 
      57             : */
      58             : //+ENDPLUMEDOC
      59             : 
      60             : namespace PLMD {
      61             : namespace clusters {
      62             : 
      63             : class ClusterDiameter : public ActionShortcut {
      64             : public:
      65             :   static void registerKeywords(Keywords& keys);
      66             :   explicit ClusterDiameter(const ActionOptions&);
      67             : };
      68             : 
      69             : PLUMED_REGISTER_ACTION(ClusterDiameter,"CLUSTER_DIAMETER")
      70             : 
      71           4 : void ClusterDiameter::registerKeywords( Keywords& keys ) {
      72           4 :   ActionShortcut::registerKeywords( keys );
      73           8 :   keys.add("optional","ARG","calculate ths radius of the cluster that are in this particular cluster");
      74           8 :   keys.add("compulsory","ATOMS","the atoms that were used to calculate the matrix that was clustered");
      75           4 :   keys.setValueDescription("the largest of all the distances between the pairs of atom in the cluster");
      76          12 :   keys.needsAction("DISTANCE_MATRIX"); keys.needsAction("OUTER_PRODUCT"); keys.needsAction("CUSTOM");
      77           8 :   keys.needsAction("FLATTEN"); keys.needsAction("HIGHEST");
      78           4 : }
      79             : 
      80           2 : ClusterDiameter::ClusterDiameter(const ActionOptions& ao):
      81             :   Action(ao),
      82           2 :   ActionShortcut(ao)
      83             : {
      84             :   // Read in the argument
      85           4 :   std::string arg_str, atdata; parse("ARG",arg_str); parse("ATOMS",atdata);
      86             :   // Distance matrix
      87           4 :   readInputLine( getShortcutLabel() + "_dmat: DISTANCE_MATRIX GROUP=" + atdata );
      88             :   // Matrix of bonds in cluster
      89           4 :   readInputLine( getShortcutLabel() + "_bmat: OUTER_PRODUCT FUNC=x*y ARG=" + arg_str + "," + arg_str );
      90             :   // Product of matrices
      91           4 :   readInputLine( getShortcutLabel() + "_dcls: CUSTOM ARG=" + getShortcutLabel() + "_dmat," + getShortcutLabel() + "_bmat FUNC=x*y PERIODIC=NO");
      92             :   // Convert matrix to a vector to get highest
      93           4 :   readInputLine( getShortcutLabel() + "_vdcls: FLATTEN ARG=" + getShortcutLabel() + "_dcls" );
      94             :   // And take the highest value
      95           4 :   readInputLine( getShortcutLabel() + ": HIGHEST ARG=" + getShortcutLabel() + "_vdcls");
      96           2 : }
      97             : 
      98             : }
      99             : }

Generated by: LCOV version 1.16