LCOV - code coverage report
Current view: top level - dimred - SketchMapProjection.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 29 29 100.0 %
Date: 2024-10-18 13:59:31 Functions: 2 3 66.7 %

          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 ); mapping::Path::registerInputFileKeywords( keys );
      48           8 :   keys.add("compulsory","PROPERTY","the property to be used in the index. This should be in the REMARK of the reference");
      49           8 :   keys.add("compulsory","WEIGHT","the weight of each individual landmark in the stress fucntion that is to be optimised");
      50           8 :   keys.add("compulsory","HIGH_DIM_FUNCTION","the parameters of the switching function in the high dimensional space");
      51           8 :   keys.add("compulsory","LOW_DIM_FUNCTION","the parameters of the switching function in the low dimensional space");
      52           8 :   keys.add("compulsory","CGTOL","1E-6","The tolerance for the conjugate gradient minimization that finds the out of sample projections");
      53           8 :   keys.setValueDescription("scalar/vector","the out-of-sample projections of the input arguments using the input sketch-map projection");
      54          16 :   keys.needsAction("RMSD"); keys.needsAction("PDB2CONSTANT"); keys.needsAction("CONSTANT"); keys.needsAction("CUSTOM");
      55           8 :   keys.needsAction("EUCLIDEAN_DISTANCE"); keys.needsAction("NORMALIZED_EUCLIDEAN_DISTANCE");
      56          12 :   keys.needsAction("SUM"); keys.needsAction("MORE_THAN"); keys.needsAction("PROJECT_POINTS");
      57           4 : }
      58             : 
      59           1 : SketchMapProjection::SketchMapProjection( const ActionOptions& ao):
      60             :   Action(ao),
      61           1 :   ActionShortcut(ao)
      62             : {
      63             :   // Use path to read in the projections
      64             :   std::string refname, refactions, metric;
      65           2 :   std::vector<std::string> argnames; parseVector("ARG",argnames);
      66           2 :   std::string type, reference_data, reference; parse("REFERENCE",reference); parse("TYPE",type);
      67           1 :   mapping::Path::readInputFrames( reference, type, argnames, false, this, reference_data );
      68             :   // And read in the data that we want on the projections
      69           2 :   std::vector<std::string> pnames; parseVector("PROPERTY",pnames);
      70           2 :   std::string weights; parse("WEIGHT",weights); pnames.push_back( weights );
      71             :   // Now create fixed vectors using some sort of reference action
      72           1 :   mapping::Path::readPropertyInformation( pnames, getShortcutLabel(), reference, this );
      73             :   // Normalise the vector of weights
      74           2 :   readInputLine( getShortcutLabel() + "_wsum: SUM PERIODIC=NO ARG=" + weights + "_ref");
      75           2 :   readInputLine( getShortcutLabel() + "_weights: CUSTOM ARG=" + getShortcutLabel() + "_wsum," +  weights + "_ref FUNC=y/x PERIODIC=NO");
      76             :   // Transform the high dimensional distances
      77           1 :   std::string hdfunc; parse("HIGH_DIM_FUNCTION",hdfunc);
      78           2 :   readInputLine( getShortcutLabel() + "_targ: MORE_THAN ARG=" + getShortcutLabel() + "_data SQUARED SWITCH={" + hdfunc + "}");
      79             :   // Create the projection object
      80           3 :   std::string ldfunc, cgtol; parse("LOW_DIM_FUNCTION",ldfunc); parse("CGTOL",cgtol);
      81           3 :   std::string argstr="ARG=" + pnames[0] + "_ref"; for(unsigned i=1; i<pnames.size()-1; ++i) argstr += "," + pnames[i] + "_ref";
      82           3 :   readInputLine( getShortcutLabel() + ": PROJECT_POINTS " + argstr + " TARGET1=" + getShortcutLabel() + "_targ " +
      83           3 :                  "FUNC1={" + ldfunc + "} WEIGHTS1=" + getShortcutLabel() + "_weights CGTOL=" + cgtol );
      84           3 : }
      85             : 
      86             : }
      87             : }

Generated by: LCOV version 1.16