Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2013-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 "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 :
39 : The following input tells plumed to print the squared modulo of each of the three lattice vectors
40 : \verbatim
41 : cell: CELL
42 : aaa: COMBINE ARG=cell.ax,cell.ay,cell.az POWERS=2,2,2 PERIODIC=NO
43 : bbb: COMBINE ARG=cell.bx,cell.by,cell.bz POWERS=2,2,2 PERIODIC=NO
44 : ccc: COMBINE ARG=cell.cx,cell.cy,cell.cz POWERS=2,2,2 PERIODIC=NO
45 : PRINT ARG=aaa,bbb,ccc
46 : \endverbatim
47 : (See also \ref COMBINE and \ref PRINT).
48 :
49 : */
50 : //+ENDPLUMEDOC
51 :
52 :
53 18 : class Cell : public Colvar {
54 : Value* components[3][3];
55 :
56 : public:
57 : explicit Cell(const ActionOptions&);
58 : // active methods:
59 : virtual void calculate();
60 : /// Register all the keywords for this action
61 : static void registerKeywords( Keywords& keys );
62 : };
63 :
64 2532 : PLUMED_REGISTER_ACTION(Cell,"CELL")
65 :
66 9 : Cell::Cell(const ActionOptions&ao):
67 9 : PLUMED_COLVAR_INIT(ao)
68 : {
69 9 : std::vector<AtomNumber> atoms;
70 9 : checkRead();
71 :
72 9 : addComponentWithDerivatives("ax"); componentIsNotPeriodic("ax"); components[0][0]=getPntrToComponent("ax");
73 9 : addComponentWithDerivatives("ay"); componentIsNotPeriodic("ay"); components[0][1]=getPntrToComponent("ay");
74 9 : addComponentWithDerivatives("az"); componentIsNotPeriodic("az"); components[0][2]=getPntrToComponent("az");
75 9 : addComponentWithDerivatives("bx"); componentIsNotPeriodic("bx"); components[1][0]=getPntrToComponent("bx");
76 9 : addComponentWithDerivatives("by"); componentIsNotPeriodic("by"); components[1][1]=getPntrToComponent("by");
77 9 : addComponentWithDerivatives("bz"); componentIsNotPeriodic("bz"); components[1][2]=getPntrToComponent("bz");
78 9 : addComponentWithDerivatives("cx"); componentIsNotPeriodic("cx"); components[2][0]=getPntrToComponent("cx");
79 9 : addComponentWithDerivatives("cy"); componentIsNotPeriodic("cy"); components[2][1]=getPntrToComponent("cy");
80 9 : addComponentWithDerivatives("cz"); componentIsNotPeriodic("cz"); components[2][2]=getPntrToComponent("cz");
81 9 : requestAtoms(atoms);
82 9 : }
83 :
84 10 : void Cell::registerKeywords( Keywords& keys ) {
85 10 : Action::registerKeywords( keys );
86 10 : ActionWithValue::registerKeywords( keys );
87 10 : ActionAtomistic::registerKeywords( keys );
88 10 : componentsAreNotOptional(keys);
89 10 : keys.addOutputComponent("ax","default","the ax component of the cell matrix");
90 10 : keys.addOutputComponent("ay","default","the ay component of the cell matrix");
91 10 : keys.addOutputComponent("az","default","the az component of the cell matrix");
92 10 : keys.addOutputComponent("bx","default","the bx component of the cell matrix");
93 10 : keys.addOutputComponent("by","default","the by component of the cell matrix");
94 10 : keys.addOutputComponent("bz","default","the bz component of the cell matrix");
95 10 : keys.addOutputComponent("cx","default","the cx component of the cell matrix");
96 10 : keys.addOutputComponent("cy","default","the cy component of the cell matrix");
97 10 : keys.addOutputComponent("cz","default","the cz component of the cell matrix");
98 10 : }
99 :
100 :
101 : // calculator
102 150 : void Cell::calculate() {
103 :
104 150 : for(int i=0; i<3; i++) for(int j=0; j<3; j++) components[i][j]->set(getBox()[i][j]);
105 1500 : for(int l=0; l<3; l++) for(int m=0; m<3; m++) {
106 1350 : Tensor der; for(int i=0; i<3; i++) der[i][m]=getBox()[l][i];
107 1350 : setBoxDerivatives(components[l][m],-der);
108 : }
109 150 : }
110 :
111 : }
112 2523 : }
113 :
114 :
115 :
|