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)

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 514 of file colvarproxy_namd.C.

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

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

int colvarproxy_namd::backup_file ( char const *  filename  ) 

Definition at line 971 of file colvarproxy_namd.C.

References NAMD_backup_file().

00972 {
00973   if (std::string(filename).rfind(std::string(".colvars.state")) != std::string::npos) {
00974     NAMD_backup_file(filename, ".old");
00975   } else {
00976     NAMD_backup_file(filename, ".BAK");
00977   }
00978   return COLVARS_OK;
00979 }

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 612 of file colvarproxy_namd.C.

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

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

int colvarproxy_namd::check_atom_id ( int  atom_number  ) 

Definition at line 566 of file colvarproxy_namd.C.

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

Referenced by init_atom().

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

void colvarproxy_namd::clear_atom ( int  index  ) 

Definition at line 673 of file colvarproxy_namd.C.

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

void colvarproxy_namd::clear_atom_group ( int  index  ) 

Definition at line 1065 of file colvarproxy_namd.C.

01066 {
01067   // do nothing, keep the NAMD arrays in sync with the colvarproxy ones
01068   colvarproxy::clear_atom_group(index);
01069 }

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

Definition at line 952 of file colvarproxy_namd.C.

00953 {
00954   std::list<std::ostream *>::iterator osi  = output_files.begin();
00955   std::list<std::string>::iterator    osni = output_stream_names.begin();
00956   for ( ; osi != output_files.end(); osi++, osni++) {
00957     if (*osni == output_name) {
00958       if (((ofstream_namd *) *osi)->is_open()) {
00959         ((ofstream_namd *) *osi)->close();
00960       }
00961       delete *osi;
00962       output_files.erase(osi);
00963       output_stream_names.erase(osni);
00964       return COLVARS_OK;
00965     }
00966   }
00967   return COLVARS_ERROR;
00968 }

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 540 of file colvarproxy_namd.C.

References fatal_error().

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

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

Definition at line 559 of file colvarproxy_namd.C.

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

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

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

Definition at line 547 of file colvarproxy_namd.C.

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

Referenced by colvarproxy_namd(), and error().

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

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

Definition at line 938 of file colvarproxy_namd.C.

00939 {
00940   std::list<std::ostream *>::iterator osi  = output_files.begin();
00941   std::list<std::string>::iterator    osni = output_stream_names.begin();
00942   for ( ; osi != output_files.end(); osi++, osni++) {
00943     if (*osi == os) {
00944       ((ofstream_namd *) *osi)->flush();
00945       return COLVARS_OK;
00946     }
00947   }
00948   return COLVARS_ERROR;
00949 }

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 645 of file colvarproxy_namd.C.

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

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

int colvarproxy_namd::init_atom ( int  atom_number  ) 

Definition at line 585 of file colvarproxy_namd.C.

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

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

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

Definition at line 995 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().

00996 {
00997   if (cvm::debug())
00998     log("Reguesting from NAMD a group of size "+cvm::to_str(atoms_ids.size())+
00999         " for collective variables calculation.\n");
01000 
01001   // Note: modifyRequestedGroups is supposed to be in sync with the colvarproxy arrays,
01002   // and to stay that way during a simulation
01003 
01004   // compare this new group to those already allocated inside GlobalMaster
01005   int ig;
01006   for (ig = 0; ig < modifyRequestedGroups().size(); ig++) {
01007     AtomIDList const &namd_group = modifyRequestedGroups()[ig];
01008     bool b_match = true;
01009 
01010     if (namd_group.size() != ((int) atoms_ids.size())) {
01011       b_match = false;
01012     } else {
01013       int ia;
01014       for (ia = 0; ia < namd_group.size(); ia++) {
01015         int const aid = atoms_ids[ia];
01016         if (namd_group[ia] != aid) {
01017           b_match = false;
01018           break;
01019         }
01020       }
01021     }
01022 
01023     if (b_match) {
01024       if (cvm::debug())
01025         log("Group was already added.\n");
01026       // this group already exists
01027       atom_groups_ncopies[ig] += 1;
01028       return ig;
01029     }
01030   }
01031 
01032   // add this group (note: the argument of add_atom_group_slot() is redundant for NAMD, and provided only for consistency)
01033   size_t const index = add_atom_group_slot(atom_groups_ids.size());
01034   modifyRequestedGroups().resize(atom_groups_ids.size());
01035   // the following is done in calculate()
01036   // modifyGroupForces().resize(atom_groups_ids.size());
01037   AtomIDList &namd_group = modifyRequestedGroups()[index];
01038   namd_group.resize(atoms_ids.size());
01039   int const n_all_atoms = Node::Object()->molecule->numAtoms;
01040   for (size_t ia = 0; ia < atoms_ids.size(); ia++) {
01041     int const aid = atoms_ids[ia];
01042     if (cvm::debug())
01043       log("Adding atom "+cvm::to_str(aid+1)+
01044           " for collective variables calculation.\n");
01045     if ( (aid < 0) || (aid >= n_all_atoms) ) {
01046       cvm::error("Error: invalid atom number specified, "+
01047                  cvm::to_str(aid+1)+"\n", INPUT_ERROR);
01048       return -1;
01049     }
01050     namd_group[ia] = aid;
01051   }
01052 
01053   update_group_properties(index);
01054 
01055   if (cvm::debug()) {
01056     log("Group has index "+cvm::to_str(index)+"\n");
01057     log("modifyRequestedGroups length = "+cvm::to_str(modifyRequestedGroups().size())+
01058         ", modifyGroupForces length = "+cvm::to_str(modifyGroupForces().size())+"\n");
01059   }
01060 
01061   return index;
01062 }

void colvarproxy_namd::init_tcl_pointers (  )  [protected]

Definition at line 484 of file colvarproxy_namd.C.

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

Referenced by colvarproxy_namd().

00485 {
00486   // Store pointer to NAMD's Tcl interpreter
00487   _tcl_interp = reinterpret_cast<void *>(Node::Object()->getScript()->interp);
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 853 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().

00857 {
00858   if (pdb_field_str.size() == 0)
00859     cvm::error("Error: must define which PDB field to use "
00860                "in order to define atoms from a PDB file.\n", INPUT_ERROR);
00861 
00862   PDB *pdb = new PDB(pdb_filename);
00863   size_t const pdb_natoms = pdb->num_atoms();
00864 
00865   e_pdb_field pdb_field_index = pdb_field_str2enum(pdb_field_str);
00866 
00867   for (size_t ipdb = 0; ipdb < pdb_natoms; ipdb++) {
00868 
00869     double atom_pdb_field_value = 0.0;
00870 
00871     switch (pdb_field_index) {
00872     case e_pdb_occ:
00873       atom_pdb_field_value = (pdb->atom(ipdb))->occupancy();
00874       break;
00875     case e_pdb_beta:
00876       atom_pdb_field_value = (pdb->atom(ipdb))->temperaturefactor();
00877       break;
00878     case e_pdb_x:
00879       atom_pdb_field_value = (pdb->atom(ipdb))->xcoor();
00880       break;
00881     case e_pdb_y:
00882       atom_pdb_field_value = (pdb->atom(ipdb))->ycoor();
00883       break;
00884     case e_pdb_z:
00885       atom_pdb_field_value = (pdb->atom(ipdb))->zcoor();
00886       break;
00887     default:
00888       break;
00889     }
00890 
00891     if ( (pdb_field_value) &&
00892          (atom_pdb_field_value != pdb_field_value) ) {
00893       continue;
00894     } else if (atom_pdb_field_value == 0.0) {
00895       continue;
00896     }
00897 
00898     if (atoms.is_enabled(colvardeps::f_ag_scalable)) {
00899       atoms.add_atom_id(ipdb);
00900     } else {
00901       atoms.add_atom(cvm::atom(ipdb+1));
00902     }
00903   }
00904 
00905   delete pdb;
00906   return (cvm::get_error() ? COLVARS_ERROR : COLVARS_OK);
00907 }

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 742 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().

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

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

Definition at line 531 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_atoms_map(), and update_group_properties().

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

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

Definition at line 910 of file colvarproxy_namd.C.

References debug, and ofstream_namd::is_open().

00912 {
00913   if (cvm::debug()) {
00914     cvm::log("Using colvarproxy_namd::output_stream()\n");
00915   }
00916   std::list<std::ostream *>::iterator osi  = output_files.begin();
00917   std::list<std::string>::iterator    osni = output_stream_names.begin();
00918   for ( ; osi != output_files.end(); osi++, osni++) {
00919     if (*osni == output_name) {
00920       return *osi;
00921     }
00922   }
00923   if (!(mode & (std::ios_base::app | std::ios_base::ate))) {
00924     colvarproxy::backup_file(output_name);
00925   }
00926   ofstream_namd *os = new ofstream_namd(output_name.c_str(), mode);
00927   if (!os->is_open()) {
00928     cvm::error("Error: cannot write to file \""+output_name+"\".\n",
00929                FILE_ERROR);
00930     return NULL;
00931   }
00932   output_stream_names.push_back(output_name);
00933   output_files.push_back(os);
00934   return os;
00935 }

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

Definition at line 680 of file colvarproxy_namd.C.

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

00683 {
00684   Position const p1(pos1.x, pos1.y, pos1.z);
00685   Position const p2(pos2.x, pos2.y, pos2.z);
00686   // return p2 - p1
00687   Vector const d = this->lattice->delta(p2, p1);
00688   return cvm::rvector(d.x, d.y, d.z);
00689 }

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 519 of file colvarproxy_namd.C.

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

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

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 271 of file colvarproxy_namd.h.

00272   {
00273     return COLVARS_OK;
00274   }

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

Definition at line 982 of file colvarproxy_namd.C.

References debug.

00983 {
00984   if (cvm::debug()) {
00985     cvm::log("Called colvarproxy_namd::script_obj_to_str().\n");
00986   }
00987 #ifdef NAMD_TCL
00988   return Tcl_GetString(reinterpret_cast<Tcl_Obj *>(obj));
00989 #else
00990   // This is most likely not going to be executed
00991   return colvarproxy::script_obj_to_str(obj);
00992 #endif
00993 }

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  )  [inline]

Definition at line 247 of file colvarproxy_namd.h.

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

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

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   }

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 1072 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().

01073 {
01074   AtomIDList const &namd_group = modifyRequestedGroups()[index];
01075   if (cvm::debug()) {
01076     log("Re-calculating total mass and charge for scalable group no. "+cvm::to_str(index+1)+" ("+
01077         cvm::to_str(namd_group.size())+" atoms).\n");
01078   }
01079 
01080   cvm::real total_mass = 0.0;
01081   cvm::real total_charge = 0.0;
01082   for (int i = 0; i < namd_group.size(); i++) {
01083     total_mass += Node::Object()->molecule->atommass(namd_group[i]);
01084     total_charge += Node::Object()->molecule->atomcharge(namd_group[i]);
01085   }
01086   atom_groups_masses[index] = total_mass;
01087   atom_groups_charges[index] = total_charge;
01088 
01089   if (cvm::debug()) {
01090     log("total mass = "+cvm::to_str(total_mass)+
01091         ", total charge = "+cvm::to_str(total_charge)+"\n");
01092   }
01093 
01094   return COLVARS_OK;
01095 }


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 Wed Aug 15 01:17:18 2018 for NAMD by  doxygen 1.4.7