Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/builder.cpp

    r632bc3 r97ebf8  
    6060#include "bondgraph.hpp"
    6161#include "boundary.hpp"
     62#include "CommandLineParser.hpp"
    6263#include "config.hpp"
    6364#include "element.hpp"
     
    7677#include "Actions/ActionRegistry.hpp"
    7778#include "Actions/ActionHistory.hpp"
     79#include "Actions/MapOfActions.hpp"
    7880#include "Actions/MethodAction.hpp"
    79 #include "Actions/small_actions.hpp"
     81#include "Actions/MoleculeAction/ChangeNameAction.hpp"
    8082#include "World.hpp"
    8183#include "version.h"
     
    14791481
    14801482/** Parses the command line options.
     1483 * Note that this function is from now on transitional. All commands that are not passed
     1484 * here are handled by CommandLineParser and the actions of CommandLineUIFactory.
    14811485 * \param argc argument count
    14821486 * \param **argv arguments array
     
    14861490 * \param *ConfigFileName pointer to config file name in **argv
    14871491 * \param *PathToDatabases pointer to db's path in **argv
     1492 * \param &ArgcList list of arguments that we do not parse here
    14881493 * \return exit code (0 - successful, all else - something's wrong)
    14891494 */
    1490 static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode,\
    1491                                    config& configuration, char *&ConfigFileName)
     1495static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode,
     1496                                   config& configuration, char *&ConfigFileName, list<int> &ArgcList)
    14921497{
    14931498  Vector x,y,z,n;  // coordinates for absolute point in cell volume
     
    15071512  molecule *mol = NULL;
    15081513  string BondGraphFileName("\n");
    1509   int verbosity = 0;
    15101514  strncpy(configuration.databasepath, LocalPath, MAXSTRINGSIZE-1);
    15111515
     
    15211525          case 'H':
    15221526          case '?':
    1523             DoLog(0) && (Log() << Verbose(0) << "MoleCuilder suite" << endl << "==================" << endl << endl);
    1524             DoLog(0) && (Log() << Verbose(0) << "Usage: " << argv[0] << "[config file] [-{acefpsthH?vfrp}] [further arguments]" << endl);
    1525             DoLog(0) && (Log() << Verbose(0) << "or simply " << argv[0] << " without arguments for interactive session." << endl);
    1526             DoLog(0) && (Log() << Verbose(0) << "\t-a Z x1 x2 x3\tAdd new atom of element Z at coordinates (x1,x2,x3)." << endl);
    1527             DoLog(0) && (Log() << Verbose(0) << "\t-A <source>\tCreate adjacency list from bonds parsed from 'dbond'-style file." <<endl);
    1528             DoLog(0) && (Log() << Verbose(0) << "\t-b xx xy xz yy yz zz\tCenter atoms in domain with given symmetric matrix of (xx,xy,xz,yy,yz,zz)." << endl);
    1529             DoLog(0) && (Log() << Verbose(0) << "\t-B xx xy xz yy yz zz\tBound atoms by domain with given symmetric matrix of (xx,xy,xz,yy,yz,zz)." << endl);
    1530             DoLog(0) && (Log() << Verbose(0) << "\t-c x1 x2 x3\tCenter atoms in domain with a minimum distance to boundary of (x1,x2,x3)." << endl);
    1531             DoLog(0) && (Log() << Verbose(0) << "\t-C <type> [params] <output> <bin output> <BinWidth> <BinStart> <BinEnd>\tPair Correlation analysis." << endl);
    1532             DoLog(0) && (Log() << Verbose(0) << "\t-d x1 x2 x3\tDuplicate cell along each axis by given factor." << endl);
    1533             DoLog(0) && (Log() << Verbose(0) << "\t-D <bond distance>\tDepth-First-Search Analysis of the molecule, giving cycles and tree/back edges." << endl);
    1534             DoLog(0) && (Log() << Verbose(0) << "\t-e <file>\tSets the databases path to be parsed (default: ./)." << endl);
    1535             DoLog(0) && (Log() << Verbose(0) << "\t-E <id> <Z>\tChange atom <id>'s element to <Z>, <id> begins at 0." << endl);
    1536             DoLog(0) && (Log() << Verbose(0) << "\t-f <dist> <order>\tFragments the molecule in BOSSANOVA manner (with/out rings compressed) and stores config files in same dir as config (return code 0 - fragmented, 2 - no fragmentation necessary)." << endl);
    1537             DoLog(0) && (Log() << Verbose(0) << "\t-F <xyz of filler> <dist_x> <dist_y> <dist_z> <epsilon> <randatom> <randmol> <DoRotate>\tFilling Box with water molecules." << endl);
    1538             DoLog(0) && (Log() << Verbose(0) << "\t-FF <MaxDistance> <xyz of filler> <dist_x> <dist_y> <dist_z> <epsilon> <randatom> <randmol> <DoRotate>\tFilling Box with water molecules." << endl);
    1539             DoLog(0) && (Log() << Verbose(0) << "\t-g <file>\tParses a bond length table from the given file." << endl);
    1540             DoLog(0) && (Log() << Verbose(0) << "\t-h/-H/-?\tGive this help screen." << endl);
    1541             DoLog(0) && (Log() << Verbose(0) << "\t-I\t Dissect current system of molecules into a set of disconnected (subgraphs of) molecules." << endl);
    1542             DoLog(0) && (Log() << Verbose(0) << "\t-j\t<path> Store all bonds to file." << endl);
    1543             DoLog(0) && (Log() << Verbose(0) << "\t-J\t<path> Store adjacency per atom to file." << endl);
    1544             DoLog(0) && (Log() << Verbose(0) << "\t-L <step0> <step1> <prefix>\tStore a linear interpolation between two configurations <step0> and <step1> into single config files with prefix <prefix> and as Trajectories into the current config file." << endl);
    1545             DoLog(0) && (Log() << Verbose(0) << "\t-m <0/1>\tCalculate (0)/ Align in(1) PAS with greatest EV along z axis." << endl);
    1546             DoLog(0) && (Log() << Verbose(0) << "\t-M <basis>\tSetting basis to store to MPQC config files." << endl);
    1547             DoLog(0) && (Log() << Verbose(0) << "\t-n\tFast parsing (i.e. no trajectories are looked for)." << endl);
    1548             DoLog(0) && (Log() << Verbose(0) << "\t-N <radius> <file>\tGet non-convex-envelope." << endl);
    1549             DoLog(0) && (Log() << Verbose(0) << "\t-o <out>\tGet volume of the convex envelope (and store to tecplot file)." << endl);
    1550             DoLog(0) && (Log() << Verbose(0) << "\t-O\tCenter atoms in origin." << endl);
    1551             DoLog(0) && (Log() << Verbose(0) << "\t-p <file>\tParse given xyz file and create raw config file from it." << endl);
    1552             DoLog(0) && (Log() << Verbose(0) << "\t-P <file>\tParse given forces file and append as an MD step to config file via Verlet." << endl);
    1553             DoLog(0) && (Log() << Verbose(0) << "\t-r <id>\t\tRemove an atom with given id." << endl);
    1554             DoLog(0) && (Log() << Verbose(0) << "\t-R <id> <radius>\t\tRemove all atoms out of sphere around a given one." << endl);
    1555             DoLog(0) && (Log() << Verbose(0) << "\t-s x1 x2 x3\tScale all atom coordinates by this vector (x1,x2,x3)." << endl);
    1556             DoLog(0) && (Log() << Verbose(0) << "\t-S <file> Store temperatures from the config file in <file>." << endl);
    1557             DoLog(0) && (Log() << Verbose(0) << "\t-t x1 x2 x3\tTranslate all atoms by this vector (x1,x2,x3)." << endl);
    1558             DoLog(0) && (Log() << Verbose(0) << "\t-T x1 x2 x3\tTranslate periodically all atoms by this vector (x1,x2,x3)." << endl);
    1559             DoLog(0) && (Log() << Verbose(0) << "\t-u rho\tsuspend in water solution and output necessary cell lengths, average density rho and repetition." << endl);
    1560             DoLog(0) && (Log() << Verbose(0) << "\t-v\t\tsets verbosity (more is more)." << endl);
    1561             DoLog(0) && (Log() << Verbose(0) << "\t-V\t\tGives version information." << endl);
    1562             DoLog(0) && (Log() << Verbose(0) << "\t-X\t\tset default name of a molecule." << endl);
    1563             DoLog(0) && (Log() << Verbose(0) << "Note: config files must not begin with '-' !" << endl);
    1564             return (1);
     1527            ArgcList.push_back(argptr-1);
     1528            return(1);
    15651529            break;
    15661530          case 'v':
    1567             while (argv[argptr-1][verbosity+1] == 'v') {
    1568               verbosity++;
    1569             }
    1570             setVerbosity(verbosity);
    1571             DoLog(0) && (Log() << Verbose(0) << "Setting verbosity to " << verbosity << "." << endl);
     1531            ArgcList.push_back(argptr-1);
     1532            return(1);
    15721533            break;
    15731534          case 'V':
    1574             DoLog(0) && (Log() << Verbose(0) << argv[0] << " " << VERSIONSTRING << endl);
    1575             DoLog(0) && (Log() << Verbose(0) << "Build your own molecule position set." << endl);
    1576             return (1);
     1535            ArgcList.push_back(argptr-1);
     1536            ArgcList.push_back(argptr);
     1537            argptr++;
    15771538            break;
    15781539          case 'B':
     
    17411702                  DoLog(2) && (Log() << Verbose(2) << "found element " << first->type->name << endl);
    17421703                for (int i=NDIM;i--;)
    1743                   first->x.x[i] = atof(argv[argptr+1+i]);
     1704                  first->x[i] = atof(argv[argptr+1+i]);
    17441705                if (first->type != NULL) {
    17451706                  mol->AddAtom(first);  // add to molecule
     
    20131974                first = World::getInstance().createAtom();
    20141975                first->type = periode->FindElement(1);
    2015                 first->x.Init(0.441, -0.143, 0.);
     1976                first->x = Vector(0.441, -0.143, 0.);
    20161977                filler->AddAtom(first);
    20171978                second = World::getInstance().createAtom();
    20181979                second->type = periode->FindElement(1);
    2019                 second->x.Init(-0.464, 1.137, 0.0);
     1980                second->x = Vector(-0.464, 1.137, 0.0);
    20201981                filler->AddAtom(second);
    20211982                third = World::getInstance().createAtom();
    20221983                third->type = periode->FindElement(8);
    2023                 third->x.Init(-0.464, 0.177, 0.);
     1984                third->x = Vector(-0.464, 0.177, 0.);
    20241985                filler->AddAtom(third);
    20251986                filler->AddBond(first, third, 1);
     
    21862147                    first = second;
    21872148                    second = first->next;
    2188                     if (first->x.DistanceSquared((const Vector *)&third->x) > tmp1*tmp1) // distance to first above radius ...
     2149                    if (first->x.DistanceSquared(third->x) > tmp1*tmp1) // distance to first above radius ...
    21892150                      mol->RemoveAtom(first);
    21902151                  }
     
    22062167                DoLog(1) && (Log() << Verbose(1) << "Translating all ions by given vector." << endl);
    22072168                for (int i=NDIM;i--;)
    2208                   x.x[i] = atof(argv[argptr+i]);
     2169                  x[i] = atof(argv[argptr+i]);
    22092170                mol->Translate((const Vector *)&x);
    22102171                argptr+=3;
     
    22222183                DoLog(1) && (Log() << Verbose(1) << "Translating all ions periodically by given vector." << endl);
    22232184                for (int i=NDIM;i--;)
    2224                   x.x[i] = atof(argv[argptr+i]);
     2185                  x[i] = atof(argv[argptr+i]);
    22252186                mol->TranslatePeriodically((const Vector *)&x);
    22262187                argptr+=3;
     
    22452206                for (int i=0;i<NDIM;i++) {
    22462207                  j += i+1;
    2247                   x.x[i] = atof(argv[NDIM+i]);
     2208                  x[i] = atof(argv[NDIM+i]);
    22482209                  cell_size[j]*=factor[i];
    22492210                }
     
    23092270                for (int i=0;i<NDIM;i++) {
    23102271                  j += i+1;
    2311                   x.x[i] = atof(argv[argptr+i]);
    2312                   cell_size[j] += x.x[i]*2.;
     2272                  x[i] = atof(argv[argptr+i]);
     2273                  cell_size[j] += x[i]*2.;
    23132274                }
    23142275                mol->Translate((const Vector *)&x);
     
    24682429                    x.Zero();
    24692430                    y.Zero();
    2470                     y.x[abs(axis)-1] = cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude
     2431                    y[abs(axis)-1] = cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude
    24712432                    for (int i=1;i<faktor;i++) {  // then add this list with respective translation factor times
    2472                       x.AddVector(&y); // per factor one cell width further
     2433                      x += y; // per factor one cell width further
    24732434                      for (int k=count;k--;) { // go through every atom of the original cell
    24742435                        first = World::getInstance().createAtom(); // create a new body
    2475                         first->x.CopyVector(vectors[k]);  // use coordinate of original atom
    2476                         first->x.AddVector(&x);      // translate the coordinates
     2436                        first->x = (*vectors[k]) + x;
    24772437                        first->type = Elements[k];  // insert original element
    24782438                        mol->AddAtom(first);        // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
     
    24842444                    // correct cell size
    24852445                    if (axis < 0) { // if sign was negative, we have to translate everything
    2486                       x.Zero();
    2487                       x.AddVector(&y);
    2488                       x.Scale(-(faktor-1));
     2446                      x =(-(faktor-1)) * y;
    24892447                      mol->Translate(&x);
    24902448                    }
     
    25142472};
    25152473
    2516 /***************************************** Functions used to build all menus **********************/
    2517 
    2518 void populateEditMoleculesMenu(Menu* editMoleculesMenu,MoleculeListClass *molecules, config *configuration, periodentafel *periode){
    2519   // build the EditMoleculesMenu
    2520   Action *createMoleculeAction = new MethodAction("createMoleculeAction",boost::bind(&MoleculeListClass::createNewMolecule,molecules,periode));
    2521   new ActionMenuItem('c',"create new molecule",editMoleculesMenu,createMoleculeAction);
    2522 
    2523   Action *loadMoleculeAction = new MethodAction("loadMoleculeAction",boost::bind(&MoleculeListClass::loadFromXYZ,molecules,periode));
    2524   new ActionMenuItem('l',"load molecule from xyz file",editMoleculesMenu,loadMoleculeAction);
    2525 
    2526   Action *changeFilenameAction = new ChangeMoleculeNameAction(molecules);
    2527   new ActionMenuItem('n',"change molecule's name",editMoleculesMenu,changeFilenameAction);
    2528 
    2529   Action *giveFilenameAction = new MethodAction("giveFilenameAction",boost::bind(&MoleculeListClass::setMoleculeFilename,molecules));
    2530   new ActionMenuItem('N',"give molecules filename",editMoleculesMenu,giveFilenameAction);
    2531 
    2532   Action *parseAtomsAction = new MethodAction("parseAtomsAction",boost::bind(&MoleculeListClass::parseXYZIntoMolecule,molecules));
    2533   new ActionMenuItem('p',"parse atoms in xyz file into molecule",editMoleculesMenu,parseAtomsAction);
    2534 
    2535   Action *eraseMoleculeAction = new MethodAction("eraseMoleculeAction",boost::bind(&MoleculeListClass::eraseMolecule,molecules));
    2536   new ActionMenuItem('r',"remove a molecule",editMoleculesMenu,eraseMoleculeAction);
    2537 
    2538 }
    2539 
    2540 
    25412474/********************************************** Main routine **************************************/
    25422475
    2543 void cleanUp(config *configuration){
    2544   UIFactory::purgeInstance();
     2476void cleanUp(){
    25452477  World::purgeInstance();
    2546   delete(configuration);
    25472478  Log() << Verbose(0) <<  "Maximum of allocated memory: "
    25482479    << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
     
    25522483  logger::purgeInstance();
    25532484  errorLogger::purgeInstance();
     2485  UIFactory::purgeInstance();
     2486  MapOfActions::purgeInstance();
     2487  CommandLineParser::purgeInstance();
    25542488  ActionRegistry::purgeInstance();
    25552489  ActionHistory::purgeInstance();
     
    25582492int main(int argc, char **argv)
    25592493{
    2560     molecule *mol = NULL;
    2561     config *configuration = new config;
     2494    config *configuration = World::getInstance().getConfig();
    25622495    Vector x, y, z, n;
    25632496    ifstream test;
    25642497    ofstream output;
    25652498    string line;
    2566     char *ConfigFileName = NULL;
    2567     int j;
     2499    char **Arguments = NULL;
     2500    int ArgcSize = 0;
     2501    bool ArgumentsCopied = false;
    25682502
    25692503    cout << ESPACKVersion << endl;
     
    25722506    // need to init the history before any action is created
    25732507    ActionHistory::init();
    2574     /* structure of ParseCommandLineOptions will be refactored later */
    2575     j = ParseCommandLineOptions(argc, argv,  World::getInstance().getMolecules(), World::getInstance().getPeriode(), *configuration, ConfigFileName);
    2576     switch (j){
    2577         case 255:
    2578         case 2:
    2579         case 1:
    2580             cleanUp(configuration);
    2581             return (j == 1 ? 0 : j);
    2582         default:
    2583             break;
     2508
     2509    // Parse command line options and if present create respective UI
     2510    {
     2511      list<int> ArgcList;
     2512      ArgcList.push_back(0); // push back program!
     2513      ArgcList.push_back(1); // push back config file name
     2514      char ConfigFileName[MAXSTRINGSIZE];
     2515      // handle arguments by ParseCommandLineOptions()
     2516      ParseCommandLineOptions(argc,argv,World::getInstance().getMolecules(),World::getInstance().getPeriode(),*World::getInstance().getConfig(), (char *&)ConfigFileName, ArgcList);
     2517      // copy all remaining arguments to a new argv
     2518      Arguments = Malloc<char *>(ArgcList.size(), "main - **Arguments");
     2519      cout << "The following arguments are handled by CommandLineParser: ";
     2520      for (list<int>::iterator ArgcRunner = ArgcList.begin(); ArgcRunner != ArgcList.end(); ++ArgcRunner) {
     2521        Arguments[ArgcSize] = Malloc<char>(strlen(argv[*ArgcRunner])+2, "main - *Arguments[]");
     2522        strcpy(Arguments[ArgcSize], argv[*ArgcRunner]);
     2523        cout << " " << argv[*ArgcRunner];
     2524        ArgcSize++;
     2525      }
     2526      cout << endl;
     2527      ArgumentsCopied = true;
     2528      // handle remaining arguments by CommandLineParser
     2529      MapOfActions::getInstance().AddOptionsToParser();
     2530      CommandLineParser::getInstance().Run(ArgcSize,Arguments);
     2531      if (!CommandLineParser::getInstance().isEmpty()) {
     2532        DoLog(0) && (Log() << Verbose(0) << "Setting UI to CommandLine." << endl);
     2533        UIFactory::makeUserInterface(UIFactory::CommandLine);
     2534      } else {
     2535        DoLog(0) && (Log() << Verbose(0) << "Setting UI to Text." << endl);
     2536        UIFactory::makeUserInterface(UIFactory::Text);
     2537      }
    25842538    }
    2585     if(World::getInstance().numMolecules() == 0){
    2586         mol = World::getInstance().createMolecule();
    2587         World::getInstance().getMolecules()->insert(mol);
    2588         cout << "Molecule created" << endl;
    2589         if(World::getInstance().getDomain()[0] == 0.){
    2590             Log() << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl;
    2591             for(int i = 0;i < 6;i++){
    2592                 Log() << Verbose(1) << "Cell size" << i << ": ";
    2593                 cin >> World::getInstance().getDomain()[i];
    2594             }
    2595         }
    2596         mol->ActiveFlag = true;
    2597     }
    25982539
    25992540    {
    2600       cout << ESPACKVersion << endl;
    2601 
    2602       setVerbosity(0);
    2603 
    2604       menuPopulaters populaters;
    2605       populaters.MakeEditMoleculesMenu = populateEditMoleculesMenu;
    2606 
    2607       UIFactory::makeUserInterface(UIFactory::Text);
    2608       MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow(populaters,World::getInstance().getMolecules(), configuration, World::getInstance().getPeriode(), ConfigFileName);
     2541      MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow();
    26092542      mainWindow->display();
    26102543      delete mainWindow;
     
    26172550        Log() << Verbose(0) << "Saving of elements.db failed." << endl;
    26182551
    2619   cleanUp(configuration);
    2620 
     2552  // free the new argv
     2553  if (ArgumentsCopied) {
     2554    for (int i=0; i<ArgcSize;i++)
     2555      Free(&Arguments[i]);
     2556    Free(&Arguments);
     2557  }
     2558
     2559  cleanUp();
    26212560  Memory::getState();
    26222561  return (0);
Note: See TracChangeset for help on using the changeset viewer.