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)
int set_unit_system (std::string const &units_in, bool check_only)
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 backend_angstrom_value ()
cvm::real boltzmann ()
cvm::real temperature ()
cvm::real rand_gaussian ()
cvm::real dt ()
virtual int replica_enabled ()
virtual int replica_index ()
virtual int num_replicas ()
virtual void replica_comm_barrier ()
virtual int replica_comm_recv (char *msg_data, int buf_len, int src_rep)
virtual int replica_comm_send (char *msg_data, int msg_len, int dest_rep)
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)
int init_volmap (int volmap_id)
int init_volmap (const char *volmap_name)
void clear_volmap (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.
SimParameterssimparams
 Pointer to the NAMD simulation input object.
BigReal thermostat_temperature
 Self-explained.
Random random
 NAMD-style PRNG object.
bool first_timestep
size_t previous_NAMD_step
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 34 of file colvarproxy_namd.h.


Constructor & Destructor Documentation

colvarproxy_namd::colvarproxy_namd (  ) 

Definition at line 38 of file colvarproxy_namd.C.

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

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

colvarproxy_namd::~colvarproxy_namd (  ) 

Definition at line 151 of file colvarproxy_namd.C.

References reduction.

00152 {
00153   delete reduction;
00154   if (script != NULL) {
00155     delete script;
00156     script = NULL;
00157   }
00158   if (colvars != NULL) {
00159     delete colvars;
00160     colvars = NULL;
00161   }
00162 }


Member Function Documentation

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

Definition at line 596 of file colvarproxy_namd.C.

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

00597 {
00598   reduction->item(REDUCTION_MISC_ENERGY) += energy;
00599 }

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

Definition at line 95 of file colvarproxy_namd.h.

00096   {
00097     return 1.0;
00098   }

int colvarproxy_namd::backup_file ( char const *  filename  ) 

Definition at line 1076 of file colvarproxy_namd.C.

References NAMD_backup_file().

Referenced by output_stream().

01077 {
01078   if (std::string(filename).rfind(std::string(".colvars.state")) != std::string::npos) {
01079     NAMD_backup_file(filename, ".old");
01080   } else {
01081     NAMD_backup_file(filename, ".BAK");
01082   }
01083   return COLVARS_OK;
01084 }

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

Definition at line 100 of file colvarproxy_namd.h.

00101   {
00102     return 0.001987191;
00103   }

void colvarproxy_namd::calculate (  )  [virtual]

Reimplemented from GlobalMaster.

Definition at line 278 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(), error(), first_timestep, GlobalMaster::getAtomIdBegin(), GlobalMaster::getAtomIdEnd(), GlobalMaster::getAtomPositionBegin(), GlobalMaster::getForceIdBegin(), GlobalMaster::getForceIdEnd(), GlobalMaster::getGridObjIndexBegin(), GlobalMaster::getGridObjIndexEnd(), GlobalMaster::getGridObjValueBegin(), GlobalMaster::getGridObjValueEnd(), GlobalMaster::getGroupPositionBegin(), GlobalMaster::getGroupPositionEnd(), GlobalMaster::getGroupTotalForceBegin(), GlobalMaster::getGroupTotalForceEnd(), GlobalMaster::getTotalForce(), GlobalMaster::lattice, log(), GlobalMaster::modifyAppliedForces(), GlobalMaster::modifyForcedAtoms(), GlobalMaster::modifyGridObjForces(), GlobalMaster::modifyGroupForces(), Node::molecule, SimParameters::N, Molecule::numAtoms, Node::Object(), Lattice::orthogonal(), previous_NAMD_step, reduction, GlobalMaster::requestedGridObjs(), GlobalMaster::requestedGroups(), ResizeArray< Elem >::resize(), Vector::set(), ResizeArray< Elem >::setall(), setup(), simparams, GlobalMaster::step, SubmitReduction::submit(), update_atoms_map(), Vector::x, Vector::y, and Vector::z.

00279 {
00280   errno = 0;
00281 
00282   if (first_timestep) {
00283 
00284     colvarproxy_namd::setup();
00285     colvars->setup();
00286     colvars->setup_input();
00287     colvars->setup_output();
00288 
00289     first_timestep = false;
00290 
00291   } else {
00292     // Use the time step number inherited from GlobalMaster
00293     if ( step - previous_NAMD_step == 1 ) {
00294       colvars->it++;
00295       b_simulation_continuing = false;
00296     } else {
00297       // Cases covered by this condition:
00298       // - run 0
00299       // - beginning of a new run statement
00300       // The internal counter is not incremented, and the objects are made
00301       // aware of this via the following flag
00302       b_simulation_continuing = true;
00303     }
00304   }
00305 
00306   previous_NAMD_step = step;
00307 
00308   {
00309     Vector const a = lattice->a();
00310     Vector const b = lattice->b();
00311     Vector const c = lattice->c();
00312     unit_cell_x.set(a.x, a.y, a.z);
00313     unit_cell_y.set(b.x, b.y, c.z);
00314     unit_cell_z.set(c.x, c.y, c.z);
00315   }
00316 
00317   if (!lattice->a_p() && !lattice->b_p() && !lattice->c_p()) {
00318     boundaries_type = boundaries_non_periodic;
00319     reset_pbc_lattice();
00320   } else if (lattice->a_p() && lattice->b_p() && lattice->c_p()) {
00321     if (lattice->orthogonal()) {
00322       boundaries_type = boundaries_pbc_ortho;
00323     } else {
00324       boundaries_type = boundaries_pbc_triclinic;
00325     }
00326     colvarproxy_system::update_pbc_lattice();
00327   } else {
00328     boundaries_type = boundaries_unsupported;
00329   }
00330 
00331   if (cvm::debug()) {
00332     cvm::log(std::string(cvm::line_marker)+
00333              "colvarproxy_namd, step no. "+cvm::to_str(colvars->it)+"\n"+
00334              "Updating atomic data arrays.\n");
00335   }
00336 
00337   // must delete the forces applied at the previous step: we can do
00338   // that because they have already been used and copied to other
00339   // memory locations
00340   modifyForcedAtoms().clear();
00341   modifyAppliedForces().clear();
00342 
00343   // prepare local arrays
00344   for (size_t i = 0; i < atoms_ids.size(); i++) {
00345     atoms_positions[i] = cvm::rvector(0.0, 0.0, 0.0);
00346     atoms_total_forces[i] = cvm::rvector(0.0, 0.0, 0.0);
00347     atoms_new_colvar_forces[i] = cvm::rvector(0.0, 0.0, 0.0);
00348   }
00349 
00350   for (size_t i = 0; i < atom_groups_ids.size(); i++) {
00351     atom_groups_total_forces[i] = cvm::rvector(0.0, 0.0, 0.0);
00352     atom_groups_new_colvar_forces[i] = cvm::rvector(0.0, 0.0, 0.0);
00353   }
00354 
00355 #if NAMD_VERSION_NUMBER >= 34471681
00356   for (int imap = 0; imap < volmaps_ids.size(); imap++) {
00357     volmaps_new_colvar_forces[imap] = 0.0;
00358   }
00359 #endif
00360 
00361   // create the atom map if needed
00362   size_t const n_all_atoms = Node::Object()->molecule->numAtoms;
00363   if (atoms_map.size() != n_all_atoms) {
00364     atoms_map.resize(n_all_atoms);
00365     atoms_map.assign(n_all_atoms, -1);
00366     update_atoms_map(getAtomIdBegin(), getAtomIdEnd());
00367   }
00368 
00369   // if new atomic positions or forces have been communicated by other GlobalMasters, add them to the atom map
00370   if ((int(atoms_ids.size()) < (getAtomIdEnd() - getAtomIdBegin())) ||
00371       (int(atoms_ids.size()) < (getForceIdEnd() - getForceIdBegin()))) {
00372     update_atoms_map(getAtomIdBegin(), getAtomIdEnd());
00373     update_atoms_map(getForceIdBegin(), getForceIdEnd());
00374   }
00375 
00376   {
00377     if (cvm::debug()) {
00378       cvm::log("Updating positions arrays.\n");
00379     }
00380     size_t n_positions = 0;
00381     AtomIDList::const_iterator a_i = getAtomIdBegin();
00382     AtomIDList::const_iterator a_e = getAtomIdEnd();
00383     PositionList::const_iterator p_i = getAtomPositionBegin();
00384 
00385     for ( ; a_i != a_e; ++a_i, ++p_i ) {
00386       atoms_positions[atoms_map[*a_i]] = cvm::rvector((*p_i).x, (*p_i).y, (*p_i).z);
00387       n_positions++;
00388     }
00389 
00390     // The following had to be relaxed because some atoms may be forced without their position being requested
00391     // if (n_positions < atoms_ids.size()) {
00392     //   cvm::error("Error: did not receive the positions of all atoms.\n", BUG_ERROR);
00393     // }
00394   }
00395 
00396   if (total_force_requested && cvm::step_relative() > 0) {
00397 
00398     // sort the force arrays the previous step
00399     // (but only do so if there *is* a previous step!)
00400 
00401     {
00402       if (cvm::debug()) {
00403         cvm::log("Updating total forces arrays.\n");
00404       }
00405       size_t n_total_forces = 0;
00406       AtomIDList::const_iterator a_i = getForceIdBegin();
00407       AtomIDList::const_iterator a_e = getForceIdEnd();
00408       ForceList::const_iterator f_i = getTotalForce();
00409 
00410       for ( ; a_i != a_e; ++a_i, ++f_i ) {
00411         atoms_total_forces[atoms_map[*a_i]] = cvm::rvector((*f_i).x, (*f_i).y, (*f_i).z);
00412         n_total_forces++;
00413       }
00414 
00415       if (n_total_forces < atoms_ids.size()) {
00416         cvm::error("Error: total forces were requested, but total forces "
00417                    "were not received for all atoms.\n"
00418                    "The most probable cause is combination of energy "
00419                    "minimization with a biasing method that requires MD (e.g. ABF).\n"
00420                    "Always run minimization and ABF separately.", INPUT_ERROR);
00421       }
00422     }
00423 
00424     {
00425       if (cvm::debug()) {
00426         cvm::log("Updating group total forces arrays.\n");
00427       }
00428       ForceList::const_iterator f_i = getGroupTotalForceBegin();
00429       ForceList::const_iterator f_e = getGroupTotalForceEnd();
00430       size_t i = 0;
00431       if ((f_e - f_i) != ((int) atom_groups_ids.size())) {
00432         cvm::error("Error: total forces were requested for scalable groups, "
00433                    "but they are not in the same number from the number of groups.\n"
00434                    "The most probable cause is combination of energy "
00435                    "minimization with a biasing method that requires MD (e.g. ABF).\n"
00436                    "Always run minimization and ABF separately.", INPUT_ERROR);
00437       }
00438       for ( ; f_i != f_e; f_i++, i++) {
00439         atom_groups_total_forces[i] = cvm::rvector((*f_i).x, (*f_i).y, (*f_i).z);
00440       }
00441     }
00442   }
00443 
00444   {
00445     if (cvm::debug()) {
00446       cvm::log("Updating group positions arrays.\n");
00447     }
00448     // update group data (only coms available so far)
00449     size_t ig;
00450     // note: getGroupMassBegin() could be used here, but masses and charges
00451     // have already been calculated from the last call to setup()
00452     PositionList::const_iterator gp_i = getGroupPositionBegin();
00453     for (ig = 0; gp_i != getGroupPositionEnd(); gp_i++, ig++) {
00454       atom_groups_coms[ig] = cvm::rvector(gp_i->x, gp_i->y, gp_i->z);
00455     }
00456   }
00457 
00458 #if NAMD_VERSION_NUMBER >= 34471681
00459   {
00460     if (cvm::debug()) {
00461       log("Updating grid objects.\n");
00462     }
00463     // Using a simple nested loop: there probably won't be so many maps that
00464     // this becomes performance-limiting
00465     IntList::const_iterator goi_i = getGridObjIndexBegin();
00466     BigRealList::const_iterator gov_i = getGridObjValueBegin();
00467     for ( ; gov_i != getGridObjValueEnd(); goi_i++, gov_i++) {
00468       for (size_t imap = 0; imap < volmaps_ids.size(); imap++) {
00469         if (volmaps_ids[imap] == *goi_i) {
00470           volmaps_values[imap] = *gov_i;
00471           break;
00472         }
00473       }
00474     }
00475   }
00476 #endif
00477 
00478   if (cvm::debug()) {
00479     cvm::log("atoms_ids = "+cvm::to_str(atoms_ids)+"\n");
00480     cvm::log("atoms_ncopies = "+cvm::to_str(atoms_ncopies)+"\n");
00481     cvm::log("atoms_masses = "+cvm::to_str(atoms_masses)+"\n");
00482     cvm::log("atoms_charges = "+cvm::to_str(atoms_charges)+"\n");
00483     cvm::log("atoms_positions = "+cvm::to_str(atoms_positions)+"\n");
00484     cvm::log("atoms_total_forces = "+cvm::to_str(atoms_total_forces)+"\n");
00485     cvm::log(cvm::line_marker);
00486 
00487     cvm::log("atom_groups_ids = "+cvm::to_str(atom_groups_ids)+"\n");
00488     cvm::log("atom_groups_ncopies = "+cvm::to_str(atom_groups_ncopies)+"\n");
00489     cvm::log("atom_groups_masses = "+cvm::to_str(atom_groups_masses)+"\n");
00490     cvm::log("atom_groups_charges = "+cvm::to_str(atom_groups_charges)+"\n");
00491     cvm::log("atom_groups_coms = "+cvm::to_str(atom_groups_coms)+"\n");
00492     cvm::log("atom_groups_total_forces = "+cvm::to_str(atom_groups_total_forces)+"\n");
00493     cvm::log(cvm::line_marker);
00494 
00495 #if NAMD_VERSION_NUMBER >= 34471681
00496     cvm::log("volmaps_ids = "+cvm::to_str(volmaps_ids)+"\n");
00497     cvm::log("volmaps_values = "+cvm::to_str(volmaps_values)+"\n");
00498     cvm::log(cvm::line_marker);
00499 #endif
00500   }
00501 
00502   // call the collective variable module
00503   if (colvars->calc() != COLVARS_OK) {
00504     cvm::error("Error in the collective variables module.\n", COLVARS_ERROR);
00505   }
00506 
00507   if (cvm::debug()) {
00508     cvm::log(cvm::line_marker);
00509     cvm::log("atoms_new_colvar_forces = "+cvm::to_str(atoms_new_colvar_forces)+"\n");
00510     cvm::log(cvm::line_marker);
00511     cvm::log("atom_groups_new_colvar_forces = "+cvm::to_str(atom_groups_new_colvar_forces)+"\n");
00512     cvm::log(cvm::line_marker);
00513 #if NAMD_VERSION_NUMBER >= 34471681
00514     cvm::log("volmaps_new_colvar_forces = "+cvm::to_str(volmaps_new_colvar_forces)+"\n");
00515     cvm::log(cvm::line_marker);
00516 #endif
00517   }
00518 
00519   // communicate all forces to the MD integrator
00520   for (size_t i = 0; i < atoms_ids.size(); i++) {
00521     cvm::rvector const &f = atoms_new_colvar_forces[i];
00522     modifyForcedAtoms().add(atoms_ids[i]);
00523     modifyAppliedForces().add(Vector(f.x, f.y, f.z));
00524   }
00525 
00526   if (atom_groups_new_colvar_forces.size() > 0) {
00527     modifyGroupForces().resize(requestedGroups().size());
00528     ForceList::iterator gf_i = modifyGroupForces().begin();
00529     for (int ig = 0; gf_i != modifyGroupForces().end(); gf_i++, ig++) {
00530       cvm::rvector const &f = atom_groups_new_colvar_forces[ig];
00531       *gf_i = Vector(f.x, f.y, f.z);
00532     }
00533   }
00534 
00535 #if NAMD_VERSION_NUMBER >= 34471681
00536   if (volmaps_new_colvar_forces.size() > 0) {
00537     modifyGridObjForces().resize(requestedGridObjs().size());
00538     modifyGridObjForces().setall(0.0);
00539     IntList::const_iterator goi_i = getGridObjIndexBegin();
00540     BigRealList::iterator gof_i = modifyGridObjForces().begin();
00541     for ( ; goi_i != getGridObjIndexEnd(); goi_i++, gof_i++) {
00542       for (size_t imap = 0; imap < volmaps_ids.size(); imap++) {
00543         if (volmaps_ids[imap] == *goi_i) {
00544           *gof_i = volmaps_new_colvar_forces[imap];
00545           break;
00546         }
00547       }
00548     }
00549   }
00550 #endif
00551 
00552   // send MISC energy
00553   reduction->submit();
00554 
00555   // NAMD does not destruct GlobalMaster objects, so we must remember
00556   // to write all output files at the end of a run
00557   if (step == simparams->N) {
00558     post_run();
00559   }
00560 }

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

Definition at line 698 of file colvarproxy_namd.C.

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

00701 {
00702   int const aid =
00703     (segment_id.size() ?
00704      Node::Object()->molecule->get_atom_from_name(segment_id.c_str(),
00705                                                   residue,
00706                                                   atom_name.c_str()) :
00707      Node::Object()->molecule->get_atom_from_name("MAIN",
00708                                                   residue,
00709                                                   atom_name.c_str()));
00710 
00711   if (aid < 0) {
00712     // get_atom_from_name() has returned an error value
00713     cvm::error("Error: could not find atom \""+
00714                atom_name+"\" in residue "+
00715                cvm::to_str(residue)+
00716                ( (segment_id != "MAIN") ?
00717                  (", segment \""+segment_id+"\"") :
00718                  ("") )+
00719                "\n", INPUT_ERROR);
00720     return INPUT_ERROR;
00721   }
00722 
00723   return aid;
00724 }

int colvarproxy_namd::check_atom_id ( int  atom_number  ) 

Definition at line 652 of file colvarproxy_namd.C.

References debug, error(), Node::molecule, Molecule::numAtoms, and Node::Object().

Referenced by init_atom().

00653 {
00654   // NAMD's internal numbering starts from zero
00655   int const aid = (atom_number-1);
00656 
00657   if (cvm::debug())
00658     cvm::log("Adding atom "+cvm::to_str(atom_number)+
00659         " for collective variables calculation.\n");
00660 
00661   if ( (aid < 0) || (aid >= Node::Object()->molecule->numAtoms) ) {
00662     cvm::error("Error: invalid atom number specified, "+
00663                cvm::to_str(atom_number)+"\n", INPUT_ERROR);
00664     return INPUT_ERROR;
00665   }
00666 
00667   return aid;
00668 }

void colvarproxy_namd::clear_atom ( int  index  ) 

Definition at line 759 of file colvarproxy_namd.C.

00760 {
00761   colvarproxy::clear_atom(index);
00762   // TODO remove it from GlobalMaster arrays?
00763 }

void colvarproxy_namd::clear_atom_group ( int  index  ) 

Definition at line 1194 of file colvarproxy_namd.C.

01195 {
01196   // do nothing, keep the NAMD arrays in sync with the colvarproxy ones
01197   colvarproxy::clear_atom_group(index);
01198 }

void colvarproxy_namd::clear_volmap ( int  index  ) 
int colvarproxy_namd::close_output_stream ( std::string const &  output_name  ) 

Definition at line 1057 of file colvarproxy_namd.C.

01058 {
01059   std::list<std::ostream *>::iterator osi  = output_files.begin();
01060   std::list<std::string>::iterator    osni = output_stream_names.begin();
01061   for ( ; osi != output_files.end(); osi++, osni++) {
01062     if (*osni == output_name) {
01063       if (((ofstream_namd *) *osi)->is_open()) {
01064         ((ofstream_namd *) *osi)->close();
01065       }
01066       delete *osi;
01067       output_files.erase(osi);
01068       output_stream_names.erase(osni);
01069       return COLVARS_OK;
01070     }
01071   }
01072   return COLVARS_ERROR;
01073 }

cvm::real colvarproxy_namd::dt (  )  [inline]
void colvarproxy_namd::error ( std::string const &  message  ) 

Definition at line 624 of file colvarproxy_namd.C.

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

Referenced by calculate(), check_atom_id(), colvarproxy_namd(), init_atom_group(), load_coords(), output_stream(), and set_unit_system().

00625 {
00626   log(message);
00627   switch (cvm::get_error()) {
00628   case FILE_ERROR:
00629     errno = EIO; break;
00630   case COLVARS_NOT_IMPLEMENTED:
00631     errno = ENOSYS; break;
00632   case MEMORY_ERROR:
00633     errno = ENOMEM; break;
00634   }
00635   char const *msg = "Error in the collective variables module "
00636     "(see above for details)";
00637   if (errno) {
00638     NAMD_err(msg);
00639   } else {
00640     NAMD_die(msg);
00641   }
00642 }

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

Definition at line 645 of file colvarproxy_namd.C.

References log().

00646 {
00647   log(message);
00648   BackEnd::exit();
00649 }

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

Definition at line 1043 of file colvarproxy_namd.C.

01044 {
01045   std::list<std::ostream *>::iterator osi  = output_files.begin();
01046   std::list<std::string>::iterator    osni = output_stream_names.begin();
01047   for ( ; osi != output_files.end(); osi++, osni++) {
01048     if (*osi == os) {
01049       ((ofstream_namd *) *osi)->flush();
01050       return COLVARS_OK;
01051     }
01052   }
01053   return COLVARS_ERROR;
01054 }

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

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

00734 {
00735   int const aid = check_atom_id(residue, atom_name, segment_id);
00736 
00737   for (size_t i = 0; i < atoms_ids.size(); i++) {
00738     if (atoms_ids[i] == aid) {
00739       // this atom id was already recorded
00740       atoms_ncopies[i] += 1;
00741       return i;
00742     }
00743   }
00744 
00745   if (cvm::debug())
00746     cvm::log("Adding atom \""+
00747         atom_name+"\" in residue "+
00748         cvm::to_str(residue)+
00749         " (index "+cvm::to_str(aid)+
00750         ") for collective variables calculation.\n");
00751 
00752   int const index = add_atom_slot(aid);
00753   modifyRequestedAtoms().add(aid);
00754   update_atom_properties(index);
00755   return index;
00756 }

int colvarproxy_namd::init_atom ( int  atom_number  ) 

Definition at line 671 of file colvarproxy_namd.C.

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

00672 {
00673   // save time by checking first whether this atom has been requested before
00674   // (this is more common than a non-valid atom number)
00675   int aid = (atom_number-1);
00676 
00677   for (size_t i = 0; i < atoms_ids.size(); i++) {
00678     if (atoms_ids[i] == aid) {
00679       // this atom id was already recorded
00680       atoms_ncopies[i] += 1;
00681       return i;
00682     }
00683   }
00684 
00685   aid = check_atom_id(atom_number);
00686 
00687   if (aid < 0) {
00688     return INPUT_ERROR;
00689   }
00690 
00691   int const index = add_atom_slot(aid);
00692   modifyRequestedAtoms().add(aid);
00693   update_atom_properties(index);
00694   return index;
00695 }

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

Definition at line 1124 of file colvarproxy_namd.C.

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

01125 {
01126   if (cvm::debug())
01127     cvm::log("Reguesting from NAMD a group of size "+cvm::to_str(atoms_ids.size())+
01128         " for collective variables calculation.\n");
01129 
01130   // Note: modifyRequestedGroups is supposed to be in sync with the colvarproxy arrays,
01131   // and to stay that way during a simulation
01132 
01133   // compare this new group to those already allocated inside GlobalMaster
01134   int ig;
01135   for (ig = 0; ig < modifyRequestedGroups().size(); ig++) {
01136     AtomIDList const &namd_group = modifyRequestedGroups()[ig];
01137     bool b_match = true;
01138 
01139     if (namd_group.size() != ((int) atoms_ids.size())) {
01140       b_match = false;
01141     } else {
01142       int ia;
01143       for (ia = 0; ia < namd_group.size(); ia++) {
01144         int const aid = atoms_ids[ia];
01145         if (namd_group[ia] != aid) {
01146           b_match = false;
01147           break;
01148         }
01149       }
01150     }
01151 
01152     if (b_match) {
01153       if (cvm::debug())
01154         cvm::log("Group was already added.\n");
01155       // this group already exists
01156       atom_groups_ncopies[ig] += 1;
01157       return ig;
01158     }
01159   }
01160 
01161   // add this group (note: the argument of add_atom_group_slot() is redundant for NAMD, and provided only for consistency)
01162   size_t const index = add_atom_group_slot(atom_groups_ids.size());
01163   modifyRequestedGroups().resize(atom_groups_ids.size());
01164   // the following is done in calculate()
01165   // modifyGroupForces().resize(atom_groups_ids.size());
01166   AtomIDList &namd_group = modifyRequestedGroups()[index];
01167   namd_group.resize(atoms_ids.size());
01168   int const n_all_atoms = Node::Object()->molecule->numAtoms;
01169   for (size_t ia = 0; ia < atoms_ids.size(); ia++) {
01170     int const aid = atoms_ids[ia];
01171     if (cvm::debug())
01172       cvm::log("Adding atom "+cvm::to_str(aid+1)+
01173           " for collective variables calculation.\n");
01174     if ( (aid < 0) || (aid >= n_all_atoms) ) {
01175       cvm::error("Error: invalid atom number specified, "+
01176                  cvm::to_str(aid+1)+"\n", INPUT_ERROR);
01177       return -1;
01178     }
01179     namd_group[ia] = aid;
01180   }
01181 
01182   update_group_properties(index);
01183 
01184   if (cvm::debug()) {
01185     cvm::log("Group has index "+cvm::to_str(index)+"\n");
01186     cvm::log("modifyRequestedGroups length = "+cvm::to_str(modifyRequestedGroups().size())+
01187         ", modifyGroupForces length = "+cvm::to_str(modifyGroupForces().size())+"\n");
01188   }
01189 
01190   return index;
01191 }

void colvarproxy_namd::init_tcl_pointers (  )  [protected]

Definition at line 565 of file colvarproxy_namd.C.

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

Referenced by colvarproxy_namd().

00566 {
00567 #ifdef NAMD_TCL
00568   // Store pointer to NAMD's Tcl interpreter
00569   tcl_interp_ = reinterpret_cast<void *>(Node::Object()->getScript()->interp);
00570 #endif
00571 }

int colvarproxy_namd::init_volmap ( const char *  volmap_name  ) 
int colvarproxy_namd::init_volmap ( int  volmap_id  ) 
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 961 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().

00965 {
00966   if (pdb_field_str.size() == 0)
00967     cvm::error("Error: must define which PDB field to use "
00968                "in order to define atoms from a PDB file.\n", INPUT_ERROR);
00969 
00970   PDB *pdb = new PDB(pdb_filename);
00971   size_t const pdb_natoms = pdb->num_atoms();
00972 
00973   e_pdb_field pdb_field_index = pdb_field_str2enum(pdb_field_str);
00974 
00975   for (size_t ipdb = 0; ipdb < pdb_natoms; ipdb++) {
00976 
00977     double atom_pdb_field_value = 0.0;
00978 
00979     switch (pdb_field_index) {
00980     case e_pdb_occ:
00981       atom_pdb_field_value = (pdb->atom(ipdb))->occupancy();
00982       break;
00983     case e_pdb_beta:
00984       atom_pdb_field_value = (pdb->atom(ipdb))->temperaturefactor();
00985       break;
00986     case e_pdb_x:
00987       atom_pdb_field_value = (pdb->atom(ipdb))->xcoor();
00988       break;
00989     case e_pdb_y:
00990       atom_pdb_field_value = (pdb->atom(ipdb))->ycoor();
00991       break;
00992     case e_pdb_z:
00993       atom_pdb_field_value = (pdb->atom(ipdb))->zcoor();
00994       break;
00995     default:
00996       break;
00997     }
00998 
00999     if ( (pdb_field_value) &&
01000          (atom_pdb_field_value != pdb_field_value) ) {
01001       continue;
01002     } else if (atom_pdb_field_value == 0.0) {
01003       continue;
01004     }
01005 
01006     if (atoms.is_enabled(colvardeps::f_ag_scalable)) {
01007       atoms.add_atom_id(ipdb);
01008     } else {
01009       atoms.add_atom(cvm::atom(ipdb+1));
01010     }
01011   }
01012 
01013   delete pdb;
01014   return (cvm::get_error() ? COLVARS_ERROR : COLVARS_OK);
01015 }

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

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

00854 {
00855   if (pdb_field_str.size() == 0 && indices.size() == 0) {
00856     cvm::error("Bug alert: either PDB field should be defined or list of "
00857                "atom IDs should be available when loading atom coordinates!\n", BUG_ERROR);
00858   }
00859 
00860   e_pdb_field pdb_field_index;
00861   bool const use_pdb_field = (pdb_field_str.size() > 0);
00862   if (use_pdb_field) {
00863     pdb_field_index = pdb_field_str2enum(pdb_field_str);
00864   }
00865 
00866   // next index to be looked up in PDB file (if list is supplied)
00867   std::vector<int>::const_iterator current_index = indices.begin();
00868 
00869   PDB *pdb = new PDB(pdb_filename);
00870   size_t const pdb_natoms = pdb->num_atoms();
00871 
00872   if (pos.size() != pdb_natoms) {
00873 
00874     bool const pos_allocated = (pos.size() > 0);
00875 
00876     size_t ipos = 0, ipdb = 0;
00877     for ( ; ipdb < pdb_natoms; ipdb++) {
00878 
00879       if (use_pdb_field) {
00880         // PDB field mode: skip atoms with wrong value in PDB field
00881         double atom_pdb_field_value = 0.0;
00882 
00883         switch (pdb_field_index) {
00884         case e_pdb_occ:
00885           atom_pdb_field_value = (pdb->atom(ipdb))->occupancy();
00886           break;
00887         case e_pdb_beta:
00888           atom_pdb_field_value = (pdb->atom(ipdb))->temperaturefactor();
00889           break;
00890         case e_pdb_x:
00891           atom_pdb_field_value = (pdb->atom(ipdb))->xcoor();
00892           break;
00893         case e_pdb_y:
00894           atom_pdb_field_value = (pdb->atom(ipdb))->ycoor();
00895           break;
00896         case e_pdb_z:
00897           atom_pdb_field_value = (pdb->atom(ipdb))->zcoor();
00898           break;
00899         default:
00900           break;
00901         }
00902 
00903         if ( (pdb_field_value) &&
00904              (atom_pdb_field_value != pdb_field_value) ) {
00905           continue;
00906         } else if (atom_pdb_field_value == 0.0) {
00907           continue;
00908         }
00909 
00910       } else {
00911         // Atom ID mode: use predefined atom IDs from the atom group
00912         if (((int) ipdb) != *current_index) {
00913           // Skip atoms not in the list
00914           continue;
00915         } else {
00916           current_index++;
00917         }
00918       }
00919 
00920       if (!pos_allocated) {
00921         pos.push_back(cvm::atom_pos(0.0, 0.0, 0.0));
00922       } else if (ipos >= pos.size()) {
00923         cvm::error("Error: the PDB file \""+
00924                    std::string(pdb_filename)+
00925                    "\" contains coordinates for "
00926                    "more atoms than needed.\n", BUG_ERROR);
00927       }
00928 
00929       pos[ipos] = cvm::atom_pos((pdb->atom(ipdb))->xcoor(),
00930                                 (pdb->atom(ipdb))->ycoor(),
00931                                 (pdb->atom(ipdb))->zcoor());
00932       ipos++;
00933       if (!use_pdb_field && current_index == indices.end())
00934         break;
00935     }
00936 
00937     if (ipos < pos.size() || (!use_pdb_field && current_index != indices.end())) {
00938       size_t n_requested = use_pdb_field ? pos.size() : indices.size();
00939       cvm::error("Error: number of matching records in the PDB file \""+
00940                  std::string(pdb_filename)+"\" ("+cvm::to_str(ipos)+
00941                  ") does not match the number of requested coordinates ("+
00942                  cvm::to_str(n_requested)+").\n", INPUT_ERROR);
00943       return COLVARS_ERROR;
00944     }
00945   } else {
00946 
00947     // when the PDB contains exactly the number of atoms of the array,
00948     // ignore the fields and just read coordinates
00949     for (size_t ia = 0; ia < pos.size(); ia++) {
00950       pos[ia] = cvm::atom_pos((pdb->atom(ia))->xcoor(),
00951                               (pdb->atom(ia))->ycoor(),
00952                               (pdb->atom(ia))->zcoor());
00953     }
00954   }
00955 
00956   delete pdb;
00957   return COLVARS_OK;
00958 }

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

Definition at line 614 of file colvarproxy_namd.C.

References endi(), and iout.

Referenced by calculate(), colvarproxy_namd(), error(), exit(), init_atom_group(), output_stream(), request_total_force(), script_obj_to_str_vector(), setup(), update_atom_properties(), update_atoms_map(), and update_group_properties().

00615 {
00616   std::istringstream is(message);
00617   std::string line;
00618   while (std::getline(is, line))
00619     iout << "colvars: " << line << "\n";
00620   iout << endi;
00621 }

int colvarproxy_namd::num_replicas (  )  [virtual]

Definition at line 1399 of file colvarproxy_namd.C.

01399                                    {
01400   return CmiNumPartitions();
01401 }

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

Definition at line 1018 of file colvarproxy_namd.C.

References backup_file(), debug, error(), ofstream_namd::is_open(), and log().

01020 {
01021   if (cvm::debug()) {
01022     cvm::log("Using colvarproxy_namd::output_stream()\n");
01023   }
01024 
01025   std::ostream *os = get_output_stream(output_name);
01026   if (os != NULL) return os;
01027 
01028   if (!(mode & (std::ios_base::app | std::ios_base::ate))) {
01029     colvarproxy::backup_file(output_name);
01030   }
01031   ofstream_namd *osf = new ofstream_namd(output_name.c_str(), mode);
01032   if (!osf->is_open()) {
01033     cvm::error("Error: cannot write to file \""+output_name+"\".\n",
01034                FILE_ERROR);
01035     return NULL;
01036   }
01037   output_stream_names.push_back(output_name);
01038   output_files.push_back(osf);
01039   return osf;
01040 }

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

Definition at line 782 of file colvarproxy_namd.C.

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

00785 {
00786   Position const p1(pos1.x, pos1.y, pos1.z);
00787   Position const p2(pos2.x, pos2.y, pos2.z);
00788   // return p2 - p1
00789   if (this->lattice != NULL) {
00790     Vector const d = this->lattice->delta(p2, p1);
00791     return cvm::rvector(d.x, d.y, d.z);
00792   }
00793   else {
00794     return colvarproxy_system::position_distance(pos1, pos2);
00795   }
00796 }

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

Definition at line 110 of file colvarproxy_namd.h.

References Random::gaussian(), and random.

00111   {
00112     return random.gaussian();
00113   }

void colvarproxy_namd::replica_comm_barrier (  )  [virtual]

Definition at line 1404 of file colvarproxy_namd.C.

References replica_barrier().

01404                                             {
01405   replica_barrier();
01406 }

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

Definition at line 1409 of file colvarproxy_namd.C.

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

01410                                                      {
01411   DataMessage *recvMsg = NULL;
01412   replica_recv(&recvMsg, src_rep, CkMyPe());
01413   CmiAssert(recvMsg != NULL);
01414   int retval = recvMsg->size;
01415   if (buf_len >= retval) {
01416     memcpy(msg_data,recvMsg->data,retval);
01417   } else {
01418     retval = 0;
01419   }
01420   CmiFree(recvMsg);
01421   return retval;
01422 }

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

Definition at line 1425 of file colvarproxy_namd.C.

References replica_send().

01426                                                       {
01427   replica_send(msg_data, msg_len, dest_rep, CkMyPe());
01428   return msg_len;
01429 }

int colvarproxy_namd::replica_enabled (  )  [virtual]

Definition at line 1385 of file colvarproxy_namd.C.

01385                                       {
01386 #if CMK_HAS_PARTITION
01387   return COLVARS_OK;
01388 #else
01389   return COLVARS_NOT_IMPLEMENTED;
01390 #endif
01391 }

int colvarproxy_namd::replica_index (  )  [virtual]

Definition at line 1394 of file colvarproxy_namd.C.

01394                                     {
01395   return CmiMyPartition();
01396 }

void colvarproxy_namd::request_total_force ( bool  yesno  ) 

Definition at line 601 of file colvarproxy_namd.C.

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

00602 {
00603   if (cvm::debug()) {
00604     cvm::log("colvarproxy_namd::request_total_force()\n");
00605   }
00606   total_force_requested = yesno;
00607   requestTotalForce(total_force_requested);
00608   if (cvm::debug()) {
00609     cvm::log("colvarproxy_namd::request_total_force() end\n");
00610   }
00611 }

int colvarproxy_namd::reset (  ) 

Definition at line 258 of file colvarproxy_namd.C.

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

00259 {
00260   int error_code = COLVARS_OK;
00261 
00262   // Unrequest all atoms and group from NAMD
00263   modifyRequestedAtoms().clear();
00264   modifyRequestedGroups().clear();
00265 #if NAMD_VERSION_NUMBER >= 34471681
00266   modifyRequestedGridObjects().clear();
00267 #endif
00268 
00269   atoms_map.clear();
00270 
00271   // Clear internal Proxy records
00272   error_code |= colvarproxy::reset();
00273 
00274   return error_code;
00275 }

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

Definition at line 578 of file colvarproxy_namd.C.

00582 {
00583   return colvarproxy::tcl_run_colvar_callback(name, cvc_values, value);
00584 }

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

00590 {
00591   return colvarproxy::tcl_run_colvar_gradient_callback(name, cvc_values,
00592                                                        gradient);
00593 }

int colvarproxy_namd::run_force_callback (  ) 

Definition at line 573 of file colvarproxy_namd.C.

00574 {
00575   return colvarproxy::tcl_run_force_callback();
00576 }

int colvarproxy_namd::scalable_group_coms (  )  [inline]

Definition at line 208 of file colvarproxy_namd.h.

00209   {
00210     return COLVARS_OK;
00211   }

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

Definition at line 1087 of file colvarproxy_namd.C.

01088 {
01089 #ifdef NAMD_TCL
01090   return colvarproxy_tcl::tcl_get_str(obj);
01091 #else
01092   // This is most likely not going to be executed
01093   return colvarproxy::script_obj_to_str(obj);
01094 #endif
01095 }

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

Definition at line 1098 of file colvarproxy_namd.C.

References debug, and log().

01099 {
01100   if (cvm::debug()) {
01101     cvm::log("Called colvarproxy_namd::script_obj_to_str_vector().\n");
01102   }
01103   std::vector<std::string> result;
01104 #ifdef NAMD_TCL
01105   Tcl_Interp *interp = reinterpret_cast<Tcl_Interp *>(tcl_interp_);
01106   Tcl_Obj *tcl_obj = reinterpret_cast<Tcl_Obj *>(obj);
01107   Tcl_Obj **tcl_list_elems = NULL;
01108   int count = 0;
01109   if (Tcl_ListObjGetElements(interp, tcl_obj, &count, &tcl_list_elems) ==
01110       TCL_OK) {
01111     result.reserve(count);
01112     for (int i = 0; i < count; i++) {
01113       result.push_back(Tcl_GetString(tcl_list_elems[i]));
01114     }
01115   } else {
01116     Tcl_SetResult(interp,
01117                   const_cast<char *>("Cannot parse Tcl list."), TCL_STATIC);
01118   }
01119 #endif
01120   return result;
01121 }

int colvarproxy_namd::set_unit_system ( std::string const &  units_in,
bool  check_only 
)

Definition at line 1228 of file colvarproxy_namd.C.

References error().

01229 {
01230   if (units_in != "real") {
01231     cvm::error("Error: Specified unit system \"" + units_in + "\" is unsupported in NAMD. Supported units are \"real\" (A, kcal/mol).\n");
01232     return COLVARS_ERROR;
01233   }
01234   return COLVARS_OK;
01235 }

int colvarproxy_namd::setup (  ) 

Definition at line 200 of file colvarproxy_namd.C.

References log(), GlobalMaster::modifyGridObjForces(), GlobalMaster::modifyRequestedGroups(), simparams, ResizeArray< Elem >::size(), update_atom_properties(), update_group_properties(), and SimParameters::wrapAll.

Referenced by calculate().

00201 {
00202   if (colvars->size() == 0) return COLVARS_OK;
00203 
00204   cvm::log("Updating NAMD interface:\n");
00205 
00206   errno = 0;
00207 
00208   if (simparams->wrapAll) {
00209     cvm::log("Warning: enabling wrapAll can lead to inconsistent results "
00210              "for Colvars calculations: please disable wrapAll, "
00211              "as is the default option in NAMD.\n");
00212   }
00213 
00214   cvm::log("updating atomic data ("+cvm::to_str(atoms_ids.size())+" atoms).\n");
00215 
00216   size_t i;
00217   for (i = 0; i < atoms_ids.size(); i++) {
00218     update_atom_properties(i);
00219 
00220     // zero out mutable arrays
00221     atoms_positions[i] = cvm::rvector(0.0, 0.0, 0.0);
00222     atoms_total_forces[i] = cvm::rvector(0.0, 0.0, 0.0);
00223     atoms_new_colvar_forces[i] = cvm::rvector(0.0, 0.0, 0.0);
00224   }
00225 
00226   size_t n_group_atoms = 0;
00227   for (int ig = 0; ig < modifyRequestedGroups().size(); ig++) {
00228     n_group_atoms += modifyRequestedGroups()[ig].size();
00229   }
00230 
00231   cvm::log("updating group data ("+cvm::to_str(atom_groups_ids.size())+
00232            " scalable groups, "+
00233            cvm::to_str(n_group_atoms)+" atoms in total).\n");
00234 
00235   // Note: groupMassBegin, groupMassEnd may be used here, but they won't work for charges
00236   for (int ig = 0; ig < modifyRequestedGroups().size(); ig++) {
00237 
00238     // update mass and charge
00239     update_group_properties(ig);
00240 
00241     atom_groups_coms[ig] = cvm::rvector(0.0, 0.0, 0.0);
00242     atom_groups_total_forces[ig] = cvm::rvector(0.0, 0.0, 0.0);
00243     atom_groups_new_colvar_forces[ig] = cvm::rvector(0.0, 0.0, 0.0);
00244   }
00245 
00246 #if NAMD_VERSION_NUMBER >= 34471681
00247   log("updating grid object data ("+cvm::to_str(volmaps_ids.size())+
00248       " grid objects in total).\n");
00249   for (int imap = 0; imap < modifyGridObjForces().size(); imap++) {
00250     volmaps_new_colvar_forces[imap] = 0.0;
00251   }
00252 #endif
00253 
00254   return COLVARS_OK;
00255 }

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

Definition at line 105 of file colvarproxy_namd.h.

References thermostat_temperature.

00106   {
00107     return thermostat_temperature;
00108   }

bool colvarproxy_namd::total_forces_enabled (  )  const [inline]

Definition at line 82 of file colvarproxy_namd.h.

00083   {
00084     return total_force_requested;
00085   }

void colvarproxy_namd::update_atom_properties ( int  index  ) 

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

00767 {
00768   Molecule *mol = Node::Object()->molecule;
00769   // update mass
00770   double const mass = mol->atommass(atoms_ids[index]);
00771   if (mass <= 0.001) {
00772     this->log("Warning: near-zero mass for atom "+
00773               cvm::to_str(atoms_ids[index]+1)+
00774               "; expect unstable dynamics if you apply forces to it.\n");
00775   }
00776   atoms_masses[index] = mass;
00777   // update charge
00778   atoms_charges[index] = mol->atomcharge(atoms_ids[index]);
00779 }

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

Definition at line 165 of file colvarproxy_namd.C.

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

Referenced by calculate().

00167 {
00168   for (AtomIDList::const_iterator a_i = begin; a_i != end; a_i++) {
00169 
00170     if (cvm::debug()) {
00171       cvm::log("Updating atoms_map for atom ID "+cvm::to_str(*a_i)+"\n");
00172     }
00173 
00174     if (atoms_map[*a_i] >= 0) continue;
00175 
00176     for (size_t i = 0; i < atoms_ids.size(); i++) {
00177       if (atoms_ids[i] == *a_i) {
00178         atoms_map[*a_i] = i;
00179         break;
00180       }
00181     }
00182 
00183     if (atoms_map[*a_i] < 0) {
00184       // this atom is probably managed by another GlobalMaster:
00185       // add it here anyway to avoid having to test for array boundaries at each step
00186       int const index = add_atom_slot(*a_i);
00187       atoms_map[*a_i] = index;
00188       update_atom_properties(index);
00189     }
00190   }
00191 
00192   if (cvm::debug()) {
00193     cvm::log("atoms_map = "+cvm::to_str(atoms_map)+".\n");
00194   }
00195 
00196   return COLVARS_OK;
00197 }

int colvarproxy_namd::update_group_properties ( int  index  ) 

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

01202 {
01203   AtomIDList const &namd_group = modifyRequestedGroups()[index];
01204   if (cvm::debug()) {
01205     cvm::log("Re-calculating total mass and charge for scalable group no. "+cvm::to_str(index+1)+" ("+
01206              cvm::to_str(namd_group.size())+" atoms).\n");
01207   }
01208 
01209   cvm::real total_mass = 0.0;
01210   cvm::real total_charge = 0.0;
01211   for (int i = 0; i < namd_group.size(); i++) {
01212     total_mass += Node::Object()->molecule->atommass(namd_group[i]);
01213     total_charge += Node::Object()->molecule->atomcharge(namd_group[i]);
01214   }
01215   atom_groups_masses[index] = total_mass;
01216   atom_groups_charges[index] = total_charge;
01217 
01218   if (cvm::debug()) {
01219     cvm::log("total mass = "+cvm::to_str(total_mass)+
01220              ", total charge = "+cvm::to_str(total_charge)+"\n");
01221   }
01222 
01223   return COLVARS_OK;
01224 }


Friends And Related Function Documentation

friend class cvm::atom [friend]

Definition at line 61 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 40 of file colvarproxy_namd.h.

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

Definition at line 51 of file colvarproxy_namd.h.

Referenced by calculate(), and colvarproxy_namd().

Definition at line 52 of file colvarproxy_namd.h.

Referenced by calculate().

NAMD-style PRNG object.

Definition at line 49 of file colvarproxy_namd.h.

Referenced by colvarproxy_namd(), and rand_gaussian().

Used to submit restraint energy as MISC.

Definition at line 55 of file colvarproxy_namd.h.

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

Pointer to the NAMD simulation input object.

Definition at line 43 of file colvarproxy_namd.h.

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

Self-explained.

Definition at line 46 of file colvarproxy_namd.h.

Referenced by colvarproxy_namd(), and temperature().


The documentation for this class was generated from the following files:

Generated on 3 Aug 2020 for NAMD by  doxygen 1.6.1