Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2015-2020 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 "core/ActionShortcut.h" 23 : #include "core/ActionRegister.h" 24 : #include "mapping/Path.h" 25 : 26 : //+PLUMEDOC DIMRED SKETCHMAP_PROJECTION 27 : /* 28 : Read in a sketch-map projection 29 : 30 : This shortcut can be used to read in a projection of a trajectory that was generated using [SKETCHMAP](SKETCHMAP.md). 31 : You can then use the coordinates that were read in to generate projections of other configurations. Examples of how 32 : this tool might be used are given in the last three papers cited below. In these papers, a sketch-map projection is 33 : computed from one particular set of data points. This sketch-map projection that was output was then used to analyse 34 : a second completely different data set. 35 : 36 : An example input that illustrates how the sketch-map projection shortcut is used is shown below: 37 : 38 : ```plumed 39 : #SETTING INPUTFILES=regtest/dimred/rt-smap-read/smap.pdb 40 : d1: DISTANCE ATOMS=1,2 41 : d2: DISTANCE ATOMS=3,4 42 : d3: DISTANCE ATOMS=5,6 43 : 44 : smap: SKETCHMAP_PROJECTION ... 45 : ARG=d1,d2,d3 REFERENCE=regtest/dimred/rt-smap-read/smap.pdb 46 : PROPERTY=smap_coord-1,smap_coord-2 CGTOL=1E-3 47 : WEIGHT=WEIGHT HIGH_DIM_FUNCTION={SMAP R_0=4 A=3 B=2} LOW_DIM_FUNCTION={SMAP R_0=4 A=1 B=2} 48 : ... 49 : 50 : PRINT ARG=smap.* FILE=colvar 51 : ``` 52 : 53 : Each frame in your input trajectory generates the three distances so one set of sketch-map coordinates are generated from each frame. 54 : Notice that if you want to generate projections of multiple input points at once you need to use [PROJECT_POINTS](PROJECT_POINTS.md) 55 : directly rather than this wrapper. 56 : 57 : The configurations of the landmark points in your sketch-map input file can also be defined in terms of a set of atomic positions. 58 : In this case the distance between the reference configurations and the instantaneous coordinates are calculated using [RMSD](RMSD.md). 59 : An input for this type of calculation is as follows: 60 : 61 : ```plumed 62 : #SETTING INPUTFILES=regtest/dimred/rt-mds-rmsd/embed.pdb.reference 63 : 64 : smap: SKETCHMAP_PROJECTION ... 65 : REFERENCE=regtest/dimred/rt-mds-rmsd/embed.pdb.reference 66 : PROPERTY=mds-1,mds-2 CGTOL=1E-3 67 : WEIGHT=weights HIGH_DIM_FUNCTION={SMAP R_0=4 A=3 B=2} LOW_DIM_FUNCTION={SMAP R_0=4 A=1 B=2} 68 : ... 69 : ``` 70 : 71 : */ 72 : //+ENDPLUMEDOC 73 : 74 : namespace PLMD { 75 : namespace dimred { 76 : 77 : class SketchMapProjection : public ActionShortcut { 78 : public: 79 : static void registerKeywords( Keywords& keys ); 80 : explicit SketchMapProjection( const ActionOptions& ao ); 81 : }; 82 : 83 : PLUMED_REGISTER_ACTION(SketchMapProjection,"SKETCHMAP_PROJECTION") 84 : 85 4 : void SketchMapProjection::registerKeywords( Keywords& keys ) { 86 4 : ActionShortcut::registerKeywords( keys ); 87 4 : mapping::Path::registerInputFileKeywords( keys ); 88 4 : keys.add("compulsory","PROPERTY","the property to be used in the index. This should be in the REMARK of the reference"); 89 4 : keys.add("compulsory","WEIGHT","the weight of each individual landmark in the stress fucntion that is to be optimised"); 90 4 : keys.add("compulsory","HIGH_DIM_FUNCTION","the parameters of the switching function in the high dimensional space"); 91 4 : keys.add("compulsory","LOW_DIM_FUNCTION","the parameters of the switching function in the low dimensional space"); 92 4 : keys.add("compulsory","CGTOL","1E-6","The tolerance for the conjugate gradient minimization that finds the out of sample projections"); 93 8 : keys.setValueDescription("scalar/vector","the out-of-sample projections of the input arguments using the input sketch-map projection"); 94 4 : keys.addDOI("10.1073/pnas.1108486108"); 95 4 : keys.addDOI("10.1073/pnas.1201152109"); 96 4 : keys.addDOI("10.1021/ct3010563"); 97 4 : keys.addDOI("10.1021/ct500950z"); 98 4 : keys.addDOI("10.1021/acs.jctc.5b00714"); 99 4 : keys.needsAction("RMSD"); 100 4 : keys.needsAction("PDB2CONSTANT"); 101 4 : keys.needsAction("CONSTANT"); 102 4 : keys.needsAction("CUSTOM"); 103 4 : keys.needsAction("EUCLIDEAN_DISTANCE"); 104 4 : keys.needsAction("NORMALIZED_EUCLIDEAN_DISTANCE"); 105 4 : keys.needsAction("SUM"); 106 4 : keys.needsAction("MORE_THAN"); 107 4 : keys.needsAction("PROJECT_POINTS"); 108 4 : } 109 : 110 1 : SketchMapProjection::SketchMapProjection( const ActionOptions& ao): 111 : Action(ao), 112 1 : ActionShortcut(ao) { 113 : // Use path to read in the projections 114 : std::string refname, refactions, metric; 115 : std::vector<std::string> argnames; 116 2 : parseVector("ARG",argnames); 117 : std::string type, reference_data, reference; 118 1 : parse("REFERENCE",reference); 119 1 : parse("TYPE",type); 120 1 : mapping::Path::readInputFrames( reference, type, argnames, false, this, reference_data ); 121 : // And read in the data that we want on the projections 122 : std::vector<std::string> pnames; 123 2 : parseVector("PROPERTY",pnames); 124 : std::string weights; 125 1 : parse("WEIGHT",weights); 126 1 : pnames.push_back( weights ); 127 : // Now create fixed vectors using some sort of reference action 128 1 : mapping::Path::readPropertyInformation( pnames, getShortcutLabel(), reference, this ); 129 : // Normalise the vector of weights 130 2 : readInputLine( getShortcutLabel() + "_wsum: SUM PERIODIC=NO ARG=" + weights + "_ref"); 131 2 : readInputLine( getShortcutLabel() + "_weights: CUSTOM ARG=" + weights + "_ref," + getShortcutLabel() + "_wsum FUNC=x/y PERIODIC=NO"); 132 : // Transform the high dimensional distances 133 : std::string hdfunc; 134 1 : parse("HIGH_DIM_FUNCTION",hdfunc); 135 2 : readInputLine( getShortcutLabel() + "_targ: MORE_THAN ARG=" + getShortcutLabel() + "_data SQUARED SWITCH={" + hdfunc + "}"); 136 : // Create the projection object 137 : std::string ldfunc, cgtol; 138 1 : parse("LOW_DIM_FUNCTION",ldfunc); 139 2 : parse("CGTOL",cgtol); 140 1 : std::string argstr="ARG=" + pnames[0] + "_ref"; 141 2 : for(unsigned i=1; i<pnames.size()-1; ++i) { 142 2 : argstr += "," + pnames[i] + "_ref"; 143 : } 144 3 : readInputLine( getShortcutLabel() + ": PROJECT_POINTS " + argstr + " TARGET1=" + getShortcutLabel() + "_targ " + 145 3 : "FUNC1={" + ldfunc + "} WEIGHTS1=" + getShortcutLabel() + "_weights CGTOL=" + cgtol ); 146 3 : } 147 : 148 : } 149 : }