LCOV - code coverage report
Current view: top level - reference - PointWiseMapping.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 51 53 96.2 %
Date: 2018-12-19 07:49:13 Functions: 10 10 100.0 %

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

Generated by: LCOV version 1.13