All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Cell.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 "Colvar.h"
23 #include "ActionRegister.h"
24 
25 #include <string>
26 #include <cmath>
27 
28 using namespace std;
29 
30 namespace PLMD{
31 namespace colvar{
32 
33 //+PLUMEDOC COLVAR CELL
34 /*
35 Calculate the components of the simulation cell
36 
37 \par Examples
38 The following input tells plumed to print the squared modulo of each of the three lattice vectors
39 \verbatim
40 cell: CELL
41 aaa: COMBINE ARG=cell.ax,cell.ay,cell.az POWERS=2,2,2 PERIODIC=NO
42 bbb: COMBINE ARG=cell.bx,cell.by,cell.bz POWERS=2,2,2 PERIODIC=NO
43 ccc: COMBINE ARG=cell.cx,cell.cy,cell.cz POWERS=2,2,2 PERIODIC=NO
44 PRINT ARG=aaa,bbb,ccc
45 \endverbatim
46 (See also \ref COMBINE and \ref PRINT).
47 
48 */
49 //+ENDPLUMEDOC
50 
51 
52 class Cell : public Colvar {
53  Value* components[3][3];
54 
55 public:
56  Cell(const ActionOptions&);
57 // active methods:
58  virtual void calculate();
59 /// Register all the keywords for this action
60  static void registerKeywords( Keywords& keys );
61 };
62 
63 PLUMED_REGISTER_ACTION(Cell,"CELL")
64 
65 Cell::Cell(const ActionOptions&ao):
67 {
68  std::vector<AtomNumber> atoms;
69  checkRead();
70 
71  addComponentWithDerivatives("ax"); componentIsNotPeriodic("ax"); components[0][0]=getPntrToComponent("ax");
72  addComponentWithDerivatives("ay"); componentIsNotPeriodic("ay"); components[0][1]=getPntrToComponent("ay");
73  addComponentWithDerivatives("az"); componentIsNotPeriodic("az"); components[0][2]=getPntrToComponent("az");
74  addComponentWithDerivatives("bx"); componentIsNotPeriodic("bx"); components[1][0]=getPntrToComponent("bx");
75  addComponentWithDerivatives("by"); componentIsNotPeriodic("by"); components[1][1]=getPntrToComponent("by");
76  addComponentWithDerivatives("bz"); componentIsNotPeriodic("bz"); components[1][2]=getPntrToComponent("bz");
77  addComponentWithDerivatives("cx"); componentIsNotPeriodic("cx"); components[2][0]=getPntrToComponent("cx");
78  addComponentWithDerivatives("cy"); componentIsNotPeriodic("cy"); components[2][1]=getPntrToComponent("cy");
79  addComponentWithDerivatives("cz"); componentIsNotPeriodic("cz"); components[2][2]=getPntrToComponent("cz");
80  requestAtoms(atoms);
81 }
82 
83 void Cell::registerKeywords( Keywords& keys ){
84  Action::registerKeywords( keys );
85  ActionWithValue::registerKeywords( keys );
86  ActionAtomistic::registerKeywords( keys );
87  componentsAreNotOptional(keys);
88  keys.addOutputComponent("ax","default","the ax component of the cell matrix");
89  keys.addOutputComponent("ay","default","the ay component of the cell matrix");
90  keys.addOutputComponent("az","default","the az component of the cell matrix");
91  keys.addOutputComponent("bx","default","the bx component of the cell matrix");
92  keys.addOutputComponent("by","default","the by component of the cell matrix");
93  keys.addOutputComponent("bz","default","the bz component of the cell matrix");
94  keys.addOutputComponent("cx","default","the cx component of the cell matrix");
95  keys.addOutputComponent("cy","default","the cy component of the cell matrix");
96  keys.addOutputComponent("cz","default","the cz component of the cell matrix");
97 }
98 
99 
100 // calculator
101 void Cell::calculate(){
102 
103  for(int i=0;i<3;i++) for(int j=0;j<3;j++) components[i][j]->set(getBox()[i][j]);
104  for(int l=0;l<3;l++) for(int m=0;m<3;m++){
105  Tensor der; for(int i=0;i<3;i++) der[i][m]=getBox()[l][i];
106  setBoxDerivatives(components[l][m],-der);
107  }
108 }
109 
110 }
111 }
112 
113 
114 
Class implementing fixed size matrices of doubles.
Definition: Tensor.h:70
A class for holding the value of a function together with its derivatives.
Definition: Value.h:46
STL namespace.
Provides the keyword CELL
Definition: Cell.cpp:52
#define PLUMED_COLVAR_INIT(ao)
Definition: Colvar.h:29
void addOutputComponent(const std::string &name, const std::string &key, const std::string &descr)
Add a potential component which can be output by this particular action.
Definition: Keywords.cpp:565
This class holds the keywords and their documentation.
Definition: Keywords.h:36
This class is used to bring the relevant information to the Action constructor.
Definition: Action.h:41
This is the abstract base class to use for implementing new collective variables, within it there is ...
Definition: Colvar.h:39
void const char const char int double int double double int int double int * m
Definition: Matrix.h:42