Collective Variables Module - Developer Documentation
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
colvarproxy_vmd.h
1 // -*- c++ -*-
2 
3 #ifndef COLVARPROXY_VMD_H
4 #define COLVARPROXY_VMD_H
5 
6 #include <tcl.h>
7 
8 #include "DrawMolecule.h"
9 #include "Timestep.h"
10 #include "Inform.h"
11 
12 #include "colvarmodule.h"
13 #include "colvarproxy.h"
14 #include "colvartypes.h"
15 #include "colvaratoms.h"
16 
17 #ifndef COLVARPROXY_VERSION
18 #define COLVARPROXY_VERSION "2016-12-23"
19 #endif
20 
21 
22 int tcl_colvars(ClientData clientdata, Tcl_Interp *interp, int argc, const char *argv[]);
23 
24 
27 class colvarproxy_vmd : public colvarproxy {
28 
29 protected:
30 
32  Tcl_Interp *interp;
34  VMDApp *vmd;
36  int vmdmolid;
38  DrawMolecule *vmdmol;
40  long int vmdmol_frame;
42  Inform msgColvars;
43 
44 public:
45 
46 
47  friend class cvm::atom;
48 
49  colvarproxy_vmd(Tcl_Interp *interp, VMDApp *vmd, int molid);
50  ~colvarproxy_vmd();
51 
52  int setup();
53 
54  int update_input();
57 
59  {
60  return 1.0;
61  }
62 
64  {
65  return 0.001987191;
66  }
67 
69  {
70  // TODO define, document and implement a user method to set the value of this
71  return 300.0;
72  }
73 
74  inline cvm::real dt()
75  {
76  // TODO define, document and implement a user method to set the value of this
77  return 1.0;
78  }
79 
81  {
82  return vmd_random_gaussian();
83  }
84 
85  inline int get_frame(long int &f)
86  {
87  f = vmdmol_frame;
88  return COLVARS_OK;
89  }
90 
91  int set_frame(long int f);
92 
93  std::string input_prefix_str;
94  std::string input_prefix()
95  {
96  return input_prefix_str;
97  }
98 
99  std::string restart_output_prefix()
100  {
101  // note: this shouldn't need to be called in VMD anyway
102  return output_prefix_str;
103  }
104 
105  std::string output_prefix_str;
106  inline std::string output_prefix()
107  {
108  return output_prefix_str;
109  }
110 
111  void add_energy(cvm::real energy);
112 
113 private:
114  bool total_force_requested;
115 public:
116  void request_total_force(bool yesno);
117 
119  cvm::atom_pos const &pos2);
121  cvm::atom_pos const &pos2);
122 
124  cvm::atom_pos const &ref_pos);
125 
126  std::string error_output;
127  void log(std::string const &message);
128  void error(std::string const &message);
129  void fatal_error(std::string const &message);
130  void exit(std::string const &message);
131 
132  // Callback functions
133  int run_force_callback();
134  int run_colvar_callback(std::string const &name,
135  std::vector<const colvarvalue *> const &cvcs,
136  colvarvalue &value);
137  int run_colvar_gradient_callback(std::string const &name,
138  std::vector<const colvarvalue *> const &cvcs,
139  std::vector<colvarvalue> &gradient);
140 
141  int load_atoms(char const *filename,
142  cvm::atom_group &atoms,
143  std::string const &pdb_field,
144  double const pdb_field_value = 0.0);
145 
146  int load_coords(char const *filename,
147  std::vector<cvm::atom_pos> &pos,
148  const std::vector<int> &indices,
149  std::string const &pdb_field,
150  double const pdb_field_value = 0.0);
151 
152  int init_atom(int atom_number);
153  int check_atom_id(int atom_number);
154  int init_atom(cvm::residue_id const &residue,
155  std::string const &atom_name,
156  std::string const &segment_id);
157  int check_atom_id(cvm::residue_id const &residue,
158  std::string const &atom_name,
159  std::string const &segment_id);
160 
161 };
162 
163 
164 
166  cvm::atom_pos const &pos2)
167 {
168  // TODO: add in the proxy constructor a check for orthonormal PBCs
169  Timestep *ts = vmdmol->get_frame(vmdmol_frame);
170  cvm::real const a = ts->a_length;
171  cvm::real const b = ts->b_length;
172  cvm::real const c = ts->c_length;
173  cvm::rvector diff = (pos2 - pos1);
174  if (a*a > 1.0e-12) {
175  while (diff.x <= -0.5*a) diff.x += a;
176  while (diff.x > 0.5*a) diff.x -= a;
177  }
178  if (b*b > 1.0e-12) {
179  while (diff.y <= -0.5*b) diff.y += b;
180  while (diff.y > 0.5*b) diff.y -= b;
181  }
182  if (c*c > 1.0e-12) {
183  while (diff.z <= -0.5*c) diff.z += c;
184  while (diff.z > 0.5*c) diff.z -= c;
185  }
186  return diff;
187 }
188 
189 
191  cvm::atom_pos const &ref_pos)
192 {
193  cvm::rvector const diff = position_distance(ref_pos, pos);
194  pos = ref_pos + diff;
195 }
196 
197 
199  cvm::atom_pos const &pos2)
200 {
201  cvm::rvector const d = position_distance(pos1, pos2);
202  return cvm::real(d.x*d.x + d.y*d.y + d.z*d.z);
203 }
204 
205 
206 
207 #endif
208 
cvm::real temperature()
Temperature of the simulation (K)
Definition: colvarproxy_vmd.h:68
cvm::real dt()
Time step of the simulation (fs)
Definition: colvarproxy_vmd.h:74
Communication between colvars and VMD (implementation of colvarproxy)
Definition: colvarproxy_vmd.h:27
void exit(std::string const &message)
Print a message to the main log and exit normally.
Definition: colvarproxy_vmd.C:272
void request_total_force(bool yesno)
Tell the proxy whether total forces are needed (may not always be available)
Definition: colvarproxy_vmd.C:232
Stores numeric id, mass and all mutable data for an atom, mostly used by a cvc.
Definition: colvaratoms.h:20
int run_force_callback()
Run a user-defined colvar forces script.
int load_atoms(char const *filename, cvm::atom_group &atoms, std::string const &pdb_field, double const pdb_field_value=0.0)
Read atom identifiers from a file.
Definition: colvarproxy_vmd.C:552
int init_atom(int atom_number)
Prepare this atom for collective variables calculation, selecting it by numeric index (1-based) ...
Definition: colvarproxy_vmd.C:633
vector of real numbers with three components
Definition: colvartypes.h:709
int set_frame(long int f)
Set the current frame number (as well as colvarmodule::it)
Definition: colvarproxy_vmd.C:278
Interface between the collective variables module and the simulation or analysis program (NAMD...
Definition: colvarproxy.h:20
cvm::real rand_gaussian()
Pseudo-random number with Gaussian distribution.
Definition: colvarproxy_vmd.h:80
Collective variables main module.
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:85
void error(std::string const &message)
Print a message to the main log and let the rest of the program handle the error. ...
Definition: colvarproxy_vmd.C:253
cvm::real unit_angstrom()
Value of the unit for atomic coordinates with respect to angstroms (used by some variables for hard-c...
Definition: colvarproxy_vmd.h:58
static std::string & output_prefix()
Accessor for the above.
Definition: colvarmodule.h:164
Value of a collective variable: this is a metatype which can be set at runtime. By default it is set ...
Definition: colvarvalue.h:34
cvm::real boltzmann()
Boltzmann constant.
Definition: colvarproxy_vmd.h:63
int setup()
(Re)initialize required member data after construction
Definition: colvarproxy_vmd.C:162
void select_closest_image(cvm::atom_pos &pos, cvm::atom_pos const &ref_pos)
Get the closest periodic image to a reference position.
Definition: colvarproxy_vmd.h:190
cvm::rvector position_distance(cvm::atom_pos const &pos1, cvm::atom_pos const &pos2)
Get the PBC-aware distance vector between two positions.
Definition: colvarproxy_vmd.h:165
int update_input()
Update data required by the colvars module (e.g. cache atom positions)
Definition: colvarproxy_vmd.C:183
void log(std::string const &message)
Print a message to the main log.
Definition: colvarproxy_vmd.C:243
int residue_id
Residue identifier.
Definition: colvarmodule.h:87
void add_energy(cvm::real energy)
Pass restraint energy value for current timestep to MD engine.
Definition: colvarproxy_vmd.C:372
Tcl_Interp * interp
pointer to the VMD Tcl interpreter
Definition: colvarproxy_vmd.h:32
void fatal_error(std::string const &message)
Print a message to the main log and exit with error code.
Definition: colvarproxy_vmd.C:264
long int vmdmol_frame
current frame (returned by vmdmol->frame())
Definition: colvarproxy_vmd.h:40
cvm::real position_dist2(cvm::atom_pos const &pos1, cvm::atom_pos const &pos2)
Get the PBC-aware square distance between two positions; may need to be reimplemented independently f...
Definition: colvarproxy_vmd.h:198
int update_atomic_properties()
Update mass, charge, etc.
Definition: colvarproxy_vmd.C:203
cvm::atom_pos pos
Current position (copied from the program, can be modified if necessary)
Definition: colvaratoms.h:40
int get_frame(long int &f)
Get the current frame number.
Definition: colvarproxy_vmd.h:85
int vmdmolid
VMD molecule id being used (must be provided at construction)
Definition: colvarproxy_vmd.h:36
int check_atom_id(int atom_number)
Check that this atom number is valid, but do not initialize the corresponding atom yet...
Definition: colvarproxy_vmd.C:614
int load_coords(char const *filename, std::vector< cvm::atom_pos > &pos, const std::vector< int > &indices, std::string const &pdb_field, double const pdb_field_value=0.0)
Load the coordinates for a group of atoms from a file (usually a PDB); if "pos" is already allocated...
Definition: colvarproxy_vmd.C:425
VMDApp * vmd
pointer to the VMD main object
Definition: colvarproxy_vmd.h:34
Inform msgColvars
output object
Definition: colvarproxy_vmd.h:42
DrawMolecule * vmdmol
pointer to VMD molecule (derived from vmdmolid)
Definition: colvarproxy_vmd.h:38
Group of atom objects, mostly used by a cvc object to gather all atomic data.
Definition: colvaratoms.h:141