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 "ManyRestraintsBase.h" 23 : #include "vesselbase/Vessel.h" 24 : 25 : namespace PLMD { 26 : namespace manyrestraints { 27 : 28 4 : void ManyRestraintsBase::registerKeywords( Keywords& keys ) { 29 4 : Action::registerKeywords( keys ); 30 4 : ActionWithValue::registerKeywords( keys ); 31 4 : ActionWithVessel::registerKeywords( keys ); 32 4 : ActionWithInputVessel::registerKeywords( keys ); 33 4 : ActionPilot::registerKeywords( keys ); 34 8 : keys.add("hidden","STRIDE","the frequency with which the forces due to the bias should be calculated. This can be used to correctly set up multistep algorithms"); 35 4 : keys.remove("TOL"); 36 8 : keys.addOutputComponent("bias","default","the instantaneous value of the bias potentials"); 37 4 : } 38 : 39 2 : ManyRestraintsBase::ManyRestraintsBase(const ActionOptions& ao): 40 : Action(ao), 41 : ActionWithValue(ao), 42 : ActionPilot(ao), 43 : ActionWithVessel(ao), 44 2 : ActionWithInputVessel(ao) 45 : { 46 : // Read in the vessel we are action on 47 2 : readArgument("bridge"); 48 2 : aves=dynamic_cast<ActionWithVessel*>( getDependencies()[0] ); 49 : 50 2 : plumed_assert( getDependencies().size()==1 && aves ); 51 2 : log.printf(" adding restraints on variables calculated by %s action with label %s\n", 52 2 : aves->getName().c_str(),aves->getLabel().c_str()); 53 : 54 : // Add a task list in order to avoid problems 55 42 : for(unsigned i=0; i<aves->getFullNumberOfTasks(); ++i) addTaskToList( aves->getTaskCode(i) ); 56 : // And turn on the derivatives (note problems here because of ActionWithValue) 57 2 : turnOnDerivatives(); needsDerivatives(); 58 : 59 : // Now create the vessel 60 2 : std::string fake_input="LABEL=bias"; 61 2 : addVessel( "SUM", fake_input, 0 ); 62 2 : readVesselKeywords(); 63 2 : } 64 : 65 740 : void ManyRestraintsBase::doJobsRequiredBeforeTaskList() { 66 740 : ActionWithVessel::doJobsRequiredBeforeTaskList(); 67 740 : ActionWithValue::clearDerivatives(); 68 740 : } 69 : 70 14800 : void ManyRestraintsBase::transformBridgedDerivatives( const unsigned& current, MultiValue& invals, MultiValue& outvals ) const { 71 : outvals.setValue( 0, invals.get(0) ); 72 : 73 : // Get the potential 74 14800 : double dval=0, val=calcPotential( invals.get(1), dval ); 75 : 76 : outvals.setValue( 1, val ); 77 236800 : for(unsigned i=0; i<invals.getNumberActive(); ++i) { 78 222000 : unsigned jder=invals.getActiveIndex(i); 79 222000 : outvals.addDerivative( 1, jder, dval*invals.getDerivative( 1, jder ) ); 80 : } 81 : 82 : // Now update the outvals derivatives lists 83 : outvals.emptyActiveMembers(); 84 236800 : for(unsigned j=0; j<invals.getNumberActive(); ++j) outvals.updateIndex( invals.getActiveIndex(j) ); 85 : outvals.completeUpdate(); 86 14800 : return; 87 : } 88 : 89 10 : void ManyRestraintsBase::apply() { 90 : plumed_dbg_assert( getNumberOfComponents()==1 ); 91 10 : getPntrToComponent(0)->addForce( -1.0*getStride() ); 92 10 : } 93 : 94 : } 95 : } 96 :