colvarproxy_namd.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_NAMD_H
00011 #define COLVARPROXY_NAMD_H
00012 
00013 #include "colvarproxy_namd_version.h"
00014 
00015 #include "Vector.h"
00016 #include "ResizeArray.h"
00017 #include "NamdTypes.h"
00018 #include "SimParameters.h"
00019 #include "Lattice.h"
00020 #include "GlobalMaster.h"
00021 #include "Random.h"
00022 
00023 #include "colvarmodule.h"
00024 #include "colvarproxy.h"
00025 #include "colvarvalue.h"
00026 
00027 // For replica exchange
00028 #include "converse.h"
00029 #include "DataExchanger.h"
00030 
00033 class colvarproxy_namd : public colvarproxy, public GlobalMaster {
00034 
00035 protected:
00036 
00039   std::vector<int> atoms_map;
00040 
00042   SimParameters const *simparams;
00043 
00045   BigReal thermostat_temperature;
00046 
00048   Random random;
00049 
00051   size_t restart_frequency_s;
00052 
00053   bool first_timestep;
00054   size_t previous_NAMD_step;
00055 
00056   bool total_force_requested;
00057 
00059   SubmitReduction *reduction;
00060 
00061 #ifdef NAMD_TCL
00062 
00063   void init_tcl_pointers();
00064 
00065 #endif
00066 
00067 public:
00068 
00069   friend class cvm::atom;
00070 
00071   colvarproxy_namd();
00072   ~colvarproxy_namd();
00073 
00074   int setup();
00075   int reset();
00076 
00077   // synchronize the local arrays with requested or forced atoms
00078   int update_atoms_map(AtomIDList::const_iterator begin,
00079                        AtomIDList::const_iterator end);
00080 
00081   void calculate();
00082 
00083   void log(std::string const &message);
00084   void error(std::string const &message);
00085   void fatal_error(std::string const &message);
00086   void exit(std::string const &message);
00087   void add_energy(cvm::real energy);
00088   void request_total_force(bool yesno);
00089 
00090   bool total_forces_enabled() const
00091   {
00092     return total_force_requested;
00093   }
00094 
00095   int run_force_callback();
00096   int run_colvar_callback(std::string const &name,
00097                           std::vector<const colvarvalue *> const &cvcs,
00098                           colvarvalue &value);
00099   int run_colvar_gradient_callback(std::string const &name,
00100                                    std::vector<const colvarvalue *> const &cvcs,
00101                                    std::vector<cvm::matrix2d<cvm::real> > &gradient);
00102 
00103   cvm::real unit_angstrom()
00104   {
00105     return 1.0;
00106   }
00107 
00108   cvm::real boltzmann()
00109   {
00110     return 0.001987191;
00111   }
00112 
00113   cvm::real temperature()
00114   {
00115     return thermostat_temperature;
00116   }
00117 
00118   cvm::real rand_gaussian()
00119   {
00120     return random.gaussian();
00121   }
00122 
00123   cvm::real dt()
00124   {
00125     return simparams->dt;
00126   }
00127 
00128 #if CMK_SMP && USE_CKLOOP
00129   int smp_enabled()
00130   {
00131     if (b_smp_active) {
00132       return COLVARS_OK;
00133     }
00134     return COLVARS_ERROR;
00135   }
00136 
00137   int smp_colvars_loop();
00138 
00139   int smp_biases_loop();
00140 
00141   int smp_biases_script_loop();
00142 
00143   friend void calc_colvars_items_smp(int first, int last, void *result, int paramNum, void *param);
00144   friend void calc_cv_biases_smp(int first, int last, void *result, int paramNum, void *param);
00145   friend void calc_cv_scripted_forces(int paramNum, void *param);
00146 
00147   int smp_thread_id()
00148   {
00149     return CkMyRank();
00150   }
00151 
00152   int smp_num_threads()
00153   {
00154     return CkMyNodeSize();
00155   }
00156 
00157 protected:
00158 
00159   CmiNodeLock charm_lock_state;
00160 
00161 public:
00162 
00163   int smp_lock()
00164   {
00165     charm_lock_state = CmiCreateLock();
00166     return COLVARS_OK;
00167   }
00168 
00169   int smp_trylock()
00170   {
00171     return COLVARS_NOT_IMPLEMENTED;
00172   }
00173 
00174   int smp_unlock()
00175   {
00176     CmiDestroyLock(charm_lock_state);
00177     return COLVARS_OK;
00178   }
00179 
00180 #endif // #if CMK_SMP && USE_CKLOOP
00181 
00182   // Replica communication functions.
00183   bool replica_enabled() {
00184 #if CMK_HAS_PARTITION
00185     return true;
00186 #else
00187     return false;
00188 #endif
00189   }
00190 
00191   int replica_index() {
00192     return CmiMyPartition();
00193   }
00194 
00195   int replica_num() {
00196     return CmiNumPartitions();
00197   }
00198 
00199   void replica_comm_barrier() {
00200     replica_barrier();
00201   }
00202 
00203   int replica_comm_recv(char* msg_data, int buf_len, int src_rep) {
00204     DataMessage *recvMsg = NULL;
00205     replica_recv(&recvMsg, src_rep, CkMyPe());
00206     CmiAssert(recvMsg != NULL);
00207     int retval = recvMsg->size;
00208     if (buf_len >= retval) {
00209       memcpy(msg_data,recvMsg->data,retval);
00210     } else {
00211       retval = 0;
00212     }
00213     CmiFree(recvMsg);
00214     return retval;
00215   }
00216 
00217   int replica_comm_send(char* msg_data, int msg_len, int dest_rep) {
00218     replica_send(msg_data, msg_len, dest_rep, CkMyPe());
00219     return msg_len;
00220   }
00221 
00222   int replica_comm_send()
00223   {
00224     return COLVARS_OK;
00225   }
00226 
00227   int replica_comm_async_send()
00228   {
00229     return COLVARS_OK;
00230   }
00231 
00232   inline size_t restart_frequency()
00233   {
00234     return restart_frequency_s;
00235   }
00236 
00237   int init_atom(int atom_number);
00238   int check_atom_id(int atom_number);
00239   int init_atom(cvm::residue_id const &residue,
00240                 std::string const     &atom_name,
00241                 std::string const     &segment_id);
00242   int check_atom_id(cvm::residue_id const &residue,
00243                     std::string const     &atom_name,
00244                     std::string const     &segment_id);
00245   void clear_atom(int index);
00246 
00247   inline void update_atom_properties(int index)
00248   {
00249     Molecule *mol = Node::Object()->molecule;
00250     // update mass
00251     atoms_masses[index] = mol->atommass(atoms_ids[index]);
00252     // update charge
00253     atoms_charges[index] = mol->atomcharge(atoms_ids[index]);
00254   }
00255 
00256   cvm::rvector position_distance(cvm::atom_pos const &pos1,
00257                                  cvm::atom_pos const &pos2) const;
00258 
00259   int load_atoms(char const *filename,
00260                  cvm::atom_group &atoms,
00261                  std::string const &pdb_field,
00262                  double const pdb_field_value = 0.0);
00263 
00264   int load_coords(char const *filename,
00265                   std::vector<cvm::atom_pos> &pos,
00266                   const std::vector<int> &indices,
00267                   std::string const &pdb_field,
00268                   double const pdb_field_value = 0.0);
00269 
00270 
00271   int scalable_group_coms()
00272   {
00273     return COLVARS_OK;
00274   }
00275   int init_atom_group(std::vector<int> const &atoms_ids);
00276   void clear_atom_group(int index);
00277   int update_group_properties(int index);
00278 
00279   std::ostream * output_stream(std::string const &output_name,
00280                                std::ios_base::openmode mode);
00281   int flush_output_stream(std::ostream *os);
00282   int close_output_stream(std::string const &output_name);
00283   int backup_file(char const *filename);
00284 
00285   char const *script_obj_to_str(unsigned char *obj);
00286 };
00287 
00288 
00289 #endif

Generated on Sat Jul 21 01:17:11 2018 for NAMD by  doxygen 1.4.7