source: src/builder.cpp@ c38826

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 c38826 was e4afb4, checked in by Frederik Heber <heber@…>, 14 years ago

Huge refactoring: Introduction of Traits to Actions.

This change is really big but the introduction of the Trait concept (at least
in its current light form) is so fundamental that lots of pieces had to be
changed in order to get everything working.

The main point why it was necessary to add these traits in the first place was
to comfortably allow for adding extension of Actions information-wise, i.e.
with stuff that is only important for the QtUI, such as icons, or tooltips, ...
This extra information should not be stored with Action itself, as it has
nothing to do with the workings of the Action. And neither should it get
stored with some blown-out-of-proportions MapOfActions class ...

The gist of the change is as follows:

  • OptionTrait contains the token, description, shortform and type of an option, such as ("position", "position in space, none, typeid(Vector)).
  • ActionTrait is the derived form for actions where additionally MenuPosition and MenuName are stored (and probably more to come for the GUI), also we have a set of OptionTrait instances, one for each option of the Action.
  • Action then contains this ActionTrait, specialized for each Action.
  • the preprocessor macros have been enhanced to gather all this information from the .def files.
  • MapOfActions is gone. Completely. Most of its use was to store this extra information and the ValueStorage part now is just in class ValueStorage.
  • ValueStorage is no more an interface to MapOfActions but as the name says a (type-safe) ValueStorage.

Listing the (remaining) changes in alphabetical order of the class:

  • Action
    • member value ::name dropped, ::getName() uses ActionTraits::getName()
    • new define NODEFAULT which is used in paramdefaults in .def files
    • all derived actions classes such as Process, Calculations, MakroAction,... have been adapated to use the ActionTrait concept as well.
  • ActionHistory
    • extraced RedoAction and UndoAction, shifted implementation into their own object files and they use .def files as well (i.e. streamlined with method used for other actions)
  • MenuDescription
    • contain information on Menus such as name, ...
    • new unit test checks for consistency
  • molecule
    • const member functions: Copy(), Output() and OutputBonds()
  • OptionRegistry
    • new registry class for options only
    • we want the same type throughout the code for each token, e.g. "position"
    • the registry containts checks for consistency
  • OptionTrait
    • default values are specified in paramdefaults, none are given by NODEFAULT
    • introduced default for translate-atoms, point-correlation, pair-correlation
  • Registry pattern
    • new unit test, but only sceleton code so far
  • ...Query, also ...Pipe
    • atoms, molecule and elements are now all const
    • also ValueStorage's signatures all have const therein
  • ValueStorage
    • set/queryCurrentValue from MapOfActions
    • at times VectorValue has been in .def files where Vector was in the signature. This is cleared. Such stuff is only present for e.g. BoxVector being queried as a Vector. But this is a feature and intended.
  • World
    • most of the (un)selection functions now work on const atoms and molecules
    • in one case we need a const_cast to remove this, but this is intentional, as the vector of selected atoms stores non-const pointers and this is ok.

There is only one test which had to be changed slightly because a specific
option token as "position" must now have the same type everywhere, e.g. always
Vector.

  • TESTFIX: Simple_configuration/2: --position -> --domain-position (and associated to BoxVector)
  • Property mode set to 100755
File size: 7.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 /** \file builder.cpp
9 *
10 * date: Jan 1, 2007
11 * author: heber
12 *
13 */
14
15/*! \page Copyright notice
16 *
17 * MoleCuilder - to create and alter molecular systems
18 * Copyright (C) 2010 University Bonn. All rights reserved.
19 *
20 */
21
22/*! \mainpage MoleCuilder - a molecular set builder
23 *
24 * This introductory shall briefly make acquainted with the program, helping in installing and a first run.
25 *
26 * \section about About the Program
27 *
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.
35 *
36 *
37 * \section install Installation
38 *
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
43 *
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
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.
49 *
50 * \section run Running
51 *
52 * The program can be executed by running: ./molecuilder
53 *
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.
61 *
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.
67 *
68 */
69
70// include config.h
71#ifdef HAVE_CONFIG_H
72#include <config.h>
73#endif
74
75#include "Helpers/MemDebug.hpp"
76
77#include "bondgraph.hpp"
78#include "config.hpp"
79#include "Helpers/Log.hpp"
80#include "molecule.hpp"
81#include "periodentafel.hpp"
82#include "tesselationhelpers.hpp"
83#include "UIElements/UIFactory.hpp"
84#include "UIElements/TextUI/TextUIFactory.hpp"
85#include "UIElements/CommandLineUI/CommandLineUIFactory.hpp"
86#include "UIElements/CommandLineUI/CommandLineParser.hpp"
87#ifdef USE_GUI_QT
88#include "UIElements/Qt4/QtUIFactory.hpp"
89#endif
90#include "UIElements/MainWindow.hpp"
91#include "UIElements/Dialog.hpp"
92#include "Menu/ActionMenuItem.hpp"
93#include "Helpers/Verbose.hpp"
94#include "World.hpp"
95
96#include "Actions/ActionRegistry.hpp"
97#include "Actions/ActionHistory.hpp"
98
99#include "Parser/ChangeTracker.hpp"
100#include "Parser/FormatParserStorage.hpp"
101
102#include "UIElements/UIFactory.hpp"
103#include "UIElements/TextUI/TextUIFactory.hpp"
104#include "UIElements/CommandLineUI/CommandLineUIFactory.hpp"
105#include "UIElements/MainWindow.hpp"
106#include "UIElements/Dialog.hpp"
107
108#include "version.h"
109
110
111/********************************************** Main routine **************************************/
112
113void cleanUp(){
114 FormatParserStorage::purgeInstance();
115 ChangeTracker::purgeInstance();
116 World::purgeInstance();
117 logger::purgeInstance();
118 errorLogger::purgeInstance();
119 UIFactory::purgeInstance();
120 ValueStorage::purgeInstance();
121 CommandLineParser::purgeInstance();
122 ActionRegistry::purgeInstance();
123 ActionHistory::purgeInstance();
124#ifdef LOG_OBSERVER
125 cout << observerLog().getLog();
126#endif
127 Memory::getState();
128}
129
130void dumpMemory(){
131 ofstream ost("molecuilder.memdump");
132 Memory::dumpMemory(ost);
133}
134
135int main(int argc, char **argv)
136{
137 // while we are non interactive, we want to abort from asserts
138 ASSERT_DO(Assert::Abort);
139 ASSERT_HOOK(dumpMemory);
140 string line;
141 char **Arguments = NULL;
142 int ArgcSize = 0;
143 int ExitFlag = 0;
144 bool ArgumentsCopied = false;
145 std::string BondGraphFileName("\n");
146
147 // print version check and copyright notice
148 cout << MOLECUILDERVERSION << endl;
149 cout << "MoleCuilder comes with ABSOLUTELY NO WARRANTY; for details type" << endl;
150 cout << "`molecuilder --warranty'." << endl;
151 cout << "`MoleCuilder - to create and alter molecular systems." << endl;
152 cout << "Copyright (C) 2010 University Bonn. All rights reserved." << endl;
153
154 setVerbosity(0);
155 // need to init the history before any action is created
156 ActionHistory::init();
157
158 // from this moment on, we need to be sure to deeinitialize in the correct order
159 // this is handled by the cleanup function
160 atexit(cleanUp);
161
162 // Parse command line options and if present create respective UI
163 {
164 // construct bond graph
165 if (World::getInstance().getConfig()->BG == NULL) {
166 World::getInstance().getConfig()->BG = new BondGraph(World::getInstance().getConfig()->GetIsAngstroem());
167 if (World::getInstance().getConfig()->BG->LoadBondLengthTable(BondGraphFileName)) {
168 DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl);
169 } else {
170 DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl);
171 }
172 }
173 // handle remaining arguments by CommandLineParser
174 if (argc>1) {
175 CommandLineParser::getInstance().InitializeCommandArguments();
176 CommandLineParser::getInstance().Run(argc,argv);
177 DoLog(0) && (Log() << Verbose(0) << "Setting UI to CommandLine." << endl);
178 UIFactory::registerFactory(new CommandLineUIFactory::description());
179 UIFactory::makeUserInterface("CommandLine");
180 } else {
181 // In the interactive mode, we can leave the user the choice in case of error
182 ASSERT_DO(Assert::Ask);
183 #ifdef USE_GUI_QT
184 DoLog(0) && (Log() << Verbose(0) << "Setting UI to Qt4." << endl);
185 UIFactory::registerFactory(new QtUIFactory::description());
186 UIFactory::makeUserInterface("Qt4");
187 #else
188 DoLog(0) && (Log() << Verbose(0) << "Setting UI to Text." << endl);
189 cout << MOLECUILDERVERSION << endl;
190 UIFactory::registerFactory(new TextUIFactory::description());
191 UIFactory::makeUserInterface("Text");
192 #endif
193 }
194 }
195
196 {
197 MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow();
198 mainWindow->display();
199 delete mainWindow;
200 }
201
202 FormatParserStorage::getInstance().SaveAll();
203 ChangeTracker::getInstance().saveStatus();
204
205 // free the new argv
206 if (ArgumentsCopied) {
207 for (int i=0; i<ArgcSize;i++)
208 delete[](Arguments[i]);
209 delete[](Arguments);
210 }
211 //delete[](ConfigFileName);
212
213 ExitFlag = World::getInstance().getExitFlag();
214 return (ExitFlag == 1 ? 0 : ExitFlag);
215}
216
217/********************************************** E N D **************************************************/
Note: See TracBrowser for help on using the repository browser.