Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2013-2019 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 4097 : class ReferenceAtoms :
45 : virtual public ReferenceConfiguration
46 : {
47 : friend class Direction;
48 : friend class SingleDomainRMSD;
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 ;
87 : /// Get the reference positions
88 : const std::vector<Vector> & getReferencePositions() const ;
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 : virtual void getAtomRequests( std::vector<AtomNumber>&, bool disable_checks=false );
93 : /// Set the indices of the reference atoms
94 : void setAtomNumbers( const std::vector<AtomNumber>& numbers );
95 : /// Set the positions of the reference atoms
96 : virtual void setReferenceAtoms( const std::vector<Vector>& conf, const std::vector<double>& align_in, const std::vector<double>& displace_in )=0;
97 : /// Print the atomic positions
98 : void printAtoms( OFile& ofile, const double& lunits ) const ;
99 : /// Return all atom indexes
100 : const std::vector<AtomNumber>& getAbsoluteIndexes();
101 : /// This returns how many atoms there should be
102 : unsigned getNumberOfAtoms() const ;
103 : /// Displace the positions of the reference atoms a bit
104 : void displaceReferenceAtoms( const double& weight, const std::vector<Vector>& dir );
105 : /// Extract a displacement from a position in space
106 0 : virtual void extractAtomicDisplacement( const std::vector<Vector>& pos, std::vector<Vector>& direction ) const {
107 0 : plumed_error();
108 : }
109 : /// Project the displacement on a vector
110 0 : virtual double projectAtomicDisplacementOnVector( const bool& normalized, const std::vector<Vector>& eigv, ReferenceValuePack& mypack ) const {
111 0 : plumed_error(); return 1;
112 : }
113 : /// Get the vector of alignment weights
114 : const std::vector<double> & getAlign() const ;
115 : /// Get the vector of displacement weights
116 : const std::vector<double> & getDisplace() const ;
117 : };
118 :
119 : inline
120 : const std::vector<double> & ReferenceAtoms::getAlign() const {
121 217283 : return align;
122 : }
123 :
124 : inline
125 : const std::vector<double> & ReferenceAtoms::getDisplace() const {
126 217284 : return displace;
127 : }
128 :
129 : inline
130 137666 : unsigned ReferenceAtoms::getNumberOfReferencePositions() const {
131 : plumed_dbg_assert( atom_der_index.size()==reference_atoms.size() );
132 137666 : return reference_atoms.size();
133 : }
134 :
135 : inline
136 : unsigned ReferenceAtoms::getNumberOfAtoms() const {
137 174434 : return reference_atoms.size();
138 : }
139 :
140 : inline
141 : unsigned ReferenceAtoms::getAtomIndex( const unsigned& iatom ) const {
142 : plumed_dbg_assert( iatom<atom_der_index.size() );
143 : plumed_dbg_assert( atom_der_index[iatom]<reference_atoms.size() );
144 36000232 : return atom_der_index[iatom];
145 : }
146 :
147 : inline
148 : Vector ReferenceAtoms::getReferencePosition( const unsigned& iatom ) const {
149 : plumed_dbg_assert( iatom<reference_atoms.size() );
150 142185 : return reference_atoms[iatom];
151 : }
152 :
153 : inline
154 2637519 : const std::vector<Vector> & ReferenceAtoms::getReferencePositions() const {
155 2637519 : return reference_atoms;
156 : }
157 :
158 : // inline
159 : // void ReferenceAtoms::addAtomicDerivatives( const unsigned& iatom, const Vector& der ){
160 : // atom_ders[ getAtomIndex(iatom) ]+=der;
161 : // }
162 :
163 : // inline
164 : // Vector ReferenceAtoms::retrieveAtomicDerivatives( const unsigned& iatom ) const {
165 : // return atom_ders[ getAtomIndex(iatom) ];
166 : // }
167 :
168 : // inline
169 : // void ReferenceAtoms::addBoxDerivatives( const Tensor& vir ){
170 : // virialWasSet=true; virial+=vir;
171 : // }
172 :
173 : inline
174 36 : const std::vector<AtomNumber>& ReferenceAtoms::getAbsoluteIndexes() {
175 36 : return indices;
176 : }
177 :
178 :
179 : }
180 : #endif
181 :
|