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 : \par Examples 34 : 35 : */ 36 : //+ENDPLUMEDOC 37 : 38 : namespace PLMD { 39 : 40 : PLUMED_REGISTER_ACTION(PbcAction,"PBC") 41 : 42 1231 : void PbcAction::registerKeywords( Keywords& keys ) { 43 1231 : Action::registerKeywords( keys ); 44 2462 : keys.add("hidden","NO_ACTION_LOG","suppresses printing from action on the log"); 45 1231 : keys.setValueDescription("a matrix containing the cell vectors that were passed from the MD code"); 46 1231 : } 47 : 48 1222 : PbcAction::PbcAction(const ActionOptions&ao): 49 : Action(ao), 50 : ActionToPutData(ao), 51 1222 : interface(NULL) { 52 1222 : std::vector<unsigned> shape(2); 53 1222 : shape[0]=shape[1]=3; 54 1222 : addValue( shape ); 55 1222 : setNotPeriodic(); 56 2444 : setUnit( "length", "energy" ); 57 1222 : getPntrToValue()->buildDataStore(); 58 1222 : getPntrToValue()->reshapeMatrixStore(3); 59 1222 : } 60 : 61 : 62 68721 : void PbcAction::setPbc() { 63 68721 : if( !interface ) { 64 1019 : std::vector<DomainDecomposition*> allput=plumed.getActionSet().select<DomainDecomposition*>(); 65 1019 : if( allput.size()>1 ) { 66 0 : warning("found more than one interface so don't know how to broadcast cell"); 67 : } 68 1019 : interface = allput[0]; 69 : } 70 68721 : Tensor box; 71 68721 : if( interface ) { 72 68721 : interface->broadcastToDomains( getPntrToValue() ); 73 : } 74 274884 : for(unsigned i=0; i<3; ++i) 75 824652 : for(unsigned j=0; j<3; ++j) { 76 618489 : box(i,j) = getPntrToValue()->get(3*i+j); 77 : } 78 68721 : pbc.setBox(box); 79 68721 : } 80 : 81 68607 : void PbcAction::wait() { 82 68607 : ActionToPutData::wait(); 83 68607 : setPbc(); 84 68607 : } 85 : 86 114 : void PbcAction::readBinary(std::istream&i) { 87 114 : ActionToPutData::readBinary(i); 88 114 : setPbc(); 89 114 : } 90 : 91 : } 92 : 93 : 94 :