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 : friend class Direction; 47 : friend class SingleDomainRMSD; 48 : friend class MultiDomainRMSD; 49 : friend class ReferenceConfiguration; 50 : private: 51 : /// This flag tells us if the user has disabled checking of the input in order to 52 : /// do fancy paths with weird inputs 53 : bool checks_were_disabled; 54 : /// The atoms to be used to align the instantaneous atomic positions 55 : /// to the reference configuration 56 : std::vector<double> align; 57 : /// The atoms to be used to calculate the distance the atoms have moved 58 : /// from the reference configuration 59 : std::vector<double> displace; 60 : /// The positions of the atoms in the reference configuration 61 : std::vector<Vector> reference_atoms; 62 : /// The indices of the atoms in the pdb file 63 : std::vector<AtomNumber> indices; 64 : /// The indeces for setting derivatives 65 : std::vector<unsigned> atom_der_index; 66 : protected: 67 : /// Read in the atoms from the pdb file 68 : void readAtomsFromPDB( const PDB&, const bool allowblocks=false ); 69 : /// Add atom indices to list 70 : void setAtomIndices( const std::vector<AtomNumber>& atomnumbers ); 71 : /// Read a list of atoms from the pdb input file 72 : bool parseAtomList( const std::string&, std::vector<unsigned>& ); 73 : /// Get the position of the ith atom 74 : Vector getReferencePosition( const unsigned& iatom ) const ; 75 : /// Add derivatives to iatom th atom in list 76 : // void addAtomicDerivatives( const unsigned& , const Vector& ); 77 : /// Get the atomic derivatives on the ith atom in the list 78 : // Vector retrieveAtomicDerivatives( const unsigned& ) const ; 79 : /// Add derivatives to the viral 80 : // void addBoxDerivatives( const Tensor& ); 81 : /// This does the checks that are always required 82 : void singleDomainRequests( std::vector<AtomNumber>&, bool disable_checks ); 83 : public: 84 : explicit ReferenceAtoms( const ReferenceConfigurationOptions& ro ); 85 : /// This returns the number of reference atom positions 86 : unsigned getNumberOfReferencePositions() const override; 87 : /// Get the reference positions 88 : const std::vector<Vector> & getReferencePositions() const override; 89 : /// This allows us to use a single pos array with RMSD objects using different atom indexes 90 : unsigned getAtomIndex( const unsigned& ) const ; 91 : /// Get the atoms required (additional checks are required when we have multiple domains) 92 : void getAtomRequests( std::vector<AtomNumber>&, bool disable_checks=false ) override; 93 : /// Set the positions of the reference atoms 94 : virtual void setReferenceAtoms( const std::vector<Vector>& conf, const std::vector<double>& align_in, const std::vector<double>& displace_in )=0; 95 : /// Return all atom indexes 96 : const std::vector<AtomNumber>& getAbsoluteIndexes() override; 97 : /// This returns how many atoms there should be 98 : unsigned getNumberOfAtoms() const ; 99 : /// Displace the positions of the reference atoms a bit 100 : void displaceReferenceAtoms( const double& weight, const std::vector<Vector>& dir ); 101 : /// Extract a displacement from a position in space 102 0 : virtual void extractAtomicDisplacement( const std::vector<Vector>& pos, std::vector<Vector>& direction ) const { 103 0 : plumed_error(); 104 : } 105 : /// Project the displacement on a vector 106 0 : virtual double projectAtomicDisplacementOnVector( const bool& normalized, const std::vector<Vector>& eigv, ReferenceValuePack& mypack ) const { 107 0 : plumed_error(); 108 : } 109 : /// Get the vector of alignment weights 110 : const std::vector<double> & getAlign() const ; 111 : /// Get the vector of displacement weights 112 : const std::vector<double> & getDisplace() const ; 113 : }; 114 : 115 : inline 116 : const std::vector<double> & ReferenceAtoms::getAlign() const { 117 271380 : return align; 118 : } 119 : 120 : inline 121 : const std::vector<double> & ReferenceAtoms::getDisplace() const { 122 271381 : return displace; 123 : } 124 : 125 : inline 126 150285 : unsigned ReferenceAtoms::getNumberOfReferencePositions() const { 127 : plumed_dbg_assert( atom_der_index.size()==reference_atoms.size() ); 128 150285 : return reference_atoms.size(); 129 : } 130 : 131 : inline 132 : unsigned ReferenceAtoms::getNumberOfAtoms() const { 133 314703 : return atom_der_index.size(); // reference_atoms.size(); 134 : } 135 : 136 : inline 137 : unsigned ReferenceAtoms::getAtomIndex( const unsigned& iatom ) const { 138 : plumed_dbg_assert( iatom<atom_der_index.size() ); 139 : plumed_dbg_assert( atom_der_index[iatom]<reference_atoms.size() ); 140 17303434 : return atom_der_index[iatom]; 141 : } 142 : 143 : inline 144 : Vector ReferenceAtoms::getReferencePosition( const unsigned& iatom ) const { 145 : plumed_dbg_assert( iatom<reference_atoms.size() ); 146 71395 : return reference_atoms[iatom]; 147 : } 148 : 149 : inline 150 2690664 : const std::vector<Vector> & ReferenceAtoms::getReferencePositions() const { 151 2690664 : return reference_atoms; 152 : } 153 : 154 : inline 155 4 : const std::vector<AtomNumber>& ReferenceAtoms::getAbsoluteIndexes() { 156 4 : return indices; 157 : } 158 : 159 : 160 : } 161 : #endif 162 :