All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Target.cpp
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 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-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
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 "Function.h"
23 #include "ActionRegister.h"
24 #include "tools/PDB.h"
25 #include "core/TargetDist.h"
26 #include "core/Atoms.h"
27 #include "core/PlumedMain.h"
28 
29 using namespace std;
30 
31 namespace PLMD {
32 namespace function{
33 
34 //+PLUMEDOC FUNCTION TARGET
35 /*
36 This function measures the pythagorean distance from a particular structure measured in the space defined by some
37 set of collective variables.
38 
39 \par Examples
40 
41 
42 */
43 //+ENDPLUMEDOC
44 
45 class Target : public Function {
46 private:
48  std::vector<double> derivs;
49 public:
50  Target(const ActionOptions&);
51  virtual void calculate();
52  static void registerKeywords(Keywords& keys );
53 };
54 
55 PLUMED_REGISTER_ACTION(Target,"TARGET")
56 
57 void Target::registerKeywords(Keywords& keys){
58  Function::registerKeywords(keys);
59  keys.use("ARG");
60  keys.add("compulsory","REFERENCE","a file in pdb format containing the reference structure. In the PDB file the atomic "
61  "coordinates and box lengths should be in Angstroms unless you are working with natural units. "
62  "If you are working with natural units then the coordinates should be in your natural length unit. "
63  "The charges and masses of the atoms (if required) should be inserted in the beta and occupancy "
64  "columns respectively. For more details on the PDB file format visit http://www.wwpdb.org/docs.html");
65  keys.add("optional","REFERENCE_VEC","the vector of values for the CVs at the reference point (if you use this you don't need REFERENCE)");
66 }
67 
68 Target::Target(const ActionOptions&ao):
69 Action(ao),
70 Function(ao),
71 target(log)
72 {
73  std::vector<double> targ;
74  parseVector("REFERENCE_VEC",targ);
75  if( targ.size()!=0 ){
76  target.read( targ, getArguments() );
77  } else {
78  string reference;
79  parse("REFERENCE",reference);
80  PDB pdb;
81  if( !pdb.read(reference,plumed.getAtoms().usingNaturalUnits(),0.1/plumed.getAtoms().getUnits().getLength()) )
82  error("missing input file " + reference);
83  printf("Read pdb file with %d atoms inside\n",pdb.size());
84  target.read( pdb, getArguments() );
85  }
86  checkRead();
87  derivs.resize( getNumberOfArguments() );
89 }
90 
92  double r=target.calculate( derivs );
93  setValue(r);
94  for(unsigned i=0;i<derivs.size();i++) setDerivative(i,derivs[i]);
95 }
96 
97 }
98 }
bool read(const std::string &file, bool naturalUnits, double scale)
Read the pdb from a file, scaling positions by a factor scale.
Definition: PDB.cpp:144
void read(const PDB &pdb, std::vector< Value * > args)
Definition: TargetDist.cpp:30
void setNotPeriodic()
Set your default value to have no periodicity.
TargetDist target
Definition: Target.cpp:47
void error(const std::string &msg) const
Crash calculation and print documentation.
Definition: Action.cpp:195
void checkRead()
Check if Action was properly read.
Definition: Action.cpp:161
STL namespace.
double calculate(std::vector< double > &derivs)
Definition: TargetDist.cpp:59
void parse(const std::string &key, T &t)
Parse one keyword as generic type.
Definition: Action.h:273
This class holds the keywords and their documentation.
Definition: Keywords.h:36
Provides the keyword TARGET
Definition: Target.cpp:45
This class is used to bring the relevant information to the Action constructor.
Definition: Action.h:41
std::vector< Value * > & getArguments()
Returns an array of pointers to the arguments.
Base class for all the input Actions.
Definition: Action.h:60
void parseVector(const std::string &key, std::vector< T > &t)
Parse one keyword as std::vector.
Definition: Action.h:311
void setValue(const double &d)
Set the default value (the one without name)
Minimalistic pdb parser.
Definition: PDB.h:38
std::vector< double > derivs
Definition: Target.cpp:48
Main plumed object.
Definition: Plumed.h:201
This is the abstract base class to use for implementing new CV function, within it there is informati...
Definition: Function.h:37
unsigned size() const
Returns the number of atoms.
Definition: PDB.cpp:72
unsigned getNumberOfArguments() const
Returns the number of arguments.
void setDerivative(int, double)
Definition: Function.h:59
virtual void calculate()
Calculate an Action.
Definition: Target.cpp:91