LCOV - code coverage report
Current view: top level - reference - PointWiseMapping.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 42 49 85.7 %
Date: 2020-11-18 11:20:57 Functions: 9 10 90.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2013-2019 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 "PointWiseMapping.h"
      23             : #include "Direction.h"
      24             : #include "FakeFrame.h"
      25             : 
      26             : namespace PLMD {
      27             : 
      28          11 : PointWiseMapping::PointWiseMapping( const std::string& type, const bool& checksoff ):
      29          11 :   MultiReferenceBase(type,checksoff)
      30             : {
      31          11 :   ispath=false;
      32          11 : }
      33             : 
      34          11 : void PointWiseMapping::setPropertyNames( const std::vector<std::string>& prop, const bool isp ) {
      35          22 :   property.resize( prop.size() ); ispath=isp;
      36          67 :   for(unsigned i=0; i<prop.size(); ++i) property[i]=prop[i];
      37          11 : }
      38             : 
      39         416 : void PointWiseMapping::readRestOfFrame() {
      40         832 :   Direction* tdir = dynamic_cast<Direction*>( getFrame( getNumberOfReferenceFrames() - 1 ) );
      41         416 :   if( tdir ) plumed_merror("cannot use directions in mapping");
      42             :   plumed_dbg_assert( property.size()>0 );
      43             : 
      44             :   std::vector<double> labelvals;
      45         416 :   if( !ispath ) {
      46         126 :     labelvals.resize( property.size() );
      47        1008 :     for(unsigned i=0; i<property.size(); ++i) parse( property[i], labelvals[i] );
      48             :   } else {
      49         290 :     labelvals.resize(1);
      50         290 :     labelvals[0]=static_cast<double>( frames.size() );
      51             :   }
      52         416 :   low_dim.push_back( labelvals );
      53             :   plumed_dbg_assert( low_dim.size()==getNumberOfReferenceFrames() );
      54         416 : }
      55             : 
      56           2 : void PointWiseMapping::clearRestOfData() {
      57           2 :   low_dim.resize(0);
      58           2 : }
      59             : 
      60         200 : void PointWiseMapping::resizeRestOfFrame() {
      61             :   plumed_dbg_assert( property.size()>0 );
      62         200 :   std::vector<double> labelvals( property.size() );
      63         200 :   low_dim.push_back( labelvals );
      64             :   plumed_dbg_assert( low_dim.size()==getNumberOfReferenceFrames() );
      65         200 : }
      66             : 
      67           0 : void PointWiseMapping::duplicateFrameList() {
      68           0 :   unsigned nframes=frames.size();
      69           0 :   for(unsigned i=0; i<nframes; ++i) {
      70           0 :     frames.push_back( new FakeFrame( ReferenceConfigurationOptions("fake") ) );
      71             :   }
      72           0 : }
      73             : 
      74          14 : unsigned PointWiseMapping::getPropertyIndex( const std::string& name ) const {
      75          37 :   for(unsigned i=0; i<property.size(); ++i) {
      76          17 :     if( name==property[i] ) return i;
      77             :   }
      78           0 :   plumed_merror("no property with name " + name + " found");
      79             :   return 0;
      80             : }
      81             : 
      82           2 : void PointWiseMapping::print( const std::string& method, const double & time, OFile& afile,
      83             :                               const std::string& fmt, const double& lunits ) {
      84           4 :   std::string descr2, descr="DESCRIPTION: results from %s analysis performed at time " + fmt +"\n";
      85           4 :   afile.printf(descr.c_str(), method.c_str(), time );
      86           2 :   if(fmt.find("-")!=std::string::npos) {
      87           0 :     descr="REMARK WEIGHT=" + fmt + " %s=" + fmt + " "; descr2="%s=" + fmt;
      88             :   } else {
      89             :     // This ensures numbers are left justified (i.e. next to the equals sign
      90             :     std::size_t psign=fmt.find("%");
      91           2 :     plumed_assert( psign!=std::string::npos );
      92          14 :     descr="REMARK WEIGHT=%-" + fmt.substr(psign+1) + " %s=%-" + fmt.substr(psign+1) + " ";
      93           6 :     descr2="%s=%-" + fmt.substr(psign+1);
      94             :   }
      95         604 :   for(unsigned i=0; i<frames.size(); ++i) {
      96         600 :     afile.printf(descr.c_str(), frames[i]->getWeight(), property[0].c_str(), low_dim[i][0] );
      97        1200 :     for(unsigned j=1; j<property.size(); ++j) afile.printf(descr2.c_str(), property[j].c_str(), low_dim[i][j]);
      98         200 :     afile.printf("\n");
      99         200 :     frames[i]->print( afile, fmt, lunits );
     100             :   }
     101           2 : }
     102             : 
     103        4839 : }

Generated by: LCOV version 1.13