Changes in src/builder.cpp [f65e1f:9907e7]
- File:
-
- 1 edited
-
src/builder.cpp (modified) (47 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/builder.cpp
rf65e1f r9907e7 53 53 54 54 #include <cstring> 55 #include <cstdlib> 55 56 56 57 #include "analysis_bonds.hpp" … … 864 865 865 866 mol->CountAtoms(); // recount atoms 866 if (mol-> AtomCount!= 0) { // if there is more than none867 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 868 869 Elements = new element *[count]; 869 870 vectors = new Vector *[count]; … … 1295 1296 // generate some KeySets 1296 1297 DoLog(0) && (Log() << Verbose(0) << "Generating KeySets." << endl); 1297 KeySet TestSets[mol-> AtomCount+1];1298 KeySet TestSets[mol->getAtomCount()+1]; 1298 1299 i=1; 1299 1300 while (Walker->next != mol->end) { … … 1306 1307 DoLog(0) && (Log() << Verbose(0) << "Testing insertion of already present item in KeySets." << endl); 1307 1308 KeySetTestPair test; 1308 test = TestSets[mol-> AtomCount-1].insert(Walker->nr);1309 test = TestSets[mol->getAtomCount()-1].insert(Walker->nr); 1309 1310 if (test.second) { 1310 1311 DoLog(1) && (Log() << Verbose(1) << "Insertion worked?!" << endl); … … 1312 1313 DoLog(1) && (Log() << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl); 1313 1314 } 1314 TestSets[mol-> AtomCount].insert(mol->end->previous->nr);1315 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); 1316 1317 1317 1318 // constructing Graph structure … … 1321 1322 // insert KeySets into Subgraphs 1322 1323 DoLog(0) && (Log() << Verbose(0) << "Inserting KeySets into Subgraph class." << endl); 1323 for (int j=0;j<mol-> AtomCount;j++) {1324 for (int j=0;j<mol->getAtomCount();j++) { 1324 1325 Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.))); 1325 1326 } 1326 1327 DoLog(0) && (Log() << Verbose(0) << "Testing insertion of already present item in Subgraph." << endl); 1327 1328 GraphTestPair test2; 1328 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.))); 1329 1330 if (test2.second) { 1330 1331 DoLog(1) && (Log() << Verbose(1) << "Insertion worked?!" << endl); … … 1494 1495 */ 1495 1496 static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode, 1496 config& configuration, char * &ConfigFileName, set<int> &ArgcList)1497 config& configuration, char **ConfigFileName, set<int> &ArgcList) 1497 1498 { 1498 1499 Vector x,y,z,n; // coordinates for absolute point in cell volume … … 1512 1513 molecule *mol = NULL; 1513 1514 string BondGraphFileName("\n"); 1514 strncpy(configuration.databasepath, LocalPath, MAXSTRINGSIZE-1);1515 bool DatabasePathGiven = false; 1515 1516 1516 1517 if (argc > 1) { // config file specified as option … … 1529 1530 break; 1530 1531 case 'v': 1531 ArgcList.insert(argptr-1); 1532 return(1); 1533 break; 1534 case 'V': 1532 setVerbosity(atoi(argv[argptr])); 1535 1533 ArgcList.insert(argptr-1); 1536 1534 ArgcList.insert(argptr); 1537 1535 argptr++; 1538 1536 break; 1537 case 'V': 1538 ArgcList.insert(argptr-1); 1539 return(1); 1540 break; 1539 1541 case 'B': 1542 ArgcList.insert(argptr-1); 1543 ArgcList.insert(argptr); 1544 ArgcList.insert(argptr+1); 1545 ArgcList.insert(argptr+2); 1546 ArgcList.insert(argptr+3); 1547 ArgcList.insert(argptr+4); 1548 ArgcList.insert(argptr+5); 1549 argptr+=6; 1540 1550 if (ExitFlag == 0) ExitFlag = 1; 1541 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])) ) {1542 ExitFlag = 255;1543 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for bounding in box: -B <xx> <xy> <xz> <yy> <yz> <zz>" << endl);1544 performCriticalExit();1545 } else {1546 SaveFlag = true;1547 j = -1;1548 DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl);1549 double * const cell_size = World::getInstance().getDomain();1550 for (int i=0;i<6;i++) {1551 cell_size[i] = atof(argv[argptr+i]);1552 }1553 argptr+=6;1554 }1555 1551 break; 1556 1552 case 'e': … … 1561 1557 DoLog(0) && (Log() << Verbose(0) << "Using " << argv[argptr] << " as elements database." << endl); 1562 1558 strncpy (configuration.databasepath, argv[argptr], MAXSTRINGSIZE-1); 1559 DatabasePathGiven = true; 1563 1560 argptr+=1; 1564 1561 } … … 1574 1571 } 1575 1572 break; 1573 case 'M': 1574 if ((argptr >= argc) || (argv[argptr][0] == '-')) { 1575 ExitFlag = 255; 1576 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for setting MPQC basis: -M <basis name>" << endl); 1577 performCriticalExit(); 1578 } else { 1579 configuration.basis = argv[argptr]; 1580 DoLog(1) && (Log() << Verbose(1) << "Setting MPQC basis to " << configuration.basis << "." << endl); 1581 argptr+=1; 1582 } 1583 break; 1576 1584 case 'n': 1577 1585 DoLog(0) && (Log() << Verbose(0) << "I won't parse trajectories." << endl); … … 1581 1589 { 1582 1590 World::getInstance().setDefaultName(argv[argptr]); 1583 DoLog(0) && (Log() << Verbose(0) << "Default name of new molecules set to " << *World::getInstance().getDefaultName() << "." << endl);1591 DoLog(0) && (Log() << Verbose(0) << "Default name of new molecules set to " << World::getInstance().getDefaultName() << "." << endl); 1584 1592 } 1585 1593 break; … … 1593 1601 1594 1602 // 3a. Parse the element database 1595 if (periode->LoadPeriodentafel(configuration.databasepath)) { 1596 DoLog(0) && (Log() << Verbose(0) << "Element list loaded successfully." << endl); 1597 //periode->Output(); 1598 } else { 1599 DoLog(0) && (Log() << Verbose(0) << "Element list loading failed." << endl); 1600 return 1; 1601 } 1603 if (DatabasePathGiven) 1604 if (periode->LoadPeriodentafel(configuration.databasepath)) { 1605 DoLog(0) && (Log() << Verbose(0) << "Element list loaded successfully." << endl); 1606 //periode->Output(); 1607 } else { 1608 DoLog(0) && (Log() << Verbose(0) << "Element list loading failed." << endl); 1609 return 1; 1610 } 1602 1611 // 3b. Find config file name and parse if possible, also BondGraphFileName 1603 1612 if (argv[1][0] != '-') { … … 1613 1622 } else { 1614 1623 DoLog(0) && (Log() << Verbose(0) << "Empty configuration file." << endl); 1615 ConfigFileName = argv[1];1624 strcpy(*ConfigFileName, argv[1]); 1616 1625 configPresent = empty; 1617 1626 output.close(); … … 1619 1628 } else { 1620 1629 test.close(); 1621 ConfigFileName = argv[1];1630 strcpy(*ConfigFileName, argv[1]); 1622 1631 DoLog(1) && (Log() << Verbose(1) << "Specified config file found, parsing ... "); 1623 switch (configuration.TestSyntax( ConfigFileName, periode)) {1632 switch (configuration.TestSyntax(*ConfigFileName, periode)) { 1624 1633 case 1: 1625 1634 DoLog(0) && (Log() << Verbose(0) << "new syntax." << endl); 1626 configuration.Load( ConfigFileName, BondGraphFileName, periode, molecules);1635 configuration.Load(*ConfigFileName, BondGraphFileName, periode, molecules); 1627 1636 configPresent = present; 1628 1637 break; 1629 1638 case 0: 1630 1639 DoLog(0) && (Log() << Verbose(0) << "old syntax." << endl); 1631 configuration.LoadOld( ConfigFileName, BondGraphFileName, periode, molecules);1640 configuration.LoadOld(*ConfigFileName, BondGraphFileName, periode, molecules); 1632 1641 configPresent = present; 1633 1642 break; … … 1650 1659 mol = World::getInstance().createMolecule(); 1651 1660 mol->ActiveFlag = true; 1652 if ( ConfigFileName != NULL)1653 mol->SetNameFromFilename( ConfigFileName);1661 if (*ConfigFileName != NULL) 1662 mol->SetNameFromFilename(*ConfigFileName); 1654 1663 molecules->insert(mol); 1655 1664 } … … 1705 1714 if (first->type != NULL) { 1706 1715 mol->AddAtom(first); // add to molecule 1707 if ((configPresent == empty) && (mol-> AtomCount!= 0))1716 if ((configPresent == empty) && (mol->getAtomCount() != 0)) 1708 1717 configPresent = present; 1709 1718 } else … … 1718 1727 if (configPresent == present) { 1719 1728 switch(argv[argptr-1][1]) { 1720 case 'M':1721 if ((argptr >= argc) || (argv[argptr][0] == '-')) {1722 ExitFlag = 255;1723 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for setting MPQC basis: -B <basis name>" << endl);1724 performCriticalExit();1725 } else {1726 configuration.basis = argv[argptr];1727 DoLog(1) && (Log() << Verbose(1) << "Setting MPQC basis to " << configuration.basis << "." << endl);1728 argptr+=1;1729 }1730 break;1731 1729 case 'D': 1732 1730 if (ExitFlag == 0) ExitFlag = 1; … … 1734 1732 DoLog(1) && (Log() << Verbose(1) << "Depth-First-Search Analysis." << endl); 1735 1733 MoleculeLeafClass *Subgraphs = NULL; // list of subgraphs from DFS analysis 1736 int *MinimumRingSize = new int[mol-> AtomCount];1734 int *MinimumRingSize = new int[mol->getAtomCount()]; 1737 1735 atom ***ListOfLocalAtoms = NULL; 1738 1736 class StackClass<bond *> *BackEdgeStack = NULL; … … 1754 1752 delete(Subgraphs); 1755 1753 for (int i=0;i<FragmentCounter;i++) 1756 Free(&ListOfLocalAtoms[i]);1757 Free(&ListOfLocalAtoms);1754 delete[](ListOfLocalAtoms[i]); 1755 delete[](ListOfLocalAtoms); 1758 1756 } 1759 1757 delete(BackEdgeStack); … … 1795 1793 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] == '-')) { 1796 1794 ExitFlag = 255; 1797 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for pair correlation analysis: -C E <Z1> <Z2> <output> <bin output> " << endl);1795 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for pair correlation analysis: -C E <Z1> <Z2> <output> <bin output> <binstart> <binend>" << endl); 1798 1796 performCriticalExit(); 1799 1797 } else { … … 1810 1808 else 1811 1809 correlationmap = PairCorrelation(molecules, elemental, elemental2); 1812 //OutputCorrelationToSurface(&output, correlationmap);1810 OutputPairCorrelation(&output, correlationmap); 1813 1811 BinPairMap *binmap = BinData( correlationmap, 0.5, BinStart, BinEnd ); 1814 1812 OutputCorrelation ( &binoutput, binmap ); … … 1826 1824 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] == '-')) { 1827 1825 ExitFlag = 255; 1828 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);1826 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for pair correlation analysis: -C P <Z1> <x> <y> <z> <output> <bin output> <binstart> <binend>" << endl); 1829 1827 performCriticalExit(); 1830 1828 } else { … … 1841 1839 else 1842 1840 correlationmap = CorrelationToPoint(molecules, elemental, Point); 1843 //OutputCorrelationToSurface(&output, correlationmap);1841 OutputCorrelationToPoint(&output, correlationmap); 1844 1842 BinPairMap *binmap = BinData( correlationmap, 0.5, BinStart, BinEnd ); 1845 1843 OutputCorrelation ( &binoutput, binmap ); … … 1882 1880 int counter = 0; 1883 1881 for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) { 1884 if ((Boundary == NULL) || (Boundary-> AtomCount < (*BigFinder)->AtomCount)) {1882 if ((Boundary == NULL) || (Boundary->getAtomCount() < (*BigFinder)->getAtomCount())) { 1885 1883 Boundary = *BigFinder; 1886 1884 } 1887 1885 counter++; 1888 1886 } 1889 bool *Actives = Malloc<bool>(counter, "ParseCommandLineOptions() - case C -- *Actives");1887 bool *Actives = new bool[counter]; 1890 1888 counter = 0; 1891 1889 for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) { … … 1913 1911 output.close(); 1914 1912 binoutput.close(); 1913 counter = 0; 1915 1914 for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) 1916 1915 (*BigFinder)->ActiveFlag = Actives[counter++]; 1917 Free(&Actives);1916 delete[](Actives); 1918 1917 delete(LCList); 1919 1918 delete(TesselStruct); … … 1941 1940 performCriticalExit(); 1942 1941 } else { 1942 mol->getAtomCount(); 1943 1943 SaveFlag = true; 1944 1944 DoLog(1) && (Log() << Verbose(1) << "Changing atom " << argv[argptr] << " to element " << argv[argptr+1] << "." << endl); … … 1950 1950 case 'F': 1951 1951 if (ExitFlag == 0) ExitFlag = 1; 1952 MaxDistance = -1; 1953 if (argv[argptr-1][2] == 'F') { // option is -FF? 1954 // fetch first argument as max distance to surface 1955 MaxDistance = atof(argv[argptr++]); 1956 DoLog(0) && (Log() << Verbose(0) << "Filling with maximum layer distance of " << MaxDistance << "." << endl); 1957 } 1958 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]))) { 1959 ExitFlag = 255; 1960 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); 1961 performCriticalExit(); 1962 } else { 1963 SaveFlag = true; 1964 DoLog(1) && (Log() << Verbose(1) << "Filling Box with water molecules." << endl); 1965 // construct water molecule 1966 molecule *filler = World::getInstance().createMolecule(); 1967 if (!filler->AddXYZFile(argv[argptr])) { 1968 DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse filler molecule from " << argv[argptr] << "." << endl); 1969 } 1970 filler->SetNameFromFilename(argv[argptr]); 1971 configuration.BG->ConstructBondGraph(filler); 1972 molecule *Filling = NULL; 1973 atom *second = NULL, *third = NULL; 1974 first = World::getInstance().createAtom(); 1975 first->type = periode->FindElement(1); 1976 first->x = Vector(0.441, -0.143, 0.); 1977 filler->AddAtom(first); 1978 second = World::getInstance().createAtom(); 1979 second->type = periode->FindElement(1); 1980 second->x = Vector(-0.464, 1.137, 0.0); 1981 filler->AddAtom(second); 1982 third = World::getInstance().createAtom(); 1983 third->type = periode->FindElement(8); 1984 third->x = Vector(-0.464, 0.177, 0.); 1985 filler->AddAtom(third); 1986 filler->AddBond(first, third, 1); 1987 filler->AddBond(second, third, 1); 1988 // call routine 1989 double distance[NDIM]; 1990 for (int i=0;i<NDIM;i++) 1991 distance[i] = atof(argv[argptr+i+1]); 1992 Filling = FillBoxWithMolecule(molecules, filler, configuration, MaxDistance, distance, atof(argv[argptr+4]), atof(argv[argptr+5]), atof(argv[argptr+6]), atoi(argv[argptr+7])); 1993 if (Filling != NULL) { 1994 Filling->ActiveFlag = false; 1995 molecules->insert(Filling); 1996 } 1997 World::getInstance().destroyMolecule(filler); 1998 argptr+=6; 1999 } 1952 ArgcList.insert(argptr-1); 1953 ArgcList.insert(argptr); 1954 ArgcList.insert(argptr+1); 1955 ArgcList.insert(argptr+2); 1956 ArgcList.insert(argptr+3); 1957 ArgcList.insert(argptr+4); 1958 ArgcList.insert(argptr+5); 1959 ArgcList.insert(argptr+6); 1960 ArgcList.insert(argptr+7); 1961 ArgcList.insert(argptr+8); 1962 ArgcList.insert(argptr+9); 1963 ArgcList.insert(argptr+10); 1964 ArgcList.insert(argptr+11); 1965 ArgcList.insert(argptr+12); 1966 argptr+=13; 2000 1967 break; 2001 1968 case 'A': … … 2007 1974 } else { 2008 1975 DoLog(0) && (Log() << Verbose(0) << "Parsing bonds from " << argv[argptr] << "." << endl); 2009 ifstream *input = new ifstream(argv[argptr]);2010 mol->CreateAdjacencyListFromDbondFile( input);2011 input ->close();1976 ifstream input(argv[argptr]); 1977 mol->CreateAdjacencyListFromDbondFile(&input); 1978 input.close(); 2012 1979 argptr+=1; 2013 1980 } … … 2059 2026 int counter = 0; 2060 2027 for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) { 2061 (*BigFinder)->CountAtoms(); 2062 if ((Boundary == NULL) || (Boundary->AtomCount < (*BigFinder)->AtomCount)) { 2028 if ((Boundary == NULL) || (Boundary->getAtomCount() < (*BigFinder)->getAtomCount())) { 2063 2029 Boundary = *BigFinder; 2064 2030 } 2065 2031 counter++; 2066 2032 } 2067 DoLog(1) && (Log() << Verbose(1) << "Biggest molecule has " << Boundary-> AtomCount<< " atoms." << endl);2033 DoLog(1) && (Log() << Verbose(1) << "Biggest molecule has " << Boundary->getAtomCount() << " atoms." << endl); 2068 2034 start = clock(); 2069 2035 LCList = new LinkedCell(Boundary, atof(argv[argptr])*2.); … … 2100 2066 if ((argptr >= argc) || (argv[argptr][0] == '-')) { 2101 2067 ExitFlag = 255; 2102 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for storing tempature: -L <step0> <step1> <prefix> <identity mapping?>" << endl);2068 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for linear interpolation: -L <step0> <step1> <prefix> <identity mapping?>" << endl); 2103 2069 performCriticalExit(); 2104 2070 } else { … … 2132 2098 case 'R': 2133 2099 if (ExitFlag == 0) ExitFlag = 1; 2134 if ((argptr+ 1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1]))) {2100 if ((argptr+3 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3]))) { 2135 2101 ExitFlag = 255; 2136 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for removing atoms: -R < id> <distance>" << endl);2102 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for removing atoms: -R <x> <y> <z> <distance>" << endl); 2137 2103 performCriticalExit(); 2138 2104 } else { 2139 2105 SaveFlag = true; 2140 DoLog(1) && (Log() << Verbose(1) << "Removing atoms around " << argv[argptr] << " with radius " << argv[argptr+1] << "." << endl); 2141 double tmp1 = atof(argv[argptr+1]); 2142 atom *third = mol->FindAtom(atoi(argv[argptr])); 2143 atom *first = mol->start; 2144 if ((third != NULL) && (first != mol->end)) { 2145 atom *second = first->next; 2146 while(second != mol->end) { 2147 first = second; 2148 second = first->next; 2149 if (first->x.DistanceSquared(third->x) > tmp1*tmp1) // distance to first above radius ... 2150 mol->RemoveAtom(first); 2106 const double radius = atof(argv[argptr+3]); 2107 Vector point(atof(argv[argptr]),atof(argv[argptr+1]),atof(argv[argptr+2])); 2108 DoLog(1) && (Log() << Verbose(1) << "Removing atoms around " << point << " with radius " << radius << "." << endl); 2109 atom *Walker = NULL; 2110 molecule::iterator advancer = mol->begin(); 2111 for(molecule::iterator iter = advancer; advancer != mol->end();) { 2112 iter = advancer++; 2113 if ((*iter)->x.DistanceSquared(point) > radius*radius){ // distance to first above radius ... 2114 Walker = (*iter); 2115 DoLog(1) && (Log() << Verbose(1) << "Removing atom " << *Walker << "." << endl); 2116 mol->RemoveAtom(*(iter)); 2117 World::getInstance().destroyAtom(Walker); 2151 2118 } 2152 } else {2153 DoeLog(1) && (eLog()<< Verbose(1) << "Removal failed due to missing atoms on molecule or wrong id." << endl);2154 2119 } 2155 argptr+= 2;2120 argptr+=4; 2156 2121 } 2157 2122 break; … … 2190 2155 case 's': 2191 2156 if (ExitFlag == 0) ExitFlag = 1; 2192 if ((argptr >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {2157 if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) { 2193 2158 ExitFlag = 255; 2194 2159 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for scaling: -s <factor_x> [factor_y] [factor_z]" << endl); 2195 2160 performCriticalExit(); 2196 2161 } else { 2197 SaveFlag = true; 2198 j = -1; 2199 DoLog(1) && (Log() << Verbose(1) << "Scaling all ion positions by factor." << endl); 2200 factor = new double[NDIM]; 2201 factor[0] = atof(argv[argptr]); 2202 factor[1] = atof(argv[argptr+1]); 2203 factor[2] = atof(argv[argptr+2]); 2204 mol->Scale((const double ** const)&factor); 2205 double * const cell_size = World::getInstance().getDomain(); 2206 for (int i=0;i<NDIM;i++) { 2207 j += i+1; 2208 x[i] = atof(argv[NDIM+i]); 2209 cell_size[j]*=factor[i]; 2210 } 2211 delete[](factor); 2162 ArgcList.insert(argptr-1); 2163 ArgcList.insert(argptr); 2164 ArgcList.insert(argptr+1); 2165 ArgcList.insert(argptr+2); 2212 2166 argptr+=3; 2213 2167 } … … 2220 2174 performCriticalExit(); 2221 2175 } else { 2222 SaveFlag = true; 2223 j = -1; 2224 DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl); 2225 double * const cell_size = World::getInstance().getDomain(); 2226 for (int i=0;i<6;i++) { 2227 cell_size[i] = atof(argv[argptr+i]); 2228 } 2229 // center 2230 mol->CenterInBox(); 2176 ArgcList.insert(argptr-1); 2177 ArgcList.insert(argptr); 2178 ArgcList.insert(argptr+1); 2179 ArgcList.insert(argptr+2); 2180 ArgcList.insert(argptr+3); 2181 ArgcList.insert(argptr+4); 2182 ArgcList.insert(argptr+5); 2231 2183 argptr+=6; 2232 2184 } … … 2239 2191 performCriticalExit(); 2240 2192 } else { 2241 SaveFlag = true; 2242 j = -1; 2243 DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl); 2244 double * const cell_size = World::getInstance().getDomain(); 2245 for (int i=0;i<6;i++) { 2246 cell_size[i] = atof(argv[argptr+i]); 2247 } 2248 // center 2249 mol->BoundInBox(); 2193 ArgcList.insert(argptr-1); 2194 ArgcList.insert(argptr); 2195 ArgcList.insert(argptr+1); 2196 ArgcList.insert(argptr+2); 2197 ArgcList.insert(argptr+3); 2198 ArgcList.insert(argptr+4); 2199 ArgcList.insert(argptr+5); 2250 2200 argptr+=6; 2251 2201 } … … 2258 2208 performCriticalExit(); 2259 2209 } else { 2260 SaveFlag = true; 2261 j = -1; 2262 DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given additional boundary." << endl); 2263 // make every coordinate positive 2264 mol->CenterEdge(&x); 2265 // update Box of atoms by boundary 2266 mol->SetBoxDimension(&x); 2267 // translate each coordinate by boundary 2268 double * const cell_size = World::getInstance().getDomain(); 2269 j=-1; 2270 for (int i=0;i<NDIM;i++) { 2271 j += i+1; 2272 x[i] = atof(argv[argptr+i]); 2273 cell_size[j] += x[i]*2.; 2274 } 2275 mol->Translate((const Vector *)&x); 2210 ArgcList.insert(argptr-1); 2211 ArgcList.insert(argptr); 2212 ArgcList.insert(argptr+1); 2213 ArgcList.insert(argptr+2); 2276 2214 argptr+=3; 2277 2215 } … … 2279 2217 case 'O': 2280 2218 if (ExitFlag == 0) ExitFlag = 1; 2281 SaveFlag = true; 2282 DoLog(1) && (Log() << Verbose(1) << "Centering atoms on edge and setting box dimensions." << endl); 2283 x.Zero(); 2284 mol->CenterEdge(&x); 2285 mol->SetBoxDimension(&x); 2219 ArgcList.insert(argptr-1); 2286 2220 argptr+=0; 2287 2221 break; … … 2293 2227 performCriticalExit(); 2294 2228 } else { 2229 mol->getAtomCount(); 2295 2230 SaveFlag = true; 2296 2231 DoLog(1) && (Log() << Verbose(1) << "Removing atom " << argv[argptr] << "." << endl); … … 2312 2247 mol->CreateAdjacencyList(atof(argv[argptr]), configuration.GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL); 2313 2248 DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl); 2314 if (mol-> first->next != mol->last) {2249 if (mol->hasBondStructure()) { 2315 2250 ExitFlag = mol->FragmentMolecule(atoi(argv[argptr+1]), &configuration); 2316 2251 } … … 2401 2336 performCriticalExit(); 2402 2337 } else { 2403 SaveFlag = true; 2404 double * const cell_size = World::getInstance().getDomain(); 2405 for (int axis = 1; axis <= NDIM; axis++) { 2406 int faktor = atoi(argv[argptr++]); 2407 int count; 2408 const element ** Elements; 2409 Vector ** vectors; 2410 if (faktor < 1) { 2411 DoeLog(1) && (eLog()<< Verbose(1) << "Repetition factor mus be greater than 1!" << endl); 2412 faktor = 1; 2413 } 2414 mol->CountAtoms(); // recount atoms 2415 if (mol->AtomCount != 0) { // if there is more than none 2416 count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand 2417 Elements = new const element *[count]; 2418 vectors = new Vector *[count]; 2419 j = 0; 2420 first = mol->start; 2421 while (first->next != mol->end) { // make a list of all atoms with coordinates and element 2422 first = first->next; 2423 Elements[j] = first->type; 2424 vectors[j] = &first->x; 2425 j++; 2426 } 2427 if (count != j) 2428 DoeLog(1) && (eLog()<< Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl); 2429 x.Zero(); 2430 y.Zero(); 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 2432 for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times 2433 x += y; // per factor one cell width further 2434 for (int k=count;k--;) { // go through every atom of the original cell 2435 first = World::getInstance().createAtom(); // create a new body 2436 first->x = (*vectors[k]) + x; 2437 first->type = Elements[k]; // insert original element 2438 mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...) 2439 } 2440 } 2441 // free memory 2442 delete[](Elements); 2443 delete[](vectors); 2444 // correct cell size 2445 if (axis < 0) { // if sign was negative, we have to translate everything 2446 x =(-(faktor-1)) * y; 2447 mol->Translate(&x); 2448 } 2449 cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor; 2450 } 2451 } 2338 ArgcList.insert(argptr-1); 2339 ArgcList.insert(argptr); 2340 ArgcList.insert(argptr+1); 2341 ArgcList.insert(argptr+2); 2342 argptr+=3; 2452 2343 } 2453 2344 break; … … 2461 2352 } while (argptr < argc); 2462 2353 if (SaveFlag) 2463 configuration.SaveAll( ConfigFileName, periode, molecules);2354 configuration.SaveAll(*ConfigFileName, periode, molecules); 2464 2355 } else { // no arguments, hence scan the elements db 2465 2356 if (periode->LoadPeriodentafel(configuration.databasepath)) … … 2476 2367 void cleanUp(){ 2477 2368 World::purgeInstance(); 2478 Log() << Verbose(0) << "Maximum of allocated memory: "2479 << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;2480 Log() << Verbose(0) << "Remaining non-freed memory: "2481 << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;2482 MemoryUsageObserver::purgeInstance();2483 2369 logger::purgeInstance(); 2484 2370 errorLogger::purgeInstance(); … … 2488 2374 ActionRegistry::purgeInstance(); 2489 2375 ActionHistory::purgeInstance(); 2376 Memory::getState(); 2490 2377 } 2491 2378 … … 2493 2380 { 2494 2381 config *configuration = World::getInstance().getConfig(); 2382 // while we are non interactive, we want to abort from asserts 2383 //ASSERT_DO(Assert::Abort); 2384 molecule *mol = NULL; 2495 2385 Vector x, y, z, n; 2496 2386 ifstream test; … … 2499 2389 char **Arguments = NULL; 2500 2390 int ArgcSize = 0; 2391 int ExitFlag = 0; 2501 2392 bool ArgumentsCopied = false; 2502 2393 char *ConfigFileName = new char[MAXSTRINGSIZE]; 2394 2395 // print version check whether arguments are present at all 2503 2396 cout << ESPACKVersion << endl; 2397 if (argc < 2) { 2398 cout << "Obtain help with " << argv[0] << " -h." << endl; 2399 cleanUp(); 2400 Memory::getState(); 2401 return(1); 2402 } 2403 2504 2404 2505 2405 setVerbosity(0); 2506 2406 // need to init the history before any action is created 2507 2407 ActionHistory::init(); 2408 2409 // In the interactive mode, we can leave the user the choice in case of error 2410 ASSERT_DO(Assert::Ask); 2411 2412 // from this moment on, we need to be sure to deeinitialize in the correct order 2413 // this is handled by the cleanup function 2414 atexit(cleanUp); 2508 2415 2509 2416 // Parse command line options and if present create respective UI … … 2512 2419 ArgcList.insert(0); // push back program! 2513 2420 ArgcList.insert(1); // push back config file name 2514 char ConfigFileName[MAXSTRINGSIZE];2515 2421 // handle arguments by ParseCommandLineOptions() 2516 ParseCommandLineOptions(argc,argv,World::getInstance().getMolecules(),World::getInstance().getPeriode(),*World::getInstance().getConfig(), (char *&)ConfigFileName, ArgcList);2422 ExitFlag = ParseCommandLineOptions(argc,argv,World::getInstance().getMolecules(),World::getInstance().getPeriode(),*World::getInstance().getConfig(), &ConfigFileName, ArgcList); 2517 2423 // copy all remaining arguments to a new argv 2518 Arguments = Malloc<char *>(ArgcList.size(), "main - **Arguments");2424 Arguments = new char *[ArgcList.size()]; 2519 2425 cout << "The following arguments are handled by CommandLineParser: "; 2520 2426 for (set<int>::iterator ArgcRunner = ArgcList.begin(); ArgcRunner != ArgcList.end(); ++ArgcRunner) { 2521 Arguments[ArgcSize] = Malloc<char>(strlen(argv[*ArgcRunner])+2, "main - *Arguments[]");2427 Arguments[ArgcSize] = new char[strlen(argv[*ArgcRunner])+2]; 2522 2428 strcpy(Arguments[ArgcSize], argv[*ArgcRunner]); 2523 2429 cout << " " << argv[*ArgcRunner]; … … 2544 2450 } 2545 2451 2546 if(World::getInstance().getPeriode()->StorePeriodentafel(configuration->databasepath)) 2547 Log() << Verbose(0) << "Saving of elements.db successful." << endl; 2548 2549 else 2550 Log() << Verbose(0) << "Saving of elements.db failed." << endl; 2452 Log() << Verbose(0) << "Saving to " << ConfigFileName << "." << endl; 2453 World::getInstance().getConfig()->SaveAll(ConfigFileName, World::getInstance().getPeriode(), World::getInstance().getMolecules()); 2551 2454 2552 2455 // free the new argv 2553 2456 if (ArgumentsCopied) { 2554 2457 for (int i=0; i<ArgcSize;i++) 2555 Free(&Arguments[i]);2556 Free(&Arguments);2458 delete[](Arguments[i]); 2459 delete[](Arguments); 2557 2460 } 2558 2559 cleanUp(); 2560 Memory::getState(); 2561 return (0); 2461 delete[](ConfigFileName); 2462 2463 return (ExitFlag == 1 ? 0 : ExitFlag); 2562 2464 } 2563 2465
Note:
See TracChangeset
for help on using the changeset viewer.
