LCOV - code coverage report
Current view: top level - adjmat - ClusteringBase.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 34 39 87.2 %
Date: 2026-03-30 13:16:06 Functions: 6 8 75.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2015-2023 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 "ClusteringBase.h"
      23             : #include "AdjacencyMatrixBase.h"
      24             : #include "AdjacencyMatrixVessel.h"
      25             : 
      26             : namespace PLMD {
      27             : namespace adjmat {
      28             : 
      29          25 : void ClusteringBase::registerKeywords( Keywords& keys ) {
      30          25 :   ActionWithInputMatrix::registerKeywords( keys );
      31          25 : }
      32             : 
      33          17 : ClusteringBase::ClusteringBase(const ActionOptions&ao):
      34             :   Action(ao),
      35             :   ActionWithInputMatrix(ao),
      36          17 :   number_of_cluster(-1) {
      37          17 :   if( getAdjacencyVessel() ) {
      38          15 :     cluster_sizes.resize(getNumberOfNodes());
      39          15 :     which_cluster.resize(getNumberOfNodes());
      40          15 :     if( getNumberOfNodeTypes()!=1 ) {
      41           0 :       error("should only be running clustering with one base multicolvar in function");
      42             :     }
      43          15 :     if( !getAdjacencyVessel()->undirectedGraph() ) {
      44           0 :       error("input contact matrix is incompatible with clustering");
      45             :     }
      46             :   }
      47          34 :   if( keywords.exists("MATRIX") ) {
      48             :     std::vector<AtomNumber> fake_atoms;
      49          15 :     setupMultiColvarBase( fake_atoms );
      50             :   }
      51          17 : }
      52             : 
      53           8 : void ClusteringBase::turnOnDerivatives() {
      54             :   // Check base multicolvar isn't density probably other things shouldn't be allowed here as well
      55           8 :   if( (getAdjacencyVessel()->getMatrixAction())->getNumberOfBaseMultiColvars()>0 ) {
      56           7 :     if( getBaseMultiColvar(0)->isDensity() ) {
      57           0 :       error("DFS clustering cannot be differentiated if base multicolvar is DENSITY");
      58             :     }
      59             :   }
      60             : 
      61             :   // Ensure that derivatives are turned on in base classes
      62           8 :   ActionWithInputMatrix::turnOnDerivatives();
      63           8 : }
      64             : 
      65          26 : void ClusteringBase::calculate() {
      66             :   // All the clusters have zero size initially
      67        8219 :   for(unsigned i=0; i<cluster_sizes.size(); ++i) {
      68        8193 :     cluster_sizes[i].first=0;
      69        8193 :     cluster_sizes[i].second=i;
      70             :   }
      71             :   // Do the clustering bit
      72          26 :   performClustering();
      73             :   // Order the clusters in the system by size (this returns ascending order )
      74          26 :   std::sort( cluster_sizes.begin(), cluster_sizes.end() );
      75          26 : }
      76             : 
      77          74 : void ClusteringBase::retrieveAtomsInCluster( const unsigned& clust, std::vector<unsigned>& myatoms ) const {
      78             :   unsigned n=0;
      79          74 :   myatoms.resize( cluster_sizes[cluster_sizes.size() - clust].first );
      80       45287 :   for(unsigned i=0; i<getNumberOfNodes(); ++i) {
      81       45213 :     if( which_cluster[i]==cluster_sizes[cluster_sizes.size() - clust].second ) {
      82        3991 :       myatoms[n]=i;
      83        3991 :       n++;
      84             :     }
      85             :   }
      86          74 : }
      87             : 
      88           0 : bool ClusteringBase::areConnected( const unsigned& iatom, const unsigned& jatom ) const {
      89           0 :   return getAdjacencyVessel()->nodesAreConnected( iatom, jatom );
      90             : }
      91             : 
      92           8 : double ClusteringBase::getCutoffForConnection() const {
      93           8 :   return getAdjacencyVessel()->getCutoffForConnection();
      94             : }
      95             : 
      96             : }
      97             : }

Generated by: LCOV version 1.16