LCOV - code coverage report
Current view: top level - adjmat - ClusteringBase.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 29 31 93.5 %
Date: 2018-12-19 07:49:13 Functions: 8 10 80.0 %

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

Generated by: LCOV version 1.13