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