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 1223 : void PbcAction::registerKeywords( Keywords& keys ) { 65 1223 : Action::registerKeywords( keys ); 66 1223 : keys.add("hidden","NO_ACTION_LOG","suppresses printing from action on the log"); 67 2446 : keys.setValueDescription("matrix","a matrix containing the cell vectors that were passed from the MD code"); 68 1223 : } 69 : 70 1216 : PbcAction::PbcAction(const ActionOptions&ao): 71 : Action(ao), 72 : ActionToPutData(ao), 73 1216 : interface(NULL) { 74 1216 : std::vector<unsigned> shape(2); 75 1216 : shape[0]=shape[1]=3; 76 1216 : addValue( shape ); 77 1216 : setNotPeriodic(); 78 2432 : setUnit( "length", "energy" ); 79 1216 : getPntrToValue()->buildDataStore(); 80 1216 : getPntrToValue()->reshapeMatrixStore(3); 81 1216 : } 82 : 83 : 84 68710 : void PbcAction::setPbc() { 85 68710 : if( !interface ) { 86 1013 : std::vector<DomainDecomposition*> allput=plumed.getActionSet().select<DomainDecomposition*>(); 87 1013 : if( allput.size()>1 ) { 88 0 : warning("found more than one interface so don't know how to broadcast cell"); 89 : } 90 1013 : interface = allput[0]; 91 : } 92 68710 : Tensor box; 93 68710 : if( interface ) { 94 68710 : interface->broadcastToDomains( getPntrToValue() ); 95 : } 96 274840 : for(unsigned i=0; i<3; ++i) 97 824520 : for(unsigned j=0; j<3; ++j) { 98 618390 : box(i,j) = getPntrToValue()->get(3*i+j); 99 : } 100 68710 : pbc.setBox(box); 101 68710 : } 102 : 103 68596 : void PbcAction::wait() { 104 68596 : ActionToPutData::wait(); 105 68596 : setPbc(); 106 68596 : } 107 : 108 114 : void PbcAction::readBinary(std::istream&i) { 109 114 : ActionToPutData::readBinary(i); 110 114 : setPbc(); 111 114 : } 112 : 113 : } 114 : 115 : 116 :