Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2014-2018 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 "BridgedMultiColvarFunction.h"
23 : #include "core/PlumedMain.h"
24 : #include "core/ActionSet.h"
25 : #include "CatomPack.h"
26 :
27 : namespace PLMD {
28 : namespace multicolvar {
29 :
30 55 : void BridgedMultiColvarFunction::registerKeywords( Keywords& keys ) {
31 55 : MultiColvarBase::registerKeywords( keys );
32 55 : keys.add("compulsory","DATA","The multicolvar that calculates the set of base quantities that we are interested in");
33 55 : }
34 :
35 43 : BridgedMultiColvarFunction::BridgedMultiColvarFunction(const ActionOptions&ao):
36 : Action(ao),
37 43 : MultiColvarBase(ao)
38 : {
39 43 : std::string mlab; parse("DATA",mlab);
40 43 : mycolv = plumed.getActionSet().selectWithLabel<MultiColvarBase*>(mlab);
41 43 : if(!mycolv) error("action labeled " + mlab + " does not exist or is not a multicolvar");
42 :
43 : // When using numerical derivatives here we must use numerical derivatives
44 : // in base multicolvar
45 43 : if( checkNumericalDerivatives() ) mycolv->useNumericalDerivatives();
46 :
47 43 : myBridgeVessel = mycolv->addBridgingVessel( this ); addDependency(mycolv);
48 43 : weightHasDerivatives=true; usespecies=mycolv->usespecies;
49 : // Number of tasks is the same as the number in the underlying MultiColvar
50 43 : for(unsigned i=0; i<mycolv->getFullNumberOfTasks(); ++i) addTaskToList( mycolv->getTaskCode(i) );
51 43 : }
52 :
53 43 : void BridgedMultiColvarFunction::turnOnDerivatives() {
54 43 : BridgedMultiColvarFunction* check = dynamic_cast<BridgedMultiColvarFunction*>( mycolv );
55 43 : if( check ) {
56 0 : if( check->getNumberOfAtoms()>0 ) error("cannot calculate required derivatives of this quantity");
57 : }
58 43 : MultiColvarBase::turnOnDerivatives();
59 43 : }
60 :
61 100553 : void BridgedMultiColvarFunction::transformBridgedDerivatives( const unsigned& current, MultiValue& invals, MultiValue& outvals ) const {
62 100553 : completeTask( current, invals, outvals );
63 :
64 : // Now update the outvals derivatives lists
65 100578 : if( derivativesAreRequired() ) {
66 93668 : outvals.emptyActiveMembers();
67 93594 : if( mycolv->isDensity() ) {
68 43317 : for(unsigned j=0; j<3; ++j) outvals.putIndexInActiveArray( 3*current+j );
69 43408 : for(unsigned j=invals.getNumberOfDerivatives()-9; j<invals.getNumberOfDerivatives(); ++j) outvals.putIndexInActiveArray(j);
70 : } else {
71 50266 : for(unsigned j=0; j<invals.getNumberActive(); ++j) outvals.putIndexInActiveArray( invals.getActiveIndex(j) );
72 : }
73 93676 : for(unsigned j=invals.getNumberOfDerivatives(); j<outvals.getNumberOfDerivatives(); ++j) outvals.putIndexInActiveArray( j );
74 93680 : outvals.completeUpdate();
75 : }
76 100586 : }
77 :
78 13042 : void BridgedMultiColvarFunction::performTask( const unsigned& taskIndex, const unsigned& current, MultiValue& myvals ) const {
79 13042 : MultiValue invals( mycolv->getNumberOfQuantities(), mycolv->getNumberOfDerivatives() );
80 13042 : invals.clearAll(); mycolv->performTask( taskIndex, current, invals );
81 13042 : transformBridgedDerivatives( taskIndex, invals, myvals );
82 13042 : }
83 :
84 60 : void BridgedMultiColvarFunction::calculateNumericalDerivatives( ActionWithValue* a ) {
85 60 : if(!a) {
86 60 : a=dynamic_cast<ActionWithValue*>(this);
87 60 : plumed_massert(a,"cannot compute numerical derivatives for an action without values");
88 : }
89 60 : if( myBridgeVessel ) {
90 60 : myBridgeVessel->completeNumericalDerivatives();
91 : } else {
92 0 : error("numerical derivatives are not implemented");
93 : }
94 60 : }
95 :
96 0 : void BridgedMultiColvarFunction::applyBridgeForces( const std::vector<double>& bb ) {
97 0 : if( getNumberOfAtoms()==0 ) return ;
98 :
99 0 : std::vector<Vector>& f( modifyForces() );
100 0 : for(unsigned i=0; i<getNumberOfAtoms(); ++i) {
101 0 : f[i][0]+=bb[3*i+0]; f[i][1]+=bb[3*i+1]; f[i][2]+=bb[3*i+2];
102 : }
103 : }
104 :
105 34 : bool BridgedMultiColvarFunction::isPeriodic() {
106 34 : return mycolv->isPeriodic();
107 : }
108 :
109 0 : void BridgedMultiColvarFunction::deactivate_task( const unsigned& taskno ) {
110 0 : plumed_merror("This should never be called");
111 : }
112 :
113 11582 : CatomPack BridgedMultiColvarFunction::getCentralAtomPack( const unsigned& basn, const unsigned& curr ) {
114 11582 : return mycolv->getCentralAtomPack( basn, curr );
115 : }
116 :
117 : }
118 2523 : }
|