示例#1
0
int colvarproxy_namd::load_atoms(char const *pdb_filename,
                                 cvm::atom_group &atoms,
                                 std::string const &pdb_field_str,
                                 double const pdb_field_value)
{
  if (pdb_field_str.size() == 0)
    cvm::error("Error: must define which PDB field to use "
               "in order to define atoms from a PDB file.\n", INPUT_ERROR);

  PDB *pdb = new PDB(pdb_filename);
  size_t const pdb_natoms = pdb->num_atoms();

  e_pdb_field pdb_field_index = pdb_field_str2enum(pdb_field_str);

  for (size_t ipdb = 0; ipdb < pdb_natoms; ipdb++) {

    double atom_pdb_field_value = 0.0;

    switch (pdb_field_index) {
    case e_pdb_occ:
      atom_pdb_field_value = (pdb->atom(ipdb))->occupancy();
      break;
    case e_pdb_beta:
      atom_pdb_field_value = (pdb->atom(ipdb))->temperaturefactor();
      break;
    case e_pdb_x:
      atom_pdb_field_value = (pdb->atom(ipdb))->xcoor();
      break;
    case e_pdb_y:
      atom_pdb_field_value = (pdb->atom(ipdb))->ycoor();
      break;
    case e_pdb_z:
      atom_pdb_field_value = (pdb->atom(ipdb))->zcoor();
      break;
    default:
      break;
    }

    if ( (pdb_field_value) &&
         (atom_pdb_field_value != pdb_field_value) ) {
      continue;
    } else if (atom_pdb_field_value == 0.0) {
      continue;
    }

    if (atoms.is_enabled(colvardeps::f_ag_scalable)) {
      atoms.add_atom_id(ipdb);
    } else {
      atoms.add_atom(cvm::atom(ipdb+1));
    }
  }

  delete pdb;
  return (cvm::get_error() ? COLVARS_ERROR : COLVARS_OK);
}
colvarvalue colvar::cvc::fdiff_change (cvm::atom_group &group)
{  
  colvarvalue change (x.type());

  if (group.old_pos.size()) {
    for (size_t i = 0; i < group.size(); i++) {
      cvm::rvector const &pold = group.old_pos[i];
      cvm::rvector const &p = group[i].pos;
      change += group[i].grad * (p - pold);
    }
  }

  // save for next step
  group.old_pos = group.positions();
  return change;
}
void colvar::cvc::parse_group (std::string const &conf, 
                               char const *group_key,
                               cvm::atom_group &group,
                               bool optional)
{
  if (key_lookup (conf, group_key)) {
    group.parse (conf, group_key);
  } else {
    if (! optional) {
      cvm::fatal_error ("Error: definition for atom group \""+
                      std::string (group_key)+"\" not found.\n");
    }
  }
}
示例#4
0
void colvar::cvc::parse_group (std::string const &conf,
                               char const *group_key,
                               cvm::atom_group &group,
                               bool optional)
{
  if (key_lookup (conf, group_key)) {
    if (group.parse (conf, group_key) != COLVARS_OK) {
      cvm::error ("Error parsing definition for atom group \""+
                         std::string (group_key)+"\".\n");
      return;
    }
  } else {
    if (! optional) {
      cvm::error ("Error: definition for atom group \""+
                      std::string (group_key)+"\" not found.\n");
      return;
    }
  }
}
示例#5
0
void colvar::cvc::debug_gradients (cvm::atom_group &group)
{
  // this function should work for any scalar variable:
  // the only difference will be the name of the atom group (here, "group")

  if (group.b_dummy) return;

  cvm::rotation const rot_0 = group.rot;
  cvm::rotation const rot_inv = group.rot.inverse();

  cvm::real const x_0 = x.real_value;

  // cvm::log ("gradients     = "+cvm::to_str (gradients)+"\n");

  // it only makes sense to debug the fit gradients
  // when the fitting group is the same as this group
  if (group.b_rotate || group.b_center)
    if (group.b_fit_gradients && (group.ref_pos_group == NULL)) {
      group.calc_fit_gradients();
      if (group.b_rotate) {
        // fit_gradients are in the original frame, we should print them in the rotated frame
        for (size_t j = 0; j < group.fit_gradients.size(); j++) {
          group.fit_gradients[j] = rot_0.rotate (group.fit_gradients[j]);
        }
      }
      cvm::log ("fit_gradients = "+cvm::to_str (group.fit_gradients)+"\n");
      if (group.b_rotate) {
        for (size_t j = 0; j < group.fit_gradients.size(); j++) {
          group.fit_gradients[j] = rot_inv.rotate (group.fit_gradients[j]);
        }
      }
    }

  for (size_t ia = 0; ia < group.size(); ia++) {

    // tests are best conducted in the unrotated (simulation) frame
    cvm::rvector const atom_grad = group.b_rotate ?
      rot_inv.rotate (group[ia].grad) :
      group[ia].grad;

    for (size_t id = 0; id < 3; id++) {
      // (re)read original positions
      group.read_positions();
      // change one coordinate
      group[ia].pos[id] += cvm::debug_gradients_step_size;
      // (re)do the fit (if defined)
      if (group.b_center || group.b_rotate) {
        group.calc_apply_roto_translation();
      }
      calc_value();
      cvm::real const x_1 = x.real_value;
      cvm::log ("Atom "+cvm::to_str (ia)+", component "+cvm::to_str (id)+":\n");
      cvm::log ("dx(actual) = "+cvm::to_str (x_1 - x_0,
                             21, 14)+"\n");
      //cvm::real const dx_pred = (group.fit_gradients.size() && (group.ref_pos_group == NULL)) ?
      cvm::real const dx_pred = (group.fit_gradients.size()) ?
        (cvm::debug_gradients_step_size * (atom_grad[id] + group.fit_gradients[ia][id])) :
        (cvm::debug_gradients_step_size * atom_grad[id]);
      cvm::log ("dx(interp) = "+cvm::to_str (dx_pred,
                             21, 14)+"\n");
      cvm::log ("|dx(actual) - dx(interp)|/|dx(actual)| = "+
                cvm::to_str (std::fabs (x_1 - x_0 - dx_pred) /
                             std::fabs (x_1 - x_0), 12, 5)+"\n");
    }
  }

/*
 * The code below is WIP
 */
//   if (group.ref_pos_group != NULL) {
//     cvm::atom_group &ref = *group.ref_pos_group;
//     group.calc_fit_gradients();
//
//     for (size_t ia = 0; ia < ref.size(); ia++) {
//
//       for (size_t id = 0; id < 3; id++) {
//         // (re)read original positions
//         group.read_positions();
//         ref.read_positions();
//         // change one coordinate
//         ref[ia].pos[id] += cvm::debug_gradients_step_size;
//         group.calc_apply_roto_translation();
//         calc_value();
//         cvm::real const x_1 = x.real_value;
//         cvm::log ("refPosGroup atom "+cvm::to_str (ia)+", component "+cvm::to_str (id)+":\n");
//         cvm::log ("dx(actual) = "+cvm::to_str (x_1 - x_0,
//                                21, 14)+"\n");
//         //cvm::real const dx_pred = (group.fit_gradients.size() && (group.ref_pos_group == NULL)) ?
//         // cvm::real const dx_pred = (group.fit_gradients.size()) ?
//         //  (cvm::debug_gradients_step_size * (atom_grad[id] + group.fit_gradients[ia][id])) :
//         //  (cvm::debug_gradients_step_size * atom_grad[id]);
//         cvm::real const dx_pred = cvm::debug_gradients_step_size * ref.fit_gradients[ia][id];
//         cvm::log ("dx(interp) = "+cvm::to_str (dx_pred,
//                                21, 14)+"\n");
//         cvm::log ("|dx(actual) - dx(interp)|/|dx(actual)| = "+
//                   cvm::to_str (std::fabs (x_1 - x_0 - dx_pred) /
//                                std::fabs (x_1 - x_0),
//                                12, 5)+
//                   ".\n");
//       }
//     }
//   }

  return;
}