Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2013-2023 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 "core/ActionRegister.h"
24 :
25 : namespace PLMD {
26 : namespace colvar {
27 :
28 : //+PLUMEDOC COLVAR CELL
29 : /*
30 : Get the components of the simulation cell
31 :
32 : The following input tells plumed to print the squared modulo of each of the three lattice vectors
33 :
34 : ```plumed
35 : cell: CELL
36 : aaa: COMBINE ARG=cell.ax,cell.ay,cell.az POWERS=2,2,2 PERIODIC=NO
37 : bbb: COMBINE ARG=cell.bx,cell.by,cell.bz POWERS=2,2,2 PERIODIC=NO
38 : ccc: COMBINE ARG=cell.cx,cell.cy,cell.cz POWERS=2,2,2 PERIODIC=NO
39 : PRINT ARG=aaa,bbb,ccc
40 : ```
41 :
42 : */
43 : //+ENDPLUMEDOC
44 :
45 :
46 : class Cell : public Colvar {
47 : Value* components[3][3];
48 :
49 : public:
50 : explicit Cell(const ActionOptions&);
51 : // active methods:
52 : void calculate() override;
53 : /// Register all the keywords for this action
54 : static void registerKeywords( Keywords& keys );
55 : };
56 :
57 : PLUMED_REGISTER_ACTION(Cell,"CELL")
58 :
59 10 : Cell::Cell(const ActionOptions&ao):
60 10 : PLUMED_COLVAR_INIT(ao) {
61 : std::vector<AtomNumber> atoms;
62 10 : checkRead();
63 :
64 20 : addComponentWithDerivatives("ax");
65 10 : componentIsNotPeriodic("ax");
66 10 : components[0][0]=getPntrToComponent("ax");
67 20 : addComponentWithDerivatives("ay");
68 10 : componentIsNotPeriodic("ay");
69 10 : components[0][1]=getPntrToComponent("ay");
70 20 : addComponentWithDerivatives("az");
71 10 : componentIsNotPeriodic("az");
72 10 : components[0][2]=getPntrToComponent("az");
73 20 : addComponentWithDerivatives("bx");
74 10 : componentIsNotPeriodic("bx");
75 10 : components[1][0]=getPntrToComponent("bx");
76 20 : addComponentWithDerivatives("by");
77 10 : componentIsNotPeriodic("by");
78 10 : components[1][1]=getPntrToComponent("by");
79 20 : addComponentWithDerivatives("bz");
80 10 : componentIsNotPeriodic("bz");
81 10 : components[1][2]=getPntrToComponent("bz");
82 20 : addComponentWithDerivatives("cx");
83 10 : componentIsNotPeriodic("cx");
84 10 : components[2][0]=getPntrToComponent("cx");
85 20 : addComponentWithDerivatives("cy");
86 10 : componentIsNotPeriodic("cy");
87 10 : components[2][1]=getPntrToComponent("cy");
88 20 : addComponentWithDerivatives("cz");
89 10 : componentIsNotPeriodic("cz");
90 10 : components[2][2]=getPntrToComponent("cz");
91 10 : requestAtoms(atoms);
92 10 : }
93 :
94 12 : void Cell::registerKeywords( Keywords& keys ) {
95 12 : Action::registerKeywords( keys );
96 12 : ActionWithValue::registerKeywords( keys );
97 12 : ActionAtomistic::registerKeywords( keys );
98 24 : keys.addOutputComponent("ax","default","scalar","the ax component of the cell matrix");
99 24 : keys.addOutputComponent("ay","default","scalar","the ay component of the cell matrix");
100 24 : keys.addOutputComponent("az","default","scalar","the az component of the cell matrix");
101 24 : keys.addOutputComponent("bx","default","scalar","the bx component of the cell matrix");
102 24 : keys.addOutputComponent("by","default","scalar","the by component of the cell matrix");
103 24 : keys.addOutputComponent("bz","default","scalar","the bz component of the cell matrix");
104 24 : keys.addOutputComponent("cx","default","scalar","the cx component of the cell matrix");
105 24 : keys.addOutputComponent("cy","default","scalar","the cy component of the cell matrix");
106 24 : keys.addOutputComponent("cz","default","scalar","the cz component of the cell matrix");
107 12 : }
108 :
109 :
110 : // calculator
111 151 : void Cell::calculate() {
112 :
113 604 : for(int i=0; i<3; i++)
114 1812 : for(int j=0; j<3; j++) {
115 1359 : components[i][j]->set(getBox()[i][j]);
116 : }
117 604 : for(int l=0; l<3; l++)
118 1812 : for(int m=0; m<3; m++) {
119 1359 : Tensor der;
120 5436 : for(int i=0; i<3; i++) {
121 4077 : der[i][m]=getBox()[l][i];
122 : }
123 1359 : setBoxDerivatives(components[l][m],-der);
124 : }
125 151 : }
126 :
127 : }
128 : }
129 :
130 :
131 :
|