Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2011-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 "core/ActionAtomistic.h"
23 : #include "core/ActionPilot.h"
24 : #include "core/ActionRegister.h"
25 : #include "tools/Vector.h"
26 : #include "tools/AtomNumber.h"
27 : #include "tools/Tools.h"
28 : #include "core/Atoms.h"
29 : #include "core/PlumedMain.h"
30 : #include "core/ActionSet.h"
31 : #include "core/SetupMolInfo.h"
32 :
33 : #include <vector>
34 : #include <string>
35 :
36 : using namespace std;
37 :
38 : namespace PLMD {
39 : namespace generic {
40 :
41 : //+PLUMEDOC GENERIC WHOLEMOLECULES
42 : /*
43 : This action is used to rebuild molecules that can become split by the periodic
44 : boundary conditions.
45 :
46 : It is similar to the ALIGN_ATOMS keyword of plumed1, and is needed since some
47 : MD dynamics code (e.g. GROMACS) can break molecules during the calculation.
48 :
49 : Running some CVs without this command can cause there to be discontinuities changes
50 : in the CV value and artifacts in the calculations. This command can be applied
51 : more than once. To see what effect is has use a variable without pbc or use
52 : the \ref DUMPATOMS directive to output the atomic positions.
53 :
54 : \attention
55 : This directive modifies the stored position at the precise moment
56 : it is executed. This means that only collective variables
57 : which are below it in the input script will see the corrected positions.
58 : As a general rule, put it at the top of the input file. Also, unless you
59 : know exactly what you are doing, leave the default stride (1), so that
60 : this action is performed at every MD step.
61 :
62 : The way WHOLEMOLECULES modifies each of the listed entities is this:
63 : - First atom of the list is left in place
64 : - Each atom of the list is shifted by a lattice vectors so that it becomes as close as possible
65 : to the previous one, iteratively.
66 :
67 : In this way, if an entity consists of a list of atoms such that consecutive atoms in the
68 : list are always closer than half a box side the entity will become whole.
69 : This can be usually achieved selecting consecute atoms (1-100), but it is also possible
70 : to skip some atoms, provided consecute chosen atoms are close enough.
71 :
72 : \par Examples
73 :
74 : This command instructs plumed to reconstruct the molecule containing atoms 1-20
75 : at every step of the calculation and dump them on a file.
76 :
77 : \verbatim
78 : # to see the effect, one could dump the atoms as they were before molecule reconstruction:
79 : # DUMPATOMS FILE=dump-broken.xyz ATOMS=1-20
80 : WHOLEMOLECULES ENTITY0=1-20
81 : DUMPATOMS FILE=dump.xyz ATOMS=1-20
82 : \endverbatim
83 : (see also \ref DUMPATOMS)
84 :
85 : This command instructs plumed to reconstruct two molecules containing atoms 1-20 and 30-40
86 :
87 : \verbatim
88 : WHOLEMOLECULES ENTITY0=1-20 ENTITY1=30-40
89 : DUMPATOMS FILE=dump.xyz ATOMS=1-20,30-40
90 : \endverbatim
91 : (see also \ref DUMPATOMS)
92 :
93 : This command instructs plumed to reconstruct the chain of backbone atoms in a
94 : protein
95 :
96 : \verbatim
97 : MOLINFO STRUCTURE=helix.pdb
98 : WHOLEMOLECULES RESIDUES=all MOLTYPE=protein
99 : \endverbatim
100 : (See also \ref MOLINFO)
101 :
102 : */
103 : //+ENDPLUMEDOC
104 :
105 :
106 10 : class WholeMolecules:
107 : public ActionPilot,
108 : public ActionAtomistic
109 : {
110 : vector<vector<AtomNumber> > groups;
111 : public:
112 : explicit WholeMolecules(const ActionOptions&ao);
113 : static void registerKeywords( Keywords& keys );
114 : void calculate();
115 164 : void apply() {}
116 : };
117 :
118 2528 : PLUMED_REGISTER_ACTION(WholeMolecules,"WHOLEMOLECULES")
119 :
120 6 : void WholeMolecules::registerKeywords( Keywords& keys ) {
121 6 : Action::registerKeywords( keys );
122 6 : ActionPilot::registerKeywords( keys );
123 6 : ActionAtomistic::registerKeywords( keys );
124 6 : keys.add("compulsory","STRIDE","1","the frequency with which molecules are reassembled. Unless you are completely certain about what you are doing leave this set equal to 1!");
125 6 : keys.add("numbered","ENTITY","the atoms that make up a molecule that you wish to align. To specify multiple molecules use a list of ENTITY keywords: ENTITY0, ENTITY1,...");
126 6 : keys.reset_style("ENTITY","atoms");
127 : keys.add("residues","RESIDUES","this command specifies that the backbone atoms in a set of residues all must be aligned. It must be used in tandem with the \\ref MOLINFO "
128 : "action and the MOLTYPE keyword. If you wish to use all the residues from all the chains in your system you can do so by "
129 : "specifying all. Alternatively, if you wish to use a subset of the residues you can specify the particular residues "
130 6 : "you are interested in as a list of numbers");
131 6 : keys.add("optional","MOLTYPE","the type of molecule that is under study. This is used to define the backbone atoms");
132 6 : }
133 :
134 5 : WholeMolecules::WholeMolecules(const ActionOptions&ao):
135 : Action(ao),
136 : ActionPilot(ao),
137 5 : ActionAtomistic(ao)
138 : {
139 5 : vector<AtomNumber> merge;
140 11 : for(int i=0;; i++) {
141 11 : vector<AtomNumber> group;
142 11 : parseAtomList("ENTITY",i,group);
143 11 : if( group.empty() ) break;
144 6 : log.printf(" atoms in entity %d : ",i);
145 6 : for(unsigned j=0; j<group.size(); ++j) log.printf("%d ",group[j].serial() );
146 6 : log.printf("\n");
147 6 : groups.push_back(group);
148 6 : merge.insert(merge.end(),group.begin(),group.end());
149 12 : }
150 :
151 : // Read residues to align from MOLINFO
152 10 : vector<string> resstrings; parseVector("RESIDUES",resstrings);
153 5 : if( resstrings.size()>0 ) {
154 0 : if( resstrings.size()==1 ) {
155 0 : if( resstrings[0]=="all" ) resstrings[0]="all-ter"; // Include terminal groups in alignment
156 : }
157 0 : string moltype; parse("MOLTYPE",moltype);
158 0 : if(moltype.length()==0) error("Found RESIDUES keyword without specification of the moleclue - use MOLTYPE");
159 0 : std::vector<SetupMolInfo*> moldat=plumed.getActionSet().select<SetupMolInfo*>();
160 0 : if( moldat.size()==0 ) error("Unable to find MOLINFO in input");
161 0 : std::vector< std::vector<AtomNumber> > backatoms;
162 0 : moldat[0]->getBackbone( resstrings, moltype, backatoms );
163 0 : for(unsigned i=0; i<backatoms.size(); ++i) {
164 0 : log.printf(" atoms in entity %u : ", static_cast<unsigned>(groups.size()+1));
165 0 : for(unsigned j=0; j<backatoms[i].size(); ++j) log.printf("%d ",backatoms[i][j].serial() );
166 0 : log.printf("\n");
167 0 : groups.push_back( backatoms[i] );
168 0 : merge.insert(merge.end(),backatoms[i].begin(),backatoms[i].end());
169 0 : }
170 : }
171 :
172 5 : if(groups.size()==0) error("no atom found for WHOLEMOLECULES!");
173 :
174 5 : checkRead();
175 5 : Tools::removeDuplicates(merge);
176 5 : requestAtoms(merge);
177 5 : doNotRetrieve();
178 10 : doNotForce();
179 5 : }
180 :
181 164 : void WholeMolecules::calculate() {
182 333 : for(unsigned i=0; i<groups.size(); ++i) {
183 4413 : for(unsigned j=0; j<groups[i].size()-1; ++j) {
184 4244 : const Vector & first (getPosition(groups[i][j]));
185 4244 : Vector & second (modifyPosition(groups[i][j+1]));
186 4244 : second=first+pbcDistance(first,second);
187 : }
188 : }
189 164 : }
190 :
191 :
192 :
193 : }
194 :
195 2523 : }
|