Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2013-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 : #ifndef __PLUMED_reference_ReferenceAtoms_h 23 : #define __PLUMED_reference_ReferenceAtoms_h 24 : 25 : #include "ReferenceConfiguration.h" 26 : 27 : namespace PLMD { 28 : 29 : class Pbc; 30 : 31 : /// \ingroup TOOLBOX 32 : /// In many applications (e.g. paths, fields, property maps) it is necessary to calculate 33 : /// the distance between two configurations. These distances can be calculated in a variety of 34 : /// different ways. For instance, one can assert that the distance between the two configuration 35 : /// is the distance one would have to move all the atoms to transform configuration 1 into configuration 36 : /// 2. Alternatively, one could calculate the values of a large set of collective coordinates in the two 37 : /// configurations and then calculate the Euclidean distances between these two points in the resulting 38 : /// high-dimensional vector space. Lastly, one can combine these two forms of distance calculation to calculate 39 : /// a hybrid distance. Plumed allows one to use all these forms of distance calculations and also to implement 40 : /// new forms of distance. You should inherit from this class if your distance involves reference atomic positions. 41 : /// This class and \ref PLMD::ReferenceArguments mirror the functionalities in and \ref PLMD::ActionAtomistic 42 : /// and \ref PLMD::ActionWithArguments respectively but for distances. 43 : 44 : class ReferenceAtoms : 45 : virtual public ReferenceConfiguration 46 : { 47 : friend class Direction; 48 : friend class SingleDomainRMSD; 49 : friend class MultiDomainRMSD; 50 : friend class ReferenceConfiguration; 51 : private: 52 : /// This flag tells us if the user has disabled checking of the input in order to 53 : /// do fancy paths with weird inputs 54 : bool checks_were_disabled; 55 : /// The atoms to be used to align the instantaneous atomic positions 56 : /// to the reference configuration 57 : std::vector<double> align; 58 : /// The atoms to be used to calculate the distance the atoms have moved 59 : /// from the reference configuration 60 : std::vector<double> displace; 61 : /// The positions of the atoms in the reference configuration 62 : std::vector<Vector> reference_atoms; 63 : /// The indices of the atoms in the pdb file 64 : std::vector<AtomNumber> indices; 65 : /// The indeces for setting derivatives 66 : std::vector<unsigned> atom_der_index; 67 : protected: 68 : /// Read in the atoms from the pdb file 69 : void readAtomsFromPDB( const PDB&, const bool allowblocks=false ); 70 : /// Add atom indices to list 71 : void setAtomIndices( const std::vector<AtomNumber>& atomnumbers ); 72 : /// Read a list of atoms from the pdb input file 73 : bool parseAtomList( const std::string&, std::vector<unsigned>& ); 74 : /// Get the position of the ith atom 75 : Vector getReferencePosition( const unsigned& iatom ) const ; 76 : /// Add derivatives to iatom th atom in list 77 : // void addAtomicDerivatives( const unsigned& , const Vector& ); 78 : /// Get the atomic derivatives on the ith atom in the list 79 : // Vector retrieveAtomicDerivatives( const unsigned& ) const ; 80 : /// Add derivatives to the viral 81 : // void addBoxDerivatives( const Tensor& ); 82 : /// This does the checks that are always required 83 : void singleDomainRequests( std::vector<AtomNumber>&, bool disable_checks ); 84 : public: 85 : explicit ReferenceAtoms( const ReferenceConfigurationOptions& ro ); 86 : /// This returns the number of reference atom positions 87 : unsigned getNumberOfReferencePositions() const override; 88 : /// Get the reference positions 89 : const std::vector<Vector> & getReferencePositions() const override; 90 : /// This allows us to use a single pos array with RMSD objects using different atom indexes 91 : unsigned getAtomIndex( const unsigned& ) const ; 92 : /// Get the atoms required (additional checks are required when we have multiple domains) 93 : void getAtomRequests( std::vector<AtomNumber>&, bool disable_checks=false ) override; 94 : /// Set the positions of the reference atoms 95 : virtual void setReferenceAtoms( const std::vector<Vector>& conf, const std::vector<double>& align_in, const std::vector<double>& displace_in )=0; 96 : /// Return all atom indexes 97 : const std::vector<AtomNumber>& getAbsoluteIndexes() override; 98 : /// This returns how many atoms there should be 99 : unsigned getNumberOfAtoms() const ; 100 : /// Displace the positions of the reference atoms a bit 101 : void displaceReferenceAtoms( const double& weight, const std::vector<Vector>& dir ); 102 : /// Extract a displacement from a position in space 103 0 : virtual void extractAtomicDisplacement( const std::vector<Vector>& pos, std::vector<Vector>& direction ) const { 104 0 : plumed_error(); 105 : } 106 : /// Project the displacement on a vector 107 0 : virtual double projectAtomicDisplacementOnVector( const bool& normalized, const std::vector<Vector>& eigv, ReferenceValuePack& mypack ) const { 108 0 : plumed_error(); 109 : } 110 : /// Get the vector of alignment weights 111 : const std::vector<double> & getAlign() const ; 112 : /// Get the vector of displacement weights 113 : const std::vector<double> & getDisplace() const ; 114 : }; 115 : 116 : inline 117 : const std::vector<double> & ReferenceAtoms::getAlign() const { 118 216762 : return align; 119 : } 120 : 121 : inline 122 : const std::vector<double> & ReferenceAtoms::getDisplace() const { 123 216763 : return displace; 124 : } 125 : 126 : inline 127 150276 : unsigned ReferenceAtoms::getNumberOfReferencePositions() const { 128 : plumed_dbg_assert( atom_der_index.size()==reference_atoms.size() ); 129 150276 : return reference_atoms.size(); 130 : } 131 : 132 : inline 133 : unsigned ReferenceAtoms::getNumberOfAtoms() const { 134 314250 : return atom_der_index.size(); // reference_atoms.size(); 135 : } 136 : 137 : inline 138 : unsigned ReferenceAtoms::getAtomIndex( const unsigned& iatom ) const { 139 : plumed_dbg_assert( iatom<atom_der_index.size() ); 140 : plumed_dbg_assert( atom_der_index[iatom]<reference_atoms.size() ); 141 9894406 : return atom_der_index[iatom]; 142 : } 143 : 144 : inline 145 : Vector ReferenceAtoms::getReferencePosition( const unsigned& iatom ) const { 146 : plumed_dbg_assert( iatom<reference_atoms.size() ); 147 67480 : return reference_atoms[iatom]; 148 : } 149 : 150 : inline 151 2636046 : const std::vector<Vector> & ReferenceAtoms::getReferencePositions() const { 152 2636046 : return reference_atoms; 153 : } 154 : 155 : inline 156 4 : const std::vector<AtomNumber>& ReferenceAtoms::getAbsoluteIndexes() { 157 4 : return indices; 158 : } 159 : 160 : 161 : } 162 : #endif 163 :