LCOV - code coverage report
Current view: top level - colvar - Cell.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 36 36 100.0 %
Date: 2024-10-11 08:09:47 Functions: 6 7 85.7 %

          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 "ActionRegister.h"
      24             : 
      25             : namespace PLMD {
      26             : namespace colvar {
      27             : 
      28             : //+PLUMEDOC COLVAR CELL
      29             : /*
      30             : Calculate the components of the simulation cell
      31             : 
      32             : \par Examples
      33             : 
      34             : The following input tells plumed to print the squared modulo of each of the three lattice vectors
      35             : \plumedfile
      36             : cell: CELL
      37             : aaa:    COMBINE ARG=cell.ax,cell.ay,cell.az POWERS=2,2,2 PERIODIC=NO
      38             : bbb:    COMBINE ARG=cell.bx,cell.by,cell.bz POWERS=2,2,2 PERIODIC=NO
      39             : ccc:    COMBINE ARG=cell.cx,cell.cy,cell.cz POWERS=2,2,2 PERIODIC=NO
      40             : PRINT ARG=aaa,bbb,ccc
      41             : \endplumedfile
      42             : 
      43             : */
      44             : //+ENDPLUMEDOC
      45             : 
      46             : 
      47             : class Cell : public Colvar {
      48             :   Value* components[3][3];
      49             : 
      50             : public:
      51             :   explicit Cell(const ActionOptions&);
      52             : // active methods:
      53             :   void calculate() override;
      54             : /// Register all the keywords for this action
      55             :   static void registerKeywords( Keywords& keys );
      56             : };
      57             : 
      58       10437 : PLUMED_REGISTER_ACTION(Cell,"CELL")
      59             : 
      60           9 : Cell::Cell(const ActionOptions&ao):
      61           9 :   PLUMED_COLVAR_INIT(ao)
      62             : {
      63             :   std::vector<AtomNumber> atoms;
      64           9 :   checkRead();
      65             : 
      66          27 :   addComponentWithDerivatives("ax"); componentIsNotPeriodic("ax"); components[0][0]=getPntrToComponent("ax");
      67          27 :   addComponentWithDerivatives("ay"); componentIsNotPeriodic("ay"); components[0][1]=getPntrToComponent("ay");
      68          27 :   addComponentWithDerivatives("az"); componentIsNotPeriodic("az"); components[0][2]=getPntrToComponent("az");
      69          27 :   addComponentWithDerivatives("bx"); componentIsNotPeriodic("bx"); components[1][0]=getPntrToComponent("bx");
      70          27 :   addComponentWithDerivatives("by"); componentIsNotPeriodic("by"); components[1][1]=getPntrToComponent("by");
      71          27 :   addComponentWithDerivatives("bz"); componentIsNotPeriodic("bz"); components[1][2]=getPntrToComponent("bz");
      72          27 :   addComponentWithDerivatives("cx"); componentIsNotPeriodic("cx"); components[2][0]=getPntrToComponent("cx");
      73          27 :   addComponentWithDerivatives("cy"); componentIsNotPeriodic("cy"); components[2][1]=getPntrToComponent("cy");
      74          27 :   addComponentWithDerivatives("cz"); componentIsNotPeriodic("cz"); components[2][2]=getPntrToComponent("cz");
      75           9 :   requestAtoms(atoms);
      76           9 : }
      77             : 
      78          10 : void Cell::registerKeywords( Keywords& keys ) {
      79          10 :   Action::registerKeywords( keys );
      80          10 :   ActionWithValue::registerKeywords( keys );
      81          10 :   ActionAtomistic::registerKeywords( keys );
      82          10 :   componentsAreNotOptional(keys);
      83          20 :   keys.addOutputComponent("ax","default","the ax component of the cell matrix");
      84          20 :   keys.addOutputComponent("ay","default","the ay component of the cell matrix");
      85          20 :   keys.addOutputComponent("az","default","the az component of the cell matrix");
      86          20 :   keys.addOutputComponent("bx","default","the bx component of the cell matrix");
      87          20 :   keys.addOutputComponent("by","default","the by component of the cell matrix");
      88          20 :   keys.addOutputComponent("bz","default","the bz component of the cell matrix");
      89          20 :   keys.addOutputComponent("cx","default","the cx component of the cell matrix");
      90          20 :   keys.addOutputComponent("cy","default","the cy component of the cell matrix");
      91          20 :   keys.addOutputComponent("cz","default","the cz component of the cell matrix");
      92          10 : }
      93             : 
      94             : 
      95             : // calculator
      96         150 : void Cell::calculate() {
      97             : 
      98        1950 :   for(int i=0; i<3; i++) for(int j=0; j<3; j++) components[i][j]->set(getBox()[i][j]);
      99        1950 :   for(int l=0; l<3; l++) for(int m=0; m<3; m++) {
     100        5400 :       Tensor der; for(int i=0; i<3; i++) der[i][m]=getBox()[l][i];
     101        1350 :       setBoxDerivatives(components[l][m],-der);
     102             :     }
     103         150 : }
     104             : 
     105             : }
     106             : }
     107             : 
     108             : 
     109             : 

Generated by: LCOV version 1.15