NAMD
colvarproxy_namd.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 
3 // This file is part of the Collective Variables module (Colvars).
4 // The original version of Colvars and its updates are located at:
5 // https://github.com/Colvars/colvars
6 // Please update all Colvars source files before making any changes.
7 // If you wish to distribute your changes, please submit them to the
8 // Colvars repository at GitHub.
9 
10 #ifndef COLVARPROXY_NAMD_H
11 #define COLVARPROXY_NAMD_H
12 
13 #ifndef NAMD_VERSION_NUMBER
14 // Assume 2.14b1 for now until the NAMD macro is merged
15 #define NAMD_VERSION_NUMBER 34471681
16 #endif
17 
19 
20 #include "Vector.h"
21 #include "ResizeArray.h"
22 #include "NamdTypes.h"
23 #include "SimParameters.h"
24 #include "Lattice.h"
25 #include "GlobalMaster.h"
26 #include "Random.h"
27 
28 #include "colvarmodule.h"
29 #include "colvarproxy.h"
30 #include "colvarvalue.h"
31 
34 class colvarproxy_namd : public colvarproxy, public GlobalMaster {
35 
36 protected:
37 
40  std::vector<int> atoms_map;
41 
44 
47 
50 
53 
56 
57  void init_tcl_pointers();
58 
59 public:
60 
61  friend class cvm::atom;
62 
65 
66  int setup();
67  int reset();
68 
69  // synchronize the local arrays with requested or forced atoms
72 
73  void calculate();
74 
75  void log(std::string const &message);
76  void error(std::string const &message);
77  int set_unit_system(std::string const &units_in, bool check_only);
78  void exit(std::string const &message);
79  void add_energy(cvm::real energy);
80  void request_total_force(bool yesno);
81 
82  bool total_forces_enabled() const
83  {
84  return total_force_requested;
85  }
86 
87  int run_force_callback();
88  int run_colvar_callback(std::string const &name,
89  std::vector<const colvarvalue *> const &cvcs,
90  colvarvalue &value);
91  int run_colvar_gradient_callback(std::string const &name,
92  std::vector<const colvarvalue *> const &cvcs,
93  std::vector<cvm::matrix2d<cvm::real> > &gradient);
94 
96  {
97  return 1.0;
98  }
99 
100  cvm::real boltzmann()
101  {
102  return 0.001987191;
103  }
104 
105  cvm::real temperature()
106  {
107  return thermostat_temperature;
108  }
109 
110  cvm::real rand_gaussian()
111  {
112  return random.gaussian();
113  }
114 
115  cvm::real dt()
116  {
117  return simparams->dt;
118  }
119 
120 #if CMK_SMP && USE_CKLOOP
121  int smp_enabled()
122  {
123  if (b_smp_active) {
124  return COLVARS_OK;
125  }
126  return COLVARS_ERROR;
127  }
128 
129  int smp_colvars_loop();
130 
131  int smp_biases_loop();
132 
133  int smp_biases_script_loop();
134 
135  friend void calc_colvars_items_smp(int first, int last, void *result, int paramNum, void *param);
136  friend void calc_cv_biases_smp(int first, int last, void *result, int paramNum, void *param);
137  friend void calc_cv_scripted_forces(int paramNum, void *param);
138 
139  int smp_thread_id()
140  {
141  return CkMyRank();
142  }
143 
144  int smp_num_threads()
145  {
146  return CkMyNodeSize();
147  }
148 
149 protected:
150 
151  CmiNodeLock charm_lock_state;
152 
153 public:
154 
155  int smp_lock()
156  {
157  charm_lock_state = CmiCreateLock();
158  return COLVARS_OK;
159  }
160 
161  int smp_trylock()
162  {
163  return COLVARS_NOT_IMPLEMENTED;
164  }
165 
166  int smp_unlock()
167  {
168  CmiDestroyLock(charm_lock_state);
169  return COLVARS_OK;
170  }
171 
172 #endif // #if CMK_SMP && USE_CKLOOP
173 
174  virtual int replica_enabled();
175  virtual int replica_index();
176  virtual int num_replicas();
177  virtual void replica_comm_barrier();
178  virtual int replica_comm_recv(char* msg_data, int buf_len, int src_rep);
179  virtual int replica_comm_send(char* msg_data, int msg_len, int dest_rep);
180 
181  int init_atom(int atom_number);
182  int check_atom_id(int atom_number);
183  int init_atom(cvm::residue_id const &residue,
184  std::string const &atom_name,
185  std::string const &segment_id);
186  int check_atom_id(cvm::residue_id const &residue,
187  std::string const &atom_name,
188  std::string const &segment_id);
189  void clear_atom(int index);
190 
191  void update_atom_properties(int index);
192 
193  cvm::rvector position_distance(cvm::atom_pos const &pos1,
194  cvm::atom_pos const &pos2) const;
195 
196  int load_atoms(char const *filename,
197  cvm::atom_group &atoms,
198  std::string const &pdb_field,
199  double const pdb_field_value = 0.0);
200 
201  int load_coords(char const *filename,
202  std::vector<cvm::atom_pos> &pos,
203  const std::vector<int> &indices,
204  std::string const &pdb_field,
205  double const pdb_field_value = 0.0);
206 
207 
209  {
210  return COLVARS_OK;
211  }
212  int init_atom_group(std::vector<int> const &atoms_ids);
213  void clear_atom_group(int index);
214  int update_group_properties(int index);
215 
216 #if NAMD_VERSION_NUMBER >= 34471681
217  int init_volmap(int volmap_id);
218  int init_volmap(const char *volmap_name);
219  void clear_volmap(int index);
220 #endif
221 
222  std::ostream * output_stream(std::string const &output_name,
223  std::ios_base::openmode mode);
224  int flush_output_stream(std::ostream *os);
225  int close_output_stream(std::string const &output_name);
226  int backup_file(char const *filename);
227 
228  char const *script_obj_to_str(unsigned char *obj);
229  std::vector<std::string> script_obj_to_str_vector(unsigned char *obj);
230 };
231 
232 
233 #endif
cvm::rvector position_distance(cvm::atom_pos const &pos1, cvm::atom_pos const &pos2) const
SimParameters * simparams
Pointer to the NAMD simulation input object.
cvm::real temperature()
Random random
NAMD-style PRNG object.
const Elem * const_iterator
Definition: ResizeArray.h:38
BigReal gaussian(void)
Definition: Random.h:116
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)
cvm::real boltzmann()
Communication between colvars and NAMD (implementation of colvarproxy)
static __thread atom * atoms
int init_atom(int atom_number)
int close_output_stream(std::string const &output_name)
bool total_forces_enabled() const
cvm::real rand_gaussian()
int init_atom_group(std::vector< int > const &atoms_ids)
int run_colvar_callback(std::string const &name, std::vector< const colvarvalue * > const &cvcs, colvarvalue &value)
char const * script_obj_to_str(unsigned char *obj)
std::vector< int > atoms_map
Array of atom indices (relative to the colvarproxy arrays), usedfor faster copy of atomic data...
Definition: Random.h:37
void clear_atom(int index)
int run_colvar_gradient_callback(std::string const &name, std::vector< const colvarvalue * > const &cvcs, std::vector< cvm::matrix2d< cvm::real > > &gradient)
void request_total_force(bool yesno)
friend class cvm::atom
int set_unit_system(std::string const &units_in, bool check_only)
void clear_volmap(int index)
std::ostream * output_stream(std::string const &output_name, std::ios_base::openmode mode)
void log(std::string const &message)
void exit(std::string const &message)
int update_group_properties(int index)
void error(std::string const &message)
virtual int replica_comm_recv(char *msg_data, int buf_len, int src_rep)
virtual int replica_index()
void update_atom_properties(int index)
std::vector< std::string > script_obj_to_str_vector(unsigned char *obj)
void clear_atom_group(int index)
int check_atom_id(int atom_number)
virtual int replica_enabled()
virtual void replica_comm_barrier()
BigReal thermostat_temperature
Self-explained.
int load_atoms(char const *filename, cvm::atom_group &atoms, std::string const &pdb_field, double const pdb_field_value=0.0)
void add_energy(cvm::real energy)
int flush_output_stream(std::ostream *os)
cvm::real backend_angstrom_value()
SubmitReduction * reduction
Used to submit restraint energy as MISC.
int backup_file(char const *filename)
int init_volmap(int volmap_id)
virtual int replica_comm_send(char *msg_data, int msg_len, int dest_rep)
int update_atoms_map(AtomIDList::const_iterator begin, AtomIDList::const_iterator end)
virtual int num_replicas()
double BigReal
Definition: common.h:114