| [bcf653] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
 | 4 |  * Copyright (C)  2010 University of Bonn. All rights reserved.
 | 
|---|
 | 5 |  * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 |  /** \file builder.cpp
 | 
|---|
| [a8bcea6] | 9 |  *
 | 
|---|
| [a356f2] | 10 |  *  date: Jan 1, 2007
 | 
|---|
 | 11 |  *  author: heber
 | 
|---|
| [a8bcea6] | 12 |  *
 | 
|---|
| [14de469] | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
| [bcf653] | 15 | /*! \page Copyright notice
 | 
|---|
 | 16 |  *
 | 
|---|
 | 17 |  *  MoleCuilder - to create and alter molecular systems
 | 
|---|
| [490038] | 18 |  *  Copyright (C) 2010  University Bonn. All rights reserved.
 | 
|---|
| [bcf653] | 19 |  *
 | 
|---|
 | 20 |  */
 | 
|---|
 | 21 | 
 | 
|---|
| [a356f2] | 22 | /*! \mainpage MoleCuilder - a molecular set builder
 | 
|---|
| [a8bcea6] | 23 |  *
 | 
|---|
| [a356f2] | 24 |  * This introductory shall briefly make acquainted with the program, helping in installing and a first run.
 | 
|---|
| [a8bcea6] | 25 |  *
 | 
|---|
| [14de469] | 26 |  * \section about About the Program
 | 
|---|
| [a8bcea6] | 27 |  *
 | 
|---|
| [a356f2] | 28 |  *  MoleCuilder is a program, written entirely in C++, that enables the construction of a coordinate set for the
 | 
|---|
 | 29 |  *  atoms making up an molecule. It allows for both building of simple molecules by adding atom-wise giving bond
 | 
|---|
 | 30 |  *  angles and distances or absolute coordinates, but also using them as templates. Regions can be specified and
 | 
|---|
 | 31 |  *  ordered to be filled with a molecule in a certain manner. Greater conglomerations of molecules can be tesselated
 | 
|---|
 | 32 |  *  and recognized as a region themselves to be subsequently surrounded by other (surface solvated) molecules.
 | 
|---|
 | 33 |  *  In the end, MoleCuilder allows the construction of arbitrary nano structures, whether they be crystalline or
 | 
|---|
 | 34 |  *  amorphic in nature.
 | 
|---|
| [a8bcea6] | 35 |  *
 | 
|---|
 | 36 |  *
 | 
|---|
| [14de469] | 37 |  * \section install Installation
 | 
|---|
| [a8bcea6] | 38 |  *
 | 
|---|
| [042f82] | 39 |  *  Installation should without problems succeed as follows:
 | 
|---|
 | 40 |  *  -# ./configure (or: mkdir build;mkdir run;cd build; ../configure --bindir=../run)
 | 
|---|
 | 41 |  *  -# make
 | 
|---|
 | 42 |  *  -# make install
 | 
|---|
| [a8bcea6] | 43 |  *
 | 
|---|
| [042f82] | 44 |  *  Further useful commands are
 | 
|---|
 | 45 |  *  -# make clean uninstall: deletes .o-files and removes executable from the given binary directory\n
 | 
|---|
 | 46 |  *  -# make doxygen-doc: Creates these html pages out of the documented source
 | 
|---|
| [a356f2] | 47 |  *  -# make check: Runs an extensive set of unit tests and a testsuite which also gives a good overview on the set of
 | 
|---|
 | 48 |  *                 functions.
 | 
|---|
| [a8bcea6] | 49 |  *
 | 
|---|
| [14de469] | 50 |  * \section run Running
 | 
|---|
| [a8bcea6] | 51 |  *
 | 
|---|
| [042f82] | 52 |  *  The program can be executed by running: ./molecuilder
 | 
|---|
| [a8bcea6] | 53 |  *
 | 
|---|
| [a356f2] | 54 |  *  MoleCuilder has three interfaces at your disposal:
 | 
|---|
 | 55 |  *  -# Textmenu: A simple interactive console-based menu, where awaits your choices and inputs in order to set atoms
 | 
|---|
 | 56 |  *               as you like
 | 
|---|
 | 57 |  *  -# CommandLineUI: Every command can also be chained up as a sequence of actions on the command line to be executed
 | 
|---|
 | 58 |  *               with any user interaction.
 | 
|---|
 | 59 |  *  -# GraphicalUI: A graphical user interface that also display the molecular structure being built and lots of other
 | 
|---|
 | 60 |  *               informations to ease the construction of bigger geometries.
 | 
|---|
| [a8bcea6] | 61 |  *
 | 
|---|
| [a356f2] | 62 |  *  The supported output formats right now are:
 | 
|---|
 | 63 |  *  -# mpqc: Configuration files of the Massively Parallel Quantum Chemistry package (Sandia labs)
 | 
|---|
 | 64 |  *  -# pcp: Configuration files of the Parallel Car-Parrinello program (Institute for Numerical Simulation)
 | 
|---|
 | 65 |  *  -# tremolo: Configuration files of TREMOLO (Institute for Numerical Simulation)
 | 
|---|
 | 66 |  *  -# xyz: the most basic format for the 3d arrangement of atoms consisting of a list of element and 3 coordinates.
 | 
|---|
| [a8bcea6] | 67 |  *
 | 
|---|
| [14de469] | 68 |  */
 | 
|---|
 | 69 | 
 | 
|---|
| [bf3817] | 70 | // include config.h
 | 
|---|
 | 71 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 72 | #include <config.h>
 | 
|---|
 | 73 | #endif
 | 
|---|
 | 74 | 
 | 
|---|
| [112b09] | 75 | #include "Helpers/MemDebug.hpp"
 | 
|---|
| [14de469] | 76 | 
 | 
|---|
| [b70721] | 77 | #include "bondgraph.hpp"
 | 
|---|
| [f66195] | 78 | #include "config.hpp"
 | 
|---|
| [952f38] | 79 | #include "Helpers/Log.hpp"
 | 
|---|
| [cee0b57] | 80 | #include "molecule.hpp"
 | 
|---|
| [f66195] | 81 | #include "periodentafel.hpp"
 | 
|---|
| [bfd839] | 82 | #include "tesselationhelpers.hpp"
 | 
|---|
| [cc04b7] | 83 | #include "UIElements/UIFactory.hpp"
 | 
|---|
| [c82d0c] | 84 | #include "UIElements/Menu/MenuDescription.hpp"
 | 
|---|
| [5f5a7b] | 85 | #include "UIElements/TextUI/TextUIFactory.hpp"
 | 
|---|
 | 86 | #include "UIElements/CommandLineUI/CommandLineUIFactory.hpp"
 | 
|---|
| [e4afb4] | 87 | #include "UIElements/CommandLineUI/CommandLineParser.hpp"
 | 
|---|
| [82b71a] | 88 | #ifdef USE_GUI_QT
 | 
|---|
| [4cf323d] | 89 | #include "UIElements/Qt4/QtUIFactory.hpp"
 | 
|---|
| [82b71a] | 90 | #endif
 | 
|---|
| [cc04b7] | 91 | #include "UIElements/MainWindow.hpp"
 | 
|---|
| [45f5d6] | 92 | #include "UIElements/Dialog.hpp"
 | 
|---|
| [b59da6] | 93 | //#include "Menu/ActionMenuItem.hpp"
 | 
|---|
| [952f38] | 94 | #include "Helpers/Verbose.hpp"
 | 
|---|
| [a356f2] | 95 | #include "World.hpp"
 | 
|---|
 | 96 | 
 | 
|---|
| [12b845] | 97 | #include "Actions/ActionRegistry.hpp"
 | 
|---|
| [d56640] | 98 | #include "Actions/ActionHistory.hpp"
 | 
|---|
| [042f82] | 99 | 
 | 
|---|
| [a356f2] | 100 | #include "Parser/ChangeTracker.hpp"
 | 
|---|
 | 101 | #include "Parser/FormatParserStorage.hpp"
 | 
|---|
| [1907a7] | 102 | 
 | 
|---|
| [a356f2] | 103 | #include "UIElements/UIFactory.hpp"
 | 
|---|
 | 104 | #include "UIElements/TextUI/TextUIFactory.hpp"
 | 
|---|
 | 105 | #include "UIElements/CommandLineUI/CommandLineUIFactory.hpp"
 | 
|---|
 | 106 | #include "UIElements/MainWindow.hpp"
 | 
|---|
 | 107 | #include "UIElements/Dialog.hpp"
 | 
|---|
| [1f1b23] | 108 | 
 | 
|---|
| [a356f2] | 109 | #include "version.h"
 | 
|---|
| [1f1b23] | 110 | 
 | 
|---|
| [ca2b83] | 111 | 
 | 
|---|
 | 112 | /********************************************** Main routine **************************************/
 | 
|---|
| [14de469] | 113 | 
 | 
|---|
| [ae21cbd] | 114 | /** In this function all dynamicly allocated member variables to static/global
 | 
|---|
 | 115 |  * variables are added to the ignore list of Memory/MemDebug.
 | 
|---|
 | 116 |  *
 | 
|---|
 | 117 |  * Use this to prevent their listing in the Memory::getState() at the end of the
 | 
|---|
 | 118 |  * program. Check with valgrind that truely no memory leak occurs!
 | 
|---|
 | 119 |  */
 | 
|---|
 | 120 | void AddStaticEntitiestoIgnoreList()
 | 
|---|
 | 121 | {
 | 
|---|
 | 122 |   // zeroVec and unitVec are global variables (on the stack) but vectorContent
 | 
|---|
 | 123 |   // within is situated on the heap and has to be ignored
 | 
|---|
 | 124 |   Memory::ignore(zeroVec.get());
 | 
|---|
 | 125 |   Memory::ignore(unitVec[0].get());
 | 
|---|
 | 126 |   Memory::ignore(unitVec[1].get());
 | 
|---|
 | 127 |   Memory::ignore(unitVec[2].get());
 | 
|---|
 | 128 | }
 | 
|---|
 | 129 | 
 | 
|---|
 | 130 | /** Cleans all singleton instances in an orderly fashion.
 | 
|---|
 | 131 |  * C++ does not guarantee any specific sequence of removal of single instances
 | 
|---|
 | 132 |  * which have static/global variables. Some singletons depend on others hence we
 | 
|---|
 | 133 |  * acertain a specific ordering here, which is is used via the atexit() hook.
 | 
|---|
 | 134 |  */
 | 
|---|
| [148d8f0] | 135 | void cleanUp(){
 | 
|---|
| [35b698] | 136 |   FormatParserStorage::purgeInstance();
 | 
|---|
| [a1e929] | 137 |   ChangeTracker::purgeInstance();
 | 
|---|
| [23b547] | 138 |   World::purgeInstance();
 | 
|---|
| [c82d0c] | 139 |   MenuDescription::purgeInstance();
 | 
|---|
| [97ebf8] | 140 |   UIFactory::purgeInstance();
 | 
|---|
| [e4afb4] | 141 |   ValueStorage::purgeInstance();
 | 
|---|
| [c6efc1] | 142 |   CommandLineParser::purgeInstance();
 | 
|---|
| [e73a8a2] | 143 |   ActionRegistry::purgeInstance();
 | 
|---|
| [76cec6] | 144 |   OptionRegistry::purgeInstance();
 | 
|---|
| [632bc3] | 145 |   ActionHistory::purgeInstance();
 | 
|---|
| [41449c] | 146 |   // we have to remove these two static as otherwise their boost::shared_ptrs are still present
 | 
|---|
 | 147 |   Action::removeStaticStateEntities();
 | 
|---|
| [ae21cbd] | 148 |   // put some static variables' dynamic contents on the Memory::ignore map to avoid their
 | 
|---|
 | 149 |   // admonishing lateron
 | 
|---|
 | 150 |   AddStaticEntitiestoIgnoreList();
 | 
|---|
| [052afe] | 151 |   logger::purgeInstance();
 | 
|---|
 | 152 |   errorLogger::purgeInstance();
 | 
|---|
| [cd5047] | 153 | #ifdef LOG_OBSERVER
 | 
|---|
 | 154 |   cout << observerLog().getLog();
 | 
|---|
 | 155 | #endif
 | 
|---|
| [68f03d] | 156 |   Memory::getState();
 | 
|---|
| [354859] | 157 | }
 | 
|---|
 | 158 | 
 | 
|---|
| [097902] | 159 | void dumpMemory(){
 | 
|---|
 | 160 |   ofstream ost("molecuilder.memdump");
 | 
|---|
 | 161 |   Memory::dumpMemory(ost);
 | 
|---|
 | 162 | }
 | 
|---|
 | 163 | 
 | 
|---|
| [ca2b83] | 164 | int main(int argc, char **argv)
 | 
|---|
 | 165 | {
 | 
|---|
| [a356f2] | 166 |   // while we are non interactive, we want to abort from asserts
 | 
|---|
| [097902] | 167 |   ASSERT_DO(Assert::Abort);
 | 
|---|
 | 168 |   ASSERT_HOOK(dumpMemory);
 | 
|---|
| [a356f2] | 169 |   string line;
 | 
|---|
 | 170 |   char **Arguments = NULL;
 | 
|---|
 | 171 |   int ArgcSize = 0;
 | 
|---|
 | 172 |   int ExitFlag = 0;
 | 
|---|
 | 173 |   bool ArgumentsCopied = false;
 | 
|---|
 | 174 |   std::string BondGraphFileName("\n");
 | 
|---|
 | 175 | 
 | 
|---|
| [bcf653] | 176 |   // print version check and copyright notice
 | 
|---|
| [5f8660a] | 177 |   cout << MOLECUILDERVERSION << endl;
 | 
|---|
| [bcf653] | 178 |   cout << "MoleCuilder comes with ABSOLUTELY NO WARRANTY; for details type" << endl;
 | 
|---|
| [7230be] | 179 |   cout << "`molecuilder --warranty'." << endl;
 | 
|---|
| [490038] | 180 |   cout << "`MoleCuilder - to create and alter molecular systems." << endl;
 | 
|---|
 | 181 |   cout << "Copyright (C) 2010  University Bonn. All rights reserved." << endl;
 | 
|---|
| [a356f2] | 182 | 
 | 
|---|
 | 183 |   setVerbosity(0);
 | 
|---|
 | 184 |   // need to init the history before any action is created
 | 
|---|
 | 185 |   ActionHistory::init();
 | 
|---|
 | 186 | 
 | 
|---|
 | 187 |   // from this moment on, we need to be sure to deeinitialize in the correct order
 | 
|---|
 | 188 |   // this is handled by the cleanup function
 | 
|---|
 | 189 |   atexit(cleanUp);
 | 
|---|
 | 190 | 
 | 
|---|
 | 191 |   // Parse command line options and if present create respective UI
 | 
|---|
 | 192 |   {
 | 
|---|
 | 193 |     // construct bond graph
 | 
|---|
 | 194 |     if (World::getInstance().getConfig()->BG == NULL) {
 | 
|---|
 | 195 |       World::getInstance().getConfig()->BG = new BondGraph(World::getInstance().getConfig()->GetIsAngstroem());
 | 
|---|
 | 196 |       if (World::getInstance().getConfig()->BG->LoadBondLengthTable(BondGraphFileName)) {
 | 
|---|
 | 197 |         DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl);
 | 
|---|
| [97ebf8] | 198 |       } else {
 | 
|---|
| [a356f2] | 199 |         DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl);
 | 
|---|
| [97ebf8] | 200 |       }
 | 
|---|
| [c6efc1] | 201 |     }
 | 
|---|
| [a356f2] | 202 |     // handle remaining arguments by CommandLineParser
 | 
|---|
| [326bbe] | 203 |     if (argc>1) {
 | 
|---|
| [e4afb4] | 204 |       CommandLineParser::getInstance().InitializeCommandArguments();
 | 
|---|
 | 205 |       CommandLineParser::getInstance().Run(argc,argv);
 | 
|---|
| [a356f2] | 206 |       DoLog(0) && (Log() << Verbose(0) << "Setting UI to CommandLine." << endl);
 | 
|---|
 | 207 |       UIFactory::registerFactory(new CommandLineUIFactory::description());
 | 
|---|
 | 208 |       UIFactory::makeUserInterface("CommandLine");
 | 
|---|
 | 209 |     } else {
 | 
|---|
| [007839] | 210 |       // In the interactive mode, we can leave the user the choice in case of error
 | 
|---|
 | 211 |       ASSERT_DO(Assert::Ask);
 | 
|---|
| [04488a] | 212 |       #ifdef USE_GUI_QT
 | 
|---|
| [4cf323d] | 213 |         DoLog(0) && (Log() << Verbose(0) << "Setting UI to Qt4." << endl);
 | 
|---|
 | 214 |         UIFactory::registerFactory(new QtUIFactory::description());
 | 
|---|
 | 215 |         UIFactory::makeUserInterface("Qt4");
 | 
|---|
| [04488a] | 216 |       #else
 | 
|---|
 | 217 |         DoLog(0) && (Log() << Verbose(0) << "Setting UI to Text." << endl);
 | 
|---|
| [5f8660a] | 218 |         cout << MOLECUILDERVERSION << endl;
 | 
|---|
| [04488a] | 219 |         UIFactory::registerFactory(new TextUIFactory::description());
 | 
|---|
 | 220 |         UIFactory::makeUserInterface("Text");
 | 
|---|
 | 221 |       #endif
 | 
|---|
| [12b845] | 222 |     }
 | 
|---|
| [a356f2] | 223 |   }
 | 
|---|
 | 224 | 
 | 
|---|
 | 225 |   {
 | 
|---|
 | 226 |     MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow();
 | 
|---|
 | 227 |     mainWindow->display();
 | 
|---|
 | 228 |     delete mainWindow;
 | 
|---|
 | 229 |   }
 | 
|---|
| [6ac7ee] | 230 | 
 | 
|---|
| [a356f2] | 231 |   FormatParserStorage::getInstance().SaveAll();
 | 
|---|
 | 232 |   ChangeTracker::getInstance().saveStatus();
 | 
|---|
| [042f82] | 233 | 
 | 
|---|
| [97ebf8] | 234 |   // free the new argv
 | 
|---|
 | 235 |   if (ArgumentsCopied) {
 | 
|---|
 | 236 |     for (int i=0; i<ArgcSize;i++)
 | 
|---|
| [920c70] | 237 |       delete[](Arguments[i]);
 | 
|---|
 | 238 |     delete[](Arguments);
 | 
|---|
| [97ebf8] | 239 |   }
 | 
|---|
| [4f7f34e] | 240 |   //delete[](ConfigFileName);
 | 
|---|
| [632bc3] | 241 | 
 | 
|---|
| [e4b5de] | 242 |   ExitFlag = World::getInstance().getExitFlag();
 | 
|---|
| [99fcaf] | 243 |   return (ExitFlag == 1 ? 0 : ExitFlag);
 | 
|---|
| [14de469] | 244 | }
 | 
|---|
 | 245 | 
 | 
|---|
 | 246 | /********************************************** E N D **************************************************/
 | 
|---|