| [14de469] | 1 | /** \file builder.cpp
 | 
|---|
| [a8bcea6] | 2 |  *
 | 
|---|
| [a356f2] | 3 |  *  date: Jan 1, 2007
 | 
|---|
 | 4 |  *  author: heber
 | 
|---|
| [a8bcea6] | 5 |  *
 | 
|---|
| [14de469] | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
| [a356f2] | 8 | /*! \mainpage MoleCuilder - a molecular set builder
 | 
|---|
| [a8bcea6] | 9 |  *
 | 
|---|
| [a356f2] | 10 |  * This introductory shall briefly make acquainted with the program, helping in installing and a first run.
 | 
|---|
| [a8bcea6] | 11 |  *
 | 
|---|
| [14de469] | 12 |  * \section about About the Program
 | 
|---|
| [a8bcea6] | 13 |  *
 | 
|---|
| [a356f2] | 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.
 | 
|---|
| [a8bcea6] | 21 |  *
 | 
|---|
 | 22 |  *
 | 
|---|
| [14de469] | 23 |  * \section install Installation
 | 
|---|
| [a8bcea6] | 24 |  *
 | 
|---|
| [042f82] | 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
 | 
|---|
| [a8bcea6] | 29 |  *
 | 
|---|
| [042f82] | 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
 | 
|---|
| [a356f2] | 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.
 | 
|---|
| [a8bcea6] | 35 |  *
 | 
|---|
| [14de469] | 36 |  * \section run Running
 | 
|---|
| [a8bcea6] | 37 |  *
 | 
|---|
| [042f82] | 38 |  *  The program can be executed by running: ./molecuilder
 | 
|---|
| [a8bcea6] | 39 |  *
 | 
|---|
| [a356f2] | 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.
 | 
|---|
| [a8bcea6] | 47 |  *
 | 
|---|
| [a356f2] | 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.
 | 
|---|
| [a8bcea6] | 53 |  *
 | 
|---|
| [14de469] | 54 |  */
 | 
|---|
 | 55 | 
 | 
|---|
| [112b09] | 56 | #include "Helpers/MemDebug.hpp"
 | 
|---|
| [14de469] | 57 | 
 | 
|---|
| [b70721] | 58 | #include "bondgraph.hpp"
 | 
|---|
| [c6efc1] | 59 | #include "CommandLineParser.hpp"
 | 
|---|
| [f66195] | 60 | #include "config.hpp"
 | 
|---|
| [e138de] | 61 | #include "log.hpp"
 | 
|---|
| [cee0b57] | 62 | #include "molecule.hpp"
 | 
|---|
| [f66195] | 63 | #include "periodentafel.hpp"
 | 
|---|
| [bfd839] | 64 | #include "tesselationhelpers.hpp"
 | 
|---|
| [cc04b7] | 65 | #include "UIElements/UIFactory.hpp"
 | 
|---|
| [5f5a7b] | 66 | #include "UIElements/TextUI/TextUIFactory.hpp"
 | 
|---|
 | 67 | #include "UIElements/CommandLineUI/CommandLineUIFactory.hpp"
 | 
|---|
| [82b71a] | 68 | #ifdef USE_GUI_QT
 | 
|---|
 | 69 | #include "UIElements/QT4/QTUIFactory.hpp"
 | 
|---|
 | 70 | #endif
 | 
|---|
| [cc04b7] | 71 | #include "UIElements/MainWindow.hpp"
 | 
|---|
| [45f5d6] | 72 | #include "UIElements/Dialog.hpp"
 | 
|---|
| [12b845] | 73 | #include "Menu/ActionMenuItem.hpp"
 | 
|---|
| [a356f2] | 74 | #include "verbose.hpp"
 | 
|---|
 | 75 | #include "World.hpp"
 | 
|---|
 | 76 | 
 | 
|---|
| [12b845] | 77 | #include "Actions/ActionRegistry.hpp"
 | 
|---|
| [d56640] | 78 | #include "Actions/ActionHistory.hpp"
 | 
|---|
| [97ebf8] | 79 | #include "Actions/MapOfActions.hpp"
 | 
|---|
| [042f82] | 80 | 
 | 
|---|
| [a356f2] | 81 | #include "Parser/ChangeTracker.hpp"
 | 
|---|
 | 82 | #include "Parser/FormatParserStorage.hpp"
 | 
|---|
| [1907a7] | 83 | 
 | 
|---|
| [a356f2] | 84 | #include "UIElements/UIFactory.hpp"
 | 
|---|
 | 85 | #include "UIElements/TextUI/TextUIFactory.hpp"
 | 
|---|
 | 86 | #include "UIElements/CommandLineUI/CommandLineUIFactory.hpp"
 | 
|---|
 | 87 | #include "UIElements/MainWindow.hpp"
 | 
|---|
 | 88 | #include "UIElements/Dialog.hpp"
 | 
|---|
| [1f1b23] | 89 | 
 | 
|---|
| [a356f2] | 90 | #include "version.h"
 | 
|---|
| [1f1b23] | 91 | 
 | 
|---|
| [ca2b83] | 92 | 
 | 
|---|
 | 93 | /********************************************** Main routine **************************************/
 | 
|---|
| [14de469] | 94 | 
 | 
|---|
| [148d8f0] | 95 | void cleanUp(){
 | 
|---|
| [35b698] | 96 |   FormatParserStorage::purgeInstance();
 | 
|---|
| [a1e929] | 97 |   ChangeTracker::purgeInstance();
 | 
|---|
| [23b547] | 98 |   World::purgeInstance();
 | 
|---|
| [354859] | 99 |   logger::purgeInstance();
 | 
|---|
 | 100 |   errorLogger::purgeInstance();
 | 
|---|
| [97ebf8] | 101 |   UIFactory::purgeInstance();
 | 
|---|
 | 102 |   MapOfActions::purgeInstance();
 | 
|---|
| [c6efc1] | 103 |   CommandLineParser::purgeInstance();
 | 
|---|
| [e73a8a2] | 104 |   ActionRegistry::purgeInstance();
 | 
|---|
| [632bc3] | 105 |   ActionHistory::purgeInstance();
 | 
|---|
| [cd5047] | 106 | #ifdef LOG_OBSERVER
 | 
|---|
 | 107 |   cout << observerLog().getLog();
 | 
|---|
 | 108 | #endif
 | 
|---|
| [68f03d] | 109 |   Memory::getState();
 | 
|---|
| [354859] | 110 | }
 | 
|---|
 | 111 | 
 | 
|---|
| [ca2b83] | 112 | int main(int argc, char **argv)
 | 
|---|
 | 113 | {
 | 
|---|
| [a356f2] | 114 |   // while we are non interactive, we want to abort from asserts
 | 
|---|
 | 115 |   //ASSERT_DO(Assert::Abort);
 | 
|---|
 | 116 |   string line;
 | 
|---|
 | 117 |   char **Arguments = NULL;
 | 
|---|
 | 118 |   int ArgcSize = 0;
 | 
|---|
 | 119 |   int ExitFlag = 0;
 | 
|---|
 | 120 |   bool ArgumentsCopied = false;
 | 
|---|
 | 121 |   std::string BondGraphFileName("\n");
 | 
|---|
 | 122 | 
 | 
|---|
 | 123 |   // print version check whether arguments are present at all
 | 
|---|
 | 124 |   cout << ESPACKVersion << endl;
 | 
|---|
 | 125 | 
 | 
|---|
 | 126 |   setVerbosity(0);
 | 
|---|
 | 127 |   // need to init the history before any action is created
 | 
|---|
 | 128 |   ActionHistory::init();
 | 
|---|
 | 129 | 
 | 
|---|
 | 130 |   // In the interactive mode, we can leave the user the choice in case of error
 | 
|---|
 | 131 |   ASSERT_DO(Assert::Ask);
 | 
|---|
 | 132 | 
 | 
|---|
 | 133 |   // from this moment on, we need to be sure to deeinitialize in the correct order
 | 
|---|
 | 134 |   // this is handled by the cleanup function
 | 
|---|
 | 135 |   atexit(cleanUp);
 | 
|---|
 | 136 | 
 | 
|---|
 | 137 |   // Parse command line options and if present create respective UI
 | 
|---|
 | 138 |   {
 | 
|---|
 | 139 |     // construct bond graph
 | 
|---|
 | 140 |     if (World::getInstance().getConfig()->BG == NULL) {
 | 
|---|
 | 141 |       World::getInstance().getConfig()->BG = new BondGraph(World::getInstance().getConfig()->GetIsAngstroem());
 | 
|---|
 | 142 |       if (World::getInstance().getConfig()->BG->LoadBondLengthTable(BondGraphFileName)) {
 | 
|---|
 | 143 |         DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl);
 | 
|---|
| [97ebf8] | 144 |       } else {
 | 
|---|
| [a356f2] | 145 |         DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl);
 | 
|---|
| [97ebf8] | 146 |       }
 | 
|---|
| [c6efc1] | 147 |     }
 | 
|---|
| [a356f2] | 148 |     // handle remaining arguments by CommandLineParser
 | 
|---|
| [326bbe] | 149 |     if (argc>1) {
 | 
|---|
 | 150 |       MapOfActions::getInstance().AddOptionsToParser();
 | 
|---|
 | 151 |       map <std::string, std::string> ShortFormToActionMap = MapOfActions::getInstance().getShortFormToActionMap();
 | 
|---|
 | 152 |       CommandLineParser::getInstance().Run(argc,argv, ShortFormToActionMap);
 | 
|---|
| [a356f2] | 153 |       DoLog(0) && (Log() << Verbose(0) << "Setting UI to CommandLine." << endl);
 | 
|---|
 | 154 |       UIFactory::registerFactory(new CommandLineUIFactory::description());
 | 
|---|
 | 155 |       UIFactory::makeUserInterface("CommandLine");
 | 
|---|
 | 156 |     } else {
 | 
|---|
| [04488a] | 157 |       #ifdef USE_GUI_QT
 | 
|---|
 | 158 |         DoLog(0) && (Log() << Verbose(0) << "Setting UI to QT4." << endl);
 | 
|---|
 | 159 |         UIFactory::registerFactory(new QTUIFactory::description());
 | 
|---|
 | 160 |         UIFactory::makeUserInterface("QT4");
 | 
|---|
 | 161 |       #else
 | 
|---|
 | 162 |         DoLog(0) && (Log() << Verbose(0) << "Setting UI to Text." << endl);
 | 
|---|
 | 163 |         cout << ESPACKVersion << endl;
 | 
|---|
 | 164 |         UIFactory::registerFactory(new TextUIFactory::description());
 | 
|---|
 | 165 |         UIFactory::makeUserInterface("Text");
 | 
|---|
 | 166 |       #endif
 | 
|---|
| [12b845] | 167 |     }
 | 
|---|
| [a356f2] | 168 |   }
 | 
|---|
 | 169 | 
 | 
|---|
 | 170 |   {
 | 
|---|
 | 171 |     MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow();
 | 
|---|
 | 172 |     mainWindow->display();
 | 
|---|
 | 173 |     delete mainWindow;
 | 
|---|
 | 174 |   }
 | 
|---|
| [6ac7ee] | 175 | 
 | 
|---|
| [a356f2] | 176 |   FormatParserStorage::getInstance().SaveAll();
 | 
|---|
 | 177 |   ChangeTracker::getInstance().saveStatus();
 | 
|---|
| [042f82] | 178 | 
 | 
|---|
| [97ebf8] | 179 |   // free the new argv
 | 
|---|
 | 180 |   if (ArgumentsCopied) {
 | 
|---|
 | 181 |     for (int i=0; i<ArgcSize;i++)
 | 
|---|
| [920c70] | 182 |       delete[](Arguments[i]);
 | 
|---|
 | 183 |     delete[](Arguments);
 | 
|---|
| [97ebf8] | 184 |   }
 | 
|---|
| [4f7f34e] | 185 |   //delete[](ConfigFileName);
 | 
|---|
| [632bc3] | 186 | 
 | 
|---|
| [e4b5de] | 187 |   ExitFlag = World::getInstance().getExitFlag();
 | 
|---|
| [99fcaf] | 188 |   return (ExitFlag == 1 ? 0 : ExitFlag);
 | 
|---|
| [14de469] | 189 | }
 | 
|---|
 | 190 | 
 | 
|---|
 | 191 | /********************************************** E N D **************************************************/
 | 
|---|