Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2011-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 "PbcAction.h" 23 : #include "DomainDecomposition.h" 24 : #include "tools/Pbc.h" 25 : #include "PlumedMain.h" 26 : #include "ActionSet.h" 27 : #include "ActionRegister.h" 28 : 29 : //+PLUMEDOC ANALYSIS PBC 30 : /* 31 : Pass the cell vectors into PLUMED. 32 : 33 : This command is used to pass the cell vectors from an MD code to PLUMED. The command is a specialised 34 : version of the [PUT](PUT.md) command that accepts a $3\times 3$ matrix. The additional specialisation is 35 : required because the cell vectors play a special role when you do calculations with PLUMED. 36 : 37 : Notice that when you create a [DOMAIN_DECOMPOSITION](DOMAIN_DECOMPOSITION.md) action a PBC action is created 38 : automatically. 39 : 40 : You would only use the PBC command if you were calling PLUMED from python or an MD code. There is no reason for using this command in a conventional PLUMED 41 : input file like this: 42 : 43 : ```plumed 44 : pbc: PBC 45 : ``` 46 : 47 : Instead this command would be called from python like this: 48 : 49 : ```python 50 : import plumed 51 : 52 : # Create a PLUMED object 53 : p = plumed.Plumed() 54 : p.cmd("readInputLine", "pbc: PBC") 55 : ``` 56 : 57 : */ 58 : //+ENDPLUMEDOC 59 : 60 : namespace PLMD { 61 : 62 : PLUMED_REGISTER_ACTION(PbcAction,"PBC") 63 : 64 2185 : void PbcAction::registerKeywords( Keywords& keys ) { 65 2185 : Action::registerKeywords( keys ); 66 2185 : keys.add("hidden","NO_ACTION_LOG","suppresses printing from action on the log"); 67 4370 : keys.setValueDescription("matrix","a matrix containing the cell vectors that were passed from the MD code"); 68 2185 : } 69 : 70 2176 : PbcAction::PbcAction(const ActionOptions&ao): 71 : Action(ao), 72 : ActionToPutData(ao), 73 2176 : interface(NULL) { 74 2176 : std::vector<std::size_t> shape(2); 75 2176 : shape[0]=shape[1]=3; 76 2176 : addValue( shape ); 77 2176 : setNotPeriodic(); 78 4352 : setUnit( "length", "energy" ); 79 2176 : getPntrToValue()->reshapeMatrixStore(3); 80 2176 : } 81 : 82 : 83 160048 : void PbcAction::setPbc() { 84 160048 : if( !interface ) { 85 1811 : std::vector<DomainDecomposition*> allput=plumed.getActionSet().select<DomainDecomposition*>(); 86 1811 : if( allput.size()>1 ) { 87 0 : warning("found more than one interface so don't know how to broadcast cell"); 88 : } 89 1811 : if( !allput.empty() ) { 90 1811 : interface = allput[0]; 91 : } 92 : } 93 160048 : Tensor box; 94 160048 : if( interface ) { 95 160048 : interface->broadcastToDomains( getPntrToValue() ); 96 : } 97 640192 : for(unsigned i=0; i<3; ++i) 98 1920576 : for(unsigned j=0; j<3; ++j) { 99 1440432 : box(i,j) = getPntrToValue()->get(3*i+j); 100 : } 101 160048 : pbc.setBox(box); 102 160048 : } 103 : 104 159922 : void PbcAction::wait() { 105 159922 : ActionToPutData::wait(); 106 159922 : setPbc(); 107 159922 : } 108 : 109 126 : void PbcAction::readBinary(std::istream&i) { 110 126 : ActionToPutData::readBinary(i); 111 126 : setPbc(); 112 126 : } 113 : 114 : } 115 : 116 : 117 :