Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

colvarproxy.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 
00003 // This file is part of the Collective Variables module (Colvars).
00004 // The original version of Colvars and its updates are located at:
00005 // https://github.com/Colvars/colvars
00006 // Please update all Colvars source files before making any changes.
00007 // If you wish to distribute your changes, please submit them to the
00008 // Colvars repository at GitHub.
00009 
00010 #ifndef COLVARPROXY_H
00011 #define COLVARPROXY_H
00012 
00013 #include "colvarmodule.h"
00014 #include "colvartypes.h"
00015 #include "colvarvalue.h"
00016 #include "colvarproxy_io.h"
00017 #include "colvarproxy_system.h"
00018 #include "colvarproxy_tcl.h"
00019 #include "colvarproxy_volmaps.h"
00020 
00034 
00035 
00036 // forward declarations
00037 class colvarscript;
00038 
00039 
00041 class colvarproxy_atoms {
00042 
00043 public:
00044 
00046   colvarproxy_atoms();
00047 
00049   virtual ~colvarproxy_atoms();
00050 
00053   virtual int init_atom(int atom_number);
00054 
00057   virtual int check_atom_id(int atom_number);
00058 
00062   virtual int init_atom(cvm::residue_id const &residue,
00063                         std::string const     &atom_name,
00064                         std::string const     &segment_id);
00065 
00067   virtual int check_atom_id(cvm::residue_id const &residue,
00068                             std::string const     &atom_name,
00069                             std::string const     &segment_id);
00070 
00073   virtual void clear_atom(int index);
00074 
00081   virtual int load_atoms(char const *filename,
00082                          cvm::atom_group &atoms,
00083                          std::string const &pdb_field,
00084                          double pdb_field_value = 0.0);
00085 
00094   virtual int load_coords(char const *filename,
00095                           std::vector<cvm::atom_pos> &pos,
00096                           std::vector<int> const &sorted_ids,
00097                           std::string const &pdb_field,
00098                           double pdb_field_value = 0.0);
00099 
00101   int reset();
00102 
00105   inline int get_atom_id(int index) const
00106   {
00107     return atoms_ids[index];
00108   }
00109 
00112   inline cvm::real get_atom_mass(int index) const
00113   {
00114     return atoms_masses[index];
00115   }
00116 
00119   inline void increase_refcount(int index)
00120   {
00121     atoms_refcount[index] += 1;
00122   }
00123 
00126   inline cvm::real get_atom_charge(int index) const
00127   {
00128     return atoms_charges[index];
00129   }
00130 
00133   inline cvm::rvector get_atom_position(int index) const
00134   {
00135     return atoms_positions[index];
00136   }
00137 
00140   inline cvm::rvector get_atom_total_force(int index) const
00141   {
00142     return atoms_total_forces[index];
00143   }
00144 
00148   inline void apply_atom_force(int index, cvm::rvector const &new_force)
00149   {
00150     atoms_new_colvar_forces[index] += new_force;
00151   }
00152 
00154   inline cvm::rvector get_atom_velocity(int /* index */)
00155   {
00156     cvm::error("Error: reading the current velocity of an atom "
00157                "is not yet implemented.\n",
00158                COLVARS_NOT_IMPLEMENTED);
00159     return cvm::rvector(0.0);
00160   }
00161 
00162   inline std::vector<int> const *get_atom_ids() const
00163   {
00164     return &atoms_ids;
00165   }
00166 
00168   size_t get_num_active_atoms() const;
00169 
00170   inline std::vector<cvm::real> const *get_atom_masses() const
00171   {
00172     return &atoms_masses;
00173   }
00174 
00175   inline std::vector<cvm::real> *modify_atom_masses()
00176   {
00177     // assume that we are requesting masses to change them
00178     updated_masses_ = true;
00179     return &atoms_masses;
00180   }
00181 
00182   inline std::vector<cvm::real> const *get_atom_charges()
00183   {
00184     return &atoms_charges;
00185   }
00186 
00187   inline std::vector<cvm::real> *modify_atom_charges()
00188   {
00189     // assume that we are requesting charges to change them
00190     updated_charges_ = true;
00191     return &atoms_charges;
00192   }
00193 
00194   inline std::vector<cvm::rvector> const *get_atom_positions() const
00195   {
00196     return &atoms_positions;
00197   }
00198 
00199   inline std::vector<cvm::rvector> *modify_atom_positions()
00200   {
00201     return &atoms_positions;
00202   }
00203 
00204   inline std::vector<cvm::rvector> const *get_atom_total_forces() const
00205   {
00206     return &atoms_total_forces;
00207   }
00208 
00209   inline std::vector<cvm::rvector> *modify_atom_total_forces()
00210   {
00211     return &atoms_total_forces;
00212   }
00213 
00214   inline std::vector<cvm::rvector> const *get_atom_applied_forces() const
00215   {
00216     return &atoms_new_colvar_forces;
00217   }
00218 
00219   inline std::vector<cvm::rvector> *modify_atom_applied_forces()
00220   {
00221     return &atoms_new_colvar_forces;
00222   }
00223 
00225   void compute_rms_atoms_applied_force();
00226 
00228   void compute_max_atoms_applied_force();
00229 
00231   inline cvm::real rms_atoms_applied_force() const
00232   {
00233     return atoms_rms_applied_force_;
00234   }
00235 
00237   inline cvm::real max_atoms_applied_force() const
00238   {
00239     return atoms_max_applied_force_;
00240   }
00241 
00243   inline int max_atoms_applied_force_id() const
00244   {
00245     return atoms_max_applied_force_id_;
00246   }
00247 
00249   inline bool updated_masses() const
00250   {
00251     return updated_masses_;
00252   }
00253 
00255   inline bool updated_charges() const
00256   {
00257     return updated_charges_;
00258   }
00259 
00260 protected:
00261 
00264   std::vector<int>          atoms_ids;
00266   std::vector<size_t>       atoms_refcount;
00268   std::vector<cvm::real>    atoms_masses;
00270   std::vector<cvm::real>    atoms_charges;
00272   std::vector<cvm::rvector> atoms_positions;
00274   std::vector<cvm::rvector> atoms_total_forces;
00276   std::vector<cvm::rvector> atoms_new_colvar_forces;
00277 
00279   cvm::real atoms_rms_applied_force_;
00280 
00282   cvm::real atoms_max_applied_force_;
00283 
00285   int atoms_max_applied_force_id_;
00286 
00288   bool updated_masses_, updated_charges_;
00289 
00292   int add_atom_slot(int atom_id);
00293 
00294 };
00295 
00296 
00299 class colvarproxy_atom_groups {
00300 
00301 public:
00302 
00304   colvarproxy_atom_groups();
00305 
00307   virtual ~colvarproxy_atom_groups();
00308 
00310   int reset();
00311 
00313   virtual int scalable_group_coms();
00314 
00316   virtual int init_atom_group(std::vector<int> const &atoms_ids);
00317 
00319   virtual void clear_atom_group(int index);
00320 
00322   inline int get_atom_group_id(int index) const
00323   {
00324     return atom_groups_ids[index];
00325   }
00326 
00328   inline cvm::real get_atom_group_mass(int index) const
00329   {
00330     return atom_groups_masses[index];
00331   }
00332 
00334   inline cvm::real get_atom_group_charge(int index) const
00335   {
00336     return atom_groups_charges[index];
00337   }
00338 
00340   inline cvm::rvector get_atom_group_com(int index) const
00341   {
00342     return atom_groups_coms[index];
00343   }
00344 
00346   inline cvm::rvector get_atom_group_total_force(int index) const
00347   {
00348     return atom_groups_total_forces[index];
00349   }
00350 
00352   inline void apply_atom_group_force(int index, cvm::rvector const &new_force)
00353   {
00354     atom_groups_new_colvar_forces[index] += new_force;
00355   }
00356 
00358   inline cvm::rvector get_atom_group_velocity(int /* index */)
00359   {
00360     cvm::error("Error: reading the current velocity of an atom group is not yet implemented.\n",
00361                COLVARS_NOT_IMPLEMENTED);
00362     return cvm::rvector(0.0);
00363   }
00364 
00365   inline std::vector<int> const *get_atom_group_ids() const
00366   {
00367     return &atom_groups_ids;
00368   }
00369 
00371   size_t get_num_active_atom_groups() const;
00372 
00373   inline std::vector<cvm::real> *modify_atom_group_masses()
00374   {
00375     // TODO updated_masses
00376     return &atom_groups_masses;
00377   }
00378 
00379   inline std::vector<cvm::real> *modify_atom_group_charges()
00380   {
00381     // TODO updated masses
00382     return &atom_groups_charges;
00383   }
00384 
00385   inline std::vector<cvm::rvector> *modify_atom_group_positions()
00386   {
00387     return &atom_groups_coms;
00388   }
00389 
00390   inline std::vector<cvm::rvector> *modify_atom_group_total_forces()
00391   {
00392     return &atom_groups_total_forces;
00393   }
00394 
00395   inline std::vector<cvm::rvector> *modify_atom_group_applied_forces()
00396   {
00397     return &atom_groups_new_colvar_forces;
00398   }
00399 
00401   void compute_rms_atom_groups_applied_force();
00402 
00404   void compute_max_atom_groups_applied_force();
00405 
00407   inline cvm::real rms_atom_groups_applied_force() const
00408   {
00409     return atom_groups_rms_applied_force_;
00410   }
00411 
00413   inline cvm::real max_atom_groups_applied_force() const
00414   {
00415     return atom_groups_max_applied_force_;
00416   }
00417 
00418 protected:
00419 
00422   std::vector<int>          atom_groups_ids;
00424   std::vector<size_t>       atom_groups_refcount;
00426   std::vector<cvm::real>    atom_groups_masses;
00428   std::vector<cvm::real>    atom_groups_charges;
00430   std::vector<cvm::rvector> atom_groups_coms;
00432   std::vector<cvm::rvector> atom_groups_total_forces;
00434   std::vector<cvm::rvector> atom_groups_new_colvar_forces;
00435 
00437   cvm::real atom_groups_rms_applied_force_;
00438 
00440   cvm::real atom_groups_max_applied_force_;
00441 
00443   int add_atom_group_slot(int atom_group_id);
00444 };
00445 
00446 
00447 #if defined(_OPENMP)
00448 #include <omp.h>
00449 #else
00450 struct omp_lock_t;
00451 #endif
00452 
00454 class colvarproxy_smp {
00455 
00456 public:
00457 
00459   colvarproxy_smp();
00460 
00462   virtual ~colvarproxy_smp();
00463 
00466   bool b_smp_active;
00467 
00469   virtual int smp_enabled();
00470 
00472   virtual int smp_colvars_loop();
00473 
00475   virtual int smp_biases_loop();
00476 
00478   virtual int smp_biases_script_loop();
00479 
00481   virtual int smp_thread_id();
00482 
00484   virtual int smp_num_threads();
00485 
00487   virtual int smp_lock();
00488 
00490   virtual int smp_trylock();
00491 
00493   virtual int smp_unlock();
00494 
00495 protected:
00496 
00498   omp_lock_t *omp_lock_state;
00499 };
00500 
00501 
00503 class colvarproxy_replicas {
00504 
00505 public:
00506 
00508   colvarproxy_replicas();
00509 
00511   virtual ~colvarproxy_replicas();
00512 
00514   virtual int replica_enabled();
00515 
00517   virtual int replica_index();
00518 
00520   virtual int num_replicas();
00521 
00523   virtual void replica_comm_barrier();
00524 
00526   virtual int replica_comm_recv(char* msg_data, int buf_len, int src_rep);
00527 
00529   virtual int replica_comm_send(char* msg_data, int msg_len, int dest_rep);
00530 
00531 };
00532 
00533 
00535 class colvarproxy_script {
00536 
00537 public:
00538 
00540   colvarproxy_script();
00541 
00543   virtual ~colvarproxy_script();
00544 
00547   colvarscript *script;
00548 
00550   bool have_scripts;
00551 
00553   virtual int run_force_callback();
00554 
00555   virtual int run_colvar_callback(
00556                 std::string const &name,
00557                 std::vector<const colvarvalue *> const &cvcs,
00558                 colvarvalue &value);
00559 
00560   virtual int run_colvar_gradient_callback(
00561                 std::string const &name,
00562                 std::vector<const colvarvalue *> const &cvcs,
00563                 std::vector<cvm::matrix2d<cvm::real> > &gradient);
00564 };
00565 
00566 
00567 
00571 class colvarproxy
00572   : public colvarproxy_system,
00573     public colvarproxy_atoms,
00574     public colvarproxy_atom_groups,
00575     public colvarproxy_volmaps,
00576     public colvarproxy_smp,
00577     public colvarproxy_replicas,
00578     public colvarproxy_script,
00579     public colvarproxy_tcl,
00580     public colvarproxy_io
00581 {
00582 
00583 public:
00584 
00586   colvarmodule *colvars;
00587 
00589   colvarproxy();
00590 
00592   virtual ~colvarproxy();
00593 
00594   virtual bool io_available() /* override */;
00595 
00597   virtual int request_deletion();
00598 
00600   inline bool delete_requested()
00601   {
00602     return b_delete_requested;
00603   }
00604 
00606   virtual int reset();
00607 
00609   virtual int parse_module_config();
00610 
00612   virtual int setup();
00613 
00615   inline bool engine_ready() const
00616   {
00617     return engine_ready_;
00618   }
00619 
00621   void add_config(std::string const &cmd, std::string const &conf);
00622 
00626   virtual int update_input();
00627 
00629   virtual int update_output();
00630 
00632   int end_of_step();
00633 
00635   virtual void log(std::string const &message);
00636 
00638   virtual void error(std::string const &message);
00639 
00641   void add_error_msg(std::string const &message);
00642 
00644   std::string const & get_error_msgs();
00645 
00647   void clear_error_msgs();
00648 
00650   inline bool simulation_running() const
00651   {
00652     return b_simulation_running;
00653   }
00654 
00658   inline bool simulation_continuing() const
00659   {
00660     return b_simulation_continuing;
00661   }
00662 
00664   int post_run();
00665 
00667   void print_input_atomic_data();
00668 
00670   void print_output_atomic_data();
00671 
00673   int get_version_from_string(char const *version_string);
00674 
00676   int version_number() const
00677   {
00678     return version_int;
00679   }
00680 
00681 protected:
00682 
00684   bool engine_ready_;
00685 
00687   std::string error_output;
00688 
00690   bool b_simulation_running;
00691 
00695   bool b_simulation_continuing;
00696 
00698   bool b_delete_requested;
00699 
00701   int version_int;
00702 
00704   size_t features_hash;
00705 
00706 private:
00707 
00709   void *config_queue_;
00710 
00711 };
00712 
00713 
00714 #endif

Generated on Fri Oct 4 02:43:46 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002