LCOV - code coverage report
Current view: top level - adjmat - ActionWithInputMatrix.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 75 79 94.9 %
Date: 2026-03-30 13:16:06 Functions: 15 16 93.8 %

          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 "ActionWithInputMatrix.h"
      23             : #include "AdjacencyMatrixVessel.h"
      24             : #include "AdjacencyMatrixBase.h"
      25             : #include "vesselbase/ActionWithVessel.h"
      26             : #include "core/PlumedMain.h"
      27             : #include "core/ActionSet.h"
      28             : 
      29             : namespace PLMD {
      30             : namespace adjmat {
      31             : 
      32          47 : void ActionWithInputMatrix::registerKeywords( Keywords& keys ) {
      33          47 :   MultiColvarBase::registerKeywords( keys );
      34          94 :   keys.add("compulsory","MATRIX","the action that calculates the adjacency matrix vessel we would like to analyze");
      35          47 : }
      36             : 
      37             : 
      38          27 : ActionWithInputMatrix::ActionWithInputMatrix(const ActionOptions& ao):
      39             :   Action(ao),
      40             :   MultiColvarBase(ao),
      41          27 :   mymatrix(NULL) {
      42          27 :   matsums=true;
      43          54 :   if( keywords.exists("MATRIX") ) {
      44             :     std::vector<AtomNumber> fake_atoms;
      45          50 :     if( !parseMultiColvarAtomList("MATRIX",-1,fake_atoms ) ) {
      46           0 :       error("unable to interpret input matrix");
      47             :     }
      48          25 :     if( mybasemulticolvars.size()!=1 ) {
      49           0 :       error("should be exactly one matrix input");
      50             :     }
      51             : 
      52             :     // Retrieve the adjacency matrix of interest
      53          25 :     for(unsigned i=0; i<mybasemulticolvars[0]->getNumberOfVessels(); ++i) {
      54          25 :       mymatrix = dynamic_cast<AdjacencyMatrixVessel*>( mybasemulticolvars[0]->getPntrToVessel(i) );
      55          25 :       if( mymatrix ) {
      56             :         break ;
      57             :       }
      58             :     }
      59          25 :     if( !mymatrix ) {
      60           0 :       error( mybasemulticolvars[0]->getLabel() + " does not calculate an adjacency matrix");
      61             :     }
      62             : 
      63          25 :     atom_lab.resize(0);
      64             :     unsigned nnodes; // Delete all the atom labels that have been created
      65          25 :     if( mymatrix->undirectedGraph() ) {
      66          23 :       nnodes = (mymatrix->function)->ablocks[0].size();
      67             :     } else {
      68           2 :       nnodes = (mymatrix->function)->ablocks[0].size() + (mymatrix->function)->ablocks[1].size();
      69             :     }
      70        6816 :     for(unsigned i=0; i<nnodes; ++i) {
      71        6791 :       atom_lab.push_back( std::pair<unsigned,unsigned>( 1, i ) );
      72             :     }
      73             :   }
      74          27 : }
      75             : 
      76       13250 : unsigned ActionWithInputMatrix::getNumberOfDerivatives() {
      77       13250 :   return (mymatrix->function)->getNumberOfDerivatives();
      78             : }
      79             : 
      80    16261547 : unsigned ActionWithInputMatrix::getNumberOfNodes() const {
      81    16261547 :   return (mymatrix->function)->ablocks[0].size();
      82             : }
      83             : 
      84       78058 : AdjacencyMatrixVessel* ActionWithInputMatrix::getAdjacencyVessel() const {
      85       78058 :   return mymatrix;
      86             : }
      87             : 
      88         504 : AtomNumber ActionWithInputMatrix::getAbsoluteIndexOfCentralAtom(const unsigned& i) const {
      89         504 :   return (mymatrix->function)->getAbsoluteIndexOfCentralAtom(i);
      90             : }
      91             : 
      92       46452 : double ActionWithInputMatrix::retrieveConnectionValue( const unsigned& i, const unsigned& j, std::vector<double>& vals ) const {
      93       46452 :   if( !mymatrix->matrixElementIsActive( i, j ) ) {
      94             :     return 0;
      95             :   }
      96       25360 :   unsigned myelem = mymatrix->getStoreIndexFromMatrixIndices( i, j );
      97             : 
      98             :   // unsigned vi; double df;
      99       25360 :   mymatrix->retrieveValueWithIndex( myelem, false, vals );
     100       25360 :   return vals[0]*vals[1];       // (mymatrix->function)->transformStoredValues( vals, vi, df );
     101             : }
     102             : 
     103        2004 : void ActionWithInputMatrix::getInputData( const unsigned& ind, const bool& normed, const multicolvar::AtomValuePack& myatoms, std::vector<double>& orient0 ) const {
     104        2004 :   if( (mymatrix->function)->mybasemulticolvars.size()==0  ) {
     105         305 :     std::vector<double> tvals( mymatrix->getNumberOfComponents() );
     106         305 :     orient0.assign(orient0.size(),0);
     107       38263 :     for(unsigned i=0; i<mymatrix->getNumberOfColumns(); ++i) {
     108       37958 :       if( mymatrix->undirectedGraph() && ind==i ) {
     109         280 :         continue;
     110             :       }
     111       37678 :       orient0[1]+=retrieveConnectionValue( ind, i, tvals );
     112             :     }
     113         305 :     orient0[0]=1.0;
     114             :     return;
     115             :   }
     116        1699 :   (mymatrix->function)->getInputData( ind, normed, myatoms, orient0 );
     117             : }
     118             : 
     119        1440 : void ActionWithInputMatrix::addConnectionDerivatives( const unsigned& i, const unsigned& j, MultiValue& myvals, MultiValue& myvout ) const {
     120        1440 :   if( !mymatrix->matrixElementIsActive( i, j ) ) {
     121           0 :     return;
     122             :   }
     123        1440 :   unsigned myelem = mymatrix->getStoreIndexFromMatrixIndices( i, j );
     124             :   // Get derivatives and add
     125        1440 :   mymatrix->retrieveDerivatives( myelem, false, myvals );
     126       31086 :   for(unsigned jd=0; jd<myvals.getNumberActive(); ++jd) {
     127       29646 :     unsigned ider=myvals.getActiveIndex(jd);
     128       29646 :     myvout.addDerivative( 1, ider, myvals.getDerivative( 1, ider ) );
     129             :   }
     130             : }
     131             : 
     132        1679 : MultiValue& ActionWithInputMatrix::getInputDerivatives( const unsigned& ind, const bool& normed, const multicolvar::AtomValuePack& myatoms ) const {
     133        1679 :   if( (mymatrix->function)->mybasemulticolvars.size()==0  ) {
     134          90 :     MultiValue& myder=mymatrix->getTemporyMultiValue(0);
     135          90 :     if( myder.getNumberOfValues()!=2 || myder.getNumberOfDerivatives()!=(mymatrix->function)->getNumberOfDerivatives() ) {
     136           3 :       myder.resize( 2, (mymatrix->function)->getNumberOfDerivatives() );
     137             :     }
     138          90 :     myder.clearAll();
     139          90 :     MultiValue myvals( (mymatrix->function)->getNumberOfQuantities(), (mymatrix->function)->getNumberOfDerivatives() );
     140         885 :     for(unsigned i=0; i<mymatrix->getNumberOfColumns(); ++i) {
     141         795 :       if( mymatrix->undirectedGraph() && ind==i ) {
     142          65 :         continue;
     143             :       }
     144         730 :       addConnectionDerivatives( ind, i, myvals, myder );
     145             :     }
     146             :     myder.updateDynamicList();
     147             :     return myder;
     148          90 :   }
     149        1589 :   return (mymatrix->function)->getInputDerivatives( ind, normed, myatoms );
     150             : }
     151             : 
     152          66 : unsigned ActionWithInputMatrix::getNumberOfNodeTypes() const {
     153          66 :   unsigned size = (mymatrix->function)->mybasemulticolvars.size();
     154             :   if( size==0 ) {
     155             :     return 1;
     156             :   }
     157             :   return size;
     158             : }
     159             : 
     160        2181 : unsigned ActionWithInputMatrix::getNumberOfQuantities() const {
     161        2181 :   if( (mymatrix->function)->mybasemulticolvars.size()==0 ) {
     162             :     return 2;
     163             :   }
     164        2082 :   return (mymatrix->function)->mybasemulticolvars[0]->getNumberOfQuantities();
     165             : }
     166             : 
     167          34 : unsigned ActionWithInputMatrix::getNumberOfAtomsInGroup( const unsigned& igrp ) const {
     168             :   plumed_dbg_assert( igrp<(mymatrix->function)->mybasemulticolvars.size() );
     169          34 :   return (mymatrix->function)->mybasemulticolvars[igrp]->getFullNumberOfTasks();
     170             : }
     171             : 
     172           7 : multicolvar::MultiColvarBase* ActionWithInputMatrix::getBaseMultiColvar( const unsigned& igrp ) const {
     173             :   plumed_dbg_assert( igrp<(mymatrix->function)->mybasemulticolvars.size() );
     174           7 :   return (mymatrix->function)->mybasemulticolvars[igrp];
     175             : }
     176             : 
     177       54763 : Vector ActionWithInputMatrix::getPositionOfAtomForLinkCells( const unsigned& iatom ) const {
     178       54763 :   return (getAdjacencyVessel()->function)->getPositionOfAtomForLinkCells( iatom );
     179             : }
     180             : 
     181             : }
     182             : }

Generated by: LCOV version 1.16