Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2011-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 : #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 : \plumedfile
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 : \endplumedfile
83 :
84 : This command instructs plumed to reconstruct two molecules containing atoms 1-20 and 30-40
85 :
86 : \plumedfile
87 : WHOLEMOLECULES ENTITY0=1-20 ENTITY1=30-40
88 : DUMPATOMS FILE=dump.xyz ATOMS=1-20,30-40
89 : \endplumedfile
90 :
91 : This command instructs plumed to reconstruct the chain of backbone atoms in a
92 : protein
93 :
94 : \plumedfile
95 : MOLINFO STRUCTURE=helix.pdb
96 : WHOLEMOLECULES RESIDUES=all MOLTYPE=protein
97 : \endplumedfile
98 :
99 : */
100 : //+ENDPLUMEDOC
101 :
102 :
103 45 : class WholeMolecules:
104 : public ActionPilot,
105 : public ActionAtomistic
106 : {
107 : vector<vector<AtomNumber> > groups;
108 : public:
109 : explicit WholeMolecules(const ActionOptions&ao);
110 : static void registerKeywords( Keywords& keys );
111 : void calculate();
112 979 : void apply() {}
113 : };
114 :
115 6467 : PLUMED_REGISTER_ACTION(WholeMolecules,"WHOLEMOLECULES")
116 :
117 16 : void WholeMolecules::registerKeywords( Keywords& keys ) {
118 16 : Action::registerKeywords( keys );
119 16 : ActionPilot::registerKeywords( keys );
120 16 : ActionAtomistic::registerKeywords( keys );
121 80 : 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!");
122 64 : 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,...");
123 48 : keys.reset_style("ENTITY","atoms");
124 64 : 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 "
125 : "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 "
126 : "specifying all. Alternatively, if you wish to use a subset of the residues you can specify the particular residues "
127 : "you are interested in as a list of numbers");
128 64 : keys.add("optional","MOLTYPE","the type of molecule that is under study. This is used to define the backbone atoms");
129 16 : }
130 :
131 15 : WholeMolecules::WholeMolecules(const ActionOptions&ao):
132 : Action(ao),
133 : ActionPilot(ao),
134 15 : ActionAtomistic(ao)
135 : {
136 : vector<AtomNumber> merge;
137 16 : for(int i=0;; i++) {
138 : vector<AtomNumber> group;
139 62 : parseAtomList("ENTITY",i,group);
140 31 : if( group.empty() ) break;
141 16 : log.printf(" atoms in entity %d : ",i);
142 1508 : for(unsigned j=0; j<group.size(); ++j) log.printf("%d ",group[j].serial() );
143 16 : log.printf("\n");
144 16 : groups.push_back(group);
145 16 : merge.insert(merge.end(),group.begin(),group.end());
146 16 : }
147 :
148 : // Read residues to align from MOLINFO
149 45 : vector<string> resstrings; parseVector("RESIDUES",resstrings);
150 15 : if( resstrings.size()>0 ) {
151 0 : if( resstrings.size()==1 ) {
152 0 : if( resstrings[0]=="all" ) resstrings[0]="all-ter"; // Include terminal groups in alignment
153 : }
154 0 : string moltype; parse("MOLTYPE",moltype);
155 0 : if(moltype.length()==0) error("Found RESIDUES keyword without specification of the moleclue - use MOLTYPE");
156 0 : std::vector<SetupMolInfo*> moldat=plumed.getActionSet().select<SetupMolInfo*>();
157 0 : if( moldat.size()==0 ) error("Unable to find MOLINFO in input");
158 0 : std::vector< std::vector<AtomNumber> > backatoms;
159 0 : moldat[0]->getBackbone( resstrings, moltype, backatoms );
160 0 : for(unsigned i=0; i<backatoms.size(); ++i) {
161 0 : log.printf(" atoms in entity %u : ", static_cast<unsigned>(groups.size()+1));
162 0 : for(unsigned j=0; j<backatoms[i].size(); ++j) log.printf("%d ",backatoms[i][j].serial() );
163 0 : log.printf("\n");
164 0 : groups.push_back( backatoms[i] );
165 0 : merge.insert(merge.end(),backatoms[i].begin(),backatoms[i].end());
166 : }
167 : }
168 :
169 15 : if(groups.size()==0) error("no atom found for WHOLEMOLECULES!");
170 :
171 15 : checkRead();
172 15 : Tools::removeDuplicates(merge);
173 15 : requestAtoms(merge);
174 : doNotRetrieve();
175 : doNotForce();
176 15 : }
177 :
178 979 : void WholeMolecules::calculate() {
179 4910 : for(unsigned i=0; i<groups.size(); ++i) {
180 36402 : for(unsigned j=0; j<groups[i].size()-1; ++j) {
181 : const Vector & first (getPosition(groups[i][j]));
182 11478 : Vector & second (modifyPosition(groups[i][j+1]));
183 11478 : second=first+pbcDistance(first,second);
184 : }
185 : }
186 979 : }
187 :
188 :
189 :
190 : }
191 :
192 4839 : }
|