LCOV - code coverage report
Current view: top level - reference - ReferenceConfiguration.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 23 35 65.7 %
Date: 2018-12-19 07:49:13 Functions: 11 19 57.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             : #ifndef __PLUMED_reference_ReferenceConfiguration_h
      23             : #define __PLUMED_reference_ReferenceConfiguration_h
      24             : 
      25             : #include <vector>
      26             : #include <string>
      27             : #include "tools/Vector.h"
      28             : #include "tools/Tensor.h"
      29             : #include "tools/Tools.h"
      30             : #include "tools/Exception.h"
      31             : #include "ReferenceValuePack.h"
      32             : #include "tools/Matrix.h"
      33             : 
      34             : namespace PLMD {
      35             : 
      36             : class Value;
      37             : class Pbc;
      38             : class OFile;
      39             : class PDB;
      40             : 
      41        2135 : class ReferenceConfigurationOptions {
      42             :   friend class ReferenceConfiguration;
      43             : private:
      44             :   std::string tt;
      45             : public:
      46             :   explicit ReferenceConfigurationOptions( const std::string& type );
      47             :   bool usingFastOption() const ;
      48             :   std::string getMultiRMSDType() const ;
      49             : };
      50             : 
      51             : /// \ingroup INHERIT
      52             : /// Abstract base class for calculating the distance from a reference configuration.
      53             : /// A reference configuration can either have a particular set of atoms in a particular
      54             : /// given configuration or it can be that a particular set of colvars have a particular
      55             : /// set of values.  It could also be a combination of both.  To allow all the posible
      56             : /// permutations and in order make it easy to add new ways of calculating the distance
      57             : /// we have implemented this using polymorphism and multiple inheritance.  The following
      58             : /// provides \ref AddingAMetric "information" on how to implement a new method for
      59             : /// calculating the distance between a pair of configurations
      60             : 
      61             : class ReferenceConfiguration {
      62             :   friend class SingleDomainRMSD;
      63             :   friend double distance( const Pbc& pbc, const std::vector<Value*> & vals, ReferenceConfiguration*, ReferenceConfiguration*, const bool& squared );
      64             : private:
      65             : /// The name of this particular config
      66             :   std::string name;
      67             : /// A weight assigned to this particular frame
      68             :   double weight;
      69             : /// A vector containing all the remarks from the pdb input
      70             :   std::vector<std::string> line;
      71             : /// This is used to store the values of arguments
      72             : //  std::vector<double> tmparg;
      73             : /// These are used to do fake things when we copy frames
      74             :   std::vector<AtomNumber> fake_atom_numbers;
      75             :   std::vector<std::string> fake_arg_names;
      76             : /// These are use by the distance function above
      77             :   std::vector<Vector> fake_refatoms;
      78             :   std::vector<double> fake_refargs;
      79             :   std::vector<double> fake_metric;
      80             : protected:
      81             : /// Derivatives wrt to the arguments
      82             : //  std::vector<double> arg_ders;
      83             : /// The virial contribution has to be stored
      84             : //  bool virialWasSet;
      85             : //  Tensor virial;
      86             : /// Derivatives wrt to the atoms
      87             : //  std::vector<Vector> atom_ders;
      88             : /// Crash with an error
      89             :   void error(const std::string& msg);
      90             : /// Clear the derivatives
      91             : //  void clearDerivatives();
      92             : public:
      93             :   explicit ReferenceConfiguration( const ReferenceConfigurationOptions& ro );
      94             : /// Destructor
      95             :   virtual ~ReferenceConfiguration();
      96             : /// Return the name of this metric
      97             :   std::string getName() const ;
      98             : ///
      99             :   virtual unsigned getNumberOfReferencePositions() const ;
     100             :   virtual unsigned getNumberOfReferenceArguments() const ;
     101             : /// Retrieve the atoms that are required for this guy
     102           0 :   virtual void getAtomRequests( std::vector<AtomNumber>&, bool disable_checks=false ) {}
     103             : /// Retrieve the arguments that are required for this guy
     104         298 :   virtual void getArgumentRequests( std::vector<std::string>&, bool disable_checks=false ) {}
     105             : /// Set the final number of arguments
     106             : //  virtual void setNumberOfArguments( const unsigned& );
     107             : /// Set the final number of atoms
     108             : //  virtual void setNumberOfAtoms( const unsigned& );
     109             : /// Set the reference configuration using a PDB
     110             :   virtual void set( const PDB& );
     111             : /// Do all local business for setting the configuration
     112             :   virtual void read( const PDB& )=0;
     113             : /// Set the weight for this frame
     114             :   void setWeight( const double& ww );
     115             : /// Return the weight for this frame
     116             :   double getWeight() const ;
     117             : /// Calculate the distance from the reference configuration
     118             :   double calculate( const std::vector<Vector>& pos, const Pbc& pbc, const std::vector<Value*>& vals, ReferenceValuePack& myder, const bool& squared=false ) const ;
     119             : /// Calculate the distance from the reference configuration
     120             :   virtual double calc( const std::vector<Vector>& pos, const Pbc& pbc, const std::vector<Value*>& vals, const std::vector<double>& args,
     121             :                        ReferenceValuePack& myder, const bool& squared ) const=0;
     122             : // /// Return the derivative wrt to the ith atom
     123             : //   Vector getAtomDerivative( const unsigned& ) const ;
     124             : // /// Return the derivative wrt to the ith argument
     125             : //   double getArgumentDerivative( const unsigned& ) const ;
     126             : /// Return the derivatives of the distance wrt the cell vectors.  This returns false
     127             : /// for everything other than DRMSD as these sort of calculations have to be done
     128             : /// separately when you use RMSD
     129             : //   bool getVirial( Tensor& virout ) const ;
     130             : /// Parse something from the pdb remarks
     131             :   template<class T>
     132             :   bool parse( const std::string&key, T&t, bool ignore_missing=false );
     133             : /// Parse vector from the pdb remarks
     134             :   template<class T>
     135             :   bool parseVector( const std::string&key, std::vector<T>&t, bool ignore_missing=false );
     136             : /// Parse a flag
     137             :   void parseFlag(const std::string&key,bool&t);
     138             : /// Check that all the remarks in the pdb have been read in
     139             :   void checkRead();
     140             : /// Copy derivatives from one frame to this frame
     141             :   void copyDerivatives( const ReferenceConfiguration* );
     142             : /// Set the atom numbers and the argument names
     143             :   void setNamesAndAtomNumbers( const std::vector<AtomNumber>& numbers, const std::vector<std::string>& arg );
     144             : /// Set the reference structure (perhaps should also pass the pbc and align and displace )
     145             :   void setReferenceConfig( const std::vector<Vector>& pos, const std::vector<double>& arg, const std::vector<double>& metric );
     146             : /// Print a pdb file containing the reference configuration
     147             :   void print( OFile& ofile, const double& time, const double& weight, const double& lunits, const double& old_norm );
     148             :   void print( OFile& ofile, const std::string& fmt, const double& lunits );
     149             : /// Get one of the referene arguments
     150           0 :   virtual double getReferenceArgument( const unsigned& i ) const { plumed_error(); return 0.0; }
     151             : /// These are overwritten in ReferenceArguments and ReferenceAtoms but are required here
     152             : /// to make PLMD::distance work
     153             :   virtual const std::vector<Vector>& getReferencePositions() const ;
     154             :   virtual const std::vector<double>& getReferenceArguments();
     155             :   virtual const std::vector<double>& getReferenceMetric();
     156             : /// These are overwritten in ReferenceArguments and ReferenceAtoms to make frame copying work
     157             :   virtual const std::vector<AtomNumber>& getAbsoluteIndexes();
     158             :   virtual const std::vector<std::string>& getArgumentNames();
     159             : /// Stuff for pca
     160           0 :   virtual bool pcaIsEnabledForThisReference() { return false; }
     161           0 :   virtual double projectAtomicDisplacementOnVector( const unsigned& i, const Matrix<Vector>& eigv, const std::vector<Vector>& pos, ReferenceValuePack& mypack ) const {
     162           0 :     plumed_error(); return 1;
     163             :   }
     164             : /// Stuff for sanity checks on distance
     165             :   bool isDirection() const ;
     166             : /// Stuff to setup pca
     167           0 :   virtual void setupPCAStorage( ReferenceValuePack& mypack ) { plumed_error(); }
     168             : };
     169             : 
     170             : // inline
     171             : // Vector ReferenceConfiguration::getAtomDerivative( const unsigned& ider ) const {
     172             : //   plumed_dbg_assert( ider<atom_ders.size() );
     173             : //   return atom_ders[ider];
     174             : // }
     175             : 
     176             : // inline
     177             : // double ReferenceConfiguration::getArgumentDerivative( const unsigned& ider ) const {
     178             : //   plumed_dbg_assert( ider<arg_ders.size() );
     179             : //   return arg_ders[ider];
     180             : // }
     181             : 
     182             : inline
     183        1786 : void ReferenceConfiguration::setWeight( const double& ww ) {
     184        1786 :   weight=ww;
     185        1786 : }
     186             : 
     187             : inline
     188     2395426 : double ReferenceConfiguration::getWeight() const {
     189     2395426 :   return weight;
     190             : }
     191             : 
     192             : template<class T>
     193        1088 : bool ReferenceConfiguration::parse(const std::string&key, T&t, bool ignore_missing ) {
     194        1088 :   bool found=Tools::parse(line,key,t);
     195        1088 :   if(!ignore_missing && !found) error(key + " is missing");
     196        1088 :   return found;
     197             : }
     198             : 
     199             : template<class T>
     200           8 : bool ReferenceConfiguration::parseVector(const std::string&key,std::vector<T>&t, bool ignore_missing) {
     201           8 :   bool found=Tools::parseVector(line,key,t);
     202           8 :   if(!ignore_missing && !found)  error(key + " is missing");
     203           8 :   return found;
     204             : }
     205             : 
     206             : inline
     207       30991 : const std::vector<Vector>& ReferenceConfiguration::getReferencePositions() const {
     208       30991 :   return fake_refatoms;
     209             : }
     210             : 
     211             : inline
     212        1099 : const std::vector<double>& ReferenceConfiguration::getReferenceArguments() {
     213        1099 :   return fake_refargs;
     214             : }
     215             : 
     216             : inline
     217           0 : const std::vector<double>& ReferenceConfiguration::getReferenceMetric() {
     218           0 :   return fake_metric;
     219             : }
     220             : 
     221             : inline
     222         200 : const std::vector<AtomNumber>& ReferenceConfiguration::getAbsoluteIndexes() {
     223         200 :   return fake_atom_numbers;
     224             : }
     225             : 
     226             : inline
     227           0 : const std::vector<std::string>& ReferenceConfiguration::getArgumentNames() {
     228           0 :   return fake_arg_names;
     229             : }
     230             : 
     231             : inline
     232           0 : unsigned ReferenceConfiguration::getNumberOfReferencePositions() const {
     233           0 :   return 0;
     234             : }
     235             : 
     236             : inline
     237      112852 : unsigned ReferenceConfiguration::getNumberOfReferenceArguments() const {
     238      112852 :   return 0;
     239             : }
     240             : 
     241             : 
     242             : 
     243             : }
     244             : #endif

Generated by: LCOV version 1.13