message: fixed slicing
diff: @@ -317,16 +317,15 @@ float CNNScorer::score(model& m, bool compute_gradient, float& affinity,
  // rmeli: Carve out ligand from movable atoms
  atomv ligand_atoms = atomv(
  m.get_movable_atoms().cbegin() + m.ligands[0].node.begin,
  - m.get_movable_atoms().cbegin() + m.ligands[0].node.begin + m.m_num_movable_atoms
  + m.get_movable_atoms().cbegin() + m.m_num_movable_atoms
  );
  vecv ligand_coords = vecv(
  m.coordinates().cbegin() + m.ligands[0].node.begin,
  - m.coordinates().cbegin() + m.ligands[0].node.begin + m.m_num_movable_atoms
  + m.coordinates().cbegin() + m.m_num_movable_atoms
  );
  - if(!cnnopts.flexopt){
  - // Ligand only
  + if(!cnnopts.flexopt){ // No flexible residues
  assert(ligand_atoms.size() == m.get_movable_atoms().size());
  assert(ligand_coords.size() == m.coordinates().size());
  }
  @@ -340,12 +339,15 @@ float CNNScorer::score(model& m, bool compute_gradient, float& affinity,
  );
  atomv inflex_atoms = atomv(
  - m.get_movable_atoms().cbegin() + m.ligands[0].node.begin + m.m_num_movable_atoms,
  + m.get_movable_atoms().cbegin() + m.m_num_movable_atoms,
  m.get_movable_atoms().cend()
  );
  - if(!cnnopts.flexopt){
  - // No atoms from flexible residues should be present
  + // Check that ligand atoms and movable atoms in flexible residues sum up to the
  + // total number of movable atoms
  + assert(flexible_atoms.size() + ligand_atoms.size() == m.m_num_movable_atoms);
  +
  + if(!cnnopts.flexopt){ // No atoms from flexible residues should be present
  assert(flexible_atoms.size() == 0);
  assert(inflex_atoms.size() == 0);
  }
  @@ -368,6 +370,11 @@ float CNNScorer::score(model& m, bool compute_gradient, float& affinity,
  m.get_fixed_atoms().cend()
  );
  + if(!cnnopts.flexopt){ // No atoms from flexible residues should be present
  + assert(receptor_atoms.size() == m.get_fixed_atoms().size());
  + }
  +
  +
  if (!cnnopts.move_minimize_frame) { //if fixed_receptor, rec_conf will be identify
  mgrid->setReceptor(receptor_atoms, m.rec_conf.position, m.rec_conf.orientation);
  } else { //don't move receptor
  @@ -419,15 +426,25 @@ float CNNScorer::score(model& m, bool compute_gradient, float& affinity,
  // Get ligand gradient
  mgrid->getLigandGradient(0, gradient);
  + assert(gradient.size() == ligand_coords.size());
  +
  // Get receptor gradient
  std::vector<gfloat3> gradient_rec;
  if (cnnopts.flexopt) { // Optimization of flexible residues
  mgrid->getReceptorGradient(0, gradient_rec);
  +
  // rmeli: Select components of flexible residues!
  + gradient_rec = std::vector<gfloat3>(
  + gradient_rec.cbegin(),
  + gradient_rec.cbegin() + flexible_atoms.size()
  + );
  +
  + assert(gradient_rec.size() == flexible_atoms.size());
  }
  // Merge ligand and flexible residues gradient
  - gradient.insert(gradient.end(), gradient_rec.begin(), gradient_rec.end());
  + // Flexible residues comes first
  + gradient.insert(gradient.begin(), gradient_rec.cbegin(), gradient_rec.cend());
  // Ligand plus flexible residues gradient
  m.add_minus_forces(gradient);
  