\section{Distance\-Constraint  Class Reference}
\label{class_DistanceConstraint}\index{DistanceConstraint@{Distance\-Constraint}}
{\tt \#include $<$distance\_\-constraint.h$>$}

Inheritance diagram for Distance\-Constraint\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=61pt]{class_DistanceConstraint_inherit_graph}
\end{center}
\end{figure}
Collaboration diagram for Distance\-Constraint:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=346pt]{class_DistanceConstraint_coll_graph}
\end{center}
\end{figure}
\subsection*{Public Methods}
\begin{CompactItemize}
\item 
{\bf Distance\-Constraint} ({\bf Constraint\-Manager} \&cm)
\item 
{\bf Distance\-Constraint} ({\bf Constraint\-Manager} \&cm, int atom\_\-i, int atom\_\-j, double distance, double var)
\item 
{\bf $\sim$Distance\-Constraint} ()
\item 
{\bf j\-Vector} {\bf d\-Stress} (int k, const {\bf j\-Vector} \&pos) const
\item 
int {\bf Compare} (const Distance\-Constraint \&dc) const
\item 
{\bf MAKECOMPARISONS\_\-WITH\_\-COMPARE} (Distance\-Constraint)
\item 
int {\bf Output} (ostream \&os) const
\item 
int {\bf Output\-Binary} (ostream \&os) const
\end{CompactItemize}
\subsection*{Static Public Attributes}
\begin{CompactItemize}
\item 
{\bf Dyn\-String} {\bf Identifier} = "atomdis:"
\end{CompactItemize}
\subsection*{Protected Methods}
\begin{CompactItemize}
\item 
double {\bf compute\-Stress} () const
\item 
double {\bf compute\-Stress} (int k, const {\bf j\-Vector} \&pos) const
\item 
double {\bf compute\-Abs\-Res} (void) const
\item 
int {\bf Read} (istream \&is)
\item 
int {\bf Read\-Binary} (istream \&is)
\begin{CompactList}\small\item\em Same scenerio as {\bf Read}() {\rm (p.\,\pageref{class_DistanceConstraint_b3})} only binary version.\item\end{CompactList}\item 
void {\bf Pre\-Setup} ()
\end{CompactItemize}
\subsection*{Protected Attributes}
\begin{CompactItemize}
\item 
int {\bf envelope\-ID}
\item 
double {\bf measured}
\item 
double {\bf variance}
\item 
double {\bf stdev}
\end{CompactItemize}


\subsection{Detailed Description}
//////////////////////////////////////////////////////////

{\bf distance\_\-constraint.h}

This is the first constraint type for GRAPE. It constrains the distance between two atoms.

////////////////////////////////////////////////////////// 



Definition at line 20 of file distance\_\-constraint.h.

\subsection{Constructor \& Destructor Documentation}
\index{DistanceConstraint@{Distance\-Constraint}!DistanceConstraint@{DistanceConstraint}}
\index{DistanceConstraint@{DistanceConstraint}!DistanceConstraint@{Distance\-Constraint}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}Distance\-Constraint::Distance\-Constraint ({\bf Constraint\-Manager} \& {\em cm})}\label{class_DistanceConstraint_a0}




Definition at line 3 of file distance\_\-constraint.C.\footnotesize\begin{verbatim}00004   : Constraint(cm,IntVec(2,-1))
00005   {
00006     // this is an unititialized distance constraint.  The two atoms
00007     // and the mesured and variance values must be added.
00008     
00009     measured = 0.0;
00010     variance = INF;
00011 \end{verbatim}\normalsize 
\index{DistanceConstraint@{Distance\-Constraint}!DistanceConstraint@{DistanceConstraint}}
\index{DistanceConstraint@{DistanceConstraint}!DistanceConstraint@{Distance\-Constraint}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}Distance\-Constraint::Distance\-Constraint ({\bf Constraint\-Manager} \& {\em cm}, int {\em i}, int {\em j}, double {\em distance}, double {\em var})}\label{class_DistanceConstraint_a1}


Takes two indices of the atoms, the measured distance between them and the variance associated with this measurement. A molecule, M, is also given to serve as a "template" structure from which the object determines the number (and types) of atoms in the molecule of interest. 

Definition at line 13 of file distance\_\-constraint.C.\footnotesize\begin{verbatim}00015   : Constraint(cm, cat( IntVec(1,((i<j) ? i : j)),
00016                         IntVec(1,((i<j) ? j : i))))
00017 { 
00018   measured = distance;
00019   variance = var;
00020   if (variance<gwNumerics::MinDistVariance)
00021     {gwNumerics::MinDistVariance = variance;}
00022 \end{verbatim}\normalsize 
\index{DistanceConstraint@{Distance\-Constraint}!~DistanceConstraint@{$\sim$DistanceConstraint}}
\index{~DistanceConstraint@{$\sim$DistanceConstraint}!DistanceConstraint@{Distance\-Constraint}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}Distance\-Constraint::$\sim$Distance\-Constraint ()\hspace{0.3cm}{\tt  [inline]}}\label{class_DistanceConstraint_a2}




Definition at line 36 of file distance\_\-constraint.h.\footnotesize\begin{verbatim}00036                         {}
00037 \end{verbatim}\normalsize 


\subsection{Member Function Documentation}
\index{DistanceConstraint@{Distance\-Constraint}!Compare@{Compare}}
\index{Compare@{Compare}!DistanceConstraint@{Distance\-Constraint}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int Distance\-Constraint::Compare (const Distance\-Constraint \& {\em dc}) const\hspace{0.3cm}{\tt  [inline]}}\label{class_DistanceConstraint_a4}




Definition at line 84 of file distance\_\-constraint.h.\footnotesize\begin{verbatim}00085 {
00086   if(supportA[0] == dc.supportA[0] && supportA[1] == dc.supportA[1])
00087     return 0;
00088   if(supportA[0]<dc.supportA[0])
00089     return -1;
00090   if(supportA[0]>dc.supportA[0])
00091     return 1;
00092   if(supportA[1]<dc.supportA[1])
00093     return -1;
00094   return 1;
00095 \end{verbatim}\normalsize 
\index{DistanceConstraint@{Distance\-Constraint}!MAKECOMPARISONS_WITH_COMPARE@{MAKECOMPARISONS\_\-WITH\_\-COMPARE}}
\index{MAKECOMPARISONS_WITH_COMPARE@{MAKECOMPARISONS\_\-WITH\_\-COMPARE}!DistanceConstraint@{Distance\-Constraint}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}Distance\-Constraint::MAKECOMPARISONS\_\-WITH\_\-COMPARE (Distance\-Constraint)}\label{class_DistanceConstraint_a5}


\index{DistanceConstraint@{Distance\-Constraint}!Output@{Output}}
\index{Output@{Output}!DistanceConstraint@{Distance\-Constraint}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int Distance\-Constraint::Output (ostream \& {\em os}) const\hspace{0.3cm}{\tt  [virtual]}}\label{class_DistanceConstraint_a6}




Reimplemented from {\bf Constraint} {\rm (p.\,\pageref{class_Constraint_a11})}.

Definition at line 235 of file distance\_\-constraint.C.\footnotesize\begin{verbatim}00236 {
00237   os << supportA[0] << ' ' << supportA[1] << ' '
00238      << measured << ' ' << variance;
00239   return 2;
00240 \end{verbatim}\normalsize 
\index{DistanceConstraint@{Distance\-Constraint}!OutputBinary@{OutputBinary}}
\index{OutputBinary@{OutputBinary}!DistanceConstraint@{Distance\-Constraint}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int Distance\-Constraint::Output\-Binary (ostream \& {\em os}) const\hspace{0.3cm}{\tt  [virtual]}}\label{class_DistanceConstraint_a7}




Reimplemented from {\bf Constraint} {\rm (p.\,\pageref{class_Constraint_a13})}.

Definition at line 250 of file distance\_\-constraint.C.\footnotesize\begin{verbatim}00251 {
00252   os <= supportA <= measured <= variance;
00253   return 2;
00254 \end{verbatim}\normalsize 
\index{DistanceConstraint@{Distance\-Constraint}!PreSetup@{PreSetup}}
\index{PreSetup@{PreSetup}!DistanceConstraint@{Distance\-Constraint}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void Distance\-Constraint::Pre\-Setup (void)\hspace{0.3cm}{\tt  [protected, virtual]}}\label{class_DistanceConstraint_b5}


The setup function is called if the uninialized constraint method is used to create the constraint to allow different data representations within the constraint. Without this, only data read in from the input file will be available to the member functions. For simple constraints, this is really not very useful. However for multi-atom constraints that need to be a little 'smarter' about data representations, the Setup function will be helpful. 

Reimplemented from {\bf Constraint} {\rm (p.\,\pageref{class_Constraint_b6})}.

Definition at line 25 of file distance\_\-constraint.C.\footnotesize\begin{verbatim}00026 {
00027   //  CString = Identifier;
00028   stdev = sqrt(variance);
00029 \end{verbatim}\normalsize 
\index{DistanceConstraint@{Distance\-Constraint}!Read@{Read}}
\index{Read@{Read}!DistanceConstraint@{Distance\-Constraint}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int Distance\-Constraint::Read (istream \& {\em is})\hspace{0.3cm}{\tt  [protected, virtual]}}\label{class_DistanceConstraint_b3}


Derived classes need to define here how to read  themselves in. Notice that the base class defines {\bf Input}() {\rm (p.\,\pageref{class_Constraint_a12})} as a wrapper around this virtual function. Subclasses should typically overwrite just the {\bf Read}() {\rm (p.\,\pageref{class_DistanceConstraint_b3})} function (and not the {\bf Input}() {\rm (p.\,\pageref{class_Constraint_a12})} function).

In the {\bf Read}() {\rm (p.\,\pageref{class_DistanceConstraint_b3})} function, the derived class should $\ast$not$\ast$ log itself with the constraint manager since this is taken care of in the base classes {\bf Input}() {\rm (p.\,\pageref{class_Constraint_a12})} function. 

Reimplemented from {\bf Constraint} {\rm (p.\,\pageref{class_Constraint_b4})}.

Definition at line 242 of file distance\_\-constraint.C.\footnotesize\begin{verbatim}00243 {
00244   is >> supportA[0] >> supportA[1] >> measured >> variance;
00245   if (variance<gwNumerics::MinDistVariance)
00246     {gwNumerics::MinDistVariance = variance;}
00247 \end{verbatim}\normalsize 
\index{DistanceConstraint@{Distance\-Constraint}!ReadBinary@{ReadBinary}}
\index{ReadBinary@{ReadBinary}!DistanceConstraint@{Distance\-Constraint}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int Distance\-Constraint::Read\-Binary (istream \& {\em is})\hspace{0.3cm}{\tt  [protected, virtual]}}\label{class_DistanceConstraint_b4}


Same scenerio as {\bf Read}() {\rm (p.\,\pageref{class_DistanceConstraint_b3})} only binary version.



Reimplemented from {\bf Constraint} {\rm (p.\,\pageref{class_Constraint_b5})}.

Definition at line 256 of file distance\_\-constraint.C.\footnotesize\begin{verbatim}00257 {
00258   is >= supportA[0] >= supportA[1] >= measured >= variance;
00259   if (variance<gwNumerics::MinDistVariance)
00260     {gwNumerics::MinDistVariance = variance;}
00261 \end{verbatim}\normalsize 
\index{DistanceConstraint@{Distance\-Constraint}!computeAbsRes@{computeAbsRes}}
\index{computeAbsRes@{computeAbsRes}!DistanceConstraint@{Distance\-Constraint}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}double Distance\-Constraint::compute\-Abs\-Res (void) const\hspace{0.3cm}{\tt  [protected, virtual]}}\label{class_DistanceConstraint_b2}


returns abs residual as a Z score, if supported, constraint overwrites 

Reimplemented from {\bf Constraint} {\rm (p.\,\pageref{class_Constraint_a28})}.

Definition at line 227 of file distance\_\-constraint.C.\footnotesize\begin{verbatim}00228 {
00229   int i=supportA[0], j=supportA[1];
00230   double calc = euclid(getMolecule()(i),getMolecule()(j));
00231   return fabs((calc-measured)/stdev);
00232 \end{verbatim}\normalsize 
\index{DistanceConstraint@{Distance\-Constraint}!computeStress@{computeStress}}
\index{computeStress@{computeStress}!DistanceConstraint@{Distance\-Constraint}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}double Distance\-Constraint::compute\-Stress (int {\em k}, const {\bf j\-Vector} \& {\em pos\_\-k}) const\hspace{0.3cm}{\tt  [protected, virtual]}}\label{class_DistanceConstraint_b1}


Returns the stress on this constraint after "pretending" the atom with index a' moved to position pos\_\-a'. This also must be overwitten by all constraints that inherit from this class 

Reimplemented from {\bf Constraint} {\rm (p.\,\pageref{class_Constraint_a27})}.

Definition at line 56 of file distance\_\-constraint.C.\footnotesize\begin{verbatim}00057 {
00058   double calc;  // calculated (current model) distance between i and j.
00059   int i=supportA[0], j=supportA[1];
00060 
00061   // If the atom that has moved does not include either of the two
00062   // atoms this constraint is defined over, then just default to reporting
00063   // how stressed we are about our two atoms.
00064   //
00065   if(k != i && k != j){
00066     cerr << "*** Called computeStress("<<k<<","<<pos_k<<") on dist constraint over atoms " ;
00067     cerr << i << " and " << j << "***" << endl;
00068     DIE("");
00069     return computeStress();
00070   }
00071   // Figure out which atom has moved and report our new satisfaction:
00072   // 
00073   if(k == i)
00074       calc = euclid(pos_k, getMolecule()(j));
00075   else
00076       calc = euclid(getMolecule()(i), pos_k);
00077   
00078   // Our new satisfaction is the difference between the measured and the
00079   // predicted distance:
00080   //
00081 //    cerr << "ORDER cmputstr-pos: " << Label() << ";calc = " << setprecision(50) << calc << endl;
00082   
00083   double R = (calc-measured)/stdev; 
00084 //   if (R>DistanceConstraint::MaxAbsResidual)
00085 //     {DistanceConstraint::MaxAbsResidual = R;}
00086 \end{verbatim}\normalsize 
\index{DistanceConstraint@{Distance\-Constraint}!computeStress@{computeStress}}
\index{computeStress@{computeStress}!DistanceConstraint@{Distance\-Constraint}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}double Distance\-Constraint::compute\-Stress () const\hspace{0.3cm}{\tt  [protected, virtual]}}\label{class_DistanceConstraint_b0}


One of the only functions that $\ast$must$\ast$ be overwritten by subclasses. Returns a value reflecting how dissatisfied this constraint is with the current molecule residing in CM'. 

Reimplemented from {\bf Constraint} {\rm (p.\,\pageref{class_Constraint_a26})}.

Definition at line 36 of file distance\_\-constraint.C.

Referenced by compute\-Stress().\footnotesize\begin{verbatim}00037 {
00038   int i=supportA[0], j=supportA[1];
00039 
00040   // Find the calculated distance in the model
00041   double calc = euclid(getMolecule()(i),getMolecule()(j));
00042 //   cerr << "ORDER cmputstr: " << Label() << ";calc = " << setprecision(50) << calc << endl;
00043 //   cerr << "ORDER cmputstr: " << Label() << ";meas = " << setprecision(50) << measured << endl;
00044   double R = (calc-measured)/stdev;
00045 //   cerr << "ORDER cmputstr: " << Label() << ";R' = " << setprecision(50) << R << endl;
00046   //  R = R/stdev;
00047 //   if (R>DistanceConstraint::MaxAbsResidual)
00048 //     {DistanceConstraint::MaxAbsResidual = R;}
00049 \end{verbatim}\normalsize 
\index{DistanceConstraint@{Distance\-Constraint}!dStress@{dStress}}
\index{dStress@{dStress}!DistanceConstraint@{Distance\-Constraint}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf j\-Vector} Distance\-Constraint::d\-Stress (int {\em k}, const {\bf j\-Vector} \& {\em pos\_\-k}) const\hspace{0.3cm}{\tt  [virtual]}}\label{class_DistanceConstraint_a3}


asking constraint number k for its 12 element d\-Stress vector we pass in pos\_\-a vector -- corresponding to the atom position if the constraint is an atom, and corresponding to the position of the atom k in question if the call is to a non-atom constraint. EG for a distance constraint atom 12 needs the d\-Stress from the d-constraint, so it will call d\-Stress on the d-constraint(12, atom\_\-pos) so the d\_\-constr can answer the question if atom 12 were in atom\_\-pos, I would say my d\-Stress is blah. 

Reimplemented from {\bf Constraint} {\rm (p.\,\pageref{class_Constraint_a6})}.

Definition at line 171 of file distance\_\-constraint.C.\footnotesize\begin{verbatim}00172 {
00173   // A HACK and a TEMPORARY FIX to an inherent logic problems in this
00174   // set of functions.  come see me w/ questions -jd
00175   
00176    int i=supportA[0], j=supportA[1];
00177 
00178   if(k != i && k != j)
00179     {
00180       cerr << "Fatal error: distance_constraint.C, dStress("<< k \
00181            <<", pos) not legal on atom " << k << endl;
00182       exit(1);
00183     }
00184 
00185   // Figure out which atom has moved and report our new satisfaction:
00186   // 
00187   double calc;
00188   if(k == i)
00189       calc = euclid(pos_k, getMolecule()(j));
00190   else
00191       calc = euclid(getMolecule()(i), pos_k);
00192   
00193 //   cerr << "ORDER dstress: " << Label() << ";calc = " << setprecision(50) << calc << endl;
00194   
00195   jVector dist(3,0.0);
00196   //  jVector return_vect(12,0.0);
00197   jVector return_vect(3,0.0);
00198   double R = (calc-measured)/stdev;
00199 
00200   //  cerr << "R=" << R << endl;
00201   
00202   if(k==i)
00203     dist = ((pos_k - getMolecule()(j))/calc/stdev);
00204   else if(k==j)
00205     dist = ((pos_k - getMolecule()(i))/calc/stdev);
00206   else {
00207     DIE("Error in distance dstress call.");
00208     return return_vect;
00209   }
00210 \end{verbatim}\normalsize 


\subsection{Member Data Documentation}
\index{DistanceConstraint@{Distance\-Constraint}!Identifier@{Identifier}}
\index{Identifier@{Identifier}!DistanceConstraint@{Distance\-Constraint}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf Dyn\-String} Distance\-Constraint::Identifier = "atomdis:"\hspace{0.3cm}{\tt  [static]}}\label{class_DistanceConstraint_p0}




Reimplemented from {\bf Constraint} {\rm (p.\,\pageref{class_Constraint_p0})}.

Definition at line 100 of file globals.C.\index{DistanceConstraint@{Distance\-Constraint}!envelopeID@{envelopeID}}
\index{envelopeID@{envelopeID}!DistanceConstraint@{Distance\-Constraint}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int Distance\-Constraint::envelope\-ID\hspace{0.3cm}{\tt  [protected]}}\label{class_DistanceConstraint_n0}




Definition at line 55 of file distance\_\-constraint.h.\index{DistanceConstraint@{Distance\-Constraint}!measured@{measured}}
\index{measured@{measured}!DistanceConstraint@{Distance\-Constraint}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}double Distance\-Constraint::measured\hspace{0.3cm}{\tt  [protected]}}\label{class_DistanceConstraint_n1}




Definition at line 71 of file distance\_\-constraint.h.\index{DistanceConstraint@{Distance\-Constraint}!stdev@{stdev}}
\index{stdev@{stdev}!DistanceConstraint@{Distance\-Constraint}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}double Distance\-Constraint::stdev\hspace{0.3cm}{\tt  [protected]}}\label{class_DistanceConstraint_n3}




Definition at line 73 of file distance\_\-constraint.h.\index{DistanceConstraint@{Distance\-Constraint}!variance@{variance}}
\index{variance@{variance}!DistanceConstraint@{Distance\-Constraint}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}double Distance\-Constraint::variance\hspace{0.3cm}{\tt  [protected]}}\label{class_DistanceConstraint_n2}




Definition at line 72 of file distance\_\-constraint.h.

The documentation for this class was generated from the following files:\begin{CompactItemize}
\item 
{\bf distance\_\-constraint.h}\item 
{\bf distance\_\-constraint.C}\item 
{\bf globals.C}\end{CompactItemize}
