Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2015-2020 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 "ValueVessel.h" 23 : 24 : namespace PLMD { 25 : namespace vesselbase { 26 : 27 320 : void ValueVessel::registerKeywords( Keywords& keys ) { 28 320 : Vessel::registerKeywords( keys ); 29 1600 : keys.add("compulsory","COMPONENT","1","the component of the vector for which to calculate this quantity"); 30 320 : } 31 : 32 320 : ValueVessel::ValueVessel( const VesselOptions& da ): 33 320 : Vessel(da) 34 : { 35 640 : parse("COMPONENT",mycomp); 36 320 : ActionWithValue* a=dynamic_cast<ActionWithValue*>( getAction() ); 37 320 : plumed_massert(a,"cannot create passable values as base action does not inherit from ActionWithValue"); 38 : int numval = getNumericalLabel(); 39 358 : if( numval<0 && a->getNumberOfComponents()==0 ) { // This allows us to make multicolvars pretend to be colvars - this is used in AlphaRMSD etc 40 36 : a->addValueWithDerivatives(); 41 36 : a->setNotPeriodic(); 42 36 : final_value=a->copyOutput( a->getNumberOfComponents()-1 ); 43 284 : } else if( numval<0 ) { 44 2 : final_value_ptr.reset(new Value); 45 2 : final_value=final_value_ptr.get(); 46 2 : final_value->setNotPeriodic(); 47 : } else { 48 1692 : plumed_massert( !a->exists(getAction()->getLabel() + "." + getLabel() ), "you can't create the name multiple times"); 49 564 : a->addComponentWithDerivatives( getLabel() ); 50 564 : a->componentIsNotPeriodic( getLabel() ); 51 282 : final_value=a->copyOutput( a->getNumberOfComponents()-1 ); 52 : } 53 320 : } 54 : 55 320 : std::string ValueVessel::description() { 56 1140 : if( final_value->getName()==getAction()->getLabel() ) return "value " + getAction()->getLabel() + " contains " + value_descriptor(); 57 284 : std::string compstr; Tools::convert(mycomp,compstr); 58 3124 : return "value " + getAction()->getLabel() + "." + getLabel() + " is obtained by taking the " + compstr + "th component and finding " + value_descriptor(); 59 : } 60 : 61 11427 : bool ValueVessel::applyForce( std::vector<double>& forces ) { 62 11427 : std::vector<double> tmpforce( forces.size() ); 63 22854 : forces.assign(forces.size(),0.0); bool wasforced=false; 64 11427 : if( final_value->applyForce( tmpforce ) ) { 65 : wasforced=true; 66 2096616 : for(unsigned j=0; j<forces.size(); ++j) forces[j]+=tmpforce[j]; 67 : } 68 11427 : return wasforced; 69 : } 70 : 71 : } 72 5517 : }