source: src/builder_init.cpp@ 111387

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 111387 was 632508, checked in by Frederik Heber <heber@…>, 14 years ago

Moved files bondgraph.?pp -> Graph/BondGraph.?pp.

  • Property mode set to 100644
File size: 6.7 KB
Line 
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/*
9 * builder_init.cpp
10 *
11 * Created on: Dec 15, 2010
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include <iostream>
23
24#include "Graph/BondGraph.hpp"
25#include "config.hpp"
26#include "CodePatterns/Log.hpp"
27#include "molecule.hpp"
28#include "periodentafel.hpp"
29#include "tesselationhelpers.hpp"
30#include "UIElements/UIFactory.hpp"
31#include "UIElements/Menu/MenuDescription.hpp"
32#include "UIElements/TextUI/TextUIFactory.hpp"
33#include "UIElements/CommandLineUI/CommandLineUIFactory.hpp"
34#include "UIElements/CommandLineUI/CommandLineParser.hpp"
35#ifdef USE_GUI_QT
36#include "UIElements/Qt4/QtUIFactory.hpp"
37#endif
38#include "UIElements/MainWindow.hpp"
39#include "UIElements/Dialog.hpp"
40//#include "Menu/ActionMenuItem.hpp"
41#include "CodePatterns/Verbose.hpp"
42#include "World.hpp"
43
44#include "Actions/ActionRegistry.hpp"
45#include "Actions/ActionHistory.hpp"
46
47#include "RandomNumbers/RandomNumberDistributionFactory.hpp"
48#include "RandomNumbers/RandomNumberEngineFactory.hpp"
49#include "RandomNumbers/RandomNumberGeneratorFactory.hpp"
50
51#include "Parser/ChangeTracker.hpp"
52#include "Parser/FormatParserStorage.hpp"
53
54#include "UIElements/UIFactory.hpp"
55#include "UIElements/TextUI/TextUIFactory.hpp"
56#include "UIElements/CommandLineUI/CommandLineUIFactory.hpp"
57#include "UIElements/MainWindow.hpp"
58#include "UIElements/Dialog.hpp"
59
60#include "version.h"
61
62#include "builder_init.hpp"
63
64/** Print some initial information output the program.
65 *
66 */
67void ProgramHeader()
68{
69 // print version check and copyright notice
70 cout << MOLECUILDERVERSION << endl;
71 cout << "MoleCuilder comes with ABSOLUTELY NO WARRANTY; for details type" << endl;
72 cout << "`molecuilder --warranty'." << endl;
73 cout << "`MoleCuilder - to create and alter molecular systems." << endl;
74 cout << "Copyright (C) 2010 University Bonn. All rights reserved." << endl;
75 cout << endl;
76}
77
78/** General stuff to intialize before UI.
79 *
80 */
81void initGeneral()
82{
83 // while we are non interactive, we want to abort from asserts
84 ASSERT_DO(Assert::Abort);
85 ASSERT_HOOK(dumpMemory);
86
87 ProgramHeader();
88
89 setVerbosity(1);
90 // need to init the history before any action is created
91 ActionHistory::init();
92
93 // from this moment on, we need to be sure to deeinitialize in the correct order
94 // this is handled by the cleanup function
95 atexit(cleanUp);
96}
97
98/** Initialize specific UIFactory.
99 *
100 * @param argc argument count
101 * @param argv argument array
102 */
103void initUI(int argc, char **argv)
104{
105 std::string BondGraphFileName("\n");
106 // Parse command line options and if present create respective UI
107 // construct bond graph
108 if (boost::filesystem::exists(BondGraphFileName)) {
109 std::ifstream input(BondGraphFileName.c_str());
110 if ((input.good()) && (World::getInstance().getBondGraph()->LoadBondLengthTable(input))) {
111 DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl);
112 } else {
113 DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl);
114 }
115 input.close();
116 }
117 // handle remaining arguments by CommandLineParser
118 if (argc>1) {
119 DoLog(0) && (Log() << Verbose(0) << "Setting UI to CommandLine." << endl);
120 CommandLineParser::getInstance().InitializeCommandArguments();
121 CommandLineParser::getInstance().Run(argc,argv);
122 UIFactory::registerFactory(new CommandLineUIFactory::description());
123 UIFactory::makeUserInterface("CommandLine");
124 } else {
125 // In the interactive mode, we can leave the user the choice in case of error
126 ASSERT_DO(Assert::Ask);
127 #ifdef USE_GUI_QT
128 DoLog(0) && (Log() << Verbose(0) << "Setting UI to Qt4." << endl);
129 UIFactory::registerFactory(new QtUIFactory::description());
130 UIFactory::makeUserInterface("Qt4");
131 #else
132 DoLog(0) && (Log() << Verbose(0) << "Setting UI to Text." << endl);
133 cout << MOLECUILDERVERSION << endl;
134 UIFactory::registerFactory(new TextUIFactory::description());
135 UIFactory::makeUserInterface("Text");
136 #endif
137 }
138}
139
140/** Create MainWindow and displays.
141 * I.e. here all the Actions are parsed and done.
142 */
143void doUI()
144{
145 MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow();
146 mainWindow->display();
147 delete mainWindow;
148}
149
150
151/** In this function all dynamicly allocated member variables to static/global
152 * variables are added to the ignore list of Memory/MemDebug.
153 *
154 * Use this to prevent their listing in the Memory::getState() at the end of the
155 * program. Check with valgrind that truely no memory leak occurs!
156 */
157void AddStaticEntitiestoIgnoreList()
158{
159 // zeroVec and unitVec are global variables (on the stack) but vectorContent
160 // within is situated on the heap and has to be ignored
161 Memory::ignore(zeroVec.get());
162 Memory::ignore(unitVec[0].get());
163 Memory::ignore(unitVec[1].get());
164 Memory::ignore(unitVec[2].get());
165}
166
167/** Cleans all singleton instances in an orderly fashion.
168 * C++ does not guarantee any specific sequence of removal of single instances
169 * which have static/global variables. Some singletons depend on others hence we
170 * acertain a specific ordering here, which is is used via the atexit() hook.
171 */
172void cleanUp()
173{
174 RandomNumberDistributionFactory::purgeInstance();
175 RandomNumberEngineFactory::purgeInstance();
176 RandomNumberGeneratorFactory::purgeInstance();
177 FormatParserStorage::purgeInstance();
178 ChangeTracker::purgeInstance();
179 World::purgeInstance();
180 MenuDescription::purgeInstance();
181 UIFactory::purgeInstance();
182 ValueStorage::purgeInstance();
183 CommandLineParser::purgeInstance();
184 ActionRegistry::purgeInstance();
185 OptionRegistry::purgeInstance();
186 ActionHistory::purgeInstance();
187 // we have to remove these two static as otherwise their boost::shared_ptrs are still present
188 Action::removeStaticStateEntities();
189 // put some static variables' dynamic contents on the Memory::ignore map to avoid their
190 // admonishing lateron
191 AddStaticEntitiestoIgnoreList();
192 logger::purgeInstance();
193 errorLogger::purgeInstance();
194#ifdef LOG_OBSERVER
195 cout << observerLog().getLog();
196#endif
197 Memory::getState();
198}
199
200/** Dump current memory chunks.
201 *
202 */
203void dumpMemory()
204{
205 ofstream ost("molecuilder.memdump");
206 Memory::dumpMemory(ost);
207}
208
209/** Save the current World to output files and exit.
210 *
211 * @return retrieved from World::getExitFlag()
212 */
213int saveAll()
214{
215 int test[500000];
216 for (size_t i=0;i<500000;++i) {
217 test[i] = (int)i;
218 }
219 FormatParserStorage::getInstance().SaveAll();
220 ChangeTracker::getInstance().saveStatus();
221
222 int ExitFlag = World::getInstance().getExitFlag();
223 return (ExitFlag == 1 ? 0 : ExitFlag);
224}
Note: See TracBrowser for help on using the repository browser.