Changes in src/builder.cpp [632bc3:97ebf8]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/builder.cpp
r632bc3 r97ebf8 60 60 #include "bondgraph.hpp" 61 61 #include "boundary.hpp" 62 #include "CommandLineParser.hpp" 62 63 #include "config.hpp" 63 64 #include "element.hpp" … … 76 77 #include "Actions/ActionRegistry.hpp" 77 78 #include "Actions/ActionHistory.hpp" 79 #include "Actions/MapOfActions.hpp" 78 80 #include "Actions/MethodAction.hpp" 79 #include "Actions/ small_actions.hpp"81 #include "Actions/MoleculeAction/ChangeNameAction.hpp" 80 82 #include "World.hpp" 81 83 #include "version.h" … … 1479 1481 1480 1482 /** 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. 1481 1485 * \param argc argument count 1482 1486 * \param **argv arguments array … … 1486 1490 * \param *ConfigFileName pointer to config file name in **argv 1487 1491 * \param *PathToDatabases pointer to db's path in **argv 1492 * \param &ArgcList list of arguments that we do not parse here 1488 1493 * \return exit code (0 - successful, all else - something's wrong) 1489 1494 */ 1490 static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode, \1491 config& configuration, char *&ConfigFileName )1495 static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode, 1496 config& configuration, char *&ConfigFileName, list<int> &ArgcList) 1492 1497 { 1493 1498 Vector x,y,z,n; // coordinates for absolute point in cell volume … … 1507 1512 molecule *mol = NULL; 1508 1513 string BondGraphFileName("\n"); 1509 int verbosity = 0;1510 1514 strncpy(configuration.databasepath, LocalPath, MAXSTRINGSIZE-1); 1511 1515 … … 1521 1525 case 'H': 1522 1526 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); 1565 1529 break; 1566 1530 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); 1572 1533 break; 1573 1534 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++; 1577 1538 break; 1578 1539 case 'B': … … 1741 1702 DoLog(2) && (Log() << Verbose(2) << "found element " << first->type->name << endl); 1742 1703 for (int i=NDIM;i--;) 1743 first->x .x[i] = atof(argv[argptr+1+i]);1704 first->x[i] = atof(argv[argptr+1+i]); 1744 1705 if (first->type != NULL) { 1745 1706 mol->AddAtom(first); // add to molecule … … 2013 1974 first = World::getInstance().createAtom(); 2014 1975 first->type = periode->FindElement(1); 2015 first->x .Init(0.441, -0.143, 0.);1976 first->x = Vector(0.441, -0.143, 0.); 2016 1977 filler->AddAtom(first); 2017 1978 second = World::getInstance().createAtom(); 2018 1979 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); 2020 1981 filler->AddAtom(second); 2021 1982 third = World::getInstance().createAtom(); 2022 1983 third->type = periode->FindElement(8); 2023 third->x .Init(-0.464, 0.177, 0.);1984 third->x = Vector(-0.464, 0.177, 0.); 2024 1985 filler->AddAtom(third); 2025 1986 filler->AddBond(first, third, 1); … … 2186 2147 first = second; 2187 2148 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 ... 2189 2150 mol->RemoveAtom(first); 2190 2151 } … … 2206 2167 DoLog(1) && (Log() << Verbose(1) << "Translating all ions by given vector." << endl); 2207 2168 for (int i=NDIM;i--;) 2208 x .x[i] = atof(argv[argptr+i]);2169 x[i] = atof(argv[argptr+i]); 2209 2170 mol->Translate((const Vector *)&x); 2210 2171 argptr+=3; … … 2222 2183 DoLog(1) && (Log() << Verbose(1) << "Translating all ions periodically by given vector." << endl); 2223 2184 for (int i=NDIM;i--;) 2224 x .x[i] = atof(argv[argptr+i]);2185 x[i] = atof(argv[argptr+i]); 2225 2186 mol->TranslatePeriodically((const Vector *)&x); 2226 2187 argptr+=3; … … 2245 2206 for (int i=0;i<NDIM;i++) { 2246 2207 j += i+1; 2247 x .x[i] = atof(argv[NDIM+i]);2208 x[i] = atof(argv[NDIM+i]); 2248 2209 cell_size[j]*=factor[i]; 2249 2210 } … … 2309 2270 for (int i=0;i<NDIM;i++) { 2310 2271 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.; 2313 2274 } 2314 2275 mol->Translate((const Vector *)&x); … … 2468 2429 x.Zero(); 2469 2430 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 magnitude2431 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 2471 2432 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 further2433 x += y; // per factor one cell width further 2473 2434 for (int k=count;k--;) { // go through every atom of the original cell 2474 2435 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; 2477 2437 first->type = Elements[k]; // insert original element 2478 2438 mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...) … … 2484 2444 // correct cell size 2485 2445 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; 2489 2447 mol->Translate(&x); 2490 2448 } … … 2514 2472 }; 2515 2473 2516 /***************************************** Functions used to build all menus **********************/2517 2518 void populateEditMoleculesMenu(Menu* editMoleculesMenu,MoleculeListClass *molecules, config *configuration, periodentafel *periode){2519 // build the EditMoleculesMenu2520 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 2541 2474 /********************************************** Main routine **************************************/ 2542 2475 2543 void cleanUp(config *configuration){ 2544 UIFactory::purgeInstance(); 2476 void cleanUp(){ 2545 2477 World::purgeInstance(); 2546 delete(configuration);2547 2478 Log() << Verbose(0) << "Maximum of allocated memory: " 2548 2479 << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl; … … 2552 2483 logger::purgeInstance(); 2553 2484 errorLogger::purgeInstance(); 2485 UIFactory::purgeInstance(); 2486 MapOfActions::purgeInstance(); 2487 CommandLineParser::purgeInstance(); 2554 2488 ActionRegistry::purgeInstance(); 2555 2489 ActionHistory::purgeInstance(); … … 2558 2492 int main(int argc, char **argv) 2559 2493 { 2560 molecule *mol = NULL; 2561 config *configuration = new config; 2494 config *configuration = World::getInstance().getConfig(); 2562 2495 Vector x, y, z, n; 2563 2496 ifstream test; 2564 2497 ofstream output; 2565 2498 string line; 2566 char *ConfigFileName = NULL; 2567 int j; 2499 char **Arguments = NULL; 2500 int ArgcSize = 0; 2501 bool ArgumentsCopied = false; 2568 2502 2569 2503 cout << ESPACKVersion << endl; … … 2572 2506 // need to init the history before any action is created 2573 2507 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 } 2584 2538 } 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 }2598 2539 2599 2540 { 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(); 2609 2542 mainWindow->display(); 2610 2543 delete mainWindow; … … 2617 2550 Log() << Verbose(0) << "Saving of elements.db failed." << endl; 2618 2551 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(); 2621 2560 Memory::getState(); 2622 2561 return (0);
Note:
See TracChangeset
for help on using the changeset viewer.