[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
|
---|
| 18 | * Copyright (C) 2010 University Bonn
|
---|
| 19 | *
|
---|
| 20 | * This program is free software; you can redistribute it and/or modify
|
---|
| 21 | * it under the terms of the GNU General Public License as published by
|
---|
| 22 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 23 | * (at your option) any later version.
|
---|
| 24 | *
|
---|
| 25 | * This program is distributed in the hope that it will be useful,
|
---|
| 26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 28 | * GNU General Public License for more details.
|
---|
| 29 | *
|
---|
| 30 | * You should have received a copy of the GNU General Public License
|
---|
| 31 | * along with this program; if not, write to the Free Software
|
---|
| 32 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
| 33 | *
|
---|
| 34 | */
|
---|
| 35 |
|
---|
[a356f2] | 36 | /*! \mainpage MoleCuilder - a molecular set builder
|
---|
[a8bcea6] | 37 | *
|
---|
[a356f2] | 38 | * This introductory shall briefly make acquainted with the program, helping in installing and a first run.
|
---|
[a8bcea6] | 39 | *
|
---|
[14de469] | 40 | * \section about About the Program
|
---|
[a8bcea6] | 41 | *
|
---|
[a356f2] | 42 | * MoleCuilder is a program, written entirely in C++, that enables the construction of a coordinate set for the
|
---|
| 43 | * atoms making up an molecule. It allows for both building of simple molecules by adding atom-wise giving bond
|
---|
| 44 | * angles and distances or absolute coordinates, but also using them as templates. Regions can be specified and
|
---|
| 45 | * ordered to be filled with a molecule in a certain manner. Greater conglomerations of molecules can be tesselated
|
---|
| 46 | * and recognized as a region themselves to be subsequently surrounded by other (surface solvated) molecules.
|
---|
| 47 | * In the end, MoleCuilder allows the construction of arbitrary nano structures, whether they be crystalline or
|
---|
| 48 | * amorphic in nature.
|
---|
[a8bcea6] | 49 | *
|
---|
| 50 | *
|
---|
[14de469] | 51 | * \section install Installation
|
---|
[a8bcea6] | 52 | *
|
---|
[042f82] | 53 | * Installation should without problems succeed as follows:
|
---|
| 54 | * -# ./configure (or: mkdir build;mkdir run;cd build; ../configure --bindir=../run)
|
---|
| 55 | * -# make
|
---|
| 56 | * -# make install
|
---|
[a8bcea6] | 57 | *
|
---|
[042f82] | 58 | * Further useful commands are
|
---|
| 59 | * -# make clean uninstall: deletes .o-files and removes executable from the given binary directory\n
|
---|
| 60 | * -# make doxygen-doc: Creates these html pages out of the documented source
|
---|
[a356f2] | 61 | * -# make check: Runs an extensive set of unit tests and a testsuite which also gives a good overview on the set of
|
---|
| 62 | * functions.
|
---|
[a8bcea6] | 63 | *
|
---|
[14de469] | 64 | * \section run Running
|
---|
[a8bcea6] | 65 | *
|
---|
[042f82] | 66 | * The program can be executed by running: ./molecuilder
|
---|
[a8bcea6] | 67 | *
|
---|
[a356f2] | 68 | * MoleCuilder has three interfaces at your disposal:
|
---|
| 69 | * -# Textmenu: A simple interactive console-based menu, where awaits your choices and inputs in order to set atoms
|
---|
| 70 | * as you like
|
---|
| 71 | * -# CommandLineUI: Every command can also be chained up as a sequence of actions on the command line to be executed
|
---|
| 72 | * with any user interaction.
|
---|
| 73 | * -# GraphicalUI: A graphical user interface that also display the molecular structure being built and lots of other
|
---|
| 74 | * informations to ease the construction of bigger geometries.
|
---|
[a8bcea6] | 75 | *
|
---|
[a356f2] | 76 | * The supported output formats right now are:
|
---|
| 77 | * -# mpqc: Configuration files of the Massively Parallel Quantum Chemistry package (Sandia labs)
|
---|
| 78 | * -# pcp: Configuration files of the Parallel Car-Parrinello program (Institute for Numerical Simulation)
|
---|
| 79 | * -# tremolo: Configuration files of TREMOLO (Institute for Numerical Simulation)
|
---|
| 80 | * -# xyz: the most basic format for the 3d arrangement of atoms consisting of a list of element and 3 coordinates.
|
---|
[a8bcea6] | 81 | *
|
---|
[14de469] | 82 | */
|
---|
| 83 |
|
---|
[bf3817] | 84 | // include config.h
|
---|
| 85 | #ifdef HAVE_CONFIG_H
|
---|
| 86 | #include <config.h>
|
---|
| 87 | #endif
|
---|
| 88 |
|
---|
[112b09] | 89 | #include "Helpers/MemDebug.hpp"
|
---|
[14de469] | 90 |
|
---|
[b70721] | 91 | #include "bondgraph.hpp"
|
---|
[c6efc1] | 92 | #include "CommandLineParser.hpp"
|
---|
[f66195] | 93 | #include "config.hpp"
|
---|
[952f38] | 94 | #include "Helpers/Log.hpp"
|
---|
[cee0b57] | 95 | #include "molecule.hpp"
|
---|
[f66195] | 96 | #include "periodentafel.hpp"
|
---|
[bfd839] | 97 | #include "tesselationhelpers.hpp"
|
---|
[cc04b7] | 98 | #include "UIElements/UIFactory.hpp"
|
---|
[5f5a7b] | 99 | #include "UIElements/TextUI/TextUIFactory.hpp"
|
---|
| 100 | #include "UIElements/CommandLineUI/CommandLineUIFactory.hpp"
|
---|
[82b71a] | 101 | #ifdef USE_GUI_QT
|
---|
| 102 | #include "UIElements/QT4/QTUIFactory.hpp"
|
---|
| 103 | #endif
|
---|
[cc04b7] | 104 | #include "UIElements/MainWindow.hpp"
|
---|
[45f5d6] | 105 | #include "UIElements/Dialog.hpp"
|
---|
[12b845] | 106 | #include "Menu/ActionMenuItem.hpp"
|
---|
[952f38] | 107 | #include "Helpers/Verbose.hpp"
|
---|
[a356f2] | 108 | #include "World.hpp"
|
---|
| 109 |
|
---|
[12b845] | 110 | #include "Actions/ActionRegistry.hpp"
|
---|
[d56640] | 111 | #include "Actions/ActionHistory.hpp"
|
---|
[97ebf8] | 112 | #include "Actions/MapOfActions.hpp"
|
---|
[042f82] | 113 |
|
---|
[a356f2] | 114 | #include "Parser/ChangeTracker.hpp"
|
---|
| 115 | #include "Parser/FormatParserStorage.hpp"
|
---|
[1907a7] | 116 |
|
---|
[a356f2] | 117 | #include "UIElements/UIFactory.hpp"
|
---|
| 118 | #include "UIElements/TextUI/TextUIFactory.hpp"
|
---|
| 119 | #include "UIElements/CommandLineUI/CommandLineUIFactory.hpp"
|
---|
| 120 | #include "UIElements/MainWindow.hpp"
|
---|
| 121 | #include "UIElements/Dialog.hpp"
|
---|
[1f1b23] | 122 |
|
---|
[a356f2] | 123 | #include "version.h"
|
---|
[1f1b23] | 124 |
|
---|
[ca2b83] | 125 |
|
---|
| 126 | /********************************************** Main routine **************************************/
|
---|
[14de469] | 127 |
|
---|
[148d8f0] | 128 | void cleanUp(){
|
---|
[35b698] | 129 | FormatParserStorage::purgeInstance();
|
---|
[a1e929] | 130 | ChangeTracker::purgeInstance();
|
---|
[23b547] | 131 | World::purgeInstance();
|
---|
[354859] | 132 | logger::purgeInstance();
|
---|
| 133 | errorLogger::purgeInstance();
|
---|
[97ebf8] | 134 | UIFactory::purgeInstance();
|
---|
| 135 | MapOfActions::purgeInstance();
|
---|
[c6efc1] | 136 | CommandLineParser::purgeInstance();
|
---|
[e73a8a2] | 137 | ActionRegistry::purgeInstance();
|
---|
[632bc3] | 138 | ActionHistory::purgeInstance();
|
---|
[cd5047] | 139 | #ifdef LOG_OBSERVER
|
---|
| 140 | cout << observerLog().getLog();
|
---|
| 141 | #endif
|
---|
[68f03d] | 142 | Memory::getState();
|
---|
[354859] | 143 | }
|
---|
| 144 |
|
---|
[097902] | 145 | void dumpMemory(){
|
---|
| 146 | ofstream ost("molecuilder.memdump");
|
---|
| 147 | Memory::dumpMemory(ost);
|
---|
| 148 | }
|
---|
| 149 |
|
---|
[ca2b83] | 150 | int main(int argc, char **argv)
|
---|
| 151 | {
|
---|
[a356f2] | 152 | // while we are non interactive, we want to abort from asserts
|
---|
[097902] | 153 | ASSERT_DO(Assert::Abort);
|
---|
| 154 | ASSERT_HOOK(dumpMemory);
|
---|
[a356f2] | 155 | string line;
|
---|
| 156 | char **Arguments = NULL;
|
---|
| 157 | int ArgcSize = 0;
|
---|
| 158 | int ExitFlag = 0;
|
---|
| 159 | bool ArgumentsCopied = false;
|
---|
| 160 | std::string BondGraphFileName("\n");
|
---|
| 161 |
|
---|
[bcf653] | 162 | // print version check and copyright notice
|
---|
[a356f2] | 163 | cout << ESPACKVersion << endl;
|
---|
[bcf653] | 164 | cout << "MoleCuilder comes with ABSOLUTELY NO WARRANTY; for details type" << endl;
|
---|
| 165 | cout << "`" << argv[0] << " --help-warranty'." << endl;
|
---|
| 166 | cout << "This is free software, and you are welcome to redistribute it" << endl;
|
---|
| 167 | cout << "under certain conditions; type `" << argv[0] << " --help-redistribute'" << endl;
|
---|
| 168 | cout << "for details." << endl;
|
---|
[a356f2] | 169 |
|
---|
| 170 | setVerbosity(0);
|
---|
| 171 | // need to init the history before any action is created
|
---|
| 172 | ActionHistory::init();
|
---|
| 173 |
|
---|
| 174 | // from this moment on, we need to be sure to deeinitialize in the correct order
|
---|
| 175 | // this is handled by the cleanup function
|
---|
| 176 | atexit(cleanUp);
|
---|
| 177 |
|
---|
| 178 | // Parse command line options and if present create respective UI
|
---|
| 179 | {
|
---|
| 180 | // construct bond graph
|
---|
| 181 | if (World::getInstance().getConfig()->BG == NULL) {
|
---|
| 182 | World::getInstance().getConfig()->BG = new BondGraph(World::getInstance().getConfig()->GetIsAngstroem());
|
---|
| 183 | if (World::getInstance().getConfig()->BG->LoadBondLengthTable(BondGraphFileName)) {
|
---|
| 184 | DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl);
|
---|
[97ebf8] | 185 | } else {
|
---|
[a356f2] | 186 | DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl);
|
---|
[97ebf8] | 187 | }
|
---|
[c6efc1] | 188 | }
|
---|
[a356f2] | 189 | // handle remaining arguments by CommandLineParser
|
---|
[326bbe] | 190 | if (argc>1) {
|
---|
| 191 | MapOfActions::getInstance().AddOptionsToParser();
|
---|
| 192 | map <std::string, std::string> ShortFormToActionMap = MapOfActions::getInstance().getShortFormToActionMap();
|
---|
| 193 | CommandLineParser::getInstance().Run(argc,argv, ShortFormToActionMap);
|
---|
[a356f2] | 194 | DoLog(0) && (Log() << Verbose(0) << "Setting UI to CommandLine." << endl);
|
---|
| 195 | UIFactory::registerFactory(new CommandLineUIFactory::description());
|
---|
| 196 | UIFactory::makeUserInterface("CommandLine");
|
---|
| 197 | } else {
|
---|
[007839] | 198 | // In the interactive mode, we can leave the user the choice in case of error
|
---|
| 199 | ASSERT_DO(Assert::Ask);
|
---|
[04488a] | 200 | #ifdef USE_GUI_QT
|
---|
| 201 | DoLog(0) && (Log() << Verbose(0) << "Setting UI to QT4." << endl);
|
---|
| 202 | UIFactory::registerFactory(new QTUIFactory::description());
|
---|
| 203 | UIFactory::makeUserInterface("QT4");
|
---|
| 204 | #else
|
---|
| 205 | DoLog(0) && (Log() << Verbose(0) << "Setting UI to Text." << endl);
|
---|
| 206 | cout << ESPACKVersion << endl;
|
---|
| 207 | UIFactory::registerFactory(new TextUIFactory::description());
|
---|
| 208 | UIFactory::makeUserInterface("Text");
|
---|
| 209 | #endif
|
---|
[12b845] | 210 | }
|
---|
[a356f2] | 211 | }
|
---|
| 212 |
|
---|
| 213 | {
|
---|
| 214 | MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow();
|
---|
| 215 | mainWindow->display();
|
---|
| 216 | delete mainWindow;
|
---|
| 217 | }
|
---|
[6ac7ee] | 218 |
|
---|
[a356f2] | 219 | FormatParserStorage::getInstance().SaveAll();
|
---|
| 220 | ChangeTracker::getInstance().saveStatus();
|
---|
[042f82] | 221 |
|
---|
[97ebf8] | 222 | // free the new argv
|
---|
| 223 | if (ArgumentsCopied) {
|
---|
| 224 | for (int i=0; i<ArgcSize;i++)
|
---|
[920c70] | 225 | delete[](Arguments[i]);
|
---|
| 226 | delete[](Arguments);
|
---|
[97ebf8] | 227 | }
|
---|
[4f7f34e] | 228 | //delete[](ConfigFileName);
|
---|
[632bc3] | 229 |
|
---|
[e4b5de] | 230 | ExitFlag = World::getInstance().getExitFlag();
|
---|
[99fcaf] | 231 | return (ExitFlag == 1 ? 0 : ExitFlag);
|
---|
[14de469] | 232 | }
|
---|
| 233 |
|
---|
| 234 | /********************************************** E N D **************************************************/
|
---|