31 #include "colvarmodule.h"
32 #include "colvaratoms.h"
33 #include "colvarproxy.h"
35 #include "colvarscript.h"
51 iout <<
"Info: initializing the colvars proxy object.\n" <<
endi;
58 input_prefix_str = std::string(input_restart ? input_restart->
data :
"");
59 if (input_prefix_str.rfind(
".colvars.state") != std::string::npos) {
61 input_prefix_str.erase(input_prefix_str.rfind(
".colvars.state"),
62 std::string(
".colvars.state").size());
84 updated_masses_ = updated_charges_ =
true;
92 if ((!output_prefix_str.size()) && (!restart_output_prefix_str.size())) {
93 error(
"Error: neither the final output state file or "
94 "the output restart file could be defined, exiting.\n");
104 if (Tcl_FindCommand(reinterpret_cast<Tcl_Interp *>(tcl_interp_),
105 "calc_colvar_forces", NULL, 0) == NULL) {
106 force_script_defined =
false;
108 force_script_defined =
true;
111 force_script_defined =
false;
112 have_scripts =
false;
117 colvars =
new colvarmodule(
this);
118 cvm::log(
"Using NAMD interface, version "+
123 colvars->read_config_file(config->
data);
127 colvars->setup_input();
128 colvars->setup_output();
135 script =
new colvarscript(
this);
139 cvm::log(
"Initializing step number as firstTimestep.\n");
140 colvars->it = colvars->it_restart =
147 iout <<
"Info: done initializing the colvars proxy object.\n" <<
endi;
154 if (script != NULL) {
158 if (colvars != NULL) {
171 cvm::log(
"Updating atoms_map for atom ID "+cvm::to_str(*a_i)+
"\n");
176 for (
size_t i = 0; i < atoms_ids.size(); i++) {
177 if (atoms_ids[i] == *a_i) {
186 int const index = add_atom_slot(*a_i);
193 cvm::log(
"atoms_map = "+cvm::to_str(
atoms_map)+
".\n");
202 if (colvars->size() == 0)
return COLVARS_OK;
204 cvm::log(
"Updating NAMD interface:\n");
209 cvm::log(
"Warning: enabling wrapAll can lead to inconsistent results "
210 "for Colvars calculations: please disable wrapAll, "
211 "as is the default option in NAMD.\n");
214 cvm::log(
"updating atomic data ("+cvm::to_str(atoms_ids.size())+
" atoms).\n");
217 for (i = 0; i < atoms_ids.size(); i++) {
221 atoms_positions[i] = cvm::rvector(0.0, 0.0, 0.0);
222 atoms_total_forces[i] = cvm::rvector(0.0, 0.0, 0.0);
223 atoms_new_colvar_forces[i] = cvm::rvector(0.0, 0.0, 0.0);
226 size_t n_group_atoms = 0;
231 cvm::log(
"updating group data ("+cvm::to_str(atom_groups_ids.size())+
232 " scalable groups, "+
233 cvm::to_str(n_group_atoms)+
" atoms in total).\n");
241 atom_groups_coms[ig] = cvm::rvector(0.0, 0.0, 0.0);
242 atom_groups_total_forces[ig] = cvm::rvector(0.0, 0.0, 0.0);
243 atom_groups_new_colvar_forces[ig] = cvm::rvector(0.0, 0.0, 0.0);
246 #if NAMD_VERSION_NUMBER >= 34471681
247 log(
"updating grid object data ("+cvm::to_str(volmaps_ids.size())+
248 " grid objects in total).\n");
250 volmaps_new_colvar_forces[imap] = 0.0;
260 int error_code = COLVARS_OK;
265 #if NAMD_VERSION_NUMBER >= 34471681
272 error_code |= colvarproxy::reset();
286 colvars->setup_input();
287 colvars->setup_output();
295 b_simulation_continuing =
false;
302 b_simulation_continuing =
true;
312 unit_cell_x.
set(a.
x, a.
y, a.
z);
313 unit_cell_y.set(b.
x, b.
y, c.
z);
314 unit_cell_z.set(c.
x, c.
y, c.
z);
318 boundaries_type = boundaries_non_periodic;
322 boundaries_type = boundaries_pbc_ortho;
324 boundaries_type = boundaries_pbc_triclinic;
326 colvarproxy_system::update_pbc_lattice();
328 boundaries_type = boundaries_unsupported;
332 cvm::log(std::string(cvm::line_marker)+
333 "colvarproxy_namd, step no. "+cvm::to_str(colvars->it)+
"\n"+
334 "Updating atomic data arrays.\n");
344 for (
size_t i = 0; i < atoms_ids.size(); i++) {
345 atoms_positions[i] = cvm::rvector(0.0, 0.0, 0.0);
346 atoms_total_forces[i] = cvm::rvector(0.0, 0.0, 0.0);
347 atoms_new_colvar_forces[i] = cvm::rvector(0.0, 0.0, 0.0);
350 for (
size_t i = 0; i < atom_groups_ids.size(); i++) {
351 atom_groups_total_forces[i] = cvm::rvector(0.0, 0.0, 0.0);
352 atom_groups_new_colvar_forces[i] = cvm::rvector(0.0, 0.0, 0.0);
355 #if NAMD_VERSION_NUMBER >= 34471681
356 for (
int imap = 0; imap < volmaps_ids.size(); imap++) {
357 volmaps_new_colvar_forces[imap] = 0.0;
378 cvm::log(
"Updating positions arrays.\n");
380 size_t n_positions = 0;
385 for ( ; a_i != a_e; ++a_i, ++p_i ) {
386 atoms_positions[
atoms_map[*a_i]] = cvm::rvector((*p_i).x, (*p_i).y, (*p_i).z);
396 if (total_force_requested && cvm::step_relative() > 0) {
403 cvm::log(
"Updating total forces arrays.\n");
405 size_t n_total_forces = 0;
410 for ( ; a_i != a_e; ++a_i, ++f_i ) {
411 atoms_total_forces[
atoms_map[*a_i]] = cvm::rvector((*f_i).x, (*f_i).y, (*f_i).z);
415 if (n_total_forces < atoms_ids.size()) {
416 cvm::error(
"Error: total forces were requested, but total forces "
417 "were not received for all atoms.\n"
418 "The most probable cause is combination of energy "
419 "minimization with a biasing method that requires MD (e.g. ABF).\n"
420 "Always run minimization and ABF separately.", INPUT_ERROR);
426 cvm::log(
"Updating group total forces arrays.\n");
431 if ((f_e - f_i) != ((
int) atom_groups_ids.size())) {
432 cvm::error(
"Error: total forces were requested for scalable groups, "
433 "but they are not in the same number from the number of groups.\n"
434 "The most probable cause is combination of energy "
435 "minimization with a biasing method that requires MD (e.g. ABF).\n"
436 "Always run minimization and ABF separately.", INPUT_ERROR);
438 for ( ; f_i != f_e; f_i++, i++) {
439 atom_groups_total_forces[i] = cvm::rvector((*f_i).x, (*f_i).y, (*f_i).z);
446 cvm::log(
"Updating group positions arrays.\n");
454 atom_groups_coms[ig] = cvm::rvector(gp_i->x, gp_i->y, gp_i->z);
458 #if NAMD_VERSION_NUMBER >= 34471681
461 log(
"Updating grid objects.\n");
468 for (
size_t imap = 0; imap < volmaps_ids.size(); imap++) {
469 if (volmaps_ids[imap] == *goi_i) {
470 volmaps_values[imap] = *gov_i;
479 cvm::log(
"atoms_ids = "+cvm::to_str(atoms_ids)+
"\n");
480 cvm::log(
"atoms_ncopies = "+cvm::to_str(atoms_ncopies)+
"\n");
481 cvm::log(
"atoms_masses = "+cvm::to_str(atoms_masses)+
"\n");
482 cvm::log(
"atoms_charges = "+cvm::to_str(atoms_charges)+
"\n");
483 cvm::log(
"atoms_positions = "+cvm::to_str(atoms_positions)+
"\n");
484 cvm::log(
"atoms_total_forces = "+cvm::to_str(atoms_total_forces)+
"\n");
485 cvm::log(cvm::line_marker);
487 cvm::log(
"atom_groups_ids = "+cvm::to_str(atom_groups_ids)+
"\n");
488 cvm::log(
"atom_groups_ncopies = "+cvm::to_str(atom_groups_ncopies)+
"\n");
489 cvm::log(
"atom_groups_masses = "+cvm::to_str(atom_groups_masses)+
"\n");
490 cvm::log(
"atom_groups_charges = "+cvm::to_str(atom_groups_charges)+
"\n");
491 cvm::log(
"atom_groups_coms = "+cvm::to_str(atom_groups_coms)+
"\n");
492 cvm::log(
"atom_groups_total_forces = "+cvm::to_str(atom_groups_total_forces)+
"\n");
493 cvm::log(cvm::line_marker);
495 #if NAMD_VERSION_NUMBER >= 34471681
496 cvm::log(
"volmaps_ids = "+cvm::to_str(volmaps_ids)+
"\n");
497 cvm::log(
"volmaps_values = "+cvm::to_str(volmaps_values)+
"\n");
498 cvm::log(cvm::line_marker);
503 if (colvars->calc() != COLVARS_OK) {
504 cvm::error(
"Error in the collective variables module.\n", COLVARS_ERROR);
508 cvm::log(cvm::line_marker);
509 cvm::log(
"atoms_new_colvar_forces = "+cvm::to_str(atoms_new_colvar_forces)+
"\n");
510 cvm::log(cvm::line_marker);
511 cvm::log(
"atom_groups_new_colvar_forces = "+cvm::to_str(atom_groups_new_colvar_forces)+
"\n");
512 cvm::log(cvm::line_marker);
513 #if NAMD_VERSION_NUMBER >= 34471681
514 cvm::log(
"volmaps_new_colvar_forces = "+cvm::to_str(volmaps_new_colvar_forces)+
"\n");
515 cvm::log(cvm::line_marker);
520 for (
size_t i = 0; i < atoms_ids.size(); i++) {
521 cvm::rvector
const &f = atoms_new_colvar_forces[i];
526 if (atom_groups_new_colvar_forces.size() > 0) {
530 cvm::rvector
const &f = atom_groups_new_colvar_forces[ig];
531 *gf_i =
Vector(f.x, f.y, f.z);
535 #if NAMD_VERSION_NUMBER >= 34471681
536 if (volmaps_new_colvar_forces.size() > 0) {
542 for (
size_t imap = 0; imap < volmaps_ids.size(); imap++) {
543 if (volmaps_ids[imap] == *goi_i) {
544 *gof_i = volmaps_new_colvar_forces[imap];
575 return colvarproxy::tcl_run_force_callback();
579 std::string
const &name,
580 std::vector<const colvarvalue *>
const &cvc_values,
583 return colvarproxy::tcl_run_colvar_callback(name, cvc_values, value);
587 std::string
const &name,
588 std::vector<const colvarvalue *>
const &cvc_values,
589 std::vector<cvm::matrix2d<cvm::real> > &gradient)
591 return colvarproxy::tcl_run_colvar_gradient_callback(name, cvc_values,
604 cvm::log(
"colvarproxy_namd::request_total_force()\n");
606 total_force_requested = yesno;
609 cvm::log(
"colvarproxy_namd::request_total_force() end\n");
616 std::istringstream is(message);
618 while (std::getline(is, line))
619 iout <<
"colvars: " << line <<
"\n";
627 switch (cvm::get_error()) {
630 case COLVARS_NOT_IMPLEMENTED:
631 errno = ENOSYS;
break;
633 errno = ENOMEM;
break;
635 char const *msg =
"Error in the collective variables module "
636 "(see above for details)";
655 int const aid = (atom_number-1);
658 cvm::log(
"Adding atom "+cvm::to_str(atom_number)+
659 " for collective variables calculation.\n");
662 cvm::error(
"Error: invalid atom number specified, "+
663 cvm::to_str(atom_number)+
"\n", INPUT_ERROR);
675 int aid = (atom_number-1);
677 for (
size_t i = 0; i < atoms_ids.size(); i++) {
678 if (atoms_ids[i] == aid) {
680 atoms_ncopies[i] += 1;
691 int const index = add_atom_slot(aid);
699 std::string
const &atom_name,
700 std::string
const &segment_id)
713 cvm::error(
"Error: could not find atom \""+
714 atom_name+
"\" in residue "+
715 cvm::to_str(residue)+
716 ( (segment_id !=
"MAIN") ?
717 (
", segment \""+segment_id+
"\"") :
732 std::string
const &atom_name,
733 std::string
const &segment_id)
735 int const aid =
check_atom_id(residue, atom_name, segment_id);
737 for (
size_t i = 0; i < atoms_ids.size(); i++) {
738 if (atoms_ids[i] == aid) {
740 atoms_ncopies[i] += 1;
746 cvm::log(
"Adding atom \""+
747 atom_name+
"\" in residue "+
748 cvm::to_str(residue)+
749 " (index "+cvm::to_str(aid)+
750 ") for collective variables calculation.\n");
752 int const index = add_atom_slot(aid);
761 colvarproxy::clear_atom(index);
770 double const mass = mol->
atommass(atoms_ids[index]);
772 this->
log(
"Warning: near-zero mass for atom "+
773 cvm::to_str(atoms_ids[index]+1)+
774 "; expect unstable dynamics if you apply forces to it.\n");
776 atoms_masses[index] = mass;
778 atoms_charges[index] = mol->
atomcharge(atoms_ids[index]);
783 cvm::atom_pos
const &pos2)
786 Position const p1(pos1.x, pos1.y, pos1.z);
787 Position const p2(pos2.x, pos2.y, pos2.z);
791 return cvm::rvector(d.
x, d.
y, d.
z);
794 return colvarproxy_system::position_distance(pos1, pos2);
815 if (colvarparse::to_lower_cppstr(pdb_field_str) ==
816 colvarparse::to_lower_cppstr(
"O")) {
820 if (colvarparse::to_lower_cppstr(pdb_field_str) ==
821 colvarparse::to_lower_cppstr(
"B")) {
825 if (colvarparse::to_lower_cppstr(pdb_field_str) ==
826 colvarparse::to_lower_cppstr(
"X")) {
830 if (colvarparse::to_lower_cppstr(pdb_field_str) ==
831 colvarparse::to_lower_cppstr(
"Y")) {
835 if (colvarparse::to_lower_cppstr(pdb_field_str) ==
836 colvarparse::to_lower_cppstr(
"Z")) {
841 cvm::error(
"Error: unsupported PDB field, \""+
842 pdb_field_str+
"\".\n", INPUT_ERROR);
850 std::vector<cvm::atom_pos> &pos,
851 const std::vector<int> &indices,
852 std::string
const &pdb_field_str,
853 double const pdb_field_value)
855 if (pdb_field_str.size() == 0 && indices.size() == 0) {
856 cvm::error(
"Bug alert: either PDB field should be defined or list of "
857 "atom IDs should be available when loading atom coordinates!\n", BUG_ERROR);
861 bool const use_pdb_field = (pdb_field_str.size() > 0);
867 std::vector<int>::const_iterator current_index = indices.begin();
869 PDB *pdb =
new PDB(pdb_filename);
870 size_t const pdb_natoms = pdb->
num_atoms();
872 if (pos.size() != pdb_natoms) {
874 bool const pos_allocated = (pos.size() > 0);
876 size_t ipos = 0, ipdb = 0;
877 for ( ; ipdb < pdb_natoms; ipdb++) {
881 double atom_pdb_field_value = 0.0;
883 switch (pdb_field_index) {
885 atom_pdb_field_value = (pdb->
atom(ipdb))->occupancy();
888 atom_pdb_field_value = (pdb->
atom(ipdb))->temperaturefactor();
891 atom_pdb_field_value = (pdb->
atom(ipdb))->xcoor();
894 atom_pdb_field_value = (pdb->
atom(ipdb))->ycoor();
897 atom_pdb_field_value = (pdb->
atom(ipdb))->zcoor();
903 if ( (pdb_field_value) &&
904 (atom_pdb_field_value != pdb_field_value) ) {
906 }
else if (atom_pdb_field_value == 0.0) {
912 if (((
int) ipdb) != *current_index) {
920 if (!pos_allocated) {
921 pos.push_back(cvm::atom_pos(0.0, 0.0, 0.0));
922 }
else if (ipos >= pos.size()) {
923 cvm::error(
"Error: the PDB file \""+
924 std::string(pdb_filename)+
925 "\" contains coordinates for "
926 "more atoms than needed.\n", BUG_ERROR);
929 pos[ipos] = cvm::atom_pos((pdb->
atom(ipdb))->xcoor(),
930 (pdb->
atom(ipdb))->ycoor(),
931 (pdb->
atom(ipdb))->zcoor());
933 if (!use_pdb_field && current_index == indices.end())
937 if (ipos < pos.size() || (!use_pdb_field && current_index != indices.end())) {
938 size_t n_requested = use_pdb_field ? pos.size() : indices.size();
939 cvm::error(
"Error: number of matching records in the PDB file \""+
940 std::string(pdb_filename)+
"\" ("+cvm::to_str(ipos)+
941 ") does not match the number of requested coordinates ("+
942 cvm::to_str(n_requested)+
").\n", INPUT_ERROR);
943 return COLVARS_ERROR;
949 for (
size_t ia = 0; ia < pos.size(); ia++) {
950 pos[ia] = cvm::atom_pos((pdb->
atom(ia))->xcoor(),
951 (pdb->
atom(ia))->ycoor(),
952 (pdb->
atom(ia))->zcoor());
962 cvm::atom_group &
atoms,
963 std::string
const &pdb_field_str,
964 double const pdb_field_value)
966 if (pdb_field_str.size() == 0)
967 cvm::error(
"Error: must define which PDB field to use "
968 "in order to define atoms from a PDB file.\n", INPUT_ERROR);
970 PDB *pdb =
new PDB(pdb_filename);
971 size_t const pdb_natoms = pdb->
num_atoms();
975 for (
size_t ipdb = 0; ipdb < pdb_natoms; ipdb++) {
977 double atom_pdb_field_value = 0.0;
979 switch (pdb_field_index) {
981 atom_pdb_field_value = (pdb->
atom(ipdb))->occupancy();
984 atom_pdb_field_value = (pdb->
atom(ipdb))->temperaturefactor();
987 atom_pdb_field_value = (pdb->
atom(ipdb))->xcoor();
990 atom_pdb_field_value = (pdb->
atom(ipdb))->ycoor();
993 atom_pdb_field_value = (pdb->
atom(ipdb))->zcoor();
999 if ( (pdb_field_value) &&
1000 (atom_pdb_field_value != pdb_field_value) ) {
1002 }
else if (atom_pdb_field_value == 0.0) {
1006 if (atoms.is_enabled(colvardeps::f_ag_scalable)) {
1007 atoms.add_atom_id(ipdb);
1014 return (cvm::get_error() ? COLVARS_ERROR : COLVARS_OK);
1019 std::ios_base::openmode mode)
1022 cvm::log(
"Using colvarproxy_namd::output_stream()\n");
1025 std::ostream *os = get_output_stream(output_name);
1026 if (os != NULL)
return os;
1028 if (!(mode & (std::ios_base::app | std::ios_base::ate))) {
1029 colvarproxy::backup_file(output_name);
1033 cvm::error(
"Error: cannot write to file \""+output_name+
"\".\n",
1037 output_stream_names.push_back(output_name);
1038 output_files.push_back(osf);
1045 std::list<std::ostream *>::iterator osi = output_files.begin();
1046 std::list<std::string>::iterator osni = output_stream_names.begin();
1047 for ( ; osi != output_files.end(); osi++, osni++) {
1053 return COLVARS_ERROR;
1059 std::list<std::ostream *>::iterator osi = output_files.begin();
1060 std::list<std::string>::iterator osni = output_stream_names.begin();
1061 for ( ; osi != output_files.end(); osi++, osni++) {
1062 if (*osni == output_name) {
1067 output_files.erase(osi);
1068 output_stream_names.erase(osni);
1072 return COLVARS_ERROR;
1078 if (std::string(filename).rfind(std::string(
".colvars.state")) != std::string::npos) {
1090 return colvarproxy_tcl::tcl_get_str(obj);
1093 return colvarproxy::script_obj_to_str(obj);
1101 cvm::log(
"Called colvarproxy_namd::script_obj_to_str_vector().\n");
1103 std::vector<std::string> result;
1105 Tcl_Interp *interp =
reinterpret_cast<Tcl_Interp *
>(tcl_interp_);
1106 Tcl_Obj *tcl_obj =
reinterpret_cast<Tcl_Obj *
>(obj);
1107 Tcl_Obj **tcl_list_elems = NULL;
1109 if (Tcl_ListObjGetElements(interp, tcl_obj, &count, &tcl_list_elems) ==
1111 result.reserve(count);
1112 for (
int i = 0; i < count; i++) {
1113 result.push_back(Tcl_GetString(tcl_list_elems[i]));
1116 Tcl_SetResult(interp,
1117 const_cast<char *>(
"Cannot parse Tcl list."), TCL_STATIC);
1127 cvm::log(
"Reguesting from NAMD a group of size "+cvm::to_str(atoms_ids.size())+
1128 " for collective variables calculation.\n");
1137 bool b_match =
true;
1139 if (namd_group.
size() != ((int) atoms_ids.size())) {
1143 for (ia = 0; ia < namd_group.
size(); ia++) {
1144 int const aid = atoms_ids[ia];
1145 if (namd_group[ia] != aid) {
1154 cvm::log(
"Group was already added.\n");
1156 atom_groups_ncopies[ig] += 1;
1162 size_t const index = add_atom_group_slot(atom_groups_ids.size());
1167 namd_group.
resize(atoms_ids.size());
1169 for (
size_t ia = 0; ia < atoms_ids.size(); ia++) {
1170 int const aid = atoms_ids[ia];
1172 cvm::log(
"Adding atom "+cvm::to_str(aid+1)+
1173 " for collective variables calculation.\n");
1174 if ( (aid < 0) || (aid >= n_all_atoms) ) {
1175 cvm::error(
"Error: invalid atom number specified, "+
1176 cvm::to_str(aid+1)+
"\n", INPUT_ERROR);
1179 namd_group[ia] = aid;
1185 cvm::log(
"Group has index "+cvm::to_str(index)+
"\n");
1197 colvarproxy::clear_atom_group(index);
1205 cvm::log(
"Re-calculating total mass and charge for scalable group no. "+cvm::to_str(index+1)+
" ("+
1206 cvm::to_str(namd_group.
size())+
" atoms).\n");
1209 cvm::real total_mass = 0.0;
1210 cvm::real total_charge = 0.0;
1211 for (
int i = 0; i < namd_group.
size(); i++) {
1215 atom_groups_masses[index] = total_mass;
1216 atom_groups_charges[index] = total_charge;
1219 cvm::log(
"total mass = "+cvm::to_str(total_mass)+
1220 ", total charge = "+cvm::to_str(total_charge)+
"\n");
1230 if (units_in !=
"real") {
1231 cvm::error(
"Error: Specified unit system \"" + units_in +
"\" is unsupported in NAMD. Supported units are \"real\" (A, kcal/mol).\n");
1232 return COLVARS_ERROR;
1238 #if NAMD_VERSION_NUMBER >= 34471681
1242 for (
size_t i = 0; i < volmaps_ids.size(); i++) {
1243 if (volmaps_ids[i] == volmap_id) {
1245 volmaps_ncopies[i] += 1;
1253 return cvm::error(
"Error: invalid numeric ID ("+cvm::to_str(volmap_id)+
1254 ") for map.\n", INPUT_ERROR);
1257 int const index = add_volmap_slot(volmap_id);
1266 if (volmap_name == NULL) {
1267 return cvm::error(
"Error: no grid object name provided.", INPUT_ERROR);
1273 if (error_code == COLVARS_OK) {
1278 if ((gfScale.
x != 0.0) || (gfScale.
y != 0.0) || (gfScale.
z != 0.0)) {
1279 error_code |= cvm::error(
"Error: GridForce map \""+
1280 std::string(volmap_name)+
1281 "\" has non-zero scale factors.\n",
1292 colvarproxy::clear_volmap(index);
1298 #if CMK_SMP && USE_CKLOOP // SMP only
1300 void calc_colvars_items_smp(
int first,
int last,
void *result,
int paramNum,
void *param)
1303 colvarmodule *cv = proxy->colvars;
1305 cvm::increase_depth();
1306 for (
int i = first; i <= last; i++) {
1307 colvar *
x = (*(cv->variables_active_smp()))[i];
1308 int x_item = (*(cv->variables_active_smp_items()))[i];
1310 cvm::log(
"["+cvm::to_str(proxy->smp_thread_id())+
"/"+cvm::to_str(proxy->smp_num_threads())+
1311 "]: calc_colvars_items_smp(), first = "+cvm::to_str(first)+
1312 ", last = "+cvm::to_str(last)+
", cv = "+
1313 x->name+
", cvc = "+cvm::to_str(x_item)+
"\n");
1315 x->calc_cvcs(x_item, 1);
1317 cvm::decrease_depth();
1321 int colvarproxy_namd::smp_colvars_loop()
1323 colvarmodule *cv = this->colvars;
1324 CkLoop_Parallelize(calc_colvars_items_smp, 1,
this,
1325 cv->variables_active_smp()->size(),
1326 0, cv->variables_active_smp()->size()-1);
1327 return cvm::get_error();
1331 void calc_cv_biases_smp(
int first,
int last,
void *result,
int paramNum,
void *param)
1334 colvarmodule *cv = proxy->colvars;
1336 cvm::increase_depth();
1337 for (
int i = first; i <= last; i++) {
1338 colvarbias *b = (*(cv->biases_active()))[i];
1340 cvm::log(
"["+cvm::to_str(proxy->smp_thread_id())+
"/"+cvm::to_str(proxy->smp_num_threads())+
1341 "]: calc_cv_biases_smp(), first = "+cvm::to_str(first)+
1342 ", last = "+cvm::to_str(last)+
", bias = "+
1347 cvm::decrease_depth();
1351 int colvarproxy_namd::smp_biases_loop()
1353 colvarmodule *cv = this->colvars;
1354 CkLoop_Parallelize(calc_cv_biases_smp, 1,
this,
1355 cv->biases_active()->size(), 0, cv->biases_active()->size()-1);
1356 return cvm::get_error();
1360 void calc_cv_scripted_forces(
int paramNum,
void *param)
1363 colvarmodule *cv = proxy->colvars;
1365 cvm::log(
"["+cvm::to_str(proxy->smp_thread_id())+
"/"+cvm::to_str(proxy->smp_num_threads())+
1366 "]: calc_cv_scripted_forces()\n");
1368 cv->calc_scripted_forces();
1372 int colvarproxy_namd::smp_biases_script_loop()
1374 colvarmodule *cv = this->colvars;
1375 CkLoop_Parallelize(calc_cv_biases_smp, 1,
this,
1376 cv->biases_active()->size(), 0, cv->biases_active()->size()-1,
1377 1, NULL, CKLOOP_NONE,
1378 calc_cv_scripted_forces, 1,
this);
1379 return cvm::get_error();
1382 #endif // #if CMK_SMP && USE_CKLOOP
1386 #if CMK_HAS_PARTITION
1389 return COLVARS_NOT_IMPLEMENTED;
1395 return CmiMyPartition();
1400 return CmiNumPartitions();
1413 CmiAssert(recvMsg != NULL);
1414 int retval = recvMsg->
size;
1415 if (buf_len >= retval) {
1416 memcpy(msg_data,recvMsg->
data,retval);
int get_atom_from_name(const char *segid, int resid, const char *aname) const
ForceList & modifyAppliedForces()
AtomIDList & modifyRequestedAtoms()
cvm::rvector position_distance(cvm::atom_pos const &pos1, cvm::atom_pos const &pos2) const
BigRealList & modifyGridObjForces()
SimParameters * simparams
Pointer to the NAMD simulation input object.
Random random
NAMD-style PRNG object.
const Elem * const_iterator
void NAMD_err(const char *err_msg)
ScriptTcl * getScript(void)
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)
AtomIDList::const_iterator getForceIdEnd()
AtomIDList::const_iterator getAtomIdBegin()
PositionList::const_iterator getGroupPositionEnd()
Communication between colvars and NAMD (implementation of colvarproxy)
static void exit(int status=0)
SimParameters * simParameters
static __thread atom * atoms
e_pdb_field pdb_field_str2enum(std::string const &pdb_field_str)
void replica_send(const char *sndbuf, int sendcount, int destPart, int destPE)
std::ostream & endi(std::ostream &s)
int init_atom(int atom_number)
ForceList::const_iterator getGroupTotalForceBegin()
SubmitReduction * willSubmit(int setID, int size=-1)
int close_output_stream(std::string const &output_name)
static ReductionMgr * Object(void)
PositionList::const_iterator getAtomPositionBegin()
const ResizeArray< AtomIDList > & requestedGroups()
char outputFilename[NAMD_FILENAME_BUFFER_SIZE]
AtomIDList::const_iterator getForceIdBegin()
int init_atom_group(std::vector< int > const &atoms_ids)
int run_colvar_callback(std::string const &name, std::vector< const colvarvalue * > const &cvcs, colvarvalue &value)
#define COLVARPROXY_VERSION
char const * script_obj_to_str(unsigned char *obj)
std::vector< int > atoms_map
Array of atom indices (relative to the colvarproxy arrays), usedfor faster copy of atomic data...
void replica_recv(DataMessage **precvMsg, int srcPart, int srcPE)
int index_for_key(const char *key)
void clear_atom(int index)
IntList::const_iterator getGridObjIndexBegin()
PDBAtom * atom(int place)
int run_colvar_gradient_callback(std::string const &name, std::vector< const colvarvalue * > const &cvcs, std::vector< cvm::matrix2d< cvm::real > > &gradient)
void request_total_force(bool yesno)
IntList & modifyRequestedGridObjects()
int set_unit_system(std::string const &units_in, bool check_only)
void clear_volmap(int index)
Vector delta(const Position &pos1, const Position &pos2) const
void setall(const Elem &elem)
std::ostream * output_stream(std::string const &output_name, std::ios_base::openmode mode)
void log(std::string const &message)
AtomIDList & modifyForcedAtoms()
void exit(std::string const &message)
ResizeArray< AtomIDList > & modifyRequestedGroups()
int update_group_properties(int index)
GridforceGrid * get_gridfrc_grid(int gridnum) const
void NAMD_die(const char *err_msg)
ForceList & modifyGroupForces()
void error(std::string const &message)
virtual int replica_comm_recv(char *msg_data, int buf_len, int src_rep)
virtual int replica_index()
MGridforceParamsList mgridforcelist
void update_atom_properties(int index)
void NAMD_backup_file(const char *filename, const char *extension)
virtual Vector get_scale(void) const =0
char restartFilename[NAMD_FILENAME_BUFFER_SIZE]
BigRealList::const_iterator getGridObjValueBegin()
std::vector< std::string > script_obj_to_str_vector(unsigned char *obj)
int add(const Elem &elem)
void clear_atom_group(int index)
IntList::const_iterator getGridObjIndexEnd()
void requestTotalForce(bool yesno=true)
AtomIDList::const_iterator getAtomIdEnd()
int check_atom_id(int atom_number)
virtual int replica_enabled()
virtual void replica_comm_barrier()
Real atomcharge(int anum) const
StringList * find(const char *name) const
BigReal thermostat_temperature
Self-explained.
int load_atoms(char const *filename, cvm::atom_group &atoms, std::string const &pdb_field, double const pdb_field_value=0.0)
void add_energy(cvm::real energy)
Real atommass(int anum) const
int flush_output_stream(std::ostream *os)
const IntList & requestedGridObjs()
SubmitReduction * reduction
Used to submit restraint energy as MISC.
int backup_file(char const *filename)
size_t previous_NAMD_step
int init_volmap(int volmap_id)
virtual int replica_comm_send(char *msg_data, int msg_len, int dest_rep)
int update_atoms_map(AtomIDList::const_iterator begin, AtomIDList::const_iterator end)
PositionList::const_iterator getGroupPositionBegin()
virtual int num_replicas()
ForceList::const_iterator getTotalForce()
BigRealList::const_iterator getGridObjValueEnd()
ForceList::const_iterator getGroupTotalForceEnd()