colvarproxy_namd Class Reference

Communication between colvars and NAMD (implementation of colvarproxy). More...

#include <colvarproxy_namd.h>

Inheritance diagram for colvarproxy_namd:

GlobalMaster List of all members.

Public Member Functions

 colvarproxy_namd ()
 ~colvarproxy_namd ()
int setup ()
int reset ()
int update_atoms_map (AtomIDList::const_iterator begin, AtomIDList::const_iterator end)
void calculate ()
void log (std::string const &message)
void error (std::string const &message)
void fatal_error (std::string const &message)
void exit (std::string const &message)
void add_energy (cvm::real energy)
void request_total_force (bool yesno)
bool total_forces_enabled () const
int run_force_callback ()
int run_colvar_callback (std::string const &name, std::vector< const colvarvalue * > const &cvcs, colvarvalue &value)
int run_colvar_gradient_callback (std::string const &name, std::vector< const colvarvalue * > const &cvcs, std::vector< cvm::matrix2d< cvm::real > > &gradient)
cvm::real unit_angstrom ()
cvm::real boltzmann ()
cvm::real temperature ()
cvm::real rand_gaussian ()
cvm::real dt ()
bool replica_enabled ()
int replica_index ()
int replica_num ()
void replica_comm_barrier ()
int replica_comm_recv (char *msg_data, int buf_len, int src_rep)
int replica_comm_send (char *msg_data, int msg_len, int dest_rep)
int replica_comm_send ()
int replica_comm_async_send ()
size_t restart_frequency ()
int init_atom (int atom_number)
int check_atom_id (int atom_number)
int init_atom (cvm::residue_id const &residue, std::string const &atom_name, std::string const &segment_id)
int check_atom_id (cvm::residue_id const &residue, std::string const &atom_name, std::string const &segment_id)
void clear_atom (int index)
void update_atom_properties (int index)
cvm::rvector position_distance (cvm::atom_pos const &pos1, cvm::atom_pos const &pos2) const
int load_atoms (char const *filename, cvm::atom_group &atoms, std::string const &pdb_field, double const pdb_field_value=0.0)
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)
int scalable_group_coms ()
int init_atom_group (std::vector< int > const &atoms_ids)
void clear_atom_group (int index)
int update_group_properties (int index)
std::ostream * output_stream (std::string const &output_name, std::ios_base::openmode mode)
int flush_output_stream (std::ostream *os)
int close_output_stream (std::string const &output_name)
int backup_file (char const *filename)
char const * script_obj_to_str (unsigned char *obj)
std::vector< std::string > script_obj_to_str_vector (unsigned char *obj)

Protected Member Functions

void init_tcl_pointers ()

Protected Attributes

std::vector< int > atoms_map
 Array of atom indices (relative to the colvarproxy arrays), usedfor faster copy of atomic data.
SimParameters const * simparams
 Pointer to the NAMD simulation input object.
BigReal thermostat_temperature
 Self-explained.
Random random
 NAMD-style PRNG object.
size_t restart_frequency_s
 How often NAMD is instructed to write state files.
bool first_timestep
size_t previous_NAMD_step
bool total_force_requested
SubmitReductionreduction
 Used to submit restraint energy as MISC.

Friends

class cvm::atom

Detailed Description

Communication between colvars and NAMD (implementation of colvarproxy).

Definition at line 33 of file colvarproxy_namd.h.


Constructor & Destructor Documentation

colvarproxy_namd::colvarproxy_namd (  ) 

Definition at line 34 of file colvarproxy_namd.C.

References COLVARPROXY_VERSION, Node::colvars, Node::configList, StringList::data, debug, endi(), fatal_error(), ConfigList::find(), first_timestep, SimParameters::firstTimestep, init_tcl_pointers(), iout, SimParameters::langevinOn, SimParameters::langevinTemp, log(), ReductionMgr::Object(), Node::Object(), SimParameters::outputFilename, random, SimParameters::randomSeed, SimParameters::reassignFreq, SimParameters::reassignTemp, reduction, REDUCTIONS_BASIC, GlobalMaster::requestTotalForce(), SimParameters::rescaleFreq, SimParameters::rescaleTemp, restart_frequency_s, SimParameters::restartFilename, SimParameters::restartFrequency, Node::simParameters, simparams, SimParameters::tCoupleOn, SimParameters::tCoupleTemp, thermostat_temperature, total_force_requested, and ReductionMgr::willSubmit().

00035 {
00036   version_int = get_version_from_string(COLVARPROXY_VERSION);
00037 
00038   first_timestep = true;
00039   total_force_requested = false;
00040   requestTotalForce(total_force_requested);
00041 
00042   // initialize pointers to NAMD configuration data
00043   simparams = Node::Object()->simParameters;
00044 
00045   if (cvm::debug())
00046     iout << "Info: initializing the colvars proxy object.\n" << endi;
00047 
00048   // find the configuration file, if provided
00049   StringList *config = Node::Object()->configList->find("colvarsConfig");
00050 
00051   // find the input state file
00052   StringList *input_restart = Node::Object()->configList->find("colvarsInput");
00053   input_prefix_str = std::string(input_restart ? input_restart->data : "");
00054   if (input_prefix_str.rfind(".colvars.state") != std::string::npos) {
00055     // strip the extension, if present
00056     input_prefix_str.erase(input_prefix_str.rfind(".colvars.state"),
00057                            std::string(".colvars.state").size());
00058   }
00059 
00060   // get the thermostat temperature
00061   if (simparams->rescaleFreq > 0)
00062     thermostat_temperature = simparams->rescaleTemp;
00063   else if (simparams->reassignFreq > 0)
00064     thermostat_temperature = simparams->reassignTemp;
00065   else if (simparams->langevinOn)
00066     thermostat_temperature = simparams->langevinTemp;
00067   else if (simparams->tCoupleOn)
00068     thermostat_temperature = simparams->tCoupleTemp;
00069   //else if (simparams->loweAndersenOn)
00070   //  thermostat_temperature = simparams->loweAndersenTemp;
00071   else
00072     thermostat_temperature = 0.0;
00073 
00074   random = Random(simparams->randomSeed);
00075 
00076   // take the output prefixes from the namd input
00077   output_prefix_str = std::string(simparams->outputFilename);
00078   restart_output_prefix_str = std::string(simparams->restartFilename);
00079   restart_frequency_s = simparams->restartFrequency;
00080 
00081   // check if it is possible to save output configuration
00082   if ((!output_prefix_str.size()) && (!restart_output_prefix_str.size())) {
00083     fatal_error("Error: neither the final output state file or "
00084                 "the output restart file could be defined, exiting.\n");
00085   }
00086 
00087 
00088 #ifdef NAMD_TCL
00089   have_scripts = true;
00090 
00091   init_tcl_pointers();
00092 
00093   // See is user-scripted forces are defined
00094   if (Tcl_FindCommand(reinterpret_cast<Tcl_Interp *>(_tcl_interp),
00095                       "calc_colvar_forces", NULL, 0) == NULL) {
00096     force_script_defined = false;
00097   } else {
00098     force_script_defined = true;
00099   }
00100 #else
00101   force_script_defined = false;
00102   have_scripts = false;
00103 #endif
00104 
00105 
00106   // initiate module: this object will be the communication proxy
00107   colvars = new colvarmodule(this);
00108   log("Using NAMD interface, version "+
00109       cvm::to_str(COLVARPROXY_VERSION)+".\n");
00110 
00111   if (config) {
00112     colvars->read_config_file(config->data);
00113   }
00114 
00115   colvars->setup();
00116   colvars->setup_input();
00117   colvars->setup_output();
00118 
00119   // save to Node for Tcl script access
00120   Node::Object()->colvars = colvars;
00121 
00122 #ifdef NAMD_TCL
00123   // Construct instance of colvars scripting interface
00124   script = new colvarscript(this);
00125 #endif
00126 
00127   if (simparams->firstTimestep != 0) {
00128     log("Initializing step number as firstTimestep.\n");
00129     colvars->it = colvars->it_restart = simparams->firstTimestep;
00130   }
00131 
00132   reduction = ReductionMgr::Object()->willSubmit(REDUCTIONS_BASIC);
00133 
00134   if (cvm::debug())
00135     iout << "Info: done initializing the colvars proxy object.\n" << endi;
00136 }

colvarproxy_namd::~colvarproxy_namd (  ) 

Definition at line 139 of file colvarproxy_namd.C.

References reduction.

00140 {
00141   delete reduction;
00142   if (script != NULL) {
00143     delete script;
00144     script = NULL;
00145   }
00146   if (colvars != NULL) {
00147     delete colvars;
00148     colvars = NULL;
00149   }
00150 }


Member Function Documentation

void colvarproxy_namd::add_energy ( cvm::real  energy  ) 

Definition at line 513 of file colvarproxy_namd.C.

References SubmitReduction::item(), reduction, and REDUCTION_MISC_ENERGY.

00514 {
00515   reduction->item(REDUCTION_MISC_ENERGY) += energy;
00516 }

int colvarproxy_namd::backup_file ( char const *  filename  ) 

Definition at line 987 of file colvarproxy_namd.C.

References NAMD_backup_file().

00988 {
00989   if (std::string(filename).rfind(std::string(".colvars.state")) != std::string::npos) {
00990     NAMD_backup_file(filename, ".old");
00991   } else {
00992     NAMD_backup_file(filename, ".BAK");
00993   }
00994   return COLVARS_OK;
00995 }

cvm::real colvarproxy_namd::boltzmann (  )  [inline]

Definition at line 108 of file colvarproxy_namd.h.

00109   {
00110     return 0.001987191;
00111   }

void colvarproxy_namd::calculate (  )  [virtual]

Reimplemented from GlobalMaster.

Definition at line 252 of file colvarproxy_namd.C.

References Lattice::a(), Lattice::a_p(), ResizeArray< Elem >::add(), atoms_map, Lattice::b(), Lattice::b_p(), ResizeArray< Elem >::begin(), Lattice::c(), Lattice::c_p(), ResizeArray< Elem >::clear(), debug, ResizeArray< Elem >::end(), f, first_timestep, GlobalMaster::getAtomIdBegin(), GlobalMaster::getAtomIdEnd(), GlobalMaster::getAtomPositionBegin(), GlobalMaster::getForceIdBegin(), GlobalMaster::getForceIdEnd(), GlobalMaster::getGroupPositionBegin(), GlobalMaster::getGroupPositionEnd(), GlobalMaster::getGroupTotalForceBegin(), GlobalMaster::getGroupTotalForceEnd(), GlobalMaster::getTotalForce(), GlobalMaster::lattice, log(), GlobalMaster::modifyAppliedForces(), GlobalMaster::modifyForcedAtoms(), GlobalMaster::modifyGroupForces(), GlobalMaster::modifyRequestedGroups(), Node::molecule, SimParameters::N, Molecule::numAtoms, Node::Object(), Lattice::orthogonal(), previous_NAMD_step, reduction, ResizeArray< Elem >::resize(), Vector::set(), setup(), simparams, GlobalMaster::step, SubmitReduction::submit(), total_force_requested, update_atoms_map(), Vector::x, Vector::y, and Vector::z.

00253 {
00254   if (first_timestep) {
00255 
00256     this->setup();
00257     colvars->setup();
00258     colvars->setup_input();
00259     colvars->setup_output();
00260 
00261     first_timestep = false;
00262 
00263   } else {
00264     // Use the time step number inherited from GlobalMaster
00265     if ( step - previous_NAMD_step == 1 ) {
00266       colvars->it++;
00267     }
00268     // Other cases could mean:
00269     // - run 0
00270     // - beginning of a new run statement
00271     // then the internal counter should not be incremented
00272   }
00273 
00274   previous_NAMD_step = step;
00275 
00276   {
00277     Vector const a = lattice->a();
00278     Vector const b = lattice->b();
00279     Vector const c = lattice->c();
00280     unit_cell_x.set(a.x, a.y, a.z);
00281     unit_cell_y.set(b.x, b.y, c.z);
00282     unit_cell_z.set(c.x, c.y, c.z);
00283   }
00284 
00285   if (!lattice->a_p() && !lattice->b_p() && !lattice->c_p()) {
00286     boundaries_type = boundaries_non_periodic;
00287     reset_pbc_lattice();
00288   } else if (lattice->a_p() && lattice->b_p() && lattice->c_p()) {
00289     if (lattice->orthogonal()) {
00290       boundaries_type = boundaries_pbc_ortho;
00291     } else {
00292       boundaries_type = boundaries_pbc_triclinic;
00293     }
00294     colvarproxy_system::update_pbc_lattice();
00295   } else {
00296     boundaries_type = boundaries_unsupported;
00297   }
00298 
00299   if (cvm::debug()) {
00300     log(std::string(cvm::line_marker)+
00301         "colvarproxy_namd, step no. "+cvm::to_str(colvars->it)+"\n"+
00302         "Updating atomic data arrays.\n");
00303   }
00304 
00305   // must delete the forces applied at the previous step: we can do
00306   // that because they have already been used and copied to other
00307   // memory locations
00308   modifyForcedAtoms().clear();
00309   modifyAppliedForces().clear();
00310 
00311   // prepare local arrays
00312   for (size_t i = 0; i < atoms_ids.size(); i++) {
00313     atoms_positions[i] = cvm::rvector(0.0, 0.0, 0.0);
00314     atoms_total_forces[i] = cvm::rvector(0.0, 0.0, 0.0);
00315     atoms_new_colvar_forces[i] = cvm::rvector(0.0, 0.0, 0.0);
00316   }
00317 
00318   for (size_t i = 0; i < atom_groups_ids.size(); i++) {
00319     atom_groups_total_forces[i] = cvm::rvector(0.0, 0.0, 0.0);
00320     atom_groups_new_colvar_forces[i] = cvm::rvector(0.0, 0.0, 0.0);
00321   }
00322 
00323   // create the atom map if needed
00324   size_t const n_all_atoms = Node::Object()->molecule->numAtoms;
00325   if (atoms_map.size() != n_all_atoms) {
00326     atoms_map.resize(n_all_atoms);
00327     atoms_map.assign(n_all_atoms, -1);
00328     update_atoms_map(getAtomIdBegin(), getAtomIdEnd());
00329   }
00330 
00331   // if new atomic positions or forces have been communicated by other GlobalMasters, add them to the atom map
00332   if ((int(atoms_ids.size()) < (getAtomIdEnd() - getAtomIdBegin())) ||
00333       (int(atoms_ids.size()) < (getForceIdEnd() - getForceIdBegin()))) {
00334     update_atoms_map(getAtomIdBegin(), getAtomIdEnd());
00335     update_atoms_map(getForceIdBegin(), getForceIdEnd());
00336   }
00337 
00338   {
00339     if (cvm::debug()) {
00340       log("Updating positions arrays.\n");
00341     }
00342     size_t n_positions = 0;
00343     AtomIDList::const_iterator a_i = getAtomIdBegin();
00344     AtomIDList::const_iterator a_e = getAtomIdEnd();
00345     PositionList::const_iterator p_i = getAtomPositionBegin();
00346 
00347     for ( ; a_i != a_e; ++a_i, ++p_i ) {
00348       atoms_positions[atoms_map[*a_i]] = cvm::rvector((*p_i).x, (*p_i).y, (*p_i).z);
00349       n_positions++;
00350     }
00351 
00352     // The following had to be relaxed because some atoms may be forced without their position being requested
00353     // if (n_positions < atoms_ids.size()) {
00354     //   cvm::error("Error: did not receive the positions of all atoms.\n", BUG_ERROR);
00355     // }
00356   }
00357 
00358   if (total_force_requested && cvm::step_relative() > 0) {
00359 
00360     // sort the force arrays the previous step
00361     // (but only do so if there *is* a previous step!)
00362 
00363     {
00364       if (cvm::debug()) {
00365         log("Updating total forces arrays.\n");
00366       }
00367       size_t n_total_forces = 0;
00368       AtomIDList::const_iterator a_i = getForceIdBegin();
00369       AtomIDList::const_iterator a_e = getForceIdEnd();
00370       ForceList::const_iterator f_i = getTotalForce();
00371 
00372       for ( ; a_i != a_e; ++a_i, ++f_i ) {
00373         atoms_total_forces[atoms_map[*a_i]] = cvm::rvector((*f_i).x, (*f_i).y, (*f_i).z);
00374         n_total_forces++;
00375       }
00376 
00377       if (n_total_forces < atoms_ids.size()) {
00378         cvm::error("Error: total forces were requested, but total forces "
00379                    "were not received for all atoms.\n"
00380                    "The most probable cause is combination of energy "
00381                    "minimization with a biasing method that requires MD (e.g. ABF).\n"
00382                    "Always run minimization and ABF separately.", INPUT_ERROR);
00383       }
00384     }
00385 
00386     {
00387       if (cvm::debug()) {
00388         log("Updating group total forces arrays.\n");
00389       }
00390       ForceList::const_iterator f_i = getGroupTotalForceBegin();
00391       ForceList::const_iterator f_e = getGroupTotalForceEnd();
00392       size_t i = 0;
00393       if ((f_e - f_i) != ((int) atom_groups_ids.size())) {
00394         cvm::error("Error: total forces were requested for scalable groups, "
00395                    "but they are not in the same number from the number of groups.\n"
00396                    "The most probable cause is combination of energy "
00397                    "minimization with a biasing method that requires MD (e.g. ABF).\n"
00398                    "Always run minimization and ABF separately.", INPUT_ERROR);
00399       }
00400       for ( ; f_i != f_e; f_i++, i++) {
00401         atom_groups_total_forces[i] = cvm::rvector((*f_i).x, (*f_i).y, (*f_i).z);
00402       }
00403     }
00404   }
00405 
00406   {
00407     if (cvm::debug()) {
00408       log("Updating group positions arrays.\n");
00409     }
00410     // update group data (only coms available so far)
00411     size_t ig;
00412     // note: getGroupMassBegin() could be used here, but masses and charges
00413     // have already been calculated from the last call to setup()
00414     PositionList::const_iterator gp_i = getGroupPositionBegin();
00415     for (ig = 0; gp_i != getGroupPositionEnd(); gp_i++, ig++) {
00416       atom_groups_coms[ig] = cvm::rvector(gp_i->x, gp_i->y, gp_i->z);
00417     }
00418   }
00419 
00420   if (cvm::debug()) {
00421     log("atoms_ids = "+cvm::to_str(atoms_ids)+"\n");
00422     log("atoms_ncopies = "+cvm::to_str(atoms_ncopies)+"\n");
00423     log("atoms_masses = "+cvm::to_str(atoms_masses)+"\n");
00424     log("atoms_charges = "+cvm::to_str(atoms_charges)+"\n");
00425     log("atoms_positions = "+cvm::to_str(atoms_positions)+"\n");
00426     log("atoms_total_forces = "+cvm::to_str(atoms_total_forces)+"\n");
00427     log(cvm::line_marker);
00428 
00429     log("atom_groups_ids = "+cvm::to_str(atom_groups_ids)+"\n");
00430     log("atom_groups_ncopies = "+cvm::to_str(atom_groups_ncopies)+"\n");
00431     log("atom_groups_masses = "+cvm::to_str(atom_groups_masses)+"\n");
00432     log("atom_groups_charges = "+cvm::to_str(atom_groups_charges)+"\n");
00433     log("atom_groups_coms = "+cvm::to_str(atom_groups_coms)+"\n");
00434     log("atom_groups_total_forces = "+cvm::to_str(atom_groups_total_forces)+"\n");
00435     log(cvm::line_marker);
00436   }
00437 
00438   // call the collective variable module
00439   if (colvars->calc() != COLVARS_OK) {
00440     cvm::error("Error in the collective variables module.\n", COLVARS_ERROR);
00441   }
00442 
00443   if (cvm::debug()) {
00444     log(cvm::line_marker);
00445     log("atoms_new_colvar_forces = "+cvm::to_str(atoms_new_colvar_forces)+"\n");
00446     log(cvm::line_marker);
00447     log("atom_groups_new_colvar_forces = "+cvm::to_str(atom_groups_new_colvar_forces)+"\n");
00448     log(cvm::line_marker);
00449   }
00450 
00451   // communicate all forces to the MD integrator
00452   for (size_t i = 0; i < atoms_ids.size(); i++) {
00453     cvm::rvector const &f = atoms_new_colvar_forces[i];
00454     modifyForcedAtoms().add(atoms_ids[i]);
00455     modifyAppliedForces().add(Vector(f.x, f.y, f.z));
00456   }
00457 
00458   {
00459     // zero out the applied forces on each group
00460     modifyGroupForces().resize(modifyRequestedGroups().size());
00461     ForceList::iterator gf_i = modifyGroupForces().begin();
00462     for (int ig = 0; gf_i != modifyGroupForces().end(); gf_i++, ig++) {
00463       cvm::rvector const &f = atom_groups_new_colvar_forces[ig];
00464       *gf_i = Vector(f.x, f.y, f.z);
00465     }
00466   }
00467 
00468   // send MISC energy
00469   reduction->submit();
00470 
00471   // NAMD does not destruct GlobalMaster objects, so we must remember
00472   // to write all output files at the end of a run
00473   if (step == simparams->N) {
00474     colvars->write_restart_file(cvm::output_prefix()+".colvars.state");
00475     colvars->write_output_files();
00476   }
00477 }

int colvarproxy_namd::check_atom_id ( cvm::residue_id const &  residue,
std::string const &  atom_name,
std::string const &  segment_id 
)

Definition at line 611 of file colvarproxy_namd.C.

References Molecule::get_atom_from_name(), Node::molecule, and Node::Object().

00614 {
00615   int const aid =
00616     (segment_id.size() ?
00617      Node::Object()->molecule->get_atom_from_name(segment_id.c_str(),
00618                                                   residue,
00619                                                   atom_name.c_str()) :
00620      Node::Object()->molecule->get_atom_from_name("MAIN",
00621                                                   residue,
00622                                                   atom_name.c_str()));
00623 
00624   if (aid < 0) {
00625     // get_atom_from_name() has returned an error value
00626     cvm::error("Error: could not find atom \""+
00627                atom_name+"\" in residue "+
00628                cvm::to_str(residue)+
00629                ( (segment_id != "MAIN") ?
00630                  (", segment \""+segment_id+"\"") :
00631                  ("") )+
00632                "\n", INPUT_ERROR);
00633     return INPUT_ERROR;
00634   }
00635 
00636   return aid;
00637 }

int colvarproxy_namd::check_atom_id ( int  atom_number  ) 

Definition at line 565 of file colvarproxy_namd.C.

References debug, log(), and Node::Object().

Referenced by init_atom().

00566 {
00567   // NAMD's internal numbering starts from zero
00568   int const aid = (atom_number-1);
00569 
00570   if (cvm::debug())
00571     log("Adding atom "+cvm::to_str(atom_number)+
00572         " for collective variables calculation.\n");
00573 
00574   if ( (aid < 0) || (aid >= Node::Object()->molecule->numAtoms) ) {
00575     cvm::error("Error: invalid atom number specified, "+
00576                cvm::to_str(atom_number)+"\n", INPUT_ERROR);
00577     return INPUT_ERROR;
00578   }
00579 
00580   return aid;
00581 }

void colvarproxy_namd::clear_atom ( int  index  ) 

Definition at line 672 of file colvarproxy_namd.C.

00673 {
00674   colvarproxy::clear_atom(index);
00675   // TODO remove it from GlobalMaster arrays?
00676 }

void colvarproxy_namd::clear_atom_group ( int  index  ) 

Definition at line 1108 of file colvarproxy_namd.C.

01109 {
01110   // do nothing, keep the NAMD arrays in sync with the colvarproxy ones
01111   colvarproxy::clear_atom_group(index);
01112 }

int colvarproxy_namd::close_output_stream ( std::string const &  output_name  ) 

Definition at line 968 of file colvarproxy_namd.C.

00969 {
00970   std::list<std::ostream *>::iterator osi  = output_files.begin();
00971   std::list<std::string>::iterator    osni = output_stream_names.begin();
00972   for ( ; osi != output_files.end(); osi++, osni++) {
00973     if (*osni == output_name) {
00974       if (((ofstream_namd *) *osi)->is_open()) {
00975         ((ofstream_namd *) *osi)->close();
00976       }
00977       delete *osi;
00978       output_files.erase(osi);
00979       output_stream_names.erase(osni);
00980       return COLVARS_OK;
00981     }
00982   }
00983   return COLVARS_ERROR;
00984 }

cvm::real colvarproxy_namd::dt (  )  [inline]

Definition at line 123 of file colvarproxy_namd.h.

References SimParameters::dt, and simparams.

Referenced by Sequencer::addForceToMomentum(), Sequencer::addMovDragToPosition(), Sequencer::addRotDragToPosition(), Sequencer::addVelocityToPosition(), Sequencer::langevinVelocities(), Sequencer::langevinVelocitiesBBK1(), Sequencer::langevinVelocitiesBBK2(), Sequencer::maximumMove(), and Sequencer::tcoupleVelocities().

00124   {
00125     return simparams->dt;
00126   }

void colvarproxy_namd::error ( std::string const &  message  ) 

Definition at line 539 of file colvarproxy_namd.C.

References fatal_error().

00540 {
00541   // In NAMD, all errors are fatal
00542   fatal_error(message);
00543 }

void colvarproxy_namd::exit ( std::string const &  message  ) 

Definition at line 558 of file colvarproxy_namd.C.

References BackEnd::exit(), and log().

00559 {
00560   log(message);
00561   BackEnd::exit();
00562 }

void colvarproxy_namd::fatal_error ( std::string const &  message  ) 

Definition at line 546 of file colvarproxy_namd.C.

References log(), NAMD_die(), and NAMD_err().

Referenced by colvarproxy_namd(), and error().

00547 {
00548   log(message);
00549   if (errno) {
00550     // log(strerror(errno));
00551     NAMD_err("Error in the collective variables module");
00552   } else {
00553     NAMD_die("Error in the collective variables module: exiting.\n");
00554   }
00555 }

int colvarproxy_namd::flush_output_stream ( std::ostream *  os  ) 

Definition at line 954 of file colvarproxy_namd.C.

00955 {
00956   std::list<std::ostream *>::iterator osi  = output_files.begin();
00957   std::list<std::string>::iterator    osni = output_stream_names.begin();
00958   for ( ; osi != output_files.end(); osi++, osni++) {
00959     if (*osi == os) {
00960       ((ofstream_namd *) *osi)->flush();
00961       return COLVARS_OK;
00962     }
00963   }
00964   return COLVARS_ERROR;
00965 }

int colvarproxy_namd::init_atom ( cvm::residue_id const &  residue,
std::string const &  atom_name,
std::string const &  segment_id 
)

For AMBER topologies, the segment id is automatically set to "MAIN" (the segment id assigned by NAMD's AMBER topology parser), and is therefore optional when an AMBER topology is used

Definition at line 644 of file colvarproxy_namd.C.

References ResizeArray< Elem >::add(), check_atom_id(), debug, log(), GlobalMaster::modifyRequestedAtoms(), and update_atom_properties().

00647 {
00648   int const aid = check_atom_id(residue, atom_name, segment_id);
00649 
00650   for (size_t i = 0; i < atoms_ids.size(); i++) {
00651     if (atoms_ids[i] == aid) {
00652       // this atom id was already recorded
00653       atoms_ncopies[i] += 1;
00654       return i;
00655     }
00656   }
00657 
00658   if (cvm::debug())
00659     log("Adding atom \""+
00660         atom_name+"\" in residue "+
00661         cvm::to_str(residue)+
00662         " (index "+cvm::to_str(aid)+
00663         ") for collective variables calculation.\n");
00664 
00665   int const index = add_atom_slot(aid);
00666   modifyRequestedAtoms().add(aid);
00667   update_atom_properties(index);
00668   return index;
00669 }

int colvarproxy_namd::init_atom ( int  atom_number  ) 

Definition at line 584 of file colvarproxy_namd.C.

References ResizeArray< Elem >::add(), check_atom_id(), GlobalMaster::modifyRequestedAtoms(), and update_atom_properties().

00585 {
00586   // save time by checking first whether this atom has been requested before
00587   // (this is more common than a non-valid atom number)
00588   int aid = (atom_number-1);
00589 
00590   for (size_t i = 0; i < atoms_ids.size(); i++) {
00591     if (atoms_ids[i] == aid) {
00592       // this atom id was already recorded
00593       atoms_ncopies[i] += 1;
00594       return i;
00595     }
00596   }
00597 
00598   aid = check_atom_id(atom_number);
00599 
00600   if (aid < 0) {
00601     return INPUT_ERROR;
00602   }
00603 
00604   int const index = add_atom_slot(aid);
00605   modifyRequestedAtoms().add(aid);
00606   update_atom_properties(index);
00607   return index;
00608 }

int colvarproxy_namd::init_atom_group ( std::vector< int > const &  atoms_ids  ) 

Definition at line 1038 of file colvarproxy_namd.C.

References debug, log(), GlobalMaster::modifyGroupForces(), GlobalMaster::modifyRequestedGroups(), Node::molecule, Molecule::numAtoms, Node::Object(), ResizeArray< Elem >::resize(), and update_group_properties().

01039 {
01040   if (cvm::debug())
01041     log("Reguesting from NAMD a group of size "+cvm::to_str(atoms_ids.size())+
01042         " for collective variables calculation.\n");
01043 
01044   // Note: modifyRequestedGroups is supposed to be in sync with the colvarproxy arrays,
01045   // and to stay that way during a simulation
01046 
01047   // compare this new group to those already allocated inside GlobalMaster
01048   int ig;
01049   for (ig = 0; ig < modifyRequestedGroups().size(); ig++) {
01050     AtomIDList const &namd_group = modifyRequestedGroups()[ig];
01051     bool b_match = true;
01052 
01053     if (namd_group.size() != ((int) atoms_ids.size())) {
01054       b_match = false;
01055     } else {
01056       int ia;
01057       for (ia = 0; ia < namd_group.size(); ia++) {
01058         int const aid = atoms_ids[ia];
01059         if (namd_group[ia] != aid) {
01060           b_match = false;
01061           break;
01062         }
01063       }
01064     }
01065 
01066     if (b_match) {
01067       if (cvm::debug())
01068         log("Group was already added.\n");
01069       // this group already exists
01070       atom_groups_ncopies[ig] += 1;
01071       return ig;
01072     }
01073   }
01074 
01075   // add this group (note: the argument of add_atom_group_slot() is redundant for NAMD, and provided only for consistency)
01076   size_t const index = add_atom_group_slot(atom_groups_ids.size());
01077   modifyRequestedGroups().resize(atom_groups_ids.size());
01078   // the following is done in calculate()
01079   // modifyGroupForces().resize(atom_groups_ids.size());
01080   AtomIDList &namd_group = modifyRequestedGroups()[index];
01081   namd_group.resize(atoms_ids.size());
01082   int const n_all_atoms = Node::Object()->molecule->numAtoms;
01083   for (size_t ia = 0; ia < atoms_ids.size(); ia++) {
01084     int const aid = atoms_ids[ia];
01085     if (cvm::debug())
01086       log("Adding atom "+cvm::to_str(aid+1)+
01087           " for collective variables calculation.\n");
01088     if ( (aid < 0) || (aid >= n_all_atoms) ) {
01089       cvm::error("Error: invalid atom number specified, "+
01090                  cvm::to_str(aid+1)+"\n", INPUT_ERROR);
01091       return -1;
01092     }
01093     namd_group[ia] = aid;
01094   }
01095 
01096   update_group_properties(index);
01097 
01098   if (cvm::debug()) {
01099     log("Group has index "+cvm::to_str(index)+"\n");
01100     log("modifyRequestedGroups length = "+cvm::to_str(modifyRequestedGroups().size())+
01101         ", modifyGroupForces length = "+cvm::to_str(modifyGroupForces().size())+"\n");
01102   }
01103 
01104   return index;
01105 }

void colvarproxy_namd::init_tcl_pointers (  )  [protected]

Definition at line 482 of file colvarproxy_namd.C.

References Node::getScript(), ScriptTcl::interp, and Node::Object().

Referenced by colvarproxy_namd().

00483 {
00484 #ifdef NAMD_TCL
00485   // Store pointer to NAMD's Tcl interpreter
00486   _tcl_interp = reinterpret_cast<void *>(Node::Object()->getScript()->interp);
00487 #endif
00488 }

int colvarproxy_namd::load_atoms ( char const *  filename,
cvm::atom_group &  atoms,
std::string const &  pdb_field,
double const   pdb_field_value = 0.0 
)

Definition at line 869 of file colvarproxy_namd.C.

References PDB::atom(), cvm::atom, e_pdb_beta, e_pdb_occ, e_pdb_x, e_pdb_y, e_pdb_z, PDB::num_atoms(), and pdb_field_str2enum().

00873 {
00874   if (pdb_field_str.size() == 0)
00875     cvm::error("Error: must define which PDB field to use "
00876                "in order to define atoms from a PDB file.\n", INPUT_ERROR);
00877 
00878   PDB *pdb = new PDB(pdb_filename);
00879   size_t const pdb_natoms = pdb->num_atoms();
00880 
00881   e_pdb_field pdb_field_index = pdb_field_str2enum(pdb_field_str);
00882 
00883   for (size_t ipdb = 0; ipdb < pdb_natoms; ipdb++) {
00884 
00885     double atom_pdb_field_value = 0.0;
00886 
00887     switch (pdb_field_index) {
00888     case e_pdb_occ:
00889       atom_pdb_field_value = (pdb->atom(ipdb))->occupancy();
00890       break;
00891     case e_pdb_beta:
00892       atom_pdb_field_value = (pdb->atom(ipdb))->temperaturefactor();
00893       break;
00894     case e_pdb_x:
00895       atom_pdb_field_value = (pdb->atom(ipdb))->xcoor();
00896       break;
00897     case e_pdb_y:
00898       atom_pdb_field_value = (pdb->atom(ipdb))->ycoor();
00899       break;
00900     case e_pdb_z:
00901       atom_pdb_field_value = (pdb->atom(ipdb))->zcoor();
00902       break;
00903     default:
00904       break;
00905     }
00906 
00907     if ( (pdb_field_value) &&
00908          (atom_pdb_field_value != pdb_field_value) ) {
00909       continue;
00910     } else if (atom_pdb_field_value == 0.0) {
00911       continue;
00912     }
00913 
00914     if (atoms.is_enabled(colvardeps::f_ag_scalable)) {
00915       atoms.add_atom_id(ipdb);
00916     } else {
00917       atoms.add_atom(cvm::atom(ipdb+1));
00918     }
00919   }
00920 
00921   delete pdb;
00922   return (cvm::get_error() ? COLVARS_ERROR : COLVARS_OK);
00923 }

int colvarproxy_namd::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 
)

Definition at line 757 of file colvarproxy_namd.C.

References PDB::atom(), e_pdb_beta, e_pdb_occ, e_pdb_x, e_pdb_y, e_pdb_z, PDB::num_atoms(), and pdb_field_str2enum().

00762 {
00763   if (pdb_field_str.size() == 0 && indices.size() == 0) {
00764     cvm::error("Bug alert: either PDB field should be defined or list of "
00765                "atom IDs should be available when loading atom coordinates!\n", BUG_ERROR);
00766   }
00767 
00768   e_pdb_field pdb_field_index;
00769   bool const use_pdb_field = (pdb_field_str.size() > 0);
00770   if (use_pdb_field) {
00771     pdb_field_index = pdb_field_str2enum(pdb_field_str);
00772   }
00773 
00774   // next index to be looked up in PDB file (if list is supplied)
00775   std::vector<int>::const_iterator current_index = indices.begin();
00776 
00777   PDB *pdb = new PDB(pdb_filename);
00778   size_t const pdb_natoms = pdb->num_atoms();
00779 
00780   if (pos.size() != pdb_natoms) {
00781 
00782     bool const pos_allocated = (pos.size() > 0);
00783 
00784     size_t ipos = 0, ipdb = 0;
00785     for ( ; ipdb < pdb_natoms; ipdb++) {
00786 
00787       if (use_pdb_field) {
00788         // PDB field mode: skip atoms with wrong value in PDB field
00789         double atom_pdb_field_value = 0.0;
00790 
00791         switch (pdb_field_index) {
00792         case e_pdb_occ:
00793           atom_pdb_field_value = (pdb->atom(ipdb))->occupancy();
00794           break;
00795         case e_pdb_beta:
00796           atom_pdb_field_value = (pdb->atom(ipdb))->temperaturefactor();
00797           break;
00798         case e_pdb_x:
00799           atom_pdb_field_value = (pdb->atom(ipdb))->xcoor();
00800           break;
00801         case e_pdb_y:
00802           atom_pdb_field_value = (pdb->atom(ipdb))->ycoor();
00803           break;
00804         case e_pdb_z:
00805           atom_pdb_field_value = (pdb->atom(ipdb))->zcoor();
00806           break;
00807         default:
00808           break;
00809         }
00810 
00811         if ( (pdb_field_value) &&
00812              (atom_pdb_field_value != pdb_field_value) ) {
00813           continue;
00814         } else if (atom_pdb_field_value == 0.0) {
00815           continue;
00816         }
00817 
00818       } else {
00819         // Atom ID mode: use predefined atom IDs from the atom group
00820         if (((int) ipdb) != *current_index) {
00821           // Skip atoms not in the list
00822           continue;
00823         } else {
00824           current_index++;
00825         }
00826       }
00827 
00828       if (!pos_allocated) {
00829         pos.push_back(cvm::atom_pos(0.0, 0.0, 0.0));
00830       } else if (ipos >= pos.size()) {
00831         cvm::error("Error: the PDB file \""+
00832                    std::string(pdb_filename)+
00833                    "\" contains coordinates for "
00834                    "more atoms than needed.\n", BUG_ERROR);
00835       }
00836 
00837       pos[ipos] = cvm::atom_pos((pdb->atom(ipdb))->xcoor(),
00838                                 (pdb->atom(ipdb))->ycoor(),
00839                                 (pdb->atom(ipdb))->zcoor());
00840       ipos++;
00841       if (!use_pdb_field && current_index == indices.end())
00842         break;
00843     }
00844 
00845     if (ipos < pos.size() || (!use_pdb_field && current_index != indices.end())) {
00846       size_t n_requested = use_pdb_field ? pos.size() : indices.size();
00847       cvm::error("Error: number of matching records in the PDB file \""+
00848                  std::string(pdb_filename)+"\" ("+cvm::to_str(ipos)+
00849                  ") does not match the number of requested coordinates ("+
00850                  cvm::to_str(n_requested)+").\n", INPUT_ERROR);
00851       return COLVARS_ERROR;
00852     }
00853   } else {
00854 
00855     // when the PDB contains exactly the number of atoms of the array,
00856     // ignore the fields and just read coordinates
00857     for (size_t ia = 0; ia < pos.size(); ia++) {
00858       pos[ia] = cvm::atom_pos((pdb->atom(ia))->xcoor(),
00859                               (pdb->atom(ia))->ycoor(),
00860                               (pdb->atom(ia))->zcoor());
00861     }
00862   }
00863 
00864   delete pdb;
00865   return COLVARS_OK;
00866 }

void colvarproxy_namd::log ( std::string const &  message  ) 

Definition at line 530 of file colvarproxy_namd.C.

References endi(), and iout.

Referenced by calculate(), check_atom_id(), colvarproxy_namd(), exit(), fatal_error(), init_atom(), init_atom_group(), setup(), update_atom_properties(), update_atoms_map(), and update_group_properties().

00531 {
00532   std::istringstream is(message);
00533   std::string line;
00534   while (std::getline(is, line))
00535     iout << "colvars: " << line << "\n";
00536   iout << endi;
00537 }

std::ostream * colvarproxy_namd::output_stream ( std::string const &  output_name,
std::ios_base::openmode  mode 
)

Definition at line 926 of file colvarproxy_namd.C.

References debug, and ofstream_namd::is_open().

00928 {
00929   if (cvm::debug()) {
00930     cvm::log("Using colvarproxy_namd::output_stream()\n");
00931   }
00932   std::list<std::ostream *>::iterator osi  = output_files.begin();
00933   std::list<std::string>::iterator    osni = output_stream_names.begin();
00934   for ( ; osi != output_files.end(); osi++, osni++) {
00935     if (*osni == output_name) {
00936       return *osi;
00937     }
00938   }
00939   if (!(mode & (std::ios_base::app | std::ios_base::ate))) {
00940     colvarproxy::backup_file(output_name);
00941   }
00942   ofstream_namd *os = new ofstream_namd(output_name.c_str(), mode);
00943   if (!os->is_open()) {
00944     cvm::error("Error: cannot write to file \""+output_name+"\".\n",
00945                FILE_ERROR);
00946     return NULL;
00947   }
00948   output_stream_names.push_back(output_name);
00949   output_files.push_back(os);
00950   return os;
00951 }

cvm::rvector colvarproxy_namd::position_distance ( cvm::atom_pos const &  pos1,
cvm::atom_pos const &  pos2 
) const

Definition at line 695 of file colvarproxy_namd.C.

References Lattice::delta(), GlobalMaster::lattice, Vector::x, Vector::y, and Vector::z.

00698 {
00699   Position const p1(pos1.x, pos1.y, pos1.z);
00700   Position const p2(pos2.x, pos2.y, pos2.z);
00701   // return p2 - p1
00702   Vector const d = this->lattice->delta(p2, p1);
00703   return cvm::rvector(d.x, d.y, d.z);
00704 }

cvm::real colvarproxy_namd::rand_gaussian (  )  [inline]

Definition at line 118 of file colvarproxy_namd.h.

References Random::gaussian(), and random.

00119   {
00120     return random.gaussian();
00121   }

int colvarproxy_namd::replica_comm_async_send (  )  [inline]

Definition at line 227 of file colvarproxy_namd.h.

00228   {
00229     return COLVARS_OK;
00230   }

void colvarproxy_namd::replica_comm_barrier (  )  [inline]

Definition at line 199 of file colvarproxy_namd.h.

References replica_barrier().

00199                               {
00200     replica_barrier();
00201   }

int colvarproxy_namd::replica_comm_recv ( char *  msg_data,
int  buf_len,
int  src_rep 
) [inline]

Definition at line 203 of file colvarproxy_namd.h.

References DataMessage::data, replica_recv(), and DataMessage::size.

00203                                                                   {
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   }

int colvarproxy_namd::replica_comm_send (  )  [inline]

Definition at line 222 of file colvarproxy_namd.h.

00223   {
00224     return COLVARS_OK;
00225   }

int colvarproxy_namd::replica_comm_send ( char *  msg_data,
int  msg_len,
int  dest_rep 
) [inline]

Definition at line 217 of file colvarproxy_namd.h.

References replica_send().

00217                                                                    {
00218     replica_send(msg_data, msg_len, dest_rep, CkMyPe());
00219     return msg_len;
00220   }

bool colvarproxy_namd::replica_enabled (  )  [inline]

Definition at line 183 of file colvarproxy_namd.h.

00183                          {
00184 #if CMK_HAS_PARTITION
00185     return true;
00186 #else
00187     return false;
00188 #endif
00189   }

int colvarproxy_namd::replica_index (  )  [inline]

Definition at line 191 of file colvarproxy_namd.h.

00191                       {
00192     return CmiMyPartition();
00193   }

int colvarproxy_namd::replica_num (  )  [inline]

Definition at line 195 of file colvarproxy_namd.h.

00195                     {
00196     return CmiNumPartitions();
00197   }

void colvarproxy_namd::request_total_force ( bool  yesno  ) 

Definition at line 518 of file colvarproxy_namd.C.

References debug, GlobalMaster::requestTotalForce(), and total_force_requested.

00519 {
00520   if (cvm::debug()) {
00521     cvm::log("colvarproxy_namd::request_total_force()\n");
00522   }
00523   total_force_requested = yesno;
00524   requestTotalForce(total_force_requested);
00525   if (cvm::debug()) {
00526     cvm::log("colvarproxy_namd::request_total_force() end\n");
00527   }
00528 }

int colvarproxy_namd::reset (  ) 

Definition at line 235 of file colvarproxy_namd.C.

References atoms_map, ResizeArray< Elem >::clear(), GlobalMaster::modifyRequestedAtoms(), and GlobalMaster::modifyRequestedGroups().

00236 {
00237   int error_code = COLVARS_OK;
00238 
00239   // Unrequest all atoms and group from NAMD
00240   modifyRequestedAtoms().clear();
00241   modifyRequestedGroups().clear();
00242 
00243   atoms_map.clear();
00244 
00245   // Clear internal Proxy records
00246   error_code |= colvarproxy::reset();
00247 
00248   return error_code;
00249 }

size_t colvarproxy_namd::restart_frequency (  )  [inline]

Definition at line 232 of file colvarproxy_namd.h.

References restart_frequency_s.

00233   {
00234     return restart_frequency_s;
00235   }

int colvarproxy_namd::run_colvar_callback ( std::string const &  name,
std::vector< const colvarvalue * > const &  cvcs,
colvarvalue &  value 
)

Definition at line 495 of file colvarproxy_namd.C.

00499 {
00500   return colvarproxy::tcl_run_colvar_callback(name, cvc_values, value);
00501 }

int colvarproxy_namd::run_colvar_gradient_callback ( std::string const &  name,
std::vector< const colvarvalue * > const &  cvcs,
std::vector< cvm::matrix2d< cvm::real > > &  gradient 
)

Definition at line 503 of file colvarproxy_namd.C.

00507 {
00508   return colvarproxy::tcl_run_colvar_gradient_callback(name, cvc_values,
00509                                                        gradient);
00510 }

int colvarproxy_namd::run_force_callback (  ) 

Definition at line 490 of file colvarproxy_namd.C.

00491 {
00492   return colvarproxy::tcl_run_force_callback();
00493 }

int colvarproxy_namd::scalable_group_coms (  )  [inline]

Definition at line 264 of file colvarproxy_namd.h.

00265   {
00266     return COLVARS_OK;
00267   }

char const * colvarproxy_namd::script_obj_to_str ( unsigned char *  obj  ) 

Definition at line 998 of file colvarproxy_namd.C.

References debug.

00999 {
01000   if (cvm::debug()) {
01001     cvm::log("Called colvarproxy_namd::script_obj_to_str().\n");
01002   }
01003 #ifdef NAMD_TCL
01004   return Tcl_GetString(reinterpret_cast<Tcl_Obj *>(obj));
01005 #else
01006   // This is most likely not going to be executed
01007   return colvarproxy::script_obj_to_str(obj);
01008 #endif
01009 }

std::vector< std::string > colvarproxy_namd::script_obj_to_str_vector ( unsigned char *  obj  ) 

Definition at line 1012 of file colvarproxy_namd.C.

References debug.

01013 {
01014   if (cvm::debug()) {
01015     cvm::log("Called colvarproxy_namd::script_obj_to_str_vector().\n");
01016   }
01017   std::vector<std::string> result;
01018 #ifdef NAMD_TCL
01019   Tcl_Interp *interp = reinterpret_cast<Tcl_Interp *>(_tcl_interp);
01020   Tcl_Obj *tcl_obj = reinterpret_cast<Tcl_Obj *>(obj);
01021   Tcl_Obj **tcl_list_elems = NULL;
01022   int count = 0;
01023   if (Tcl_ListObjGetElements(interp, tcl_obj, &count, &tcl_list_elems) ==
01024       TCL_OK) {
01025     result.reserve(count);
01026     for (int i = 0; i < count; i++) {
01027       result.push_back(Tcl_GetString(tcl_list_elems[i]));
01028     }
01029   } else {
01030     Tcl_SetResult(interp,
01031                   const_cast<char *>("Cannot parse Tcl list."), TCL_STATIC);
01032   }
01033 #endif
01034   return result;
01035 }

int colvarproxy_namd::setup (  ) 

Definition at line 188 of file colvarproxy_namd.C.

References log(), GlobalMaster::modifyRequestedGroups(), simparams, update_atom_properties(), update_group_properties(), and SimParameters::wrapAll.

Referenced by calculate().

00189 {
00190   if (colvars->size() == 0) return COLVARS_OK;
00191 
00192   log("Updating NAMD interface:\n");
00193 
00194   if (simparams->wrapAll) {
00195     cvm::log("Warning: enabling wrapAll can lead to inconsistent results "
00196              "for Colvars calculations: please disable wrapAll, "
00197              "as is the default option in NAMD.\n");
00198   }
00199 
00200   log("updating atomic data ("+cvm::to_str(atoms_ids.size())+" atoms).\n");
00201 
00202   size_t i;
00203   for (i = 0; i < atoms_ids.size(); i++) {
00204     update_atom_properties(i);
00205 
00206     // zero out mutable arrays
00207     atoms_positions[i] = cvm::rvector(0.0, 0.0, 0.0);
00208     atoms_total_forces[i] = cvm::rvector(0.0, 0.0, 0.0);
00209     atoms_new_colvar_forces[i] = cvm::rvector(0.0, 0.0, 0.0);
00210   }
00211 
00212   size_t n_group_atoms = 0;
00213   for (int ig = 0; ig < modifyRequestedGroups().size(); ig++) {
00214     n_group_atoms += modifyRequestedGroups()[ig].size();
00215   }
00216 
00217   log("updating group data ("+cvm::to_str(atom_groups_ids.size())+" scalable groups, "+
00218       cvm::to_str(n_group_atoms)+" atoms in total).\n");
00219 
00220   // Note: groupMassBegin, groupMassEnd may be used here, but they won't work for charges
00221   for (int ig = 0; ig < modifyRequestedGroups().size(); ig++) {
00222 
00223     // update mass and charge
00224     update_group_properties(ig);
00225 
00226     atom_groups_coms[ig] = cvm::rvector(0.0, 0.0, 0.0);
00227     atom_groups_total_forces[ig] = cvm::rvector(0.0, 0.0, 0.0);
00228     atom_groups_new_colvar_forces[ig] = cvm::rvector(0.0, 0.0, 0.0);
00229   }
00230 
00231   return COLVARS_OK;
00232 }

cvm::real colvarproxy_namd::temperature (  )  [inline]

Definition at line 113 of file colvarproxy_namd.h.

References thermostat_temperature.

00114   {
00115     return thermostat_temperature;
00116   }

bool colvarproxy_namd::total_forces_enabled (  )  const [inline]

Definition at line 90 of file colvarproxy_namd.h.

References total_force_requested.

00091   {
00092     return total_force_requested;
00093   }

cvm::real colvarproxy_namd::unit_angstrom (  )  [inline]

Definition at line 103 of file colvarproxy_namd.h.

00104   {
00105     return 1.0;
00106   }

void colvarproxy_namd::update_atom_properties ( int  index  ) 

Definition at line 679 of file colvarproxy_namd.C.

References Molecule::atomcharge(), Molecule::atommass(), log(), Node::molecule, and Node::Object().

Referenced by init_atom(), setup(), and update_atoms_map().

00680 {
00681   Molecule *mol = Node::Object()->molecule;
00682   // update mass
00683   double const mass = mol->atommass(atoms_ids[index]);
00684   if (mass <= 0.001) {
00685     this->log("Warning: near-zero mass for atom "+
00686               cvm::to_str(atoms_ids[index]+1)+
00687               "; expect unstable dynamics if you apply forces to it.\n");
00688   }
00689   atoms_masses[index] = mass;
00690   // update charge
00691   atoms_charges[index] = mol->atomcharge(atoms_ids[index]);
00692 }

int colvarproxy_namd::update_atoms_map ( AtomIDList::const_iterator  begin,
AtomIDList::const_iterator  end 
)

Definition at line 153 of file colvarproxy_namd.C.

References atoms_map, debug, log(), and update_atom_properties().

Referenced by calculate().

00155 {
00156   for (AtomIDList::const_iterator a_i = begin; a_i != end; a_i++) {
00157 
00158     if (cvm::debug()) {
00159       cvm::log("Updating atoms_map for atom ID "+cvm::to_str(*a_i)+"\n");
00160     }
00161 
00162     if (atoms_map[*a_i] >= 0) continue;
00163 
00164     for (size_t i = 0; i < atoms_ids.size(); i++) {
00165       if (atoms_ids[i] == *a_i) {
00166         atoms_map[*a_i] = i;
00167         break;
00168       }
00169     }
00170 
00171     if (atoms_map[*a_i] < 0) {
00172       // this atom is probably managed by another GlobalMaster:
00173       // add it here anyway to avoid having to test for array boundaries at each step
00174       int const index = add_atom_slot(*a_i);
00175       atoms_map[*a_i] = index;
00176       update_atom_properties(index);
00177     }
00178   }
00179 
00180   if (cvm::debug()) {
00181     log("atoms_map = "+cvm::to_str(atoms_map)+".\n");
00182   }
00183 
00184   return COLVARS_OK;
00185 }

int colvarproxy_namd::update_group_properties ( int  index  ) 

Definition at line 1115 of file colvarproxy_namd.C.

References Molecule::atomcharge(), Molecule::atommass(), debug, log(), GlobalMaster::modifyRequestedGroups(), Node::molecule, Node::Object(), and ResizeArray< Elem >::size().

Referenced by init_atom_group(), and setup().

01116 {
01117   AtomIDList const &namd_group = modifyRequestedGroups()[index];
01118   if (cvm::debug()) {
01119     log("Re-calculating total mass and charge for scalable group no. "+cvm::to_str(index+1)+" ("+
01120         cvm::to_str(namd_group.size())+" atoms).\n");
01121   }
01122 
01123   cvm::real total_mass = 0.0;
01124   cvm::real total_charge = 0.0;
01125   for (int i = 0; i < namd_group.size(); i++) {
01126     total_mass += Node::Object()->molecule->atommass(namd_group[i]);
01127     total_charge += Node::Object()->molecule->atomcharge(namd_group[i]);
01128   }
01129   atom_groups_masses[index] = total_mass;
01130   atom_groups_charges[index] = total_charge;
01131 
01132   if (cvm::debug()) {
01133     log("total mass = "+cvm::to_str(total_mass)+
01134         ", total charge = "+cvm::to_str(total_charge)+"\n");
01135   }
01136 
01137   return COLVARS_OK;
01138 }


Friends And Related Function Documentation

friend class cvm::atom [friend]

Definition at line 69 of file colvarproxy_namd.h.

Referenced by load_atoms().


Member Data Documentation

std::vector<int> colvarproxy_namd::atoms_map [protected]

Array of atom indices (relative to the colvarproxy arrays), usedfor faster copy of atomic data.

Definition at line 39 of file colvarproxy_namd.h.

Referenced by calculate(), reset(), and update_atoms_map().

bool colvarproxy_namd::first_timestep [protected]

Definition at line 53 of file colvarproxy_namd.h.

Referenced by calculate(), and colvarproxy_namd().

size_t colvarproxy_namd::previous_NAMD_step [protected]

Definition at line 54 of file colvarproxy_namd.h.

Referenced by calculate().

Random colvarproxy_namd::random [protected]

NAMD-style PRNG object.

Definition at line 48 of file colvarproxy_namd.h.

Referenced by colvarproxy_namd(), and rand_gaussian().

SubmitReduction* colvarproxy_namd::reduction [protected]

Used to submit restraint energy as MISC.

Definition at line 59 of file colvarproxy_namd.h.

Referenced by add_energy(), calculate(), colvarproxy_namd(), and ~colvarproxy_namd().

size_t colvarproxy_namd::restart_frequency_s [protected]

How often NAMD is instructed to write state files.

Definition at line 51 of file colvarproxy_namd.h.

Referenced by colvarproxy_namd(), and restart_frequency().

SimParameters const* colvarproxy_namd::simparams [protected]

Pointer to the NAMD simulation input object.

Definition at line 42 of file colvarproxy_namd.h.

Referenced by calculate(), colvarproxy_namd(), dt(), and setup().

BigReal colvarproxy_namd::thermostat_temperature [protected]

Self-explained.

Definition at line 45 of file colvarproxy_namd.h.

Referenced by colvarproxy_namd(), and temperature().

bool colvarproxy_namd::total_force_requested [protected]

Definition at line 56 of file colvarproxy_namd.h.

Referenced by calculate(), colvarproxy_namd(), request_total_force(), and total_forces_enabled().


The documentation for this class was generated from the following files:
Generated on Tue Oct 23 01:17:19 2018 for NAMD by  doxygen 1.4.7