\section{gw\-Relax\-Atom  Class Reference}
\label{class_gwRelaxAtom}\index{gwRelaxAtom@{gw\-Relax\-Atom}}
{\tt \#include $<$gw\_\-relax\_\-atom.h$>$}

Inheritance diagram for gw\-Relax\-Atom\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=56pt]{class_gwRelaxAtom_inherit_graph}
\end{center}
\end{figure}
Collaboration diagram for gw\-Relax\-Atom:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=347pt]{class_gwRelaxAtom_coll_graph}
\end{center}
\end{figure}
\subsection*{Public Methods}
\begin{CompactItemize}
\item 
{\bf gw\-Relax\-Atom} (const gw\-Relax\-Atom \&ra)
\begin{CompactList}\small\item\em Copy Constructor.\item\end{CompactList}\item 
{\bf gw\-Relax\-Atom} ({\bf Constraint\-Manager} \&cm, int index)
\begin{CompactList}\small\item\em Constructor takes a reference to a constraint manager, and the index of the atom.\item\end{CompactList}\item 
{\bf $\sim$gw\-Relax\-Atom} ()
\item 
int {\bf run} ()
\item 
int {\bf get\-Index} (void) const
\begin{CompactList}\small\item\em return index of the atom the class is acting on.\item\end{CompactList}\end{CompactItemize}
\subsection*{Static Public Attributes}
\begin{CompactItemize}
\item 
int {\bf max\_\-iterations} = 40
\begin{CompactList}\small\item\em Maximum nuber of times to perform linesearch while updating atom.\item\end{CompactList}\end{CompactItemize}
\subsection*{Private Attributes}
\begin{CompactItemize}
\item 
int {\bf atom\_\-index}
\begin{CompactList}\small\item\em The index of the atom in the molecule this process is associated with.\item\end{CompactList}\end{CompactItemize}


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

File: {\bf gw\_\-relax\_\-atom.h}

This class re-implements exactly the atom relaxtion code from Glenn Williams' Gnomad software. A modified Gauss Newton using the gradient and Hessian determine the optimal direction of travel for the atom, and a 2nd oder polynomial line search determines the best new position. Hard constraint provides both Van del Waals excusion and the ability to perform local pertubation.

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



Definition at line 25 of file gw\_\-relax\_\-atom.h.

\subsection{Constructor \& Destructor Documentation}
\index{gwRelaxAtom@{gw\-Relax\-Atom}!gwRelaxAtom@{gwRelaxAtom}}
\index{gwRelaxAtom@{gwRelaxAtom}!gwRelaxAtom@{gw\-Relax\-Atom}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}gw\-Relax\-Atom::gw\-Relax\-Atom (const gw\-Relax\-Atom \& {\em ra})}\label{class_gwRelaxAtom_a0}


Copy Constructor.



Definition at line 4 of file gw\_\-relax\_\-atom.C.\footnotesize\begin{verbatim}00005   : SatisfyMolecule(*(ra.CM))
00006 {
00007   atom_index = ra.atom_index;
00008 \end{verbatim}\normalsize 
\index{gwRelaxAtom@{gw\-Relax\-Atom}!gwRelaxAtom@{gwRelaxAtom}}
\index{gwRelaxAtom@{gwRelaxAtom}!gwRelaxAtom@{gw\-Relax\-Atom}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}gw\-Relax\-Atom::gw\-Relax\-Atom ({\bf Constraint\-Manager} \& {\em cm}, int {\em temp\_\-index})}\label{class_gwRelaxAtom_a1}


Constructor takes a reference to a constraint manager, and the index of the atom.



Definition at line 10 of file gw\_\-relax\_\-atom.C.\footnotesize\begin{verbatim}00011   : SatisfyMolecule(cm)
00012 {
00013   atom_index = temp_index;
00014   // gwRA assumes that static double ls_deriv_tolerance, 
00015   // static double ls_dist_tolerance,
00016 \end{verbatim}\normalsize 
\index{gwRelaxAtom@{gw\-Relax\-Atom}!~gwRelaxAtom@{$\sim$gwRelaxAtom}}
\index{~gwRelaxAtom@{$\sim$gwRelaxAtom}!gwRelaxAtom@{gw\-Relax\-Atom}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}gw\-Relax\-Atom::$\sim$gw\-Relax\-Atom ()}\label{class_gwRelaxAtom_a2}




Definition at line 18 of file gw\_\-relax\_\-atom.C.\footnotesize\begin{verbatim}00019 {
00020   // Do *not* delete constraint manager (or M for that matter)!
00021 \end{verbatim}\normalsize 


\subsection{Member Function Documentation}
\index{gwRelaxAtom@{gw\-Relax\-Atom}!getIndex@{getIndex}}
\index{getIndex@{getIndex}!gwRelaxAtom@{gw\-Relax\-Atom}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int gw\-Relax\-Atom::get\-Index (void) const\hspace{0.3cm}{\tt  [inline]}}\label{class_gwRelaxAtom_a4}


return index of the atom the class is acting on.



Definition at line 71 of file gw\_\-relax\_\-atom.h.\footnotesize\begin{verbatim}00071                                            {return atom_index;}
00072 \end{verbatim}\normalsize 
\index{gwRelaxAtom@{gw\-Relax\-Atom}!run@{run}}
\index{run@{run}!gwRelaxAtom@{gw\-Relax\-Atom}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int gw\-Relax\-Atom::run ()\hspace{0.3cm}{\tt  [virtual]}}\label{class_gwRelaxAtom_a3}


Execute this process. Returns the exit status of the process (0 is success, non-zero is error). 

Reimplemented from {\bf Process} {\rm (p.\,\pageref{class_Process_a1})}.

Definition at line 23 of file gw\_\-relax\_\-atom.C.\footnotesize\begin{verbatim}00024 {
00025 
00026 #ifdef JOB_VERBOSE
00027   cerr <<endl<< "Start: \tgwRelaxAtom::run() atom=" << atom_index << endl;
00028 #endif
00029   
00030 #ifdef JOB_VERBOSE2
00031   cerr << "Value: \tgwRelexAtom::run() priority atom " << atom_index << "before ="<< getPriority() << endl;
00032 #endif
00033 
00034 
00035 // #ifdef GNOMAD_OUTPUT
00036 //   printf("  In move_atom for atom %d\n\n", atom_index);
00037 // #endif
00038   
00039   //  cerr << ";" << atom_index ;
00040   
00041   jVector hessian(6,0.0);  
00042   // 3x3 Hessian symmetric matrix of partial derivatives dr/di*dr/dj, where
00043   // i and j iterate over x,y,z dimension, and r is the residual
00044   // of this atom.
00045   // 0 1 2
00046   // 1 3 4
00047   // 2 4 5
00048   
00049   jVector gradient(3,0.0);
00050   // Gradient vector.
00051   
00052   jVector prev_gradient(3,0.0);
00053   // previous Gradient vector.
00054   
00055   jVector direction(3,0.0);
00056   // Direction atom moves during each step inside iteration
00057 
00058   jVector prev_direction(3,0.0);
00059   // previous Direction atom moves during each step inside iteration
00060 
00061   jVector start_position = CM->getPosition(atom_index);
00062 
00063   jVector step_position = start_position;
00064   // pulls the x,y,z coordinate of the atom before relaxation.
00065 
00066   jVector prev_position = start_position;
00067 
00068   jVector new_position = start_position;
00069   
00070    //  jVector temp_vector(12,0.0);
00071   // FIX  a hack to hold the dStress(int) returnval.
00072   
00073   double step_length = 0;
00074   double new_step_length = 0;  
00075   double derivative;
00076   int iteration = 0;
00077   register int i;
00078   bool ContinueFlag = true;
00079   
00080   for(i=0; i<3; i++) gradient[i] = 0.0;  // reset jVectors
00081   for(i=0; i<6; i++) hessian[i] = 0.0;
00082 
00083 #ifdef GNOMAD_OUTPUT
00084   printf("    x0, y0, z0 = %lf, %lf, %lf\n", start_position[0], start_position[1], start_position[2]);
00085   printf("    f0 = %lf\n\n", CM->stress(atom_index));
00086 #endif
00087   
00088   // 'iteration' loop
00089   while (ContinueFlag){
00090 
00091 #ifdef JOB_VERBOSE2
00092     cerr << "Working\tgwRelaxAtom::run() start iteration number " << iteration << endl << endl;
00093     cerr << "Value: \tgwRelaxAtom::run() step_position (start of iteration)=  " << step_position <<endl;
00094     cerr << "Value: \tgwRelaxAtom::run() prev_position (start of iteration)=  " << prev_position <<endl;
00095     cerr << "Stress = "<< setprecision(25) <<CM->stress(atom_index,step_position) << setprecision(8)  <<endl;
00096 #endif
00097 
00098 
00099     if (iteration >= max_iterations) {
00100       //      cerr << "X";
00101       break;  // break condition on iteration count
00102     }
00103     
00104     gradient = CM->dStress(atom_index, step_position);
00105 
00106     if (iteration == 0) {
00107       hessian[0] = hessian[3] =  hessian[5] =  1;
00108       direction = (-1)*gradient;
00109       
00110     } // first iteration only
00111     else { // all other iters
00112     
00113       gwNumerics::bfgs_step(step_position, prev_position,
00114                             gradient, prev_gradient,
00115                             hessian, direction);
00116       // sets hessian and direction
00117     }
00118   
00119     derivative = direction*gradient;
00120 #ifdef JOB_VERBOSE2
00121     cerr << "Value: \tgwRelaxAtom::run() gradient = " << gradient << endl;
00122     cerr << "Value: \tgwRelaxAtom::run() hessian0 = "
00123          << hessian[0] << "\t" << hessian[1]  << "\t" << hessian[2]  << "\t" << endl;
00124     cerr << "Value: \tgwRelaxAtom::run() hessian1 = "
00125          << hessian[1]  << "\t" << hessian[3]  << "\t" << hessian[4] << endl;
00126     cerr << "Value: \tgwRelaxAtom::run() hessian2 = "
00127          << hessian[2]  << "\t" << hessian[4]  << "\t" << hessian[5] << endl;
00128     cerr << "Value: \tgwRelaxAtom::run() direction =  " << direction << endl;
00129     cerr << "Value: \tgwRelaxAtom::run() derivative =  " << derivative << endl;
00130 #endif
00131     
00132     if (fabs(derivative) < gwNumerics::ls_deriv_tolerance) {
00133 #ifdef JOB_VERBOSE2
00134       if (iteration == 0) {prev_direction = direction;}
00135       cerr << "break on derivative too small" << endl;
00136     cerr << "Value: \tgwRelaxAtom::breaking step_position =  " << step_position <<endl;
00137     cerr << "Value: \tgwRelaxAtom::breaking prev_position =  " << prev_position <<endl;
00138 #endif
00139       break; // break condition on derivative
00140     }
00141         
00142     ContinueFlag = gwNumerics::CubicLineSearch(step_position, direction, \
00143                                    derivative, *CM, \
00144                                    atom_index, new_position, new_step_length);
00145     // both new_position and step_length are reset here
00146 
00147 #ifdef JOB_VERBOSE2
00148     cerr << "Line search done, ContinueFlag = "<< ContinueFlag << endl;
00149     cerr << "Value: \tgwRelaxAtom::run() step_length =  " << step_length << endl;
00150     cerr << "Value: \tgwRelaxAtom::run() new_step_length =  " << new_step_length << endl;
00151     cerr << "Value: \tgwRelaxAtom::run() new_position =  " << new_position <<endl;
00152 #endif
00153     
00154     if (ContinueFlag) {  // successful line search
00155       prev_position = step_position;
00156       step_position = new_position;
00157       prev_direction = direction;
00158       prev_gradient = gradient;
00159       step_length = new_step_length;
00160 //       cerr << "Value: \tgwRelaxAtom::breaking step_length =  " << step_length <<endl;
00161 //       cerr << "Value: \tgwRelaxAtom::breaking new_step_length =  " << new_step_length <<endl;
00162 
00163       //     } else {
00164 //     if (iteration == 0){
00165 //      prev_direction = direction;
00166 //      WARN ("debug from gnomad");
00167 //      cerr << "prev_direction =  " << prev_direction << endl;
00168 //      cerr << "direction =       " << direction << endl;
00169 //     }
00170     }
00171     
00172 #ifdef JOB_VERBOSE2
00173     cerr << "Value: \tgwRelaxAtom::run() step_position (end of iteration)=  " << step_position << endl;
00174     cerr << "Working\tgwRelaxAtom::run() done iteration number " << iteration << endl << endl;
00175 #endif          
00176 
00177     iteration++;
00178   } // end of inner iteration loop
00179 
00180 // #ifdef GNOMAD_OUTPUT
00181 //     printf("  In vdw_segs\n");
00182 //     printf("    initial x, y, z = %lf  %lf  %lf\n", prev_position[0], prev_position[1], prev_position[2]);
00183 //     printf("    initial direction vector = %lf  %lf  %lf\n", prev_direction[0], prev_direction[1], prev_direction[2]);
00184 //   //  printf("    initial lbound, ubound = %lf %lf\n", *lbound, *ubound);
00185 //   //  printf("    num_segments = %d\n\n", *num_segments);
00186 // #endif
00187 
00188   
00189   //  if (step_length != 1) cerr  << step_length << endl;
00190   
00191   /* do hard constraint (VDW) check. */
00192   //jVector ddd = prev_position;
00193   
00194   
00195 
00196 //     cerr << "Value: \tgwRelaxAtom::after iterator step_position =  " << step_position <<endl;
00197 //     cerr << "Value: \tgwRelaxAtom::after iterator prev_position =  " << prev_position <<endl;
00198 //     cerr << "Value: \tgwRelaxAtom::after iterator step_length =  " << step_length <<endl;
00199     
00200     new_position = gwNumerics::SetHCPosition2(start_position, prev_position,prev_direction,
00201                                             *CM, atom_index, step_length, gwNumerics::MaxAbsDistRes);
00202 
00203 
00204 //   jVector new_position2 = gwNumerics::SetHCPosition(start_position, prev_position,prev_direction,
00205 //                                                  *CM, atom_index, step_length);
00206 // 
00207 //   if (euclid(new_position, new_position2) > 0.5) {
00208 //     cout << "\nACK:  atom=" << atom_index << " grd=" << new_position << " trd=" << new_position2 << flush;
00209 //   }
00210   
00211     CM->setPosition(atom_index, new_position);
00212 
00213 //   if (EC){
00214 //     //    direction = EC->getDirection(new_position);
00215 //     //  cerr << "atom_index:" << atom_index << "pos: " << new_position << "Dir:" << direction << endl;
00216 //     CM->setPosition(atom_index, new_position+direction);
00217 //   }
00218 
00219     
00220   //  DLList<int> Moved;
00221   //  CM->setPosition(atom_index, prev_position+(prev_direction*step_length));
00222   //  gwNumerics::LocalPert(atom_index, *CM, CM->stress(atom_index), start_position);
00223   //cerr <<"PRE-SPREAD DIST MOVED"<< euclid(prev_position,start_position) << endl;
00224   //  gwNumerics::SpreadR(atom_index, CM->getRadius(atom_index), Moved,
00225   //          0, *CM, CM->getPosition(atom_index), prev_direction);
00226 
00227 
00228   
00229   // shows how much Hard constraint would have moved the atom
00230   // ddd = (ddd -  CM->getMolecule()(atom_index));
00231   // cerr << ddd.mag() << endl;
00232 
00233 
00234 
00235 // #ifdef GNOMAD_OUTPUT
00236 //   printf("  after checks for atom %d\n", atom_index);
00237 //   printf("    x, y, z = %lf  %lf  %lf\n", CM->getMolecule()(atom_index)[0],  CM->getMolecule()(atom_index)[1],
00238 //       CM->getMolecule()(atom_index)[2]);
00239 //   printf("    fv = %lf\n",  CM->stress(atom_index));
00240 //     
00241 // //   printf("    atomcount = %d\n", );
00242 // //   maxresid = 0.0;
00243 // //   for(i=0; i<ndis; i++) {
00244 // //     if(dis[i].resid>maxresid) {
00245 // //       maxresid = dis[i].resid;
00246 // //       maxatom1 = dis[i].atom1;
00247 // //       maxatom2 = dis[i].atom2;
00248 // //     }
00249 // //   }
00250 \end{verbatim}\normalsize 


\subsection{Member Data Documentation}
\index{gwRelaxAtom@{gw\-Relax\-Atom}!atom_index@{atom\_\-index}}
\index{atom_index@{atom\_\-index}!gwRelaxAtom@{gw\-Relax\-Atom}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int gw\-Relax\-Atom::atom\_\-index\hspace{0.3cm}{\tt  [private]}}\label{class_gwRelaxAtom_o0}


The index of the atom in the molecule this process is associated with.



Definition at line 67 of file gw\_\-relax\_\-atom.h.\index{gwRelaxAtom@{gw\-Relax\-Atom}!max_iterations@{max\_\-iterations}}
\index{max_iterations@{max\_\-iterations}!gwRelaxAtom@{gw\-Relax\-Atom}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int gw\-Relax\-Atom::max\_\-iterations = 40\hspace{0.3cm}{\tt  [static]}}\label{class_gwRelaxAtom_p0}


Maximum nuber of times to perform linesearch while updating atom.



Definition at line 32 of file globals.C.

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