All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
WholeMolecules.cpp
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 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-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
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 \par Examples
63 
64 This command instructs plumed to reconstruct the molecule containing atoms 1-20
65 at every step of the calculation and dump them on a file.
66 
67 \verbatim
68 # to see the effect, one could dump the atoms as they were before molecule reconstruction:
69 # DUMPATOMS FILE=dump-broken.xyz ATOMS=1-20
70 WHOLEMOLECULES STRIDE=1 ENTITY0=1-20
71 DUMPATOMS FILE=dump.xyz ATOMS=1-20
72 \endverbatim
73 (see also \ref DUMPATOMS)
74 
75 This command instructs plumed to reconstruct two molecules containing atoms 1-20 and 30-40
76 
77 \verbatim
78 WHOLEMOLECULES STRIDE=1 ENTITY0=1-20 ENTITY1=30-40
79 DUMPATOMS FILE=dump.xyz ATOMS=1-20,30-40
80 \endverbatim
81 (see also \ref DUMPATOMS)
82 
83 This command instructs plumed to reconstruct the chain of backbone atoms in a
84 protein
85 
86 \verbatim
87 MOLINFO STRUCTURE=helix.pdb
88 WHOLEMOLECULES STRIDE=1 RESIDUES=ALL RES_ATOMS=N,CA,CB,C,O
89 \endverbatim
90 (See also \ref MOLINFO)
91 
92 */
93 //+ENDPLUMEDOC
94 
95 
97  public ActionPilot,
98  public ActionAtomistic
99 {
100  vector<vector<AtomNumber> > groups;
101 public:
102  WholeMolecules(const ActionOptions&ao);
103  static void registerKeywords( Keywords& keys );
104  void calculate();
105  void apply(){}
106 };
107 
108 PLUMED_REGISTER_ACTION(WholeMolecules,"WHOLEMOLECULES")
109 
110 void WholeMolecules::registerKeywords( Keywords& keys ){
111  ActionAtomistic::registerKeywords( keys );
112  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!");
113  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: ENTITY1, ENTITY2,...");
114  keys.reset_style("ENTITY","atoms");
115  keys.add("residues","RESIDUES","this command specifies a set of residues which all must be aligned. It must be used in tandem with the \\ref MOLINFO "
116  "action and the RES_ATOMS keyword. If you wish to use all the residues from all the chains in your system you can do so by "
117  "specifying all. Alternatively, if you wish to use a subset of the residues you can specify the particular residues "
118  "you are interested in as a list of numbers");
119  keys.add("optional","RES_ATOMS","this command tells plumed what atoms should be aligned in each of the residues that are being aligned");
120 }
121 
122 WholeMolecules::WholeMolecules(const ActionOptions&ao):
123 Action(ao),
124 ActionPilot(ao),
125 ActionAtomistic(ao)
126 {
127  vector<AtomNumber> merge;
128  for(int i=0;;i++){
129  vector<AtomNumber> group;
130  parseAtomList("ENTITY",i,group);
131  if( group.empty() ) break;
132  log.printf(" atoms in entity %d : ",i);
133  for(unsigned j=0;j<group.size();++j) log.printf("%d ",group[j].serial() );
134  log.printf("\n");
135  groups.push_back(group);
136  merge.insert(merge.end(),group.begin(),group.end());
137  }
138 
139  // Read residues to align from MOLINFO
140  vector<string> resstrings; parseVector("RESIDUES",resstrings);
141  if( resstrings.size()>0 ){
142  vector<string> backnames; parseVector("RES_ATOMS",backnames);
143  if(backnames.size()==0) error("Found RESIDUES keyword without any specification of the atoms that should be in a residue - use RES_ATOMS");
144  std::vector<SetupMolInfo*> moldat=plumed.getActionSet().select<SetupMolInfo*>();
145  if( moldat.size()==0 ) error("Unable to find MOLINFO in input");
146  std::vector< std::vector<AtomNumber> > backatoms;
147  moldat[0]->getBackbone( resstrings, backnames, backatoms );
148  for(unsigned i=0;i<backatoms.size();++i){
149  log.printf(" atoms in entity %d : ", groups.size()+1 );
150  for(unsigned j=0;j<backatoms[i].size();++j) log.printf("%d ",backatoms[i][j].serial() );
151  log.printf("\n");
152  groups.push_back( backatoms[i] );
153  merge.insert(merge.end(),backatoms[i].begin(),backatoms[i].end());
154  }
155  }
156 
157  if(groups.size()==0) error("no atom found for WHOLEMOLECULES!");
158 
159  checkRead();
161  requestAtoms(merge);
162 }
163 
165  for(unsigned i=0;i<groups.size();++i){
166  for(unsigned j=0;j<groups[i].size()-1;++j){
167  Vector & first (atoms.modifyPosition(groups[i][j]));
168  Vector & second (atoms.modifyPosition(groups[i][j+1]));
169  second=first+pbcDistance(first,second);
170  }
171  }
172 }
173 
174 
175 
176 }
177 
178 }
Log & log
Reference to the log stream.
Definition: Action.h:93
This is used to create PLMD::Action objects that are run with some set frequency. ...
Definition: ActionPilot.h:39
Class implementing fixed size vectors of doubles.
Definition: Vector.h:74
void error(const std::string &msg) const
Crash calculation and print documentation.
Definition: Action.cpp:195
void checkRead()
Check if Action was properly read.
Definition: Action.cpp:161
STL namespace.
void parseAtomList(const std::string &key, std::vector< AtomNumber > &t)
Parse a list of atoms without a numbered keyword.
void calculate()
Calculate an Action.
This class holds the keywords and their documentation.
Definition: Keywords.h:36
vector< vector< AtomNumber > > groups
Provides the keyword WHOLEMOLECULES
This class is used to bring the relevant information to the Action constructor.
Definition: Action.h:41
Action used to create objects that access the positions of the atoms from the MD code.
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
Definition: OFile.cpp:82
void apply()
Apply an Action.
Base class for all the input Actions.
Definition: Action.h:60
void parseVector(const std::string &key, std::vector< T > &t)
Parse one keyword as std::vector.
Definition: Action.h:311
Vector & modifyPosition(AtomNumber i)
Definition: Atoms.h:197
static void removeDuplicates(std::vector< T > &vec)
Remove duplicates from a vector of type T.
Definition: Tools.h:150
Vector pbcDistance(const Vector &, const Vector &) const
Compute the pbc distance between two positions.
void requestAtoms(const std::vector< AtomNumber > &a)
Request an array of atoms.
Main plumed object.
Definition: Plumed.h:201