Skip to content

Commit

Permalink
Honor the value of forceNoPBC when comparing values of distanceVec va…
Browse files Browse the repository at this point in the history
…riables
  • Loading branch information
giacomofiorin committed Dec 4, 2023
1 parent 6e02473 commit e75f004
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
10 changes: 5 additions & 5 deletions doc/colvars-refman-main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1651,11 +1651,11 @@
\cvsubsubsec{\texttt{distanceVec}: distance vector between two groups.}{sec:cvc_distanceVec}
\labelkey{colvar|distanceVec}

The \texttt{distanceVec~\{...\}} block defines
a distance vector component, which accepts the same keywords as
the component \texttt{distance}: \texttt{group1}, \texttt{group2}, and
\texttt{forceNoPBC}. Its value is the 3-vector joining the centers
of mass of \texttt{group1} and \texttt{group2}.
The \texttt{distanceVec} component computes the 3-dimensional vector joining the centers of mass of
\texttt{group1} and \texttt{group2}. Its values are therefore multi-dimensional and are subject to
the restrictions listed in \ref{sec:cvc_non_scalar}. Moreover, when computing differences between
two different values of a \texttt{distanceVec} variable the minimum-image convention is assumed
(unless \refkey{forceNoPBC}{colvar|cvc|forceNoPBC} is enabled).

\begin{cvcoptions}
\item %
Expand Down
23 changes: 14 additions & 9 deletions src/colvarcomp_distances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,27 +125,32 @@ void colvar::distance_vec::apply_force(colvarvalue const &force)
}


cvm::real colvar::distance_vec::dist2(colvarvalue const &x1,
colvarvalue const &x2) const
cvm::real colvar::distance_vec::dist2(colvarvalue const &x1, colvarvalue const &x2) const
{
return (cvm::position_distance(x1.rvector_value, x2.rvector_value)).norm2();
if (is_enabled(f_cvc_pbc_minimum_image)) {
return (cvm::position_distance(x1.rvector_value, x2.rvector_value)).norm2();
}
return (x2.rvector_value - x1.rvector_value).norm2();
}


colvarvalue colvar::distance_vec::dist2_lgrad(colvarvalue const &x1,
colvarvalue const &x2) const
colvarvalue colvar::distance_vec::dist2_lgrad(colvarvalue const &x1, colvarvalue const &x2) const
{
return 2.0 * cvm::position_distance(x2.rvector_value, x1.rvector_value);
if (is_enabled(f_cvc_pbc_minimum_image)) {
return cvm::position_distance(x1.rvector_value, x2.rvector_value);
}
return 2.0 * (x2.rvector_value - x1.rvector_value);
}


colvarvalue colvar::distance_vec::dist2_rgrad(colvarvalue const &x1,
colvarvalue const &x2) const
colvarvalue colvar::distance_vec::dist2_rgrad(colvarvalue const &x1, colvarvalue const &x2) const
{
return 2.0 * cvm::position_distance(x2.rvector_value, x1.rvector_value);
return distance_vec::dist2_lgrad(x1, x2);
}


void colvar::distance_vec::wrap(colvarvalue & /* x_unwrapped */) const {}


colvar::distance_z::distance_z()
{
Expand Down

0 comments on commit e75f004

Please sign in to comment.