Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2013-2019 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 16 : 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 8 : keys.remove("TOL");
36 16 : 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 4 : readArgument("bridge");
48 4 : aves=dynamic_cast<ActionWithVessel*>( getDependencies()[0] );
49 :
50 4 : plumed_assert( getDependencies().size()==1 && aves );
51 4 : 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 124 : 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 4 : 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 29600 : double dval=0, val=calcPotential( invals.get(1), dval );
75 :
76 : outvals.setValue( 1, val );
77 458800 : 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 458800 : 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 4839 : }
96 :
|