| 1 | /** \file builder.cpp
 | 
|---|
| 2 |  *
 | 
|---|
| 3 |  *  date: Jan 1, 2007
 | 
|---|
| 4 |  *  author: heber
 | 
|---|
| 5 |  *
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | /*! \mainpage MoleCuilder - a molecular set builder
 | 
|---|
| 9 |  *
 | 
|---|
| 10 |  * This introductory shall briefly make acquainted with the program, helping in installing and a first run.
 | 
|---|
| 11 |  *
 | 
|---|
| 12 |  * \section about About the Program
 | 
|---|
| 13 |  *
 | 
|---|
| 14 |  *  MoleCuilder is a program, written entirely in C++, that enables the construction of a coordinate set for the
 | 
|---|
| 15 |  *  atoms making up an molecule. It allows for both building of simple molecules by adding atom-wise giving bond
 | 
|---|
| 16 |  *  angles and distances or absolute coordinates, but also using them as templates. Regions can be specified and
 | 
|---|
| 17 |  *  ordered to be filled with a molecule in a certain manner. Greater conglomerations of molecules can be tesselated
 | 
|---|
| 18 |  *  and recognized as a region themselves to be subsequently surrounded by other (surface solvated) molecules.
 | 
|---|
| 19 |  *  In the end, MoleCuilder allows the construction of arbitrary nano structures, whether they be crystalline or
 | 
|---|
| 20 |  *  amorphic in nature.
 | 
|---|
| 21 |  *
 | 
|---|
| 22 |  *
 | 
|---|
| 23 |  * \section install Installation
 | 
|---|
| 24 |  *
 | 
|---|
| 25 |  *  Installation should without problems succeed as follows:
 | 
|---|
| 26 |  *  -# ./configure (or: mkdir build;mkdir run;cd build; ../configure --bindir=../run)
 | 
|---|
| 27 |  *  -# make
 | 
|---|
| 28 |  *  -# make install
 | 
|---|
| 29 |  *
 | 
|---|
| 30 |  *  Further useful commands are
 | 
|---|
| 31 |  *  -# make clean uninstall: deletes .o-files and removes executable from the given binary directory\n
 | 
|---|
| 32 |  *  -# make doxygen-doc: Creates these html pages out of the documented source
 | 
|---|
| 33 |  *  -# make check: Runs an extensive set of unit tests and a testsuite which also gives a good overview on the set of
 | 
|---|
| 34 |  *                 functions.
 | 
|---|
| 35 |  *
 | 
|---|
| 36 |  * \section run Running
 | 
|---|
| 37 |  *
 | 
|---|
| 38 |  *  The program can be executed by running: ./molecuilder
 | 
|---|
| 39 |  *
 | 
|---|
| 40 |  *  MoleCuilder has three interfaces at your disposal:
 | 
|---|
| 41 |  *  -# Textmenu: A simple interactive console-based menu, where awaits your choices and inputs in order to set atoms
 | 
|---|
| 42 |  *               as you like
 | 
|---|
| 43 |  *  -# CommandLineUI: Every command can also be chained up as a sequence of actions on the command line to be executed
 | 
|---|
| 44 |  *               with any user interaction.
 | 
|---|
| 45 |  *  -# GraphicalUI: A graphical user interface that also display the molecular structure being built and lots of other
 | 
|---|
| 46 |  *               informations to ease the construction of bigger geometries.
 | 
|---|
| 47 |  *
 | 
|---|
| 48 |  *  The supported output formats right now are:
 | 
|---|
| 49 |  *  -# mpqc: Configuration files of the Massively Parallel Quantum Chemistry package (Sandia labs)
 | 
|---|
| 50 |  *  -# pcp: Configuration files of the Parallel Car-Parrinello program (Institute for Numerical Simulation)
 | 
|---|
| 51 |  *  -# tremolo: Configuration files of TREMOLO (Institute for Numerical Simulation)
 | 
|---|
| 52 |  *  -# xyz: the most basic format for the 3d arrangement of atoms consisting of a list of element and 3 coordinates.
 | 
|---|
| 53 |  *
 | 
|---|
| 54 |  */
 | 
|---|
| 55 | 
 | 
|---|
| 56 | #include "Helpers/MemDebug.hpp"
 | 
|---|
| 57 | 
 | 
|---|
| 58 | #include "bondgraph.hpp"
 | 
|---|
| 59 | #include "CommandLineParser.hpp"
 | 
|---|
| 60 | #include "config.hpp"
 | 
|---|
| 61 | #include "log.hpp"
 | 
|---|
| 62 | #include "verbose.hpp"
 | 
|---|
| 63 | #include "World.hpp"
 | 
|---|
| 64 | 
 | 
|---|
| 65 | #include "Actions/ActionRegistry.hpp"
 | 
|---|
| 66 | #include "Actions/ActionHistory.hpp"
 | 
|---|
| 67 | #include "Actions/MapOfActions.hpp"
 | 
|---|
| 68 | 
 | 
|---|
| 69 | #include "Parser/ChangeTracker.hpp"
 | 
|---|
| 70 | #include "Parser/FormatParserStorage.hpp"
 | 
|---|
| 71 | 
 | 
|---|
| 72 | #include "UIElements/UIFactory.hpp"
 | 
|---|
| 73 | #include "UIElements/TextUI/TextUIFactory.hpp"
 | 
|---|
| 74 | #include "UIElements/CommandLineUI/CommandLineUIFactory.hpp"
 | 
|---|
| 75 | #include "UIElements/MainWindow.hpp"
 | 
|---|
| 76 | #include "UIElements/Dialog.hpp"
 | 
|---|
| 77 | 
 | 
|---|
| 78 | #include "version.h"
 | 
|---|
| 79 | 
 | 
|---|
| 80 | 
 | 
|---|
| 81 | /********************************************** Main routine **************************************/
 | 
|---|
| 82 | 
 | 
|---|
| 83 | void cleanUp(){
 | 
|---|
| 84 |   FormatParserStorage::purgeInstance();
 | 
|---|
| 85 |   ChangeTracker::purgeInstance();
 | 
|---|
| 86 |   World::purgeInstance();
 | 
|---|
| 87 |   logger::purgeInstance();
 | 
|---|
| 88 |   errorLogger::purgeInstance();
 | 
|---|
| 89 |   UIFactory::purgeInstance();
 | 
|---|
| 90 |   MapOfActions::purgeInstance();
 | 
|---|
| 91 |   CommandLineParser::purgeInstance();
 | 
|---|
| 92 |   ActionRegistry::purgeInstance();
 | 
|---|
| 93 |   ActionHistory::purgeInstance();
 | 
|---|
| 94 | #ifdef LOG_OBSERVER
 | 
|---|
| 95 |   cout << observerLog().getLog();
 | 
|---|
| 96 | #endif
 | 
|---|
| 97 |   Memory::getState();
 | 
|---|
| 98 | }
 | 
|---|
| 99 | 
 | 
|---|
| 100 | int main(int argc, char **argv)
 | 
|---|
| 101 | {
 | 
|---|
| 102 |   // while we are non interactive, we want to abort from asserts
 | 
|---|
| 103 |   //ASSERT_DO(Assert::Abort);
 | 
|---|
| 104 |   string line;
 | 
|---|
| 105 |   char **Arguments = NULL;
 | 
|---|
| 106 |   int ArgcSize = 0;
 | 
|---|
| 107 |   int ExitFlag = 0;
 | 
|---|
| 108 |   bool ArgumentsCopied = false;
 | 
|---|
| 109 |   std::string BondGraphFileName("\n");
 | 
|---|
| 110 |   FormatParserStorage::getInstance().addMpqc();
 | 
|---|
| 111 |   FormatParserStorage::getInstance().addPcp();
 | 
|---|
| 112 |   FormatParserStorage::getInstance().addXyz();
 | 
|---|
| 113 | 
 | 
|---|
| 114 |   // print version check whether arguments are present at all
 | 
|---|
| 115 |   cout << ESPACKVersion << endl;
 | 
|---|
| 116 | 
 | 
|---|
| 117 |   setVerbosity(0);
 | 
|---|
| 118 |   // need to init the history before any action is created
 | 
|---|
| 119 |   ActionHistory::init();
 | 
|---|
| 120 | 
 | 
|---|
| 121 |   // In the interactive mode, we can leave the user the choice in case of error
 | 
|---|
| 122 |   ASSERT_DO(Assert::Ask);
 | 
|---|
| 123 | 
 | 
|---|
| 124 |   // from this moment on, we need to be sure to deeinitialize in the correct order
 | 
|---|
| 125 |   // this is handled by the cleanup function
 | 
|---|
| 126 |   atexit(cleanUp);
 | 
|---|
| 127 | 
 | 
|---|
| 128 |   // Parse command line options and if present create respective UI
 | 
|---|
| 129 |   {
 | 
|---|
| 130 |     // construct bond graph
 | 
|---|
| 131 |     if (World::getInstance().getConfig()->BG == NULL) {
 | 
|---|
| 132 |       World::getInstance().getConfig()->BG = new BondGraph(World::getInstance().getConfig()->GetIsAngstroem());
 | 
|---|
| 133 |       if (World::getInstance().getConfig()->BG->LoadBondLengthTable(BondGraphFileName)) {
 | 
|---|
| 134 |         DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl);
 | 
|---|
| 135 |       } else {
 | 
|---|
| 136 |         DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl);
 | 
|---|
| 137 |       }
 | 
|---|
| 138 |     }
 | 
|---|
| 139 |     // handle remaining arguments by CommandLineParser
 | 
|---|
| 140 |     if (argc>1) {
 | 
|---|
| 141 |       MapOfActions::getInstance().AddOptionsToParser();
 | 
|---|
| 142 |       map <std::string, std::string> ShortFormToActionMap = MapOfActions::getInstance().getShortFormToActionMap();
 | 
|---|
| 143 |       CommandLineParser::getInstance().Run(argc,argv, ShortFormToActionMap);
 | 
|---|
| 144 |       DoLog(0) && (Log() << Verbose(0) << "Setting UI to CommandLine." << endl);
 | 
|---|
| 145 |       UIFactory::registerFactory(new CommandLineUIFactory::description());
 | 
|---|
| 146 |       UIFactory::makeUserInterface("CommandLine");
 | 
|---|
| 147 |     } else {
 | 
|---|
| 148 |       DoLog(0) && (Log() << Verbose(0) << "Setting UI to Text." << endl);
 | 
|---|
| 149 |       UIFactory::registerFactory(new TextUIFactory::description());
 | 
|---|
| 150 |       UIFactory::makeUserInterface("Text");
 | 
|---|
| 151 |     }
 | 
|---|
| 152 |   }
 | 
|---|
| 153 | 
 | 
|---|
| 154 |   {
 | 
|---|
| 155 |     MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow();
 | 
|---|
| 156 |     mainWindow->display();
 | 
|---|
| 157 |     delete mainWindow;
 | 
|---|
| 158 |   }
 | 
|---|
| 159 | 
 | 
|---|
| 160 |   FormatParserStorage::getInstance().SaveAll();
 | 
|---|
| 161 |   ChangeTracker::getInstance().saveStatus();
 | 
|---|
| 162 | 
 | 
|---|
| 163 |   // free the new argv
 | 
|---|
| 164 |   if (ArgumentsCopied) {
 | 
|---|
| 165 |     for (int i=0; i<ArgcSize;i++)
 | 
|---|
| 166 |       delete[](Arguments[i]);
 | 
|---|
| 167 |     delete[](Arguments);
 | 
|---|
| 168 |   }
 | 
|---|
| 169 |   //delete[](ConfigFileName);
 | 
|---|
| 170 | 
 | 
|---|
| 171 |   ExitFlag = World::getInstance().getExitFlag();
 | 
|---|
| 172 |   return (ExitFlag == 1 ? 0 : ExitFlag);
 | 
|---|
| 173 | }
 | 
|---|
| 174 | 
 | 
|---|
| 175 | /********************************************** E N D **************************************************/
 | 
|---|