Changes in src/builder.cpp [68f03d:980dd6]
- File:
-
- 1 edited
-
src/builder.cpp (modified) (34 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/builder.cpp
r68f03d r980dd6 53 53 54 54 #include <cstring> 55 #include <cstdlib> 55 56 56 57 #include "analysis_bonds.hpp" … … 60 61 #include "bondgraph.hpp" 61 62 #include "boundary.hpp" 63 #include "CommandLineParser.hpp" 62 64 #include "config.hpp" 63 65 #include "element.hpp" … … 76 78 #include "Actions/ActionRegistry.hpp" 77 79 #include "Actions/ActionHistory.hpp" 80 #include "Actions/MapOfActions.hpp" 78 81 #include "Actions/MethodAction.hpp" 79 #include "Actions/ small_actions.hpp"82 #include "Actions/MoleculeAction/ChangeNameAction.hpp" 80 83 #include "World.hpp" 81 84 #include "version.h" … … 862 865 863 866 mol->CountAtoms(); // recount atoms 864 if (mol-> AtomCount!= 0) { // if there is more than none865 count = mol-> AtomCount; // is changed becausing of adding, thus has to be stored away beforehand867 if (mol->getAtomCount() != 0) { // if there is more than none 868 count = mol->getAtomCount(); // is changed becausing of adding, thus has to be stored away beforehand 866 869 Elements = new element *[count]; 867 870 vectors = new Vector *[count]; … … 1293 1296 // generate some KeySets 1294 1297 DoLog(0) && (Log() << Verbose(0) << "Generating KeySets." << endl); 1295 KeySet TestSets[mol-> AtomCount+1];1298 KeySet TestSets[mol->getAtomCount()+1]; 1296 1299 i=1; 1297 1300 while (Walker->next != mol->end) { … … 1304 1307 DoLog(0) && (Log() << Verbose(0) << "Testing insertion of already present item in KeySets." << endl); 1305 1308 KeySetTestPair test; 1306 test = TestSets[mol-> AtomCount-1].insert(Walker->nr);1309 test = TestSets[mol->getAtomCount()-1].insert(Walker->nr); 1307 1310 if (test.second) { 1308 1311 DoLog(1) && (Log() << Verbose(1) << "Insertion worked?!" << endl); … … 1310 1313 DoLog(1) && (Log() << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl); 1311 1314 } 1312 TestSets[mol-> AtomCount].insert(mol->end->previous->nr);1313 TestSets[mol-> AtomCount].insert(mol->end->previous->previous->previous->nr);1315 TestSets[mol->getAtomCount()].insert(mol->end->previous->nr); 1316 TestSets[mol->getAtomCount()].insert(mol->end->previous->previous->previous->nr); 1314 1317 1315 1318 // constructing Graph structure … … 1319 1322 // insert KeySets into Subgraphs 1320 1323 DoLog(0) && (Log() << Verbose(0) << "Inserting KeySets into Subgraph class." << endl); 1321 for (int j=0;j<mol-> AtomCount;j++) {1324 for (int j=0;j<mol->getAtomCount();j++) { 1322 1325 Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.))); 1323 1326 } 1324 1327 DoLog(0) && (Log() << Verbose(0) << "Testing insertion of already present item in Subgraph." << endl); 1325 1328 GraphTestPair test2; 1326 test2 = Subgraphs.insert(GraphPair (TestSets[mol-> AtomCount],pair<int, double>(counter++, 1.)));1329 test2 = Subgraphs.insert(GraphPair (TestSets[mol->getAtomCount()],pair<int, double>(counter++, 1.))); 1327 1330 if (test2.second) { 1328 1331 DoLog(1) && (Log() << Verbose(1) << "Insertion worked?!" << endl); … … 1479 1482 1480 1483 /** Parses the command line options. 1484 * Note that this function is from now on transitional. All commands that are not passed 1485 * here are handled by CommandLineParser and the actions of CommandLineUIFactory. 1481 1486 * \param argc argument count 1482 1487 * \param **argv arguments array … … 1486 1491 * \param *ConfigFileName pointer to config file name in **argv 1487 1492 * \param *PathToDatabases pointer to db's path in **argv 1493 * \param &ArgcList list of arguments that we do not parse here 1488 1494 * \return exit code (0 - successful, all else - something's wrong) 1489 1495 */ 1490 static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode, \1491 config& configuration, char * &ConfigFileName)1496 static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode, 1497 config& configuration, char **ConfigFileName, set<int> &ArgcList) 1492 1498 { 1493 1499 Vector x,y,z,n; // coordinates for absolute point in cell volume … … 1507 1513 molecule *mol = NULL; 1508 1514 string BondGraphFileName("\n"); 1509 int verbosity = 0; 1510 strncpy(configuration.databasepath, LocalPath, MAXSTRINGSIZE-1); 1515 bool DatabasePathGiven = false; 1511 1516 1512 1517 if (argc > 1) { // config file specified as option … … 1521 1526 case 'H': 1522 1527 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); 1528 ArgcList.insert(argptr-1); 1529 return(1); 1565 1530 break; 1566 1531 case 'v': 1567 while (argv[argptr-1][verbosity+1] == 'v') { 1568 verbosity++; 1532 if ((argptr >= argc) || (argv[argptr][0] == '-')) { 1533 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for specifying verbosity: -v <level>" << endl); 1534 performCriticalExit(); 1535 } else { 1536 setVerbosity(atoi(argv[argptr])); 1537 ArgcList.insert(argptr-1); 1538 ArgcList.insert(argptr); 1539 argptr++; 1569 1540 } 1570 setVerbosity(verbosity);1571 DoLog(0) && (Log() << Verbose(0) << "Setting verbosity to " << verbosity << "." << endl);1572 1541 break; 1573 1542 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); 1543 ArgcList.insert(argptr-1); 1544 return(1); 1577 1545 break; 1578 1546 case 'B': 1579 1547 if (ExitFlag == 0) ExitFlag = 1; 1580 if ((argptr+5 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) ) { 1581 ExitFlag = 255; 1582 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for bounding in box: -B <xx> <xy> <xz> <yy> <yz> <zz>" << endl); 1548 if ((argptr+5 >= argc)) { 1549 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for setting Box: -B <xx> <<xy> <<xz> <yy> <yz> <zz>" << endl); 1583 1550 performCriticalExit(); 1584 1551 } else { 1585 SaveFlag = true;1586 j = -1;1587 DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl);1588 double * const cell_size = World::getInstance().getDomain();1589 for (int i=0;i<6;i++) {1590 cell_size[i] = atof(argv[argptr+i]);1591 }1552 ArgcList.insert(argptr-1); 1553 ArgcList.insert(argptr); 1554 ArgcList.insert(argptr+1); 1555 ArgcList.insert(argptr+2); 1556 ArgcList.insert(argptr+3); 1557 ArgcList.insert(argptr+4); 1558 ArgcList.insert(argptr+5); 1592 1559 argptr+=6; 1593 1560 } … … 1598 1565 performCriticalExit(); 1599 1566 } else { 1600 DoLog(0) && (Log() << Verbose(0) << "Using " << argv[argptr] << " as elements database." << endl);1601 strncpy (configuration.databasepath, argv[argptr], MAXSTRINGSIZE-1);1567 ArgcList.insert(argptr-1); 1568 ArgcList.insert(argptr); 1602 1569 argptr+=1; 1603 1570 } … … 1608 1575 performCriticalExit(); 1609 1576 } else { 1610 BondGraphFileName = argv[argptr]; 1611 DoLog(0) && (Log() << Verbose(0) << "Using " << BondGraphFileName << " as bond length table." << endl); 1577 ArgcList.insert(argptr-1); 1578 ArgcList.insert(argptr); 1579 argptr+=1; 1580 } 1581 break; 1582 case 'M': 1583 if ((argptr >= argc) || (argv[argptr][0] == '-')) { 1584 ExitFlag = 255; 1585 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for setting MPQC basis: -M <basis name>" << endl); 1586 performCriticalExit(); 1587 } else { 1588 ArgcList.insert(argptr-1); 1589 ArgcList.insert(argptr); 1612 1590 argptr+=1; 1613 1591 } 1614 1592 break; 1615 1593 case 'n': 1616 DoLog(0) && (Log() << Verbose(0) << "I won't parse trajectories." << endl); 1617 configuration.FastParsing = true; 1594 if ((argptr >= argc) || (argv[argptr][0] == '-')) { 1595 ExitFlag = 255; 1596 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for setting fast-parsing: -n <0/1>" << endl); 1597 performCriticalExit(); 1598 } else { 1599 ArgcList.insert(argptr-1); 1600 ArgcList.insert(argptr); 1601 argptr+=1; 1602 } 1618 1603 break; 1619 1604 case 'X': 1620 { 1621 World::getInstance().setDefaultName(argv[argptr]); 1622 DoLog(0) && (Log() << Verbose(0) << "Default name of new molecules set to " << *World::getInstance().getDefaultName() << "." << endl); 1605 if ((argptr >= argc) || (argv[argptr][0] == '-')) { 1606 ExitFlag = 255; 1607 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for setting default molecule name: -X <name>" << endl); 1608 performCriticalExit(); 1609 } else { 1610 ArgcList.insert(argptr-1); 1611 ArgcList.insert(argptr); 1612 argptr+=1; 1623 1613 } 1624 1614 break; … … 1631 1621 } while (argptr < argc); 1632 1622 1633 // 3a. Parse the element database1634 if (periode->LoadPeriodentafel(configuration.databasepath)) {1635 DoLog(0) && (Log() << Verbose(0) << "Element list loaded successfully." << endl);1636 //periode->Output();1637 } else {1638 DoLog(0) && (Log() << Verbose(0) << "Element list loading failed." << endl);1639 return 1;1640 }1641 1623 // 3b. Find config file name and parse if possible, also BondGraphFileName 1642 1624 if (argv[1][0] != '-') { … … 1652 1634 } else { 1653 1635 DoLog(0) && (Log() << Verbose(0) << "Empty configuration file." << endl); 1654 ConfigFileName = argv[1];1636 strcpy(*ConfigFileName, argv[1]); 1655 1637 configPresent = empty; 1656 1638 output.close(); … … 1658 1640 } else { 1659 1641 test.close(); 1660 ConfigFileName = argv[1];1642 strcpy(*ConfigFileName, argv[1]); 1661 1643 DoLog(1) && (Log() << Verbose(1) << "Specified config file found, parsing ... "); 1662 switch (configuration.TestSyntax( ConfigFileName, periode)) {1644 switch (configuration.TestSyntax(*ConfigFileName, periode)) { 1663 1645 case 1: 1664 1646 DoLog(0) && (Log() << Verbose(0) << "new syntax." << endl); 1665 configuration.Load( ConfigFileName, BondGraphFileName, periode, molecules);1647 configuration.Load(*ConfigFileName, BondGraphFileName, periode, molecules); 1666 1648 configPresent = present; 1667 1649 break; 1668 1650 case 0: 1669 1651 DoLog(0) && (Log() << Verbose(0) << "old syntax." << endl); 1670 configuration.LoadOld( ConfigFileName, BondGraphFileName, periode, molecules);1652 configuration.LoadOld(*ConfigFileName, BondGraphFileName, periode, molecules); 1671 1653 configPresent = present; 1672 1654 break; … … 1689 1671 mol = World::getInstance().createMolecule(); 1690 1672 mol->ActiveFlag = true; 1691 if ( ConfigFileName != NULL)1692 mol->SetNameFromFilename( ConfigFileName);1673 if (*ConfigFileName != NULL) 1674 mol->SetNameFromFilename(*ConfigFileName); 1693 1675 molecules->insert(mol); 1694 }1695 if (configuration.BG == NULL) {1696 configuration.BG = new BondGraph(configuration.GetIsAngstroem());1697 if ((!BondGraphFileName.empty()) && (configuration.BG->LoadBondLengthTable(BondGraphFileName))) {1698 DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl);1699 } else {1700 DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl);1701 }1702 1676 } 1703 1677 … … 1729 1703 case 'a': 1730 1704 if (ExitFlag == 0) ExitFlag = 1; 1731 if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3]))) {1705 if ((argptr+4 >= argc) || (argv[argptr][0] == '-')) { 1732 1706 ExitFlag = 255; 1733 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for adding atom: -a <element><x> <y> <z>" << endl);1707 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough arguments for adding atom: -a <Z> --position <x> <y> <z>" << endl); 1734 1708 performCriticalExit(); 1735 1709 } else { 1736 SaveFlag = true; 1737 Log() << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), "; 1738 first = World::getInstance().createAtom(); 1739 first->type = periode->FindElement(atoi(argv[argptr])); 1740 if (first->type != NULL) 1741 DoLog(2) && (Log() << Verbose(2) << "found element " << first->type->name << endl); 1742 for (int i=NDIM;i--;) 1743 first->x[i] = atof(argv[argptr+1+i]); 1744 if (first->type != NULL) { 1745 mol->AddAtom(first); // add to molecule 1746 if ((configPresent == empty) && (mol->AtomCount != 0)) 1747 configPresent = present; 1748 } else 1749 DoeLog(1) && (eLog()<< Verbose(1) << "Could not find the specified element." << endl); 1750 argptr+=4; 1710 ArgcList.insert(argptr-1); 1711 ArgcList.insert(argptr); 1712 ArgcList.insert(argptr+1); 1713 ArgcList.insert(argptr+2); 1714 ArgcList.insert(argptr+3); 1715 ArgcList.insert(argptr+4); 1716 argptr+=5; 1751 1717 } 1752 1718 break; … … 1757 1723 if (configPresent == present) { 1758 1724 switch(argv[argptr-1][1]) { 1759 case 'M': 1725 case 'D': 1726 if (ExitFlag == 0) ExitFlag = 1; 1760 1727 if ((argptr >= argc) || (argv[argptr][0] == '-')) { 1761 1728 ExitFlag = 255; 1762 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for setting MPQC basis: -B <basis name>" << endl);1729 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for depth-first-search analysis: -D <max. bond distance>" << endl); 1763 1730 performCriticalExit(); 1764 1731 } else { 1765 configuration.basis = argv[argptr];1766 DoLog(1) && (Log() << Verbose(1) << "Setting MPQC basis to " << configuration.basis << "." << endl);1732 ArgcList.insert(argptr-1); 1733 ArgcList.insert(argptr); 1767 1734 argptr+=1; 1768 1735 } 1769 break;1770 case 'D':1771 if (ExitFlag == 0) ExitFlag = 1;1772 {1773 DoLog(1) && (Log() << Verbose(1) << "Depth-First-Search Analysis." << endl);1774 MoleculeLeafClass *Subgraphs = NULL; // list of subgraphs from DFS analysis1775 int *MinimumRingSize = new int[mol->AtomCount];1776 atom ***ListOfLocalAtoms = NULL;1777 class StackClass<bond *> *BackEdgeStack = NULL;1778 class StackClass<bond *> *LocalBackEdgeStack = NULL;1779 mol->CreateAdjacencyList(atof(argv[argptr]), configuration.GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);1780 Subgraphs = mol->DepthFirstSearchAnalysis(BackEdgeStack);1781 if (Subgraphs != NULL) {1782 int FragmentCounter = 0;1783 while (Subgraphs->next != NULL) {1784 Subgraphs = Subgraphs->next;1785 Subgraphs->FillBondStructureFromReference(mol, FragmentCounter, ListOfLocalAtoms, false); // we want to keep the created ListOfLocalAtoms1786 LocalBackEdgeStack = new StackClass<bond *> (Subgraphs->Leaf->BondCount);1787 Subgraphs->Leaf->PickLocalBackEdges(ListOfLocalAtoms[FragmentCounter], BackEdgeStack, LocalBackEdgeStack);1788 Subgraphs->Leaf->CyclicStructureAnalysis(LocalBackEdgeStack, MinimumRingSize);1789 delete(LocalBackEdgeStack);1790 delete(Subgraphs->previous);1791 FragmentCounter++;1792 }1793 delete(Subgraphs);1794 for (int i=0;i<FragmentCounter;i++)1795 Free(&ListOfLocalAtoms[i]);1796 Free(&ListOfLocalAtoms);1797 }1798 delete(BackEdgeStack);1799 delete[](MinimumRingSize);1800 }1801 //argptr+=1;1802 1736 break; 1803 1737 case 'I': 1804 1738 DoLog(1) && (Log() << Verbose(1) << "Dissecting molecular system into a set of disconnected subgraphs ... " << endl); 1805 // @TODO rather do the dissection afterwards 1806 molecules->DissectMoleculeIntoConnectedSubgraphs(periode, &configuration); 1807 mol = NULL; 1808 if (molecules->ListOfMolecules.size() != 0) { 1809 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) 1810 if ((*ListRunner)->ActiveFlag) { 1811 mol = *ListRunner; 1812 break; 1813 } 1814 } 1815 if ((mol == NULL) && (!molecules->ListOfMolecules.empty())) { 1816 mol = *(molecules->ListOfMolecules.begin()); 1817 if (mol != NULL) 1818 mol->ActiveFlag = true; 1819 } 1739 ArgcList.insert(argptr-1); 1740 argptr+=0; 1820 1741 break; 1821 1742 case 'C': 1822 1743 { 1823 int ranges[3] = {1, 1, 1};1824 bool periodic = (argv[argptr-1][2] =='p');1825 1744 if (ExitFlag == 0) ExitFlag = 1; 1826 if ((argptr >= argc)) {1745 if ((argptr+11 >= argc)) { 1827 1746 ExitFlag = 255; 1828 1747 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for pair correlation analysis: -C[p] <type: E/P/S> [more params] <output> <bin output> <BinStart> <BinEnd>" << endl); … … 1831 1750 switch(argv[argptr][0]) { 1832 1751 case 'E': 1833 { 1834 if ((argptr+6 >= argc) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+5])) || (!IsValidNumber(argv[argptr+6])) || (!IsValidNumber(argv[argptr+2])) || (argv[argptr+1][0] == '-') || (argv[argptr+2][0] == '-') || (argv[argptr+3][0] == '-') || (argv[argptr+4][0] == '-')) { 1835 ExitFlag = 255; 1836 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for pair correlation analysis: -C E <Z1> <Z2> <output> <bin output>" << endl); 1837 performCriticalExit(); 1838 } else { 1839 ofstream output(argv[argptr+3]); 1840 ofstream binoutput(argv[argptr+4]); 1841 const double BinStart = atof(argv[argptr+5]); 1842 const double BinEnd = atof(argv[argptr+6]); 1843 1844 const element *elemental = periode->FindElement((const int) atoi(argv[argptr+1])); 1845 const element *elemental2 = periode->FindElement((const int) atoi(argv[argptr+2])); 1846 PairCorrelationMap *correlationmap = NULL; 1847 if (periodic) 1848 correlationmap = PeriodicPairCorrelation(molecules, elemental, elemental2, ranges); 1849 else 1850 correlationmap = PairCorrelation(molecules, elemental, elemental2); 1851 //OutputCorrelationToSurface(&output, correlationmap); 1852 BinPairMap *binmap = BinData( correlationmap, 0.5, BinStart, BinEnd ); 1853 OutputCorrelation ( &binoutput, binmap ); 1854 output.close(); 1855 binoutput.close(); 1856 delete(binmap); 1857 delete(correlationmap); 1858 argptr+=7; 1859 } 1860 } 1752 ArgcList.insert(argptr-1); 1753 ArgcList.insert(argptr); 1754 ArgcList.insert(argptr+1); 1755 ArgcList.insert(argptr+2); 1756 ArgcList.insert(argptr+3); 1757 ArgcList.insert(argptr+4); 1758 ArgcList.insert(argptr+5); 1759 ArgcList.insert(argptr+6); 1760 ArgcList.insert(argptr+7); 1761 ArgcList.insert(argptr+8); 1762 ArgcList.insert(argptr+9); 1763 ArgcList.insert(argptr+10); 1764 ArgcList.insert(argptr+11); 1765 argptr+=12; 1861 1766 break; 1862 1767 1863 1768 case 'P': 1864 { 1865 if ((argptr+8 >= argc) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+7])) || (!IsValidNumber(argv[argptr+8])) || (argv[argptr+1][0] == '-') || (argv[argptr+2][0] == '-') || (argv[argptr+3][0] == '-') || (argv[argptr+4][0] == '-') || (argv[argptr+5][0] == '-') || (argv[argptr+6][0] == '-')) { 1866 ExitFlag = 255; 1867 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for pair correlation analysis: -C P <Z1> <x> <y> <z> <output> <bin output>" << endl); 1868 performCriticalExit(); 1869 } else { 1870 ofstream output(argv[argptr+5]); 1871 ofstream binoutput(argv[argptr+6]); 1872 const double BinStart = atof(argv[argptr+7]); 1873 const double BinEnd = atof(argv[argptr+8]); 1874 1875 const element *elemental = periode->FindElement((const int) atoi(argv[argptr+1])); 1876 Vector *Point = new Vector((const double) atof(argv[argptr+1]),(const double) atof(argv[argptr+2]),(const double) atof(argv[argptr+3])); 1877 CorrelationToPointMap *correlationmap = NULL; 1878 if (periodic) 1879 correlationmap = PeriodicCorrelationToPoint(molecules, elemental, Point, ranges); 1880 else 1881 correlationmap = CorrelationToPoint(molecules, elemental, Point); 1882 //OutputCorrelationToSurface(&output, correlationmap); 1883 BinPairMap *binmap = BinData( correlationmap, 0.5, BinStart, BinEnd ); 1884 OutputCorrelation ( &binoutput, binmap ); 1885 output.close(); 1886 binoutput.close(); 1887 delete(Point); 1888 delete(binmap); 1889 delete(correlationmap); 1890 argptr+=9; 1891 } 1892 } 1769 ArgcList.insert(argptr-1); 1770 ArgcList.insert(argptr); 1771 ArgcList.insert(argptr+1); 1772 ArgcList.insert(argptr+2); 1773 ArgcList.insert(argptr+3); 1774 ArgcList.insert(argptr+4); 1775 ArgcList.insert(argptr+5); 1776 ArgcList.insert(argptr+6); 1777 ArgcList.insert(argptr+7); 1778 ArgcList.insert(argptr+8); 1779 ArgcList.insert(argptr+9); 1780 ArgcList.insert(argptr+10); 1781 ArgcList.insert(argptr+11); 1782 ArgcList.insert(argptr+12); 1783 ArgcList.insert(argptr+13); 1784 ArgcList.insert(argptr+14); 1785 argptr+=15; 1893 1786 break; 1894 1787 1895 1788 case 'S': 1896 { 1897 if ((argptr+6 >= argc) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) || (!IsValidNumber(argv[argptr+6])) || (argv[argptr+1][0] == '-') || (argv[argptr+2][0] == '-') || (argv[argptr+3][0] == '-')) { 1898 ExitFlag = 255; 1899 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for pair correlation analysis: -C S <Z> <output> <bin output> <BinWidth> <BinStart> <BinEnd>" << endl); 1900 performCriticalExit(); 1901 } else { 1902 ofstream output(argv[argptr+2]); 1903 ofstream binoutput(argv[argptr+3]); 1904 const double radius = 4.; 1905 const double BinWidth = atof(argv[argptr+4]); 1906 const double BinStart = atof(argv[argptr+5]); 1907 const double BinEnd = atof(argv[argptr+6]); 1908 double LCWidth = 20.; 1909 if (BinEnd > 0) { 1910 if (BinEnd > 2.*radius) 1911 LCWidth = BinEnd; 1912 else 1913 LCWidth = 2.*radius; 1914 } 1915 1916 // get the boundary 1917 class molecule *Boundary = NULL; 1918 class Tesselation *TesselStruct = NULL; 1919 const LinkedCell *LCList = NULL; 1920 // find biggest molecule 1921 int counter = 0; 1922 for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) { 1923 if ((Boundary == NULL) || (Boundary->AtomCount < (*BigFinder)->AtomCount)) { 1924 Boundary = *BigFinder; 1925 } 1926 counter++; 1927 } 1928 bool *Actives = Malloc<bool>(counter, "ParseCommandLineOptions() - case C -- *Actives"); 1929 counter = 0; 1930 for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) { 1931 Actives[counter++] = (*BigFinder)->ActiveFlag; 1932 (*BigFinder)->ActiveFlag = (*BigFinder == Boundary) ? false : true; 1933 } 1934 LCList = new LinkedCell(Boundary, LCWidth); 1935 const element *elemental = periode->FindElement((const int) atoi(argv[argptr+1])); 1936 FindNonConvexBorder(Boundary, TesselStruct, LCList, radius, NULL); 1937 CorrelationToSurfaceMap *surfacemap = NULL; 1938 if (periodic) 1939 surfacemap = PeriodicCorrelationToSurface( molecules, elemental, TesselStruct, LCList, ranges); 1940 else 1941 surfacemap = CorrelationToSurface( molecules, elemental, TesselStruct, LCList); 1942 OutputCorrelationToSurface(&output, surfacemap); 1943 // check whether radius was appropriate 1944 { 1945 double start; double end; 1946 GetMinMax( surfacemap, start, end); 1947 if (LCWidth < end) 1948 DoeLog(1) && (eLog()<< Verbose(1) << "Linked Cell width is smaller than the found range of values! Bins can only be correct up to: " << radius << "." << endl); 1949 } 1950 BinPairMap *binmap = BinData( surfacemap, BinWidth, BinStart, BinEnd ); 1951 OutputCorrelation ( &binoutput, binmap ); 1952 output.close(); 1953 binoutput.close(); 1954 for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) 1955 (*BigFinder)->ActiveFlag = Actives[counter++]; 1956 Free(&Actives); 1957 delete(LCList); 1958 delete(TesselStruct); 1959 delete(binmap); 1960 delete(surfacemap); 1961 argptr+=7; 1962 } 1963 } 1789 ArgcList.insert(argptr-1); 1790 ArgcList.insert(argptr); 1791 ArgcList.insert(argptr+1); 1792 ArgcList.insert(argptr+2); 1793 ArgcList.insert(argptr+3); 1794 ArgcList.insert(argptr+4); 1795 ArgcList.insert(argptr+5); 1796 ArgcList.insert(argptr+6); 1797 ArgcList.insert(argptr+7); 1798 ArgcList.insert(argptr+8); 1799 ArgcList.insert(argptr+9); 1800 ArgcList.insert(argptr+10); 1801 ArgcList.insert(argptr+11); 1802 ArgcList.insert(argptr+12); 1803 ArgcList.insert(argptr+13); 1804 ArgcList.insert(argptr+14); 1805 argptr+=15; 1964 1806 break; 1965 1807 … … 1975 1817 case 'E': 1976 1818 if (ExitFlag == 0) ExitFlag = 1; 1977 if ((argptr+ 1 >= argc) || (!IsValidNumber(argv[argptr])) || (argv[argptr+1][0] == '-')) {1819 if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr]))) { 1978 1820 ExitFlag = 255; 1979 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for changing element: -E <atom nr.> <element>" << endl);1821 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for changing element: -E <atom nr.> --element <Z>" << endl); 1980 1822 performCriticalExit(); 1981 1823 } else { 1982 SaveFlag = true;1983 DoLog(1) && (Log() << Verbose(1) << "Changing atom " << argv[argptr] << " to element " << argv[argptr+1] << "." << endl);1984 first = mol->FindAtom(atoi(argv[argptr]));1985 first->type = periode->FindElement(atoi(argv[argptr+1]));1986 argptr+= 2;1824 ArgcList.insert(argptr-1); 1825 ArgcList.insert(argptr); 1826 ArgcList.insert(argptr+1); 1827 ArgcList.insert(argptr+2); 1828 argptr+=3; 1987 1829 } 1988 1830 break; 1989 1831 case 'F': 1990 1832 if (ExitFlag == 0) ExitFlag = 1; 1991 MaxDistance = -1; 1992 if (argv[argptr-1][2] == 'F') { // option is -FF? 1993 // fetch first argument as max distance to surface 1994 MaxDistance = atof(argv[argptr++]); 1995 DoLog(0) && (Log() << Verbose(0) << "Filling with maximum layer distance of " << MaxDistance << "." << endl); 1996 } 1997 if ((argptr+7 >=argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) || (!IsValidNumber(argv[argptr+6])) || (!IsValidNumber(argv[argptr+7]))) { 1833 if ((argptr+12 >= argc) || (argv[argptr][0] == '-')) { 1998 1834 ExitFlag = 255; 1999 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for filling box with water: -F <xyz of filler> <dist_x> <dist_y> <dist_z> <boundary> <randatom> <randmol> <DoRotate>" << endl);1835 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for filling with molecule: -F <filler xyz file> --MaxDistance <distance or -1> --distances <x> <y> <z> --lengths <surface> <randatm> <randmol> --DoRotate <0/1>" << endl); 2000 1836 performCriticalExit(); 2001 1837 } else { 2002 SaveFlag = true; 2003 DoLog(1) && (Log() << Verbose(1) << "Filling Box with water molecules." << endl); 2004 // construct water molecule 2005 molecule *filler = World::getInstance().createMolecule(); 2006 if (!filler->AddXYZFile(argv[argptr])) { 2007 DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse filler molecule from " << argv[argptr] << "." << endl); 2008 } 2009 filler->SetNameFromFilename(argv[argptr]); 2010 configuration.BG->ConstructBondGraph(filler); 2011 molecule *Filling = NULL; 2012 atom *second = NULL, *third = NULL; 2013 first = World::getInstance().createAtom(); 2014 first->type = periode->FindElement(1); 2015 first->x = Vector(0.441, -0.143, 0.); 2016 filler->AddAtom(first); 2017 second = World::getInstance().createAtom(); 2018 second->type = periode->FindElement(1); 2019 second->x = Vector(-0.464, 1.137, 0.0); 2020 filler->AddAtom(second); 2021 third = World::getInstance().createAtom(); 2022 third->type = periode->FindElement(8); 2023 third->x = Vector(-0.464, 0.177, 0.); 2024 filler->AddAtom(third); 2025 filler->AddBond(first, third, 1); 2026 filler->AddBond(second, third, 1); 2027 // call routine 2028 double distance[NDIM]; 2029 for (int i=0;i<NDIM;i++) 2030 distance[i] = atof(argv[argptr+i+1]); 2031 Filling = FillBoxWithMolecule(molecules, filler, configuration, MaxDistance, distance, atof(argv[argptr+4]), atof(argv[argptr+5]), atof(argv[argptr+6]), atoi(argv[argptr+7])); 2032 if (Filling != NULL) { 2033 Filling->ActiveFlag = false; 2034 molecules->insert(Filling); 2035 } 2036 World::getInstance().destroyMolecule(filler); 2037 argptr+=6; 1838 ArgcList.insert(argptr-1); 1839 ArgcList.insert(argptr); 1840 ArgcList.insert(argptr+1); 1841 ArgcList.insert(argptr+2); 1842 ArgcList.insert(argptr+3); 1843 ArgcList.insert(argptr+4); 1844 ArgcList.insert(argptr+5); 1845 ArgcList.insert(argptr+6); 1846 ArgcList.insert(argptr+7); 1847 ArgcList.insert(argptr+8); 1848 ArgcList.insert(argptr+9); 1849 ArgcList.insert(argptr+10); 1850 ArgcList.insert(argptr+11); 1851 ArgcList.insert(argptr+12); 1852 argptr+=13; 2038 1853 } 2039 1854 break; 2040 1855 case 'A': 1856 if (ExitFlag == 0) ExitFlag = 1; 1857 if ((argptr+2 >= argc) || (argv[argptr][0] == '-')) { 1858 ExitFlag =255; 1859 DoeLog(0) && (eLog()<< Verbose(0) << "Missing source file for bonds in molecule: -A <bond sourcefile> --molecule-by-id <molecule_id>" << endl); 1860 performCriticalExit(); 1861 } else { 1862 ArgcList.insert(argptr-1); 1863 ArgcList.insert(argptr); 1864 ArgcList.insert(argptr+1); 1865 ArgcList.insert(argptr+2); 1866 argptr+=3; 1867 } 1868 break; 1869 1870 case 'J': 1871 if (ExitFlag == 0) ExitFlag = 1; 1872 if ((argptr+2 >= argc) || (argv[argptr][0] == '-')) { 1873 ExitFlag =255; 1874 DoeLog(0) && (eLog()<< Verbose(0) << "Missing path of adjacency file: -J <path> --molecule-by-id <molecule_id>" << endl); 1875 performCriticalExit(); 1876 } else { 1877 ArgcList.insert(argptr-1); 1878 ArgcList.insert(argptr); 1879 ArgcList.insert(argptr+1); 1880 ArgcList.insert(argptr+2); 1881 argptr+=3; 1882 } 1883 break; 1884 1885 case 'j': 2041 1886 if (ExitFlag == 0) ExitFlag = 1; 2042 1887 if ((argptr >= argc) || (argv[argptr][0] == '-')) { 2043 1888 ExitFlag =255; 2044 DoeLog(0) && (eLog()<< Verbose(0) << "Missing source file for bonds in molecule: -A <bond sourcefile>" << endl);1889 DoeLog(0) && (eLog()<< Verbose(0) << "Missing path of bonds file: -j <path> --molecule-by-id <molecule_id>" << endl); 2045 1890 performCriticalExit(); 2046 1891 } else { 2047 DoLog(0) && (Log() << Verbose(0) << "Parsing bonds from " << argv[argptr] << "." << endl);2048 ifstream *input = new ifstream(argv[argptr]);2049 mol->CreateAdjacencyListFromDbondFile(input);2050 input->close();2051 argptr+= 1;2052 } 2053 break; 2054 2055 case ' J':2056 if (ExitFlag == 0) ExitFlag = 1; 2057 if ((argptr >= argc) || (argv[argptr][0] == '-')){2058 ExitFlag = 255;2059 DoeLog(0) && (eLog()<< Verbose(0) << " Missing path of adjacency file: -j <path>" << endl);1892 ArgcList.insert(argptr-1); 1893 ArgcList.insert(argptr); 1894 ArgcList.insert(argptr+1); 1895 ArgcList.insert(argptr+2); 1896 argptr+=3; 1897 } 1898 break; 1899 1900 case 'N': 1901 if (ExitFlag == 0) ExitFlag = 1; 1902 if ((argptr+4 >= argc) || (argv[argptr][0] == '-')){ 1903 ExitFlag = 255; 1904 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for non-convex envelope: -N <molecule_id> --sphere-radius <radius> --nonconvex-file <output prefix>" << endl); 2060 1905 performCriticalExit(); 2061 1906 } else { 2062 DoLog(0) && (Log() << Verbose(0) << "Storing adjacency to path " << argv[argptr] << "." << endl); 2063 configuration.BG->ConstructBondGraph(mol); 2064 mol->StoreAdjacencyToFile(NULL, argv[argptr]); 2065 argptr+=1; 2066 } 2067 break; 2068 2069 case 'j': 2070 if (ExitFlag == 0) ExitFlag = 1; 2071 if ((argptr >= argc) || (argv[argptr][0] == '-')) { 2072 ExitFlag =255; 2073 DoeLog(0) && (eLog()<< Verbose(0) << "Missing path of bonds file: -j <path>" << endl); 1907 ArgcList.insert(argptr-1); 1908 ArgcList.insert(argptr); 1909 ArgcList.insert(argptr+1); 1910 ArgcList.insert(argptr+2); 1911 ArgcList.insert(argptr+3); 1912 ArgcList.insert(argptr+4); 1913 argptr+=5; 1914 } 1915 break; 1916 case 'S': 1917 if (ExitFlag == 0) ExitFlag = 1; 1918 if ((argptr+2 >= argc) || (argv[argptr][0] == '-')) { 1919 ExitFlag = 255; 1920 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for storing tempature: -S <temperature file> --molecule-by-id 0" << endl); 2074 1921 performCriticalExit(); 2075 1922 } else { 2076 DoLog(0) && (Log() << Verbose(0) << "Storing bonds to path " << argv[argptr] << "." << endl);2077 configuration.BG->ConstructBondGraph(mol);2078 mol->StoreBondsToFile(NULL, argv[argptr]);2079 argptr+=1;2080 }2081 break;2082 2083 case ' N':2084 if (ExitFlag == 0) ExitFlag = 1; 2085 if ((argptr+ 1 >= argc) || (argv[argptr+1][0] == '-')){1923 ArgcList.insert(argptr-1); 1924 ArgcList.insert(argptr); 1925 ArgcList.insert(argptr+1); 1926 ArgcList.insert(argptr+2); 1927 argptr+=3; 1928 } 1929 break; 1930 case 'L': 1931 if (ExitFlag == 0) ExitFlag = 1; 1932 if ((argptr+8 >= argc) || (argv[argptr][0] == '-')) { 2086 1933 ExitFlag = 255; 2087 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for non-convex envelope: -o <radius> <tecplot output file>" << endl);1934 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for linear interpolation: -L <prefix> --start-step <step0> --end-step <step1> --molecule-by-id 0 --id-mapping <0/1>" << endl); 2088 1935 performCriticalExit(); 2089 1936 } else { 2090 class Tesselation *T = NULL; 2091 const LinkedCell *LCList = NULL; 2092 molecule * Boundary = NULL; 2093 //string filename(argv[argptr+1]); 2094 //filename.append(".csv"); 2095 DoLog(0) && (Log() << Verbose(0) << "Evaluating non-convex envelope of biggest molecule."); 2096 DoLog(1) && (Log() << Verbose(1) << "Using rolling ball of radius " << atof(argv[argptr]) << " and storing tecplot data in " << argv[argptr+1] << "." << endl); 2097 // find biggest molecule 2098 int counter = 0; 2099 for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) { 2100 (*BigFinder)->CountAtoms(); 2101 if ((Boundary == NULL) || (Boundary->AtomCount < (*BigFinder)->AtomCount)) { 2102 Boundary = *BigFinder; 2103 } 2104 counter++; 2105 } 2106 DoLog(1) && (Log() << Verbose(1) << "Biggest molecule has " << Boundary->AtomCount << " atoms." << endl); 2107 start = clock(); 2108 LCList = new LinkedCell(Boundary, atof(argv[argptr])*2.); 2109 if (!FindNonConvexBorder(Boundary, T, LCList, atof(argv[argptr]), argv[argptr+1])) 2110 ExitFlag = 255; 2111 //FindDistributionOfEllipsoids(T, &LCList, N, number, filename.c_str()); 2112 end = clock(); 2113 DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl); 2114 delete(LCList); 2115 delete(T); 2116 argptr+=2; 2117 } 2118 break; 2119 case 'S': 2120 if (ExitFlag == 0) ExitFlag = 1; 2121 if ((argptr >= argc) || (argv[argptr][0] == '-')) { 1937 ArgcList.insert(argptr-1); 1938 ArgcList.insert(argptr); 1939 ArgcList.insert(argptr+1); 1940 ArgcList.insert(argptr+2); 1941 ArgcList.insert(argptr+3); 1942 ArgcList.insert(argptr+4); 1943 ArgcList.insert(argptr+5); 1944 ArgcList.insert(argptr+6); 1945 ArgcList.insert(argptr+7); 1946 ArgcList.insert(argptr+8); 1947 argptr+=9; 1948 } 1949 break; 1950 case 'P': 1951 if (ExitFlag == 0) ExitFlag = 1; 1952 if ((argptr+2 >= argc) || (argv[argptr][0] == '-')) { 2122 1953 ExitFlag = 255; 2123 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for storing tempature: -S <temperature file>" << endl);1954 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for parsing and integrating forces: -P <forces file> --molecule-by-id <molecule_id>" << endl); 2124 1955 performCriticalExit(); 2125 1956 } else { 2126 DoLog(1) && (Log() << Verbose(1) << "Storing temperatures in " << argv[argptr] << "." << endl); 2127 ofstream *output = new ofstream(argv[argptr], ios::trunc); 2128 if (!mol->OutputTemperatureFromTrajectories(output, 0, mol->MDSteps)) 2129 DoLog(2) && (Log() << Verbose(2) << "File could not be written." << endl); 2130 else 2131 DoLog(2) && (Log() << Verbose(2) << "File stored." << endl); 2132 output->close(); 2133 delete(output); 2134 argptr+=1; 2135 } 2136 break; 2137 case 'L': 2138 if (ExitFlag == 0) ExitFlag = 1; 2139 if ((argptr >= argc) || (argv[argptr][0] == '-')) { 1957 ArgcList.insert(argptr-1); 1958 ArgcList.insert(argptr); 1959 ArgcList.insert(argptr+1); 1960 ArgcList.insert(argptr+2); 1961 argptr+=3; 1962 } 1963 break; 1964 case 'R': 1965 if (ExitFlag == 0) ExitFlag = 1; 1966 if ((argptr+4 >= argc) || (argv[argptr][0] == '-')) { 2140 1967 ExitFlag = 255; 2141 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for storing tempature: -L <step0> <step1> <prefix> <identity mapping?>" << endl);1968 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for removing atoms: -R <distance> --position <x> <y> <z>" << endl); 2142 1969 performCriticalExit(); 2143 1970 } else { 2144 SaveFlag = true; 2145 DoLog(1) && (Log() << Verbose(1) << "Linear interpolation between configuration " << argv[argptr] << " and " << argv[argptr+1] << "." << endl); 2146 if (atoi(argv[argptr+3]) == 1) 2147 DoLog(1) && (Log() << Verbose(1) << "Using Identity for the permutation map." << endl); 2148 if (!mol->LinearInterpolationBetweenConfiguration(atoi(argv[argptr]), atoi(argv[argptr+1]), argv[argptr+2], configuration, atoi(argv[argptr+3])) == 1 ? true : false) 2149 DoLog(2) && (Log() << Verbose(2) << "Could not store " << argv[argptr+2] << " files." << endl); 2150 else 2151 DoLog(2) && (Log() << Verbose(2) << "Steps created and " << argv[argptr+2] << " files stored." << endl); 2152 argptr+=4; 2153 } 2154 break; 2155 case 'P': 2156 if (ExitFlag == 0) ExitFlag = 1; 2157 if ((argptr >= argc) || (argv[argptr][0] == '-')) { 1971 ArgcList.insert(argptr-1); 1972 ArgcList.insert(argptr); 1973 ArgcList.insert(argptr+1); 1974 ArgcList.insert(argptr+2); 1975 ArgcList.insert(argptr+3); 1976 ArgcList.insert(argptr+4); 1977 argptr+=5; 1978 } 1979 break; 1980 case 't': 1981 if (ExitFlag == 0) ExitFlag = 1; 1982 if ((argptr+4 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) { 2158 1983 ExitFlag = 255; 2159 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for parsing and integrating forces: -P <forces file>" << endl);1984 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for translation: -t <x> <y> <z> --molecule-by-id <molecule_id> --periodic <0/1>" << endl); 2160 1985 performCriticalExit(); 2161 1986 } else { 2162 SaveFlag = true; 2163 DoLog(1) && (Log() << Verbose(1) << "Parsing forces file and Verlet integrating." << endl); 2164 if (!mol->VerletForceIntegration(argv[argptr], configuration)) 2165 DoLog(2) && (Log() << Verbose(2) << "File not found." << endl); 2166 else 2167 DoLog(2) && (Log() << Verbose(2) << "File found and parsed." << endl); 2168 argptr+=1; 2169 } 2170 break; 2171 case 'R': 2172 if (ExitFlag == 0) ExitFlag = 1; 2173 if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1]))) { 2174 ExitFlag = 255; 2175 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for removing atoms: -R <id> <distance>" << endl); 2176 performCriticalExit(); 2177 } else { 2178 SaveFlag = true; 2179 DoLog(1) && (Log() << Verbose(1) << "Removing atoms around " << argv[argptr] << " with radius " << argv[argptr+1] << "." << endl); 2180 double tmp1 = atof(argv[argptr+1]); 2181 atom *third = mol->FindAtom(atoi(argv[argptr])); 2182 atom *first = mol->start; 2183 if ((third != NULL) && (first != mol->end)) { 2184 atom *second = first->next; 2185 while(second != mol->end) { 2186 first = second; 2187 second = first->next; 2188 if (first->x.DistanceSquared(third->x) > tmp1*tmp1) // distance to first above radius ... 2189 mol->RemoveAtom(first); 2190 } 2191 } else { 2192 DoeLog(1) && (eLog()<< Verbose(1) << "Removal failed due to missing atoms on molecule or wrong id." << endl); 2193 } 2194 argptr+=2; 2195 } 2196 break; 2197 case 't': 1987 ArgcList.insert(argptr-1); 1988 ArgcList.insert(argptr); 1989 ArgcList.insert(argptr+1); 1990 ArgcList.insert(argptr+2); 1991 ArgcList.insert(argptr+3); 1992 ArgcList.insert(argptr+4); 1993 ArgcList.insert(argptr+5); 1994 ArgcList.insert(argptr+6); 1995 argptr+=7; 1996 } 1997 break; 1998 case 's': 2198 1999 if (ExitFlag == 0) ExitFlag = 1; 2199 2000 if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) { 2200 ExitFlag = 255;2201 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for translation: -t <x> <y> <z>" << endl);2202 performCriticalExit();2203 } else {2204 if (ExitFlag == 0) ExitFlag = 1;2205 SaveFlag = true;2206 DoLog(1) && (Log() << Verbose(1) << "Translating all ions by given vector." << endl);2207 for (int i=NDIM;i--;)2208 x[i] = atof(argv[argptr+i]);2209 mol->Translate((const Vector *)&x);2210 argptr+=3;2211 }2212 break;2213 case 'T':2214 if (ExitFlag == 0) ExitFlag = 1;2215 if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {2216 ExitFlag = 255;2217 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for periodic translation: -T <x> <y> <z>" << endl);2218 performCriticalExit();2219 } else {2220 if (ExitFlag == 0) ExitFlag = 1;2221 SaveFlag = true;2222 DoLog(1) && (Log() << Verbose(1) << "Translating all ions periodically by given vector." << endl);2223 for (int i=NDIM;i--;)2224 x[i] = atof(argv[argptr+i]);2225 mol->TranslatePeriodically((const Vector *)&x);2226 argptr+=3;2227 }2228 break;2229 case 's':2230 if (ExitFlag == 0) ExitFlag = 1;2231 if ((argptr >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {2232 2001 ExitFlag = 255; 2233 2002 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for scaling: -s <factor_x> [factor_y] [factor_z]" << endl); 2234 2003 performCriticalExit(); 2235 2004 } else { 2236 SaveFlag = true; 2237 j = -1; 2238 DoLog(1) && (Log() << Verbose(1) << "Scaling all ion positions by factor." << endl); 2239 factor = new double[NDIM]; 2240 factor[0] = atof(argv[argptr]); 2241 factor[1] = atof(argv[argptr+1]); 2242 factor[2] = atof(argv[argptr+2]); 2243 mol->Scale((const double ** const)&factor); 2244 double * const cell_size = World::getInstance().getDomain(); 2245 for (int i=0;i<NDIM;i++) { 2246 j += i+1; 2247 x[i] = atof(argv[NDIM+i]); 2248 cell_size[j]*=factor[i]; 2249 } 2250 delete[](factor); 2005 ArgcList.insert(argptr-1); 2006 ArgcList.insert(argptr); 2007 ArgcList.insert(argptr+1); 2008 ArgcList.insert(argptr+2); 2251 2009 argptr+=3; 2252 2010 } … … 2259 2017 performCriticalExit(); 2260 2018 } else { 2261 SaveFlag = true; 2262 j = -1; 2263 DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl); 2264 double * const cell_size = World::getInstance().getDomain(); 2265 for (int i=0;i<6;i++) { 2266 cell_size[i] = atof(argv[argptr+i]); 2267 } 2268 // center 2269 mol->CenterInBox(); 2019 ArgcList.insert(argptr-1); 2020 ArgcList.insert(argptr); 2021 ArgcList.insert(argptr+1); 2022 ArgcList.insert(argptr+2); 2023 ArgcList.insert(argptr+3); 2024 ArgcList.insert(argptr+4); 2025 ArgcList.insert(argptr+5); 2270 2026 argptr+=6; 2271 2027 } … … 2278 2034 performCriticalExit(); 2279 2035 } else { 2280 SaveFlag = true; 2281 j = -1; 2282 DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl); 2283 double * const cell_size = World::getInstance().getDomain(); 2284 for (int i=0;i<6;i++) { 2285 cell_size[i] = atof(argv[argptr+i]); 2286 } 2287 // center 2288 mol->BoundInBox(); 2036 ArgcList.insert(argptr-1); 2037 ArgcList.insert(argptr); 2038 ArgcList.insert(argptr+1); 2039 ArgcList.insert(argptr+2); 2040 ArgcList.insert(argptr+3); 2041 ArgcList.insert(argptr+4); 2042 ArgcList.insert(argptr+5); 2289 2043 argptr+=6; 2290 2044 } … … 2297 2051 performCriticalExit(); 2298 2052 } else { 2299 SaveFlag = true; 2300 j = -1; 2301 DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given additional boundary." << endl); 2302 // make every coordinate positive 2303 mol->CenterEdge(&x); 2304 // update Box of atoms by boundary 2305 mol->SetBoxDimension(&x); 2306 // translate each coordinate by boundary 2307 double * const cell_size = World::getInstance().getDomain(); 2308 j=-1; 2309 for (int i=0;i<NDIM;i++) { 2310 j += i+1; 2311 x[i] = atof(argv[argptr+i]); 2312 cell_size[j] += x[i]*2.; 2313 } 2314 mol->Translate((const Vector *)&x); 2053 ArgcList.insert(argptr-1); 2054 ArgcList.insert(argptr); 2055 ArgcList.insert(argptr+1); 2056 ArgcList.insert(argptr+2); 2315 2057 argptr+=3; 2316 2058 } … … 2318 2060 case 'O': 2319 2061 if (ExitFlag == 0) ExitFlag = 1; 2320 SaveFlag = true; 2321 DoLog(1) && (Log() << Verbose(1) << "Centering atoms on edge and setting box dimensions." << endl); 2322 x.Zero(); 2323 mol->CenterEdge(&x); 2324 mol->SetBoxDimension(&x); 2062 ArgcList.insert(argptr-1); 2325 2063 argptr+=0; 2326 2064 break; … … 2332 2070 performCriticalExit(); 2333 2071 } else { 2334 SaveFlag = true; 2335 DoLog(1) && (Log() << Verbose(1) << "Removing atom " << argv[argptr] << "." << endl); 2336 atom *first = mol->FindAtom(atoi(argv[argptr])); 2337 mol->RemoveAtom(first); 2072 ArgcList.insert(argptr-1); 2073 ArgcList.insert(argptr); 2338 2074 argptr+=1; 2339 2075 } … … 2341 2077 case 'f': 2342 2078 if (ExitFlag == 0) ExitFlag = 1; 2343 if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1]))) {2079 if ((argptr+1 >= argc) || (argv[argptr][0] == '-')) { 2344 2080 ExitFlag = 255; 2345 2081 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for fragmentation: -f <max. bond distance> <bond order>" << endl); 2346 2082 performCriticalExit(); 2347 2083 } else { 2348 DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with bond distance " << argv[argptr] << " angstroem, order of " << argv[argptr+1] << "." << endl); 2349 DoLog(0) && (Log() << Verbose(0) << "Creating connection matrix..." << endl); 2350 start = clock(); 2351 mol->CreateAdjacencyList(atof(argv[argptr]), configuration.GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL); 2352 DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl); 2353 if (mol->first->next != mol->last) { 2354 ExitFlag = mol->FragmentMolecule(atoi(argv[argptr+1]), &configuration); 2355 } 2356 end = clock(); 2357 DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl); 2358 argptr+=2; 2084 ArgcList.insert(argptr-1); 2085 ArgcList.insert(argptr); 2086 ArgcList.insert(argptr+1); 2087 ArgcList.insert(argptr+2); 2088 ArgcList.insert(argptr+3); 2089 ArgcList.insert(argptr+4); 2090 argptr+=5; 2359 2091 } 2360 2092 break; … … 2369 2101 SaveFlag = true; 2370 2102 DoLog(0) && (Log() << Verbose(0) << "Converting to prinicipal axis system." << endl); 2103 mol->PrincipalAxisSystem((bool)j); 2371 2104 } else 2372 DoLog(0) && (Log() << Verbose(0) << "Evaluating prinicipal axis." << endl);2373 mol->PrincipalAxisSystem((bool)j);2105 ArgcList.insert(argptr-1); 2106 argptr+=0; 2374 2107 break; 2375 2108 case 'o': 2376 2109 if (ExitFlag == 0) ExitFlag = 1; 2377 if ((argptr+ 1>= argc) || (argv[argptr][0] == '-')){2110 if ((argptr+4 >= argc) || (argv[argptr][0] == '-')){ 2378 2111 ExitFlag = 255; 2379 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for convex envelope: -o < convex output file> <non-convexoutput file>" << endl);2112 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for convex envelope: -o <molecule_id> --output-file <output file> --output-file <binned output file>" << endl); 2380 2113 performCriticalExit(); 2381 2114 } else { 2382 class Tesselation *TesselStruct = NULL; 2383 const LinkedCell *LCList = NULL; 2384 DoLog(0) && (Log() << Verbose(0) << "Evaluating volume of the convex envelope."); 2385 DoLog(1) && (Log() << Verbose(1) << "Storing tecplot convex data in " << argv[argptr] << "." << endl); 2386 DoLog(1) && (Log() << Verbose(1) << "Storing tecplot non-convex data in " << argv[argptr+1] << "." << endl); 2387 LCList = new LinkedCell(mol, 10.); 2388 //FindConvexBorder(mol, LCList, argv[argptr]); 2389 FindNonConvexBorder(mol, TesselStruct, LCList, 5., argv[argptr+1]); 2390 // RemoveAllBoundaryPoints(TesselStruct, mol, argv[argptr]); 2391 double volumedifference = ConvexizeNonconvexEnvelope(TesselStruct, mol, argv[argptr]); 2392 double clustervolume = VolumeOfConvexEnvelope(TesselStruct, &configuration); 2393 DoLog(0) && (Log() << Verbose(0) << "The tesselated volume area is " << clustervolume << " " << (configuration.GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl); 2394 DoLog(0) && (Log() << Verbose(0) << "The non-convex tesselated volume area is " << clustervolume-volumedifference << " " << (configuration.GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl); 2395 delete(TesselStruct); 2396 delete(LCList); 2397 argptr+=2; 2115 ArgcList.insert(argptr-1); 2116 ArgcList.insert(argptr); 2117 ArgcList.insert(argptr+1); 2118 ArgcList.insert(argptr+2); 2119 ArgcList.insert(argptr+3); 2120 ArgcList.insert(argptr+4); 2121 argptr+=5; 2398 2122 } 2399 2123 break; … … 2416 2140 performCriticalExit(); 2417 2141 } else { 2418 double density; 2419 SaveFlag = true; 2420 DoLog(0) && (Log() << Verbose(0) << "Evaluating necessary cell volume for a cluster suspended in water."); 2421 density = atof(argv[argptr++]); 2422 if (density < 1.0) { 2423 DoeLog(1) && (eLog()<< Verbose(1) << "Density must be greater than 1.0g/cm^3 !" << endl); 2424 density = 1.3; 2425 } 2426 // for(int i=0;i<NDIM;i++) { 2427 // repetition[i] = atoi(argv[argptr++]); 2428 // if (repetition[i] < 1) 2429 // DoeLog(1) && (eLog()<< Verbose(1) << "repetition value must be greater 1!" << endl); 2430 // repetition[i] = 1; 2431 // } 2432 PrepareClustersinWater(&configuration, mol, volume, density); // if volume == 0, will calculate from ConvexEnvelope 2142 ArgcList.insert(argptr-1); 2143 ArgcList.insert(argptr); 2144 argptr+=1; 2433 2145 } 2434 2146 break; … … 2440 2152 performCriticalExit(); 2441 2153 } else { 2442 SaveFlag = true; 2443 double * const cell_size = World::getInstance().getDomain(); 2444 for (int axis = 1; axis <= NDIM; axis++) { 2445 int faktor = atoi(argv[argptr++]); 2446 int count; 2447 const element ** Elements; 2448 Vector ** vectors; 2449 if (faktor < 1) { 2450 DoeLog(1) && (eLog()<< Verbose(1) << "Repetition factor mus be greater than 1!" << endl); 2451 faktor = 1; 2452 } 2453 mol->CountAtoms(); // recount atoms 2454 if (mol->AtomCount != 0) { // if there is more than none 2455 count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand 2456 Elements = new const element *[count]; 2457 vectors = new Vector *[count]; 2458 j = 0; 2459 first = mol->start; 2460 while (first->next != mol->end) { // make a list of all atoms with coordinates and element 2461 first = first->next; 2462 Elements[j] = first->type; 2463 vectors[j] = &first->x; 2464 j++; 2465 } 2466 if (count != j) 2467 DoeLog(1) && (eLog()<< Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl); 2468 x.Zero(); 2469 y.Zero(); 2470 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 for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times 2472 x += y; // per factor one cell width further 2473 for (int k=count;k--;) { // go through every atom of the original cell 2474 first = World::getInstance().createAtom(); // create a new body 2475 first->x = (*vectors[k]) + x; 2476 first->type = Elements[k]; // insert original element 2477 mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...) 2478 } 2479 } 2480 // free memory 2481 delete[](Elements); 2482 delete[](vectors); 2483 // correct cell size 2484 if (axis < 0) { // if sign was negative, we have to translate everything 2485 x =(-(faktor-1)) * y; 2486 mol->Translate(&x); 2487 } 2488 cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor; 2489 } 2490 } 2154 ArgcList.insert(argptr-1); 2155 ArgcList.insert(argptr); 2156 ArgcList.insert(argptr+1); 2157 ArgcList.insert(argptr+2); 2158 argptr+=3; 2491 2159 } 2492 2160 break; … … 2500 2168 } while (argptr < argc); 2501 2169 if (SaveFlag) 2502 configuration.SaveAll( ConfigFileName, periode, molecules);2170 configuration.SaveAll(*ConfigFileName, periode, molecules); 2503 2171 } else { // no arguments, hence scan the elements db 2504 2172 if (periode->LoadPeriodentafel(configuration.databasepath)) … … 2511 2179 }; 2512 2180 2513 /***************************************** Functions used to build all menus **********************/2514 2515 void populateEditMoleculesMenu(Menu* editMoleculesMenu,MoleculeListClass *molecules, config *configuration, periodentafel *periode){2516 // build the EditMoleculesMenu2517 Action *createMoleculeAction = new MethodAction("createMoleculeAction",boost::bind(&MoleculeListClass::createNewMolecule,molecules,periode));2518 new ActionMenuItem('c',"create new molecule",editMoleculesMenu,createMoleculeAction);2519 2520 Action *loadMoleculeAction = new MethodAction("loadMoleculeAction",boost::bind(&MoleculeListClass::loadFromXYZ,molecules,periode));2521 new ActionMenuItem('l',"load molecule from xyz file",editMoleculesMenu,loadMoleculeAction);2522 2523 Action *changeFilenameAction = new ChangeMoleculeNameAction(molecules);2524 new ActionMenuItem('n',"change molecule's name",editMoleculesMenu,changeFilenameAction);2525 2526 Action *giveFilenameAction = new MethodAction("giveFilenameAction",boost::bind(&MoleculeListClass::setMoleculeFilename,molecules));2527 new ActionMenuItem('N',"give molecules filename",editMoleculesMenu,giveFilenameAction);2528 2529 Action *parseAtomsAction = new MethodAction("parseAtomsAction",boost::bind(&MoleculeListClass::parseXYZIntoMolecule,molecules));2530 new ActionMenuItem('p',"parse atoms in xyz file into molecule",editMoleculesMenu,parseAtomsAction);2531 2532 Action *eraseMoleculeAction = new MethodAction("eraseMoleculeAction",boost::bind(&MoleculeListClass::eraseMolecule,molecules));2533 new ActionMenuItem('r',"remove a molecule",editMoleculesMenu,eraseMoleculeAction);2534 2535 }2536 2537 2538 2181 /********************************************** Main routine **************************************/ 2539 2182 2540 void cleanUp(config *configuration){ 2541 UIFactory::purgeInstance(); 2183 void cleanUp(){ 2542 2184 World::purgeInstance(); 2543 delete(configuration);2544 Log() << Verbose(0) << "Maximum of allocated memory: "2545 << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;2546 Log() << Verbose(0) << "Remaining non-freed memory: "2547 << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;2548 MemoryUsageObserver::purgeInstance();2549 2185 logger::purgeInstance(); 2550 2186 errorLogger::purgeInstance(); 2187 UIFactory::purgeInstance(); 2188 MapOfActions::purgeInstance(); 2189 CommandLineParser::purgeInstance(); 2551 2190 ActionRegistry::purgeInstance(); 2552 2191 ActionHistory::purgeInstance(); … … 2556 2195 int main(int argc, char **argv) 2557 2196 { 2197 config *configuration = World::getInstance().getConfig(); 2198 // while we are non interactive, we want to abort from asserts 2199 //ASSERT_DO(Assert::Abort); 2558 2200 molecule *mol = NULL; 2559 config *configuration = new config;2560 2201 Vector x, y, z, n; 2561 2202 ifstream test; 2562 2203 ofstream output; 2563 2204 string line; 2564 char *ConfigFileName = NULL; 2565 int j; 2566 2205 char **Arguments = NULL; 2206 int ArgcSize = 0; 2207 int ExitFlag = 0; 2208 bool ArgumentsCopied = false; 2209 char *ConfigFileName = new char[MAXSTRINGSIZE]; 2210 2211 // print version check whether arguments are present at all 2567 2212 cout << ESPACKVersion << endl; 2213 if (argc < 2) { 2214 cout << "Obtain help with " << argv[0] << " -h." << endl; 2215 cleanUp(); 2216 Memory::getState(); 2217 return(1); 2218 } 2219 2568 2220 2569 2221 setVerbosity(0); 2570 2222 // need to init the history before any action is created 2571 2223 ActionHistory::init(); 2572 /* structure of ParseCommandLineOptions will be refactored later */ 2573 j = ParseCommandLineOptions(argc, argv, World::getInstance().getMolecules(), World::getInstance().getPeriode(), *configuration, ConfigFileName); 2574 switch (j){ 2575 case 255: 2576 case 2: 2577 case 1: 2578 cleanUp(configuration); 2579 return (j == 1 ? 0 : j); 2580 default: 2581 break; 2224 2225 // In the interactive mode, we can leave the user the choice in case of error 2226 ASSERT_DO(Assert::Ask); 2227 2228 // from this moment on, we need to be sure to deeinitialize in the correct order 2229 // this is handled by the cleanup function 2230 atexit(cleanUp); 2231 2232 // Parse command line options and if present create respective UI 2233 { 2234 set<int> ArgcList; 2235 ArgcList.insert(0); // push back program! 2236 ArgcList.insert(1); // push back config file name 2237 // handle arguments by ParseCommandLineOptions() 2238 ExitFlag = ParseCommandLineOptions(argc,argv,World::getInstance().getMolecules(),World::getInstance().getPeriode(),*World::getInstance().getConfig(), &ConfigFileName, ArgcList); 2239 World::getInstance().setExitFlag(ExitFlag); 2240 // copy all remaining arguments to a new argv 2241 Arguments = new char *[ArgcList.size()]; 2242 cout << "The following arguments are handled by CommandLineParser: "; 2243 for (set<int>::iterator ArgcRunner = ArgcList.begin(); ArgcRunner != ArgcList.end(); ++ArgcRunner) { 2244 Arguments[ArgcSize] = new char[strlen(argv[*ArgcRunner])+2]; 2245 strcpy(Arguments[ArgcSize], argv[*ArgcRunner]); 2246 cout << " " << argv[*ArgcRunner]; 2247 ArgcSize++; 2248 } 2249 cout << endl; 2250 ArgumentsCopied = true; 2251 // handle remaining arguments by CommandLineParser 2252 MapOfActions::getInstance().AddOptionsToParser(); 2253 map <std::string, std::string> ShortFormToActionMap = MapOfActions::getInstance().getShortFormToActionMap(); 2254 CommandLineParser::getInstance().Run(ArgcSize,Arguments, ShortFormToActionMap); 2255 if (!CommandLineParser::getInstance().isEmpty()) { 2256 DoLog(0) && (Log() << Verbose(0) << "Setting UI to CommandLine." << endl); 2257 UIFactory::makeUserInterface(UIFactory::CommandLine); 2258 } else { 2259 DoLog(0) && (Log() << Verbose(0) << "Setting UI to Text." << endl); 2260 UIFactory::makeUserInterface(UIFactory::Text); 2261 } 2582 2262 } 2583 if(World::getInstance().numMolecules() == 0){2584 mol = World::getInstance().createMolecule();2585 World::getInstance().getMolecules()->insert(mol);2586 cout << "Molecule created" << endl;2587 if(World::getInstance().getDomain()[0] == 0.){2588 Log() << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl;2589 for(int i = 0;i < 6;i++){2590 Log() << Verbose(1) << "Cell size" << i << ": ";2591 cin >> World::getInstance().getDomain()[i];2592 }2593 }2594 mol->ActiveFlag = true;2595 }2596 2263 2597 2264 { 2598 cout << ESPACKVersion << endl; 2599 2600 setVerbosity(0); 2601 2602 menuPopulaters populaters; 2603 populaters.MakeEditMoleculesMenu = populateEditMoleculesMenu; 2604 2605 UIFactory::makeUserInterface(UIFactory::Text); 2606 MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow(populaters,World::getInstance().getMolecules(), configuration, World::getInstance().getPeriode(), ConfigFileName); 2265 MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow(); 2607 2266 mainWindow->display(); 2608 2267 delete mainWindow; 2609 2268 } 2610 2269 2611 if(World::getInstance().getPeriode()->StorePeriodentafel(configuration->databasepath)) 2612 Log() << Verbose(0) << "Saving of elements.db successful." << endl; 2613 2614 else 2615 Log() << Verbose(0) << "Saving of elements.db failed." << endl; 2616 2617 cleanUp(configuration); 2618 2619 return (0); 2270 Log() << Verbose(0) << "Saving to " << ConfigFileName << "." << endl; 2271 World::getInstance().getConfig()->SaveAll(ConfigFileName, World::getInstance().getPeriode(), World::getInstance().getMolecules()); 2272 2273 // free the new argv 2274 if (ArgumentsCopied) { 2275 for (int i=0; i<ArgcSize;i++) 2276 delete[](Arguments[i]); 2277 delete[](Arguments); 2278 } 2279 delete[](ConfigFileName); 2280 2281 ExitFlag = World::getInstance().getExitFlag(); 2282 return (ExitFlag == 1 ? 0 : ExitFlag); 2620 2283 } 2621 2284
Note:
See TracChangeset
for help on using the changeset viewer.
