00001 #ifndef COLVARPROXY_NAMD_H
00002 #define COLVARPROXY_NAMD_H
00003
00004 #include "Vector.h"
00005 #include "ResizeArray.h"
00006 #include "NamdTypes.h"
00007 #include "SimParameters.h"
00008 #include "Lattice.h"
00009 #include "GlobalMaster.h"
00010 #include "Random.h"
00011
00012 #include "colvarmodule.h"
00013 #include "colvarproxy.h"
00014
00015
00018 class colvarproxy_namd : public colvarproxy, public GlobalMaster {
00019
00020 protected:
00021
00023 SimParameters const *simparams;
00025 Lattice const *lattice;
00026
00027 BigReal thermostat_temperature;
00028
00030 Random random;
00031
00032 std::string input_prefix_str, output_prefix_str, restart_output_prefix_str;
00033 size_t restart_frequency_s;
00034 size_t previous_NAMD_step;
00035 bool first_timestep;
00036 bool system_force_requested;
00037
00038 std::vector<int> colvars_atoms;
00039 std::vector<size_t> colvars_atoms_ncopies;
00040 std::vector<cvm::rvector> positions;
00041 std::vector<cvm::rvector> total_forces;
00042 std::vector<cvm::rvector> applied_forces;
00043
00044 size_t init_namd_atom (AtomID const &aid);
00045
00046 SubmitReduction *reduction;
00047 public:
00048
00049 friend class cvm::atom;
00050
00051 colvarproxy_namd();
00052 ~colvarproxy_namd();
00053
00056 void calculate();
00057
00058 void add_energy (cvm::real energy);
00059 void request_system_force (bool yesno);
00060 void log (std::string const &message);
00061 void fatal_error (std::string const &message);
00062 void exit (std::string const &message);
00063
00064 inline cvm::real unit_angstrom()
00065 {
00066 return 1.0;
00067 }
00068
00069 cvm::real boltzmann()
00070 {
00071 return 0.001987191;
00072 }
00073
00074 cvm::real temperature()
00075 {
00076 return thermostat_temperature;
00077 }
00078
00079 cvm::real dt()
00080 {
00081 return simparams->dt;
00082 }
00083
00084 inline std::string input_prefix()
00085 {
00086 return input_prefix_str;
00087 }
00088 inline std::string restart_output_prefix()
00089 {
00090 return restart_output_prefix_str;
00091 }
00092 inline std::string output_prefix()
00093 {
00094 return output_prefix_str;
00095 }
00096 inline size_t restart_frequency()
00097 {
00098 return restart_frequency_s;
00099 }
00100
00101 cvm::rvector position_distance (cvm::atom_pos const &pos1,
00102 cvm::atom_pos const &pos2);
00103 cvm::real position_dist2 (cvm::atom_pos const &pos1,
00104 cvm::atom_pos const &pos2);
00105
00106 void select_closest_image (cvm::atom_pos &pos,
00107 cvm::atom_pos const &ref_pos);
00108
00109
00110 void load_atoms (char const *filename,
00111 std::vector<cvm::atom> &atoms,
00112 std::string const pdb_field,
00113 double const pdb_field_value = 0.0);
00114
00115 void load_coords (char const *filename,
00116 std::vector<cvm::atom_pos> &pos,
00117 const std::vector<int> &indices,
00118 std::string const pdb_field,
00119 double const pdb_field_value = 0.0);
00120
00121 void backup_file (char const *filename);
00122
00123 cvm::real rand_gaussian (void)
00124 {
00125 return random.gaussian();
00126 }
00127 };
00128
00129
00130 inline cvm::rvector colvarproxy_namd::position_distance (cvm::atom_pos const &pos1,
00131 cvm::atom_pos const &pos2)
00132 {
00133 Position const p1 (pos1.x, pos1.y, pos1.z);
00134 Position const p2 (pos2.x, pos2.y, pos2.z);
00135
00136 Vector const d = this->lattice->delta (p2, p1);
00137 return cvm::rvector (d.x, d.y, d.z);
00138 }
00139
00140
00141 inline void colvarproxy_namd::select_closest_image (cvm::atom_pos &pos,
00142 cvm::atom_pos const &ref_pos)
00143 {
00144 Position const p (pos.x, pos.y, pos.z);
00145 Position const rp (ref_pos.x, ref_pos.y, ref_pos.z);
00146 ScaledPosition const srp = this->lattice->scale (rp);
00147 Position const np = this->lattice->nearest (p, srp);
00148 pos.x = np.x;
00149 pos.y = np.y;
00150 pos.z = np.z;
00151 }
00152
00153
00154 inline cvm::real colvarproxy_namd::position_dist2 (cvm::atom_pos const &pos1,
00155 cvm::atom_pos const &pos2)
00156 {
00157 Lattice const *l = this->lattice;
00158 Vector const p1 (pos1.x, pos1.y, pos1.z);
00159 Vector const p2 (pos2.x, pos2.y, pos2.z);
00160 Vector const d = l->delta (p1, p2);
00161 return cvm::real (d.x*d.x + d.y*d.y + d.z*d.z);
00162 }
00163
00164
00165
00166 #endif
00167
00168
00169
00170
00171
00172