\section{grape.C File Reference}
\label{grape_C}\index{grape.C@{grape.C}}
{\tt \#include $<$fstream.h$>$}\par
{\tt \#include "dynstring.h"}\par
{\tt \#include "dllist.h"}\par
{\tt \#include "constraint\_\-manager.h"}\par
{\tt \#include "constraint\_\-registry.h"}\par
{\tt \#include "error\_\-handler.h"}\par
{\tt \#include "globals.h"}\par


Include dependency graph for grape.C:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=206pt]{grape_C_incl}
\end{center}
\end{figure}
\subsection*{Functions}
\begin{CompactItemize}
\item 
void {\bf print\_\-usage} (ostream \&os)
\begin{CompactList}\small\item\em Prints information about usage.\item\end{CompactList}\item 
void {\bf print\_\-help} (ostream \&os)
\begin{CompactList}\small\item\em Prints full help.\item\end{CompactList}\item 
int {\bf main} (int argc, char $\ast$$\ast$argv)
\end{CompactItemize}


\subsection{Function Documentation}
\index{grape.C@{grape.C}!main@{main}}
\index{main@{main}!grape.C@{grape.C}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int main (int {\em argc}, char $\ast$$\ast$ {\em argv})}\label{grape_C_a2}




Definition at line 17 of file grape.C.\footnotesize\begin{verbatim}00017                                  {
00018   if(argc < 2)
00019     {            
00020       print_usage(cout);
00021       return 0;
00022     }
00023   
00024   cerr << "Begin: ";
00025   for (int i =0; i < argc; i++){
00026     cerr << argv[i]<<" ";
00027   }
00028   cerr << endl;
00029   
00031   DLList<DynString> ArgList;
00032 
00034   DLList<DynString> ConstraintFileList;
00035 
00037   Molecule * predictedMolecule=0;
00038 
00039   ofstream *AnimOut = 0;
00040   // default fstream for xmol frames
00041   
00042   // Iterate through all the command line arguments:
00043   DynString arg;
00044 
00045   // File for initial positions
00046   DynString positionFile = "";
00047   
00048   SatisfyMolecule * TOP;
00049 
00050   // Command-line argument.
00051   ifstream * input=0;
00052   // Parameter input stream.
00053   int argStart = 1;
00054 
00055   // See if the user has specified a parameter file.  It is a 
00056   // parameter file if the first argument does *not* start with
00057   // a dash, '-' (i.e. it is not a flag).
00058   //
00059 
00060   DynString BaseFN = "grape-output"; // final xmol filename
00061   DynString AnimFN = ""; // anim filename -- defaults to off
00062   
00063   
00064   if(argv[1][0] != '-')
00065     {
00066       // Read in the arguments from the parameter file.  This file should
00067       // contain flags (including their dashes) followed immediately by
00068       // the values associated with them.  Warning: this processing step
00069       // ignores white space!
00070       //
00071       if(!(input = new ifstream(argv[1])))
00072         {
00073           cerr << "Could not open/find parameter file, " << argv[1]
00074                << ", quitting. Try -help option.\n";
00075           return 1;
00076         }
00077       while(!input->eof() && !input->bad())
00078         {
00079           *input >> arg;
00080 
00081           if(arg[0] == '#')
00082             arg.EatLine(*input);
00083           // Ignore lines that begin with a pound, '#', sign:
00084           else
00085             ArgList.AddToBack(arg);
00086         }
00087       ArgList.RemoveFromBack();  // Get rid of the eof character.
00088 
00089       delete input; input=0;
00090       argStart=2;
00091     }
00092 
00093   // Copy the arguments from the command line onto our argument list:
00094   //
00095   for(int a=argStart; a<argc; ++a)
00096     ArgList.AddToBack(DynString(argv[a]));
00097 
00098   while(ArgList)
00099     {
00100       arg = ArgList.RemoveFromFront();
00101       
00102       if((arg == DynString("-residues")) ||
00103               (arg == DynString("-res"))) {
00104           
00105         // Check to see if we've already read in a molecule:
00106           if(predictedMolecule)
00107             {
00108               cerr << "Warning: More than one file has been supplied for "
00109                    << "the initial molecule.\nWill use the molecule "
00110                    << "specified in the file listed last.\n";
00111               delete predictedMolecule; predictedMolecule=0;
00112             }
00113           arg = ArgList.RemoveFromFront();  // Get number of atoms
00114           if((input = new ifstream(arg.GetData())))
00115             {     
00116               predictedMolecule = new Molecule;
00117           
00118               if(predictedMolecule->readFasta(*input)<2)
00119                 {
00120                   cerr << "Error generating molecule from residue sequence.\n";
00121                   delete predictedMolecule; predictedMolecule=0;
00122                 }
00123               delete input;input = 0;
00124             } else {
00125               cerr << "Could not open initial FASTA file, " << arg
00126                    << ", will try default location.\n";
00127               
00128             }     
00129       }
00130 
00131       // Initial atom positions
00132       //
00133       else if((arg == DynString("-initial")) ||
00134               (arg == DynString("-init")) ||
00135               (arg == DynString("-i"))) {
00136 
00137         positionFile = ArgList.RemoveFromFront();  // Get the name of the xmol file.
00138 
00139       }
00140 
00141       else if(arg == DynString("-random")){
00142         
00143         positionFile = "random";
00144 
00145       }
00146 
00147 
00148       // Constraint file is being specified.
00149       //
00150       else if((arg == DynString("-constraint")) ||
00151               (arg == DynString("-constraints")) ||
00152               (arg == DynString("-c")))
00153         {
00154           // Just add this file to the list of files that contain
00155           // constraints for right now.  We'll read these in once 
00156           // we're sure we have an initial molecule.
00157           //
00158           arg = ArgList.RemoveFromFront();
00159           ConstraintFileList.AddToBack(arg);
00160         }
00161 
00162 //       // Read in van der Waal radius:
00163 //       //
00164 //       else if(arg == DynString("-vdw") ||
00165 //            arg == DynString("-vdwradius"))
00166 //      {
00167 //        double val[4];
00168 //        for(int i=0; i<4; ++i){
00169 //          if (ArgList.IsEmpty()) {
00170 //            DIE("Error while parsing the vdw arguments. Try -help option.");
00171 //          }
00172 //          arg = ArgList.RemoveFromFront();
00173 //          val[i] = arg.ToDbl();
00174 //        }
00175 //        gwNumerics::VDWRadius = val;
00176 //      }
00177 //      
00178 //       // Read in local perturbation radius:
00179 //       //
00180 //       else if(arg == DynString("-lpr") ||
00181 //            arg == DynString("-lpradius"))
00182 //      {
00183 //        double val[4];
00184 //        for(int i=0; i<4; ++i){
00185 //          if (ArgList.IsEmpty()) {
00186 //            DIE("Error while  parsing the lpr arguments. Try -help option.");
00187 //          }
00188 //          arg = ArgList.RemoveFromFront();
00189 //          val[i] = arg.ToDbl();
00190 //        }
00191 //        gwNumerics::LPertRadius = val;
00192 //      }
00193 
00194       // Set vdw checking vs all or vs moved
00195       //
00196       else if(arg == DynString("-vom"))
00197         {
00198           if (ArgList.IsEmpty()) {
00199             DIE("Error while  parsing the vom argument. Try -help option.");
00200           }
00201           arg = ArgList.RemoveFromFront();
00202           if(arg == DynString("true") || arg == DynString("t") ||
00203              arg == DynString("True") || arg == DynString("TRUE") ||
00204              arg == DynString("T") || arg == DynString("1"))
00205             gwNumerics::UseOnlyMoved = true;
00206           else if(arg == DynString("false") || arg == DynString("f") ||
00207                   arg == DynString("False") || arg == DynString("FALSE") ||
00208                   arg == DynString("F") || arg == DynString("0"))             
00209             gwNumerics::UseOnlyMoved = false;
00210           else cerr << "Unable do understand vom arg. Not set -- defaults to true\n";     
00211         }
00212 
00213       
00214 
00215       else if(arg == DynString("-f") ||
00216               arg == DynString("-filebase"))
00217         {
00218             arg = ArgList.RemoveFromFront();
00219             if (arg[0] != '-'){
00220               BaseFN = arg;
00221             } else {
00222               DIE("Confused by filename ");
00223             }
00224         }
00225 
00226       
00227       // Read in flag for local perturbations:
00228       //
00229       else if(arg == DynString("-lp") ||
00230               arg == DynString("-lpert") )
00231         {
00232           arg = ArgList.RemoveFromFront();
00233           if(arg == DynString("true") || arg == DynString("t") ||
00234              arg == DynString("True") || arg == DynString("TRUE") ||
00235              arg == DynString("T") || arg == DynString("1"))
00236             gwNumerics::LocalPerturb = true;
00237           else if(arg == DynString("false") || arg == DynString("f") ||
00238                   arg == DynString("False") || arg == DynString("FALSE") ||
00239                   arg == DynString("F") || arg == DynString("0"))             
00240             gwNumerics::LocalPerturb = false;
00241           else cerr << "Unable do understand lp or lpert. Not set.\n";
00242         }
00243 
00244       // Least-squares success tolerance:
00245       //
00246       else if(arg == DynString("-lssucc"))
00247         {
00248           arg = ArgList.RemoveFromFront();
00249           gwNumerics::ls_succ_tolerance = arg.ToDbl();
00250         }
00251         
00252       // Read in the least-squares derivative tolerance:
00253       //
00254       else if(arg == DynString("-lsderiv"))
00255         {
00256           arg = ArgList.RemoveFromFront();
00257           gwNumerics::ls_deriv_tolerance = arg.ToDbl();
00258         }
00259 
00260       // Read in the least-squares distance tolerance:
00261       //
00262       else if(arg == DynString("-lsdist"))
00263         {
00264           arg = ArgList.RemoveFromFront();
00265           gwNumerics::ls_dist_tolerance = arg.ToDbl();
00266         }
00267 
00268       // Set the maximum number of iterations allowed:
00269       //
00270       else if(arg == DynString("-iter"))
00271         {
00272           arg = ArgList.RemoveFromFront();
00273           gwRelaxAtom::max_iterations = arg.ToInt();
00274         }
00275 
00276       // Set the number of cycles:
00277       //
00278       else if(arg == DynString("-cycles"))
00279         {
00280           arg = ArgList.RemoveFromFront();
00281           int n = arg.ToInt();
00282           jdIterator::MaxIterations = n;          
00283           StopEval::Enable = false;  // turn off auto stop (early) features
00284         }
00285 
00286       else if((arg == DynString("-buildcycles")) ||
00287                (arg == DynString("-bc")) )
00288         {
00289           arg = ArgList.RemoveFromFront();
00290           AtomBuildup::MaxIterations = arg.ToInt();
00291           arg = ArgList.RemoveFromFront();        
00292           AtomBuildup::MaxFinalIterations = arg.ToInt();
00293         }
00294       
00295       
00296       else if(arg == DynString("-cyclelimit"))
00297         {
00298           arg = ArgList.RemoveFromFront();
00299           jdIterator::MaxIterations = arg.ToInt();
00300         }
00301 
00302       else if ((arg == DynString("-quiet")) ||
00303                (arg == DynString("-q")))
00304         {
00305           StopEval::Quiet = true;
00306         }
00307 
00308       else if (arg == DynString("-rtp"))
00309         {
00310           StopEval::Quiet = true;
00311           StopEval::VerboseOn = false;
00312           StopEval::Rtp  = true;
00313         }
00314 
00315       else if((arg == DynString("-anim")) ||
00316                (arg == DynString("-a")))
00317         {
00318           arg = ArgList.RemoveFromFront();
00319           AnimFrame::Enabled = true;
00320           AnimFN = arg;
00321         }
00322       else if(arg == DynString("-help"))
00323         {
00324           print_help(cout);
00325           return 0;
00326             
00327         }
00328 
00329       // Ignore the bogus parameter.
00330       //
00331       else
00332         {
00333           cerr << "Unknown argument, " << arg << ", given, ignoring.\n";
00334         }
00335     }// end processing of arglist
00336 
00337   
00338   // If we havent read in a set of residues, quit.
00339   if(!predictedMolecule)
00340     {
00341       cerr << "No initial molecule specified, quitting. Try -help option.\n";
00342       return 3;
00343     }
00344   
00345   if (positionFile != "") {
00346     // no atom buildup, specify positions    
00347     
00348     if (positionFile != "random") {
00349       if((input = new ifstream(positionFile.GetData())))
00350         {
00351           if(predictedMolecule->readXmol(*input)<2)
00352             {
00353               cerr << "Error reading initial positions from " << positionFile << ".  Check the file.\n";
00354               delete predictedMolecule; predictedMolecule=0;
00355               return 4;
00356             }
00357           delete input; input=0;
00358         }
00359       else
00360         {
00361           cerr << "Could not open initial molecule file, " << positionFile << ".\n";
00362           return 5;
00363         }
00364     } else {
00365       // set postions randomly
00366       if(predictedMolecule->setRandom()<2)      {
00367         cerr << "Error generating random molecule.\n";
00368         delete predictedMolecule; predictedMolecule=0;
00369         return 6;
00370       }        
00371     }
00372 
00373   }
00374   
00375   // Now that we've got an actual molecule, we can create a constraint
00376   // manager and read in the constraints:
00377   //
00378   ConstraintManager CM(*predictedMolecule);
00379   //  CM.RandomPerturb(.1);
00380   
00381   int num_read = 0;
00382   
00383   while(ConstraintFileList)
00384     {
00385       // Get the filename and then open the file and then read the
00386       // constraints in using the constraint manager.
00387       arg = ConstraintFileList.RemoveFromFront();
00388       input = new ifstream(arg.GetData());
00389       if(input->good())
00390         {
00391           // Use the registry's routine to read in constraints and
00392           // append them to the constraint manager.
00393           //
00394 
00395           num_read += ConstraintRegistry::readConstraints(*input,CM);
00396           delete input; input=0;
00397         } else {
00398           cerr << "\n\nWhile reading file: " << arg.GetData() << endl;
00399           DIE ("Cannot open file");
00400         }
00401 
00402     }      
00403 
00404   if (num_read == 0) {
00405     DIE ("You have no constraints");
00406   }
00407 
00408   //
00409   // Begin Sanity Checks
00410   //
00411 
00412   //    DLList<Atom> LA;
00413   //     Atom atom;
00414   //     for(int i=0; i<predictedMolecule->Number(); ++i)
00415   //       {
00416   //         LA = CM.getAssocAtoms(i);
00417   //    cout << "atom(" << i << "): ";
00418   //    while(LA)
00419   //      {
00420   //        atom = LA.RemoveFromFront();
00421   //        cout << atom.ID() << ' ';
00422   //      }
00423   //         cout << '\n';
00424   //       }
00425   //     
00426   //     DLList<Constraint*>::ConstIterator it;
00427   //     Constraint * c;
00428   //     for(it = CM.getConstraintList().GetConstIterator(); it; ++it)
00429   //       {
00430   //         c = *it;
00431   //    cout << *c << '\n';
00432   //       }
00433   // 
00434   // 
00435   //
00436   // End Sanity Checks
00437   //
00438 
00439   if (positionFile != "") {
00440     TOP = new jdIterator(CM);
00441   } else {
00442     TOP = new AtomBuildup(CM);
00443   }
00444 \end{verbatim}\normalsize 
\index{grape.C@{grape.C}!print_help@{print\_\-help}}
\index{print_help@{print\_\-help}!grape.C@{grape.C}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void print\_\-help (ostream \& {\em os})}\label{grape_C_a1}


Prints full help.



Definition at line 484 of file grape.C.\footnotesize\begin{verbatim}00485 {
00486   os    << "\nHELP for using GRAPE\n\n";
00487   print_usage(os);
00488   os    << "Additional Options:\n"
00489         << "  {-vdw | -vdwradius} n1 n2 n3 n4\n"
00490         << "     Sets a global Van Der Waals Radius for Objective Function \n"
00491         << "     Values less than n1 to radius value n2 and to value n4 for \n"
00492         << "     OFV > n3+n1.\n"
00493         << "  {-lp | -lpert} {0|1|true|false}\n"
00494         << "     Enables or disables local pertubation.\n"
00495         << "  {-lpr | -lpradius} n1 n2 n3 n4\n"
00496         << "     Sets the global local perturbation radius as described above\n"
00497         << "  {-cycles n}\n"
00498         << "     Forces the simluation to run for n cycles.\n"
00499         << "  {-cyclelimit n}\n"
00500         << "     Limits the simluation to run for at most n cycles.\n"
00501         << "  {-a | -anim} cout | cerr | filename \n"
00502         << "     Write out xmol animation frames to stream or file.\n"
00503         << "  {-f | -filebase} filename \n"
00504         << "     Write final atom positions to filename\n"
00505         << "  {-q | -quiet} \n"
00506         << "     Run in quiet mode. \n"
00507         << "  {-rtp}
00508 \end{verbatim}\normalsize 
\index{grape.C@{grape.C}!print_usage@{print\_\-usage}}
\index{print_usage@{print\_\-usage}!grape.C@{grape.C}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void print\_\-usage (ostream \& {\em os})}\label{grape_C_a0}


Prints information about usage.



Definition at line 471 of file grape.C.\footnotesize\begin{verbatim}00472 {
00473   os    << "\nUsage: grape <-help> [optionfilename | options] \n\n"
00474         << "Required options:\n"
00475         << "  {-initial | -init | -i} <filename>  | -random n }\n"
00476         << "     Initial molecule: xmol file or random molecule with n atoms\n"
00477         << "  or {-residue | -res} <filename>}\n"
00478         << "     Initial molecule: fasta file, implies random start <for now>\n"
00479         << "  {-constraints | -c}
00480 \end{verbatim}\normalsize 
