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

          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 "MultiReferenceBase.h"
      23             : #include "tools/Communicator.h"
      24             : #include "MetricRegister.h"
      25             : 
      26             : namespace PLMD {
      27             : 
      28          12 : MultiReferenceBase::MultiReferenceBase( const std::string& type, const bool& checksoff ):
      29             :   wasSet(false),
      30             :   skipchecks(checksoff),
      31          12 :   mtype(type)
      32             : {
      33          12 :   if(checksoff) plumed_assert( mtype.length()==0 );
      34          12 : }
      35             : 
      36          24 : MultiReferenceBase::~MultiReferenceBase() {
      37          12 :   for(unsigned i=0; i<frames.size(); ++i) delete frames[i];
      38          12 : }
      39             : 
      40           2 : void MultiReferenceBase::clearFrames() {
      41           2 :   for(unsigned i=0; i<frames.size(); ++i) delete frames[i];
      42           2 :   frames.resize(0);
      43           2 :   clearRestOfData();
      44           2 : }
      45             : 
      46         306 : void MultiReferenceBase::readFrame( PDB& mypdb ) {
      47         306 :   wasSet=true;
      48             :   // If skipchecks are enabled metric types must be specified in the input file
      49         306 :   ReferenceConfiguration* mymsd=metricRegister().create<ReferenceConfiguration>( mtype, mypdb );
      50             :   // Save everything
      51         306 :   frames.push_back( mymsd );
      52             :   // Do reading in derived class
      53         306 :   readRestOfFrame();
      54             :   // Check readin was succesfull
      55         306 :   mymsd->checkRead();
      56         306 : }
      57             : 
      58          11 : void MultiReferenceBase::getAtomAndArgumentRequirements( std::vector<AtomNumber>& atoms, std::vector<std::string>& args ) {
      59          11 :   plumed_assert( atoms.size()==0 && args.size()==0 );
      60         317 :   for(unsigned i=0; i<frames.size(); ++i) {
      61         306 :     frames[i]->getAtomRequests( atoms );
      62         306 :     frames[i]->getArgumentRequests( args );
      63             :   }
      64          11 : }
      65             : 
      66             : // void MultiReferenceBase::setNumberOfAtomsAndArguments( const unsigned& natoms, const unsigned& nargs ){
      67             : //   for(unsigned i=0;i<frames.size();++i){
      68             : //       frames[i]->setNumberOfAtoms( natoms );
      69             : //       frames[i]->setNumberOfArguments( nargs );
      70             : //   }
      71             : // }
      72             : 
      73         200 : void MultiReferenceBase::copyFrame( ReferenceConfiguration* frameToCopy ) {
      74             :   // Create a reference configuration of the appropriate type
      75         200 :   ReferenceConfiguration* mymsd=metricRegister().create<ReferenceConfiguration>( frameToCopy->getName() );
      76             :   // Copy names of arguments and and indexes
      77         200 :   mymsd->setNamesAndAtomNumbers( frameToCopy->getAbsoluteIndexes(), frameToCopy->getArgumentNames() );
      78             :   // Copy reference positions, reference arguments and reference metric
      79         200 :   mymsd->setReferenceConfig( frameToCopy->getReferencePositions(), frameToCopy->getReferenceArguments(), frameToCopy->getReferenceMetric() );
      80             :   // Copy weight
      81         200 :   mymsd->setWeight( frameToCopy->getWeight() );
      82             :   // Easy bit - copy the frame
      83         200 :   frames.push_back( mymsd );
      84             :   // This resizes the low dim array
      85         200 :   resizeRestOfFrame();
      86         200 : }
      87             : 
      88           7 : void MultiReferenceBase::setWeights( const std::vector<double>& weights ) {
      89           7 :   plumed_assert( weights.size()==frames.size() );
      90           7 :   for(unsigned i=0; i<weights.size(); ++i) frames[i]->setWeight( weights[i] );
      91           7 : }
      92             : 
      93             : 
      94           2 : void MultiReferenceBase::calculateAllDistances( const Pbc& pbc, const std::vector<Value*> & vals, Communicator& comm, Matrix<double>& distances, const bool& squared ) {
      95           2 :   distances=0.0;
      96           2 :   unsigned k=0, size=comm.Get_size(), rank=comm.Get_rank();
      97         200 :   for(unsigned i=1; i<frames.size(); ++i) {
      98       10098 :     for(unsigned j=0; j<i; ++j) {
      99        9900 :       if( (k++)%size!=rank ) continue;
     100        9900 :       distances(i,j) = distances(j,i) = distance( pbc, vals, frames[i], frames[j], squared );
     101             :     }
     102             :   }
     103           2 :   comm.Sum( distances );
     104           2 : }
     105             : 
     106        2523 : }

Generated by: LCOV version 1.13