LCOV - code coverage report
Current view: top level - adjmat - ClusterAnalysisBase.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 45 54 83.3 %
Date: 2026-03-30 13:16:06 Functions: 12 15 80.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 "ClusterAnalysisBase.h"
      23             : 
      24             : namespace PLMD {
      25             : namespace adjmat {
      26             : 
      27          70 : void ClusterAnalysisBase::registerKeywords( Keywords& keys ) {
      28          70 :   MultiColvarBase::registerKeywords( keys );
      29         140 :   keys.add("compulsory","CLUSTERS","the label of the action that does the clustering");
      30          70 : }
      31             : 
      32          54 : ClusterAnalysisBase::ClusterAnalysisBase(const ActionOptions& ao):
      33             :   Action(ao),
      34             :   MultiColvarBase(ao),
      35         108 :   myfvals(0,0),
      36          54 :   myfatoms( myfvals, this ),
      37          54 :   myclusters(NULL) {
      38             :   // This makes these colvars behave appropriately with dump and analysis
      39          54 :   matsums=usespecies=true;
      40             :   std::vector<AtomNumber> fake_atoms;
      41             :   // Find what action we are taking the clusters from
      42         108 :   if( !parseMultiColvarAtomList("CLUSTERS",-1,fake_atoms ) ) {
      43           0 :     error("unable to interpret input CLUSTERS" );
      44             :   }
      45          54 :   if( mybasemulticolvars.size()!=1 ) {
      46           0 :     error("should be exactly one multicolvar input");
      47             :   }
      48          54 :   atom_lab.resize(0);
      49          54 :   myclusters = dynamic_cast<ClusteringBase*>( mybasemulticolvars[0] );
      50          54 :   if( !myclusters ) {
      51           0 :     error("input label is not that of a DFS object");
      52             :   }
      53             :   // Setup the atom pack
      54          54 :   myfatoms.setNumberOfAtoms( myclusters->getNumberOfNodes() );
      55          54 :   myfvals.getIndices().resize( myclusters->getNumberOfNodes() );
      56       33703 :   for(unsigned i=0; i<myclusters->getNumberOfNodes(); ++i) {
      57             :     myfatoms.setAtomIndex( i, i );
      58             :   }
      59          54 : }
      60             : 
      61           8 : void ClusterAnalysisBase::turnOnDerivatives() {
      62             :   // Check for dubious vessels
      63          18 :   for(unsigned i=0; i<getNumberOfVessels(); ++i) {
      64          20 :     if( getPntrToVessel(i)->getName()=="MEAN" ) {
      65           0 :       error("MEAN of cluster is not differentiable");
      66             :     }
      67          20 :     if( getPntrToVessel(i)->getName()=="VMEAN" ) {
      68           0 :       error("VMEAN of cluster is not differentiable");
      69             :     }
      70             :   }
      71           8 :   MultiColvarBase::turnOnDerivatives();
      72           8 : }
      73             : 
      74        2073 : unsigned ClusterAnalysisBase::getNumberOfQuantities() const {
      75        2073 :   return myclusters->getNumberOfQuantities();
      76             : }
      77             : 
      78    15981876 : unsigned ClusterAnalysisBase::getNumberOfNodes() const {
      79    15981876 :   return myclusters->getNumberOfNodes();
      80             : }
      81             : 
      82           4 : unsigned ClusterAnalysisBase::getNumberOfClusters() const {
      83           4 :   return myclusters->getNumberOfClusters();
      84             : }
      85             : 
      86          11 : bool ClusterAnalysisBase::isPeriodic() {
      87          11 :   return mybasemulticolvars[0]->isPeriodic();
      88             : }
      89             : 
      90          66 : void ClusterAnalysisBase::retrieveAtomsInCluster( const unsigned& clust, std::vector<unsigned>& myatoms ) const {
      91          66 :   myclusters->retrieveAtomsInCluster( clust, myatoms );
      92          66 : }
      93             : 
      94           1 : bool ClusterAnalysisBase::nodeIsActive( const unsigned& ind ) const {
      95           1 :   return myclusters->isCurrentlyActive( ind );
      96             : }
      97             : 
      98        1801 : void ClusterAnalysisBase::getPropertiesOfNode( const unsigned& ind, std::vector<double>& vals ) const {
      99        1801 :   myclusters->getInputData( ind, false, myfatoms, vals );
     100        1801 : }
     101             : 
     102        1604 : void ClusterAnalysisBase::getNodePropertyDerivatives( const unsigned& ind, MultiValue& myvals ) const {
     103        1604 :   myvals=myclusters->getInputDerivatives( ind, false, myfatoms );
     104        1604 : }
     105             : 
     106        1975 : Vector ClusterAnalysisBase::getPositionOfAtomForLinkCells( const unsigned& iatom ) const {
     107        1975 :   return myclusters->getPositionOfAtomForLinkCells( iatom );
     108             : }
     109             : 
     110           0 : double ClusterAnalysisBase::getCutoffForConnection() const {
     111           0 :   return myclusters->getCutoffForConnection();
     112             : }
     113             : 
     114           0 : bool ClusterAnalysisBase::areConnected( const unsigned& ind1, const unsigned& ind2 ) const {
     115           0 :   return myclusters->areConnected( ind1, ind2 );
     116             : }
     117             : 
     118             : }
     119             : }

Generated by: LCOV version 1.16