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 "MultiColvarBase.h"
23 : #include "AtomValuePack.h"
24 : #include "tools/SwitchingFunction.h"
25 : #include "core/ActionRegister.h"
26 :
27 : #include <string>
28 : #include <cmath>
29 :
30 : using namespace std;
31 :
32 : namespace PLMD {
33 : namespace multicolvar {
34 :
35 : //+PLUMEDOC MCOLVAR BRIDGE
36 : /*
37 : Calculate the number of atoms that bridge two parts of a structure
38 :
39 : This quantity calculates:
40 :
41 : \f[
42 : f(x) = \sum_{ijk} s_A(r_{ij})s_B(r_{ik})
43 : \f]
44 :
45 : where the sum over \f$i\f$ is over all the ``bridging atoms" and
46 : \f$s_A\f$ and \f$s_B\f$ are \ref switchingfunction.
47 :
48 : \par Examples
49 :
50 : The following example instructs plumed to calculate the number of water molecules
51 : that are bridging betweeen atoms 1-10 and atoms 11-20 and to print the value
52 : to a file
53 :
54 : \plumedfile
55 : BRIDGE BRIDGING_ATOMS=100-200 GROUPA=1-10 GROUPB=11-20 LABEL=w1
56 : PRINT ARG=a1.mean FILE=colvar
57 : \endplumedfile
58 :
59 : */
60 : //+ENDPLUMEDOC
61 :
62 18 : class Bridge : public MultiColvarBase {
63 : private:
64 : Vector dij, dik;
65 : SwitchingFunction sf1;
66 : SwitchingFunction sf2;
67 : public:
68 : static void registerKeywords( Keywords& keys );
69 : explicit Bridge(const ActionOptions&);
70 : // active methods:
71 : virtual double compute( const unsigned& tindex, AtomValuePack& myatoms ) const ;
72 0 : bool isPeriodic() { return false; }
73 : };
74 :
75 6461 : PLUMED_REGISTER_ACTION(Bridge,"BRIDGE")
76 :
77 10 : void Bridge::registerKeywords( Keywords& keys ) {
78 10 : MultiColvarBase::registerKeywords( keys );
79 40 : keys.add("atoms-2","BRIDGING_ATOMS","The list of atoms that can form the bridge between the two interesting parts "
80 : "of the structure.");
81 40 : keys.add("atoms-2","GROUPA","The list of atoms that are in the first interesting part of the structure");
82 40 : keys.add("atoms-2","GROUPB","The list of atoms that are in the second interesting part of the structure");
83 40 : keys.add("optional","SWITCH","The parameters of the two \\ref switchingfunction in the above formula");
84 40 : keys.add("optional","SWITCHA","The \\ref switchingfunction on the distance between bridging atoms and the atoms in "
85 : "group A");
86 40 : keys.add("optional","SWITCHB","The \\ref switchingfunction on the distance between the bridging atoms and the atoms in "
87 : "group B");
88 10 : }
89 :
90 9 : Bridge::Bridge(const ActionOptions&ao):
91 : Action(ao),
92 9 : MultiColvarBase(ao)
93 : {
94 : // Read in the atoms
95 : std::vector<AtomNumber> all_atoms;
96 36 : readThreeGroups("GROUPA","GROUPB","BRIDGING_ATOMS",false,true,all_atoms);
97 : // Setup the multicolvar base
98 9 : setupMultiColvarBase( all_atoms );
99 : // Setup Central atom atoms
100 9 : std::vector<bool> catom_ind(3, false); catom_ind[0]=true;
101 9 : setAtomsForCentralAtom( catom_ind );
102 :
103 18 : std::string sfinput,errors; parse("SWITCH",sfinput);
104 9 : if( sfinput.length()>0 ) {
105 9 : sf1.set(sfinput,errors);
106 9 : if( errors.length()!=0 ) error("problem reading SWITCH keyword : " + errors );
107 9 : sf2.set(sfinput,errors);
108 9 : if( errors.length()!=0 ) error("problem reading SWITCH keyword : " + errors );
109 : } else {
110 0 : parse("SWITCHA",sfinput);
111 0 : if(sfinput.length()>0) {
112 0 : weightHasDerivatives=true;
113 0 : sf1.set(sfinput,errors);
114 0 : if( errors.length()!=0 ) error("problem reading SWITCHA keyword : " + errors );
115 0 : sfinput.clear(); parse("SWITCHB",sfinput);
116 0 : if(sfinput.length()==0) error("found SWITCHA keyword without SWITCHB");
117 0 : sf2.set(sfinput,errors);
118 0 : if( errors.length()!=0 ) error("problem reading SWITCHB keyword : " + errors );
119 : } else {
120 0 : error("missing definition of switching functions");
121 : }
122 : }
123 27 : log.printf(" distance between bridging atoms and atoms in GROUPA must be less than %s\n",sf1.description().c_str());
124 27 : log.printf(" distance between bridging atoms and atoms in GROUPB must be less than %s\n",sf2.description().c_str());
125 :
126 : // Setup link cells
127 9 : setLinkCellCutoff( sf1.get_dmax() + sf2.get_dmax() );
128 :
129 : // And setup the ActionWithVessel
130 9 : if( getNumberOfVessels()!=0 ) error("should not have vessels for this action");
131 : std::string fake_input;
132 18 : addVessel( "SUM", fake_input, -1 ); // -1 here means that this value will be named getLabel()
133 9 : readVesselKeywords();
134 : // And check everything has been read in correctly
135 9 : checkRead();
136 9 : }
137 :
138 50537 : double Bridge::compute( const unsigned& tindex, AtomValuePack& myatoms ) const {
139 : double tot=0;
140 1142718 : for(unsigned i=2; i<myatoms.getNumberOfAtoms(); ++i) {
141 1041644 : Vector dij=getSeparation( myatoms.getPosition(i), myatoms.getPosition(0) );
142 520822 : double dw1, w1=sf1.calculateSqr( dij.modulo2(), dw1 );
143 520822 : Vector dik=getSeparation( myatoms.getPosition(i), myatoms.getPosition(1) );
144 520822 : double dw2, w2=sf2.calculateSqr( dik.modulo2(), dw2 );
145 :
146 520822 : tot += w1*w2;
147 : // And finish the calculation
148 520822 : addAtomDerivatives( 1, 0, w2*dw1*dij, myatoms );
149 520822 : addAtomDerivatives( 1, 1, w1*dw2*dik, myatoms );
150 520822 : addAtomDerivatives( 1, i, -w1*dw2*dik-w2*dw1*dij, myatoms );
151 520822 : myatoms.addBoxDerivatives( 1, w1*(-dw2)*Tensor(dik,dik)+w2*(-dw1)*Tensor(dij,dij) );
152 : }
153 50537 : return tot;
154 : }
155 :
156 : }
157 4839 : }
|