LCOV - code coverage report
Current view: top level - analysis - DataCollectionObject.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 28 29 96.6 %
Date: 2026-03-30 13:16:06 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2016-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 "DataCollectionObject.h"
      23             : #include "tools/PDB.h"
      24             : 
      25             : namespace PLMD {
      26             : namespace analysis {
      27             : 
      28        7556 : void DataCollectionObject::setAtomNumbersAndArgumentNames( const std::string& action_label, const std::vector<AtomNumber>& ind, const std::vector<std::string>& arg_names ) {
      29        7556 :   myaction=action_label;
      30        7556 :   indices.resize( ind.size() );
      31        7556 :   positions.resize( indices.size() );
      32       21193 :   for(unsigned i=0; i<ind.size(); ++i) {
      33       13637 :     indices[i]=ind[i];
      34             :   }
      35       16583 :   for(unsigned i=0; i<arg_names.size(); ++i) {
      36        9027 :     args.insert( std::pair<std::string,double>( arg_names[i], 0.0 ) );
      37             :   }
      38        7556 : }
      39             : 
      40        7556 : void DataCollectionObject::setAtomPositions( const std::vector<Vector>& pos ) {
      41             :   plumed_dbg_assert( pos.size()==positions.size() && pos.size()==indices.size() );
      42       21193 :   for(unsigned i=0; i<positions.size(); ++i) {
      43       13637 :     positions[i]=pos[i];
      44             :   }
      45        7556 : }
      46             : 
      47       16321 : void DataCollectionObject::setArgument( const std::string& name, const double& value ) {
      48             :   std::map<std::string,double>::iterator it = args.find(name);
      49       16321 :   if( it!=args.end() ) {
      50        9627 :     it->second = value;
      51             :   } else {
      52        6694 :     args.insert( std::pair<std::string,double>( name, value ) );
      53             :   }
      54       16321 : }
      55             : 
      56      522438 : bool DataCollectionObject::transferDataToPDB( PDB& mypdb ) {
      57             :   // Check if PDB contains argument names
      58      522438 :   std::vector<std::string> pdb_args( mypdb.getArgumentNames() );
      59             :   // Now set the argument values
      60             :   std::map<std::string,double>::iterator it;
      61     2024164 :   for(unsigned i=0; i<pdb_args.size(); ++i) {
      62             :     it=args.find( pdb_args[i] );
      63     1501726 :     if( it==args.end() ) {
      64             :       return false;
      65             :     }
      66     1501726 :     mypdb.setArgumentValue( pdb_args[i], it->second );
      67             :   }
      68             :   // Now set the atomic positions
      69      522438 :   std::vector<AtomNumber> pdb_pos( mypdb.getAtomNumbers() );
      70      522438 :   if( pdb_pos.size()==positions.size() ) {
      71      492718 :     mypdb.setAtomPositions( positions );
      72       29720 :   } else if( pdb_pos.size()>0 ) {
      73           0 :     plumed_merror("This feature is currently not ready");
      74             :   }
      75             :   return true;
      76      522438 : }
      77             : 
      78             : }
      79             : }

Generated by: LCOV version 1.16