ClusterAnalysisBase::ClusterAnalysisBase(const ActionOptions& ao):
Action(ao),
MultiColvarBase(ao),
myfvals(0,0),
myfatoms( myfvals, this ),
myclusters(NULL)
{
  // This makes these colvars behave appropriately with dump and analysis
  matsums=usespecies=true; std::vector<AtomNumber> fake_atoms;
  // Find what action we are taking the clusters from
  if( !parseMultiColvarAtomList("CLUSTERS",-1,fake_atoms ) ) error("unable to interpret input CLUSTERS" );
  if( mybasemulticolvars.size()!=1 ) error("should be exactly one multicolvar input");
  atom_lab.resize(0); myclusters = dynamic_cast<ClusteringBase*>( mybasemulticolvars[0] );
  if( !myclusters ) error("input label is not that of a DFS object");
  // Setup the atom pack
  myfatoms.setNumberOfAtoms( myclusters->getNumberOfNodes() );
  myfvals.getIndices().resize( myclusters->getNumberOfNodes() );
  for(unsigned i=0;i<myclusters->getNumberOfNodes();++i) myfatoms.setAtomIndex( i, i );
}
ActionWithInputMatrix::ActionWithInputMatrix(const ActionOptions& ao):
  Action(ao),
  MultiColvarBase(ao),
  mymatrix(NULL)
{
  matsums=true;
  if( keywords.exists("MATRIX") ) {
    std::vector<AtomNumber> fake_atoms;
    if( !parseMultiColvarAtomList("MATRIX",-1,fake_atoms ) ) error("unable to interpret input matrix");
    if( mybasemulticolvars.size()!=1 ) error("should be exactly one matrix input");

    // Retrieve the adjacency matrix of interest
    for(unsigned i=0; i<mybasemulticolvars[0]->getNumberOfVessels(); ++i) {
      mymatrix = dynamic_cast<AdjacencyMatrixVessel*>( mybasemulticolvars[0]->getPntrToVessel(i) );
      if( mymatrix ) break ;
    }
    if( !mymatrix ) error( mybasemulticolvars[0]->getLabel() + " does not calculate an adjacency matrix");

    atom_lab.resize(0); unsigned nnodes; // Delete all the atom labels that have been created
    if( mymatrix->undirectedGraph() ) nnodes = (mymatrix->function)->ablocks[0].size();
    else nnodes = (mymatrix->function)->ablocks[0].size() + (mymatrix->function)->ablocks[1].size();
    for(unsigned i=0; i<nnodes; ++i) atom_lab.push_back( std::pair<unsigned,unsigned>( 1, i ) );
  }
}