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