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 : \par Examples 31 : 32 : */ 33 : //+ENDPLUMEDOC 34 : 35 : namespace PLMD { 36 : namespace dimred { 37 : 38 : class SketchMapProjection : public ActionShortcut { 39 : public: 40 : static void registerKeywords( Keywords& keys ); 41 : explicit SketchMapProjection( const ActionOptions& ao ); 42 : }; 43 : 44 : PLUMED_REGISTER_ACTION(SketchMapProjection,"SKETCHMAP_PROJECTION") 45 : 46 4 : void SketchMapProjection::registerKeywords( Keywords& keys ) { 47 4 : ActionShortcut::registerKeywords( keys ); 48 4 : mapping::Path::registerInputFileKeywords( keys ); 49 4 : keys.add("compulsory","PROPERTY","the property to be used in the index. This should be in the REMARK of the reference"); 50 4 : keys.add("compulsory","WEIGHT","the weight of each individual landmark in the stress fucntion that is to be optimised"); 51 4 : keys.add("compulsory","HIGH_DIM_FUNCTION","the parameters of the switching function in the high dimensional space"); 52 4 : keys.add("compulsory","LOW_DIM_FUNCTION","the parameters of the switching function in the low dimensional space"); 53 4 : keys.add("compulsory","CGTOL","1E-6","The tolerance for the conjugate gradient minimization that finds the out of sample projections"); 54 8 : keys.setValueDescription("scalar/vector","the out-of-sample projections of the input arguments using the input sketch-map projection"); 55 4 : keys.needsAction("RMSD"); 56 4 : keys.needsAction("PDB2CONSTANT"); 57 4 : keys.needsAction("CONSTANT"); 58 4 : keys.needsAction("CUSTOM"); 59 4 : keys.needsAction("EUCLIDEAN_DISTANCE"); 60 4 : keys.needsAction("NORMALIZED_EUCLIDEAN_DISTANCE"); 61 4 : keys.needsAction("SUM"); 62 4 : keys.needsAction("MORE_THAN"); 63 4 : keys.needsAction("PROJECT_POINTS"); 64 4 : } 65 : 66 1 : SketchMapProjection::SketchMapProjection( const ActionOptions& ao): 67 : Action(ao), 68 1 : ActionShortcut(ao) { 69 : // Use path to read in the projections 70 : std::string refname, refactions, metric; 71 : std::vector<std::string> argnames; 72 2 : parseVector("ARG",argnames); 73 : std::string type, reference_data, reference; 74 1 : parse("REFERENCE",reference); 75 1 : parse("TYPE",type); 76 1 : mapping::Path::readInputFrames( reference, type, argnames, false, this, reference_data ); 77 : // And read in the data that we want on the projections 78 : std::vector<std::string> pnames; 79 2 : parseVector("PROPERTY",pnames); 80 : std::string weights; 81 1 : parse("WEIGHT",weights); 82 1 : pnames.push_back( weights ); 83 : // Now create fixed vectors using some sort of reference action 84 1 : mapping::Path::readPropertyInformation( pnames, getShortcutLabel(), reference, this ); 85 : // Normalise the vector of weights 86 2 : readInputLine( getShortcutLabel() + "_wsum: SUM PERIODIC=NO ARG=" + weights + "_ref"); 87 2 : readInputLine( getShortcutLabel() + "_weights: CUSTOM ARG=" + getShortcutLabel() + "_wsum," + weights + "_ref FUNC=y/x PERIODIC=NO"); 88 : // Transform the high dimensional distances 89 : std::string hdfunc; 90 1 : parse("HIGH_DIM_FUNCTION",hdfunc); 91 2 : readInputLine( getShortcutLabel() + "_targ: MORE_THAN ARG=" + getShortcutLabel() + "_data SQUARED SWITCH={" + hdfunc + "}"); 92 : // Create the projection object 93 : std::string ldfunc, cgtol; 94 1 : parse("LOW_DIM_FUNCTION",ldfunc); 95 2 : parse("CGTOL",cgtol); 96 1 : std::string argstr="ARG=" + pnames[0] + "_ref"; 97 2 : for(unsigned i=1; i<pnames.size()-1; ++i) { 98 2 : argstr += "," + pnames[i] + "_ref"; 99 : } 100 3 : readInputLine( getShortcutLabel() + ": PROJECT_POINTS " + argstr + " TARGET1=" + getShortcutLabel() + "_targ " + 101 3 : "FUNC1={" + ldfunc + "} WEIGHTS1=" + getShortcutLabel() + "_weights CGTOL=" + cgtol ); 102 3 : } 103 : 104 : } 105 : }