Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/builder.cpp

    r68f03d r980dd6  
    5353
    5454#include <cstring>
     55#include <cstdlib>
    5556
    5657#include "analysis_bonds.hpp"
     
    6061#include "bondgraph.hpp"
    6162#include "boundary.hpp"
     63#include "CommandLineParser.hpp"
    6264#include "config.hpp"
    6365#include "element.hpp"
     
    7678#include "Actions/ActionRegistry.hpp"
    7779#include "Actions/ActionHistory.hpp"
     80#include "Actions/MapOfActions.hpp"
    7881#include "Actions/MethodAction.hpp"
    79 #include "Actions/small_actions.hpp"
     82#include "Actions/MoleculeAction/ChangeNameAction.hpp"
    8083#include "World.hpp"
    8184#include "version.h"
     
    862865
    863866        mol->CountAtoms(); // recount atoms
    864         if (mol->AtomCount != 0) {  // if there is more than none
    865           count = mol->AtomCount;  // is changed becausing of adding, thus has to be stored away beforehand
     867        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
    866869          Elements = new element *[count];
    867870          vectors = new Vector *[count];
     
    12931296  // generate some KeySets
    12941297  DoLog(0) && (Log() << Verbose(0) << "Generating KeySets." << endl);
    1295   KeySet TestSets[mol->AtomCount+1];
     1298  KeySet TestSets[mol->getAtomCount()+1];
    12961299  i=1;
    12971300  while (Walker->next != mol->end) {
     
    13041307  DoLog(0) && (Log() << Verbose(0) << "Testing insertion of already present item in KeySets." << endl);
    13051308  KeySetTestPair test;
    1306   test = TestSets[mol->AtomCount-1].insert(Walker->nr);
     1309  test = TestSets[mol->getAtomCount()-1].insert(Walker->nr);
    13071310  if (test.second) {
    13081311    DoLog(1) && (Log() << Verbose(1) << "Insertion worked?!" << endl);
     
    13101313    DoLog(1) && (Log() << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl);
    13111314  }
    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);
    13141317
    13151318  // constructing Graph structure
     
    13191322  // insert KeySets into Subgraphs
    13201323  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++) {
    13221325    Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.)));
    13231326  }
    13241327  DoLog(0) && (Log() << Verbose(0) << "Testing insertion of already present item in Subgraph." << endl);
    13251328  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.)));
    13271330  if (test2.second) {
    13281331    DoLog(1) && (Log() << Verbose(1) << "Insertion worked?!" << endl);
     
    14791482
    14801483/** 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.
    14811486 * \param argc argument count
    14821487 * \param **argv arguments array
     
    14861491 * \param *ConfigFileName pointer to config file name in **argv
    14871492 * \param *PathToDatabases pointer to db's path in **argv
     1493 * \param &ArgcList list of arguments that we do not parse here
    14881494 * \return exit code (0 - successful, all else - something's wrong)
    14891495 */
    1490 static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode,\
    1491                                    config& configuration, char *&ConfigFileName)
     1496static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode,
     1497                                   config& configuration, char **ConfigFileName, set<int> &ArgcList)
    14921498{
    14931499  Vector x,y,z,n;  // coordinates for absolute point in cell volume
     
    15071513  molecule *mol = NULL;
    15081514  string BondGraphFileName("\n");
    1509   int verbosity = 0;
    1510   strncpy(configuration.databasepath, LocalPath, MAXSTRINGSIZE-1);
     1515  bool DatabasePathGiven = false;
    15111516
    15121517  if (argc > 1) { // config file specified as option
     
    15211526          case 'H':
    15221527          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);
    15651530            break;
    15661531          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++;
    15691540            }
    1570             setVerbosity(verbosity);
    1571             DoLog(0) && (Log() << Verbose(0) << "Setting verbosity to " << verbosity << "." << endl);
    15721541            break;
    15731542          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);
    15771545            break;
    15781546          case 'B':
    15791547            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);
    15831550              performCriticalExit();
    15841551            } 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);
    15921559              argptr+=6;
    15931560            }
     
    15981565              performCriticalExit();
    15991566            } 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);
    16021569              argptr+=1;
    16031570            }
     
    16081575              performCriticalExit();
    16091576            } 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);
    16121590              argptr+=1;
    16131591            }
    16141592            break;
    16151593          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            }
    16181603            break;
    16191604          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;
    16231613            }
    16241614            break;
     
    16311621    } while (argptr < argc);
    16321622
    1633     // 3a. Parse the element database
    1634     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     }
    16411623    // 3b. Find config file name and parse if possible, also BondGraphFileName
    16421624    if (argv[1][0] != '-') {
     
    16521634        } else {
    16531635          DoLog(0) && (Log() << Verbose(0) << "Empty configuration file." << endl);
    1654           ConfigFileName = argv[1];
     1636          strcpy(*ConfigFileName, argv[1]);
    16551637          configPresent = empty;
    16561638          output.close();
     
    16581640      } else {
    16591641        test.close();
    1660         ConfigFileName = argv[1];
     1642        strcpy(*ConfigFileName, argv[1]);
    16611643        DoLog(1) && (Log() << Verbose(1) << "Specified config file found, parsing ... ");
    1662         switch (configuration.TestSyntax(ConfigFileName, periode)) {
     1644        switch (configuration.TestSyntax(*ConfigFileName, periode)) {
    16631645          case 1:
    16641646            DoLog(0) && (Log() << Verbose(0) << "new syntax." << endl);
    1665             configuration.Load(ConfigFileName, BondGraphFileName, periode, molecules);
     1647            configuration.Load(*ConfigFileName, BondGraphFileName, periode, molecules);
    16661648            configPresent = present;
    16671649            break;
    16681650          case 0:
    16691651            DoLog(0) && (Log() << Verbose(0) << "old syntax." << endl);
    1670             configuration.LoadOld(ConfigFileName, BondGraphFileName, periode, molecules);
     1652            configuration.LoadOld(*ConfigFileName, BondGraphFileName, periode, molecules);
    16711653            configPresent = present;
    16721654            break;
     
    16891671       mol = World::getInstance().createMolecule();
    16901672       mol->ActiveFlag = true;
    1691        if (ConfigFileName != NULL)
    1692          mol->SetNameFromFilename(ConfigFileName);
     1673       if (*ConfigFileName != NULL)
     1674         mol->SetNameFromFilename(*ConfigFileName);
    16931675       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        }
    17021676     }
    17031677
     
    17291703            case 'a':
    17301704              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] == '-')) {
    17321706                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);
    17341708                performCriticalExit();
    17351709              } 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;
    17511717              }
    17521718              break;
     
    17571723        if (configPresent == present) {
    17581724          switch(argv[argptr-1][1]) {
    1759             case 'M':
     1725            case 'D':
     1726              if (ExitFlag == 0) ExitFlag = 1;
    17601727              if ((argptr >= argc) || (argv[argptr][0] == '-')) {
    17611728                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);
    17631730                performCriticalExit();
    17641731              } 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);
    17671734                argptr+=1;
    17681735              }
    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 analysis
    1775                 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 ListOfLocalAtoms
    1786                     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;
    18021736              break;
    18031737            case 'I':
    18041738              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;
    18201741              break;
    18211742            case 'C':
    18221743              {
    1823                 int ranges[3] = {1, 1, 1};
    1824                 bool periodic = (argv[argptr-1][2] =='p');
    18251744                if (ExitFlag == 0) ExitFlag = 1;
    1826                 if ((argptr >= argc)) {
     1745                if ((argptr+11 >= argc)) {
    18271746                  ExitFlag = 255;
    18281747                  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);
     
    18311750                  switch(argv[argptr][0]) {
    18321751                    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;
    18611766                      break;
    18621767
    18631768                    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;
    18931786                      break;
    18941787
    18951788                    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;
    19641806                      break;
    19651807
     
    19751817            case 'E':
    19761818              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]))) {
    19781820                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);
    19801822                performCriticalExit();
    19811823              } 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;
    19871829              }
    19881830              break;
    19891831            case 'F':
    19901832              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] == '-')) {
    19981834                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);
    20001836                performCriticalExit();
    20011837              } 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;
    20381853              }
    20391854              break;
    20401855            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':
    20411886              if (ExitFlag == 0) ExitFlag = 1;
    20421887              if ((argptr >= argc) || (argv[argptr][0] == '-')) {
    20431888                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);
    20451890                performCriticalExit();
    20461891              } 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);
    20601905                performCriticalExit();
    20611906              } 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);
    20741921                performCriticalExit();
    20751922              } 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] == '-')) {
    20861933                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);
    20881935                performCriticalExit();
    20891936              } 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] == '-')) {
    21221953                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);
    21241955                performCriticalExit();
    21251956              } 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] == '-'))  {
    21401967                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);
    21421969                performCriticalExit();
    21431970              } 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])) ) {
    21581983                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);
    21601985                performCriticalExit();
    21611986              } 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':
    21981999              if (ExitFlag == 0) ExitFlag = 1;
    21992000              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])) ) {
    22322001                ExitFlag = 255;
    22332002                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for scaling: -s <factor_x> [factor_y] [factor_z]" << endl);
    22342003                performCriticalExit();
    22352004              } 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);
    22512009                argptr+=3;
    22522010              }
     
    22592017                performCriticalExit();
    22602018              } 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);
    22702026                argptr+=6;
    22712027              }
     
    22782034                performCriticalExit();
    22792035              } 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);
    22892043                argptr+=6;
    22902044              }
     
    22972051                performCriticalExit();
    22982052              } 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);
    23152057                argptr+=3;
    23162058              }
     
    23182060            case 'O':
    23192061              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);
    23252063              argptr+=0;
    23262064              break;
     
    23322070                performCriticalExit();
    23332071              } 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);
    23382074                argptr+=1;
    23392075              }
     
    23412077            case 'f':
    23422078              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] == '-')) {
    23442080                ExitFlag = 255;
    23452081                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for fragmentation: -f <max. bond distance> <bond order>" << endl);
    23462082                performCriticalExit();
    23472083              } 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;
    23592091              }
    23602092              break;
     
    23692101                SaveFlag = true;
    23702102                DoLog(0) && (Log() << Verbose(0) << "Converting to prinicipal axis system." << endl);
     2103                mol->PrincipalAxisSystem((bool)j);
    23712104              } else
    2372                 DoLog(0) && (Log() << Verbose(0) << "Evaluating prinicipal axis." << endl);
    2373               mol->PrincipalAxisSystem((bool)j);
     2105                ArgcList.insert(argptr-1);
     2106                argptr+=0;
    23742107              break;
    23752108            case 'o':
    23762109              if (ExitFlag == 0) ExitFlag = 1;
    2377               if ((argptr+1 >= argc) || (argv[argptr][0] == '-')){
     2110              if ((argptr+4 >= argc) || (argv[argptr][0] == '-')){
    23782111                ExitFlag = 255;
    2379                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for convex envelope: -o <convex output file> <non-convex output 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);
    23802113                performCriticalExit();
    23812114              } 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;
    23982122              }
    23992123              break;
     
    24162140                  performCriticalExit();
    24172141              } 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;
    24332145              }
    24342146              break;
     
    24402152                performCriticalExit();
    24412153              } 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;
    24912159              }
    24922160              break;
     
    25002168    } while (argptr < argc);
    25012169    if (SaveFlag)
    2502       configuration.SaveAll(ConfigFileName, periode, molecules);
     2170      configuration.SaveAll(*ConfigFileName, periode, molecules);
    25032171  } else {  // no arguments, hence scan the elements db
    25042172    if (periode->LoadPeriodentafel(configuration.databasepath))
     
    25112179};
    25122180
    2513 /***************************************** Functions used to build all menus **********************/
    2514 
    2515 void populateEditMoleculesMenu(Menu* editMoleculesMenu,MoleculeListClass *molecules, config *configuration, periodentafel *periode){
    2516   // build the EditMoleculesMenu
    2517   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 
    25382181/********************************************** Main routine **************************************/
    25392182
    2540 void cleanUp(config *configuration){
    2541   UIFactory::purgeInstance();
     2183void cleanUp(){
    25422184  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();
    25492185  logger::purgeInstance();
    25502186  errorLogger::purgeInstance();
     2187  UIFactory::purgeInstance();
     2188  MapOfActions::purgeInstance();
     2189  CommandLineParser::purgeInstance();
    25512190  ActionRegistry::purgeInstance();
    25522191  ActionHistory::purgeInstance();
     
    25562195int main(int argc, char **argv)
    25572196{
     2197    config *configuration = World::getInstance().getConfig();
     2198    // while we are non interactive, we want to abort from asserts
     2199    //ASSERT_DO(Assert::Abort);
    25582200    molecule *mol = NULL;
    2559     config *configuration = new config;
    25602201    Vector x, y, z, n;
    25612202    ifstream test;
    25622203    ofstream output;
    25632204    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
    25672212    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
    25682220
    25692221    setVerbosity(0);
    25702222    // need to init the history before any action is created
    25712223    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      }
    25822262    }
    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     }
    25962263
    25972264    {
    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();
    26072266      mainWindow->display();
    26082267      delete mainWindow;
    26092268    }
    26102269
    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);
    26202283}
    26212284
Note: See TracChangeset for help on using the changeset viewer.