Changes in / [1f1b23:a25aae]


Ignore:
Files:
58 added
13 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    r1f1b23 ra25aae  
    33
    44EXTRA_DIST = autogen.sh
     5
     6.PHONY: doc
     7doc:
     8        cd doc && make doxygen-docs
  • doc/Doxyfile

    r1f1b23 ra25aae  
    125125# configuration options related to source browsing
    126126#---------------------------------------------------------------------------
    127 SOURCE_BROWSER         = NO
     127SOURCE_BROWSER         = YES
    128128INLINE_SOURCES         = NO
    129129STRIP_CODE_COMMENTS    = YES
  • src/Makefile.am

    r1f1b23 ra25aae  
    88ANALYSISHEADER = analysis_bonds.hpp analysis_correlation.hpp
    99
    10 SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} bond.cpp bondgraph.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp graph.cpp helpers.cpp info.cpp leastsquaremin.cpp linkedcell.cpp log.cpp logger.cpp memoryusageobserver.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp
    11 HEADER = ${ANALYSISHEADER} ${ATOMHEADER} bond.hpp bondgraph.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp errorlogger.hpp graph.hpp helpers.hpp info.hpp leastsquaremin.hpp linkedcell.hpp lists.hpp log.hpp logger.hpp memoryallocator.hpp memoryusageobserver.hpp molecule.hpp molecule_template.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp
     10ACTIONSSOURCE = Actions/Action.cpp Actions/MethodAction.cpp Actions/ActionSequence.cpp Actions/MakroAction.cpp Actions/ErrorAction.cpp Actions/small_actions.cpp Actions/ActionRegistry.cpp
     11ACTIONSHEADER = Actions/Action.hpp Actions/MethodAction.hpp Actions/ActionSequence.hpp Actions/MakroAction.hpp Actions/ErrorAction.hpp Actions/small_actions.hpp Actions/ActionRegistry.hpp
     12
     13PATTERNSOURCE = Patterns/Observer.cpp
     14PATTERNHEADER = Patterns/Observer.hpp
     15
     16VIEWSOURCE = Views/View.cpp Views/StringView.cpp Views/MethodStringView.cpp Views/StreamStringView.cpp
     17VIEWHEADER = Views/View.hpp Views/StringView.hpp Views/MethodStringView.hpp Views/StreamStringView.hpp
     18
     19MENUSOURCE = Menu/Menu.cpp Menu/TextMenu.cpp Menu/MenuItem.cpp Menu/SubMenuItem.cpp Menu/ActionMenuItem.cpp Menu/SeperatorItem.cpp Menu/DisplayMenuItem.cpp
     20MENUHEADER = Menu/Menu.hpp Menu/TextMenu.hpp Menu/MenuItem.hpp Menu/SubMenuItem.hpp Menu/ActionMenuItem.hpp Menu/SeperatorItem.hpp Menu/DisplayMenuItem.hpp
     21
     22UISOURCE = ${ACTIONSSOURCE} ${VIEWSOURCE} ${MENUSOURCE} UIElements/UIFactory.cpp UIElements/TextUIFactory.cpp UIElements/MainWindow.cpp UIElements/TextWindow.cpp UIElements/Dialog.cpp UIElements/TextDialog.cpp
     23UIHEADER = ${ACTIONSHEADER} ${VIEWHEADER} ${MENUHEADER} UIElements/UIFactory.hpp UIElements/TextUIFactory.hpp UIElements/MainWindow.hpp UIElements/TextWindow.hpp UIElements/Dialog.hpp UIElements/TextDialog.hpp
     24
     25SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} ${PATTERNSOURCE} ${UISOURCE} bond.cpp bondgraph.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp graph.cpp helpers.cpp info.cpp leastsquaremin.cpp linkedcell.cpp log.cpp logger.cpp memoryusageobserver.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp menu.cpp
     26HEADER = ${ANALYSISHEADER} ${ATOMHEADER} ${PATTERNHEADER} ${UIHEADER} bond.hpp bondgraph.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp errorlogger.hpp graph.hpp helpers.hpp info.hpp leastsquaremin.hpp linkedcell.hpp lists.hpp log.hpp logger.hpp memoryallocator.hpp memoryusageobserver.hpp molecule.hpp molecule_template.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp menu.hpp
    1227
    1328BOOST_LIB = $(BOOST_LDFLAGS) $(BOOST_MPL_LIB)
  • src/builder.cpp

    r1f1b23 ra25aae  
    4848
    4949
     50#include <boost/bind.hpp>
     51
    5052using namespace std;
    5153
     
    6769#include "molecule.hpp"
    6870#include "periodentafel.hpp"
     71#include "UIElements/UIFactory.hpp"
     72#include "UIElements/MainWindow.hpp"
     73#include "UIElements/Dialog.hpp"
     74#include "Menu/ActionMenuItem.hpp"
     75#include "Actions/ActionRegistry.hpp"
     76#include "Actions/MethodAction.hpp"
     77#include "Actions/small_actions.hpp"
    6978#include "version.h"
    7079
    7180/********************************************* Subsubmenu routine ************************************/
    72 
     81#if 0
    7382/** Submenu for adding atoms to the molecule.
    7483 * \param *periode periodentafel
     
    258267        if (i >= 2) {
    259268          first->x.LSQdistance((const Vector **)atoms, i);
    260 
    261269          first->x.Output();
    262270          first->type = periode->AskElement();  // give type
     
    11551163};
    11561164
    1157 
    11581165/********************************************** Test routine **************************************/
    11591166
     
    12391246};
    12401247
    1241 /** Tries given filename or standard on saving the config file.
    1242  * \param *ConfigFileName name of file
    1243  * \param *configuration pointer to configuration structure with all the values
    1244  * \param *periode pointer to periodentafel structure with all the elements
    1245  * \param *molecules list of molecules structure with all the atoms and coordinates
    1246  */
    1247 static void SaveConfig(char *ConfigFileName, config *configuration, periodentafel *periode, MoleculeListClass *molecules)
    1248 {
    1249   char filename[MAXSTRINGSIZE];
    1250   ofstream output;
    1251   molecule *mol = new molecule(periode);
    1252   mol->SetNameFromFilename(ConfigFileName);
    1253 
    1254   if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
    1255     eLog() << Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl;
    1256   }
    1257 
    1258 
    1259   // first save as PDB data
    1260   if (ConfigFileName != NULL)
    1261     strcpy(filename, ConfigFileName);
    1262   if (output == NULL)
    1263     strcpy(filename,"main_pcp_linux");
    1264   Log() << Verbose(0) << "Saving as pdb input ";
    1265   if (configuration->SavePDB(filename, molecules))
    1266     Log() << Verbose(0) << "done." << endl;
    1267   else
    1268     Log() << Verbose(0) << "failed." << endl;
    1269 
    1270   // then save as tremolo data file
    1271   if (ConfigFileName != NULL)
    1272     strcpy(filename, ConfigFileName);
    1273   if (output == NULL)
    1274     strcpy(filename,"main_pcp_linux");
    1275   Log() << Verbose(0) << "Saving as tremolo data input ";
    1276   if (configuration->SaveTREMOLO(filename, molecules))
    1277     Log() << Verbose(0) << "done." << endl;
    1278   else
    1279     Log() << Verbose(0) << "failed." << endl;
    1280 
    1281   // translate each to its center and merge all molecules in MoleculeListClass into this molecule
    1282   int N = molecules->ListOfMolecules.size();
    1283   int *src = new int[N];
    1284   N=0;
    1285   for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
    1286     src[N++] = (*ListRunner)->IndexNr;
    1287     (*ListRunner)->Translate(&(*ListRunner)->Center);
    1288   }
    1289   molecules->SimpleMultiAdd(mol, src, N);
    1290   delete[](src);
    1291 
    1292   // ... and translate back
    1293   for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
    1294     (*ListRunner)->Center.Scale(-1.);
    1295     (*ListRunner)->Translate(&(*ListRunner)->Center);
    1296     (*ListRunner)->Center.Scale(-1.);
    1297   }
    1298 
    1299   Log() << Verbose(0) << "Storing configuration ... " << endl;
    1300   // get correct valence orbitals
    1301   mol->CalculateOrbitals(*configuration);
    1302   configuration->InitMaxMinStopStep = configuration->MaxMinStopStep = configuration->MaxPsiDouble;
    1303   if (ConfigFileName != NULL) { // test the file name
    1304     strcpy(filename, ConfigFileName);
    1305     output.open(filename, ios::trunc);
    1306   } else if (strlen(configuration->configname) != 0) {
    1307     strcpy(filename, configuration->configname);
    1308     output.open(configuration->configname, ios::trunc);
    1309     } else {
    1310       strcpy(filename, DEFAULTCONFIG);
    1311       output.open(DEFAULTCONFIG, ios::trunc);
    1312     }
    1313   output.close();
    1314   output.clear();
    1315   Log() << Verbose(0) << "Saving of config file ";
    1316   if (configuration->Save(filename, periode, mol))
    1317     Log() << Verbose(0) << "successful." << endl;
    1318   else
    1319     Log() << Verbose(0) << "failed." << endl;
    1320 
    1321   // and save to xyz file
    1322   if (ConfigFileName != NULL) {
    1323     strcpy(filename, ConfigFileName);
    1324     strcat(filename, ".xyz");
    1325     output.open(filename, ios::trunc);
    1326   }
    1327   if (output == NULL) {
    1328     strcpy(filename,"main_pcp_linux");
    1329     strcat(filename, ".xyz");
    1330     output.open(filename, ios::trunc);
    1331   }
    1332   Log() << Verbose(0) << "Saving of XYZ file ";
    1333   if (mol->MDSteps <= 1) {
    1334     if (mol->OutputXYZ(&output))
    1335       Log() << Verbose(0) << "successful." << endl;
    1336     else
    1337       Log() << Verbose(0) << "failed." << endl;
    1338   } else {
    1339     if (mol->OutputTrajectoriesXYZ(&output))
    1340       Log() << Verbose(0) << "successful." << endl;
    1341     else
    1342       Log() << Verbose(0) << "failed." << endl;
    1343   }
    1344   output.close();
    1345   output.clear();
    1346 
    1347   // and save as MPQC configuration
    1348   if (ConfigFileName != NULL)
    1349     strcpy(filename, ConfigFileName);
    1350   if (output == NULL)
    1351     strcpy(filename,"main_pcp_linux");
    1352   Log() << Verbose(0) << "Saving as mpqc input ";
    1353   if (configuration->SaveMPQC(filename, mol))
    1354     Log() << Verbose(0) << "done." << endl;
    1355   else
    1356     Log() << Verbose(0) << "failed." << endl;
    1357 
    1358   if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
    1359     eLog() << Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl;
    1360   }
    1361 
    1362   delete(mol);
    1363 };
     1248#endif
    13641249
    13651250/** Parses the command line options.
     
    13731258 * \return exit code (0 - successful, all else - something's wrong)
    13741259 */
    1375 static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode, config& configuration, char *&ConfigFileName)
     1260static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode,\
     1261                                   config& configuration, char *&ConfigFileName)
    13761262{
    13771263  Vector x,y,z,n;  // coordinates for absolute point in cell volume
     
    22412127    } while (argptr < argc);
    22422128    if (SaveFlag)
    2243       SaveConfig(ConfigFileName, &configuration, periode, molecules);
     2129      configuration.SaveAll(ConfigFileName, periode, molecules);
    22442130  } else {  // no arguments, hence scan the elements db
    22452131    if (periode->LoadPeriodentafel(configuration.databasepath))
     
    22522138};
    22532139
     2140/***************************************** Functions used to build all menus **********************/
     2141
     2142void populateEditMoleculesMenu(Menu* editMoleculesMenu,MoleculeListClass *molecules, config *configuration, periodentafel *periode){
     2143  // build the EditMoleculesMenu
     2144  Action *createMoleculeAction = new MethodAction("createMoleculeAction",boost::bind(&MoleculeListClass::createNewMolecule,molecules,periode));
     2145  new ActionMenuItem('c',"create new molecule",editMoleculesMenu,createMoleculeAction);
     2146
     2147  Action *loadMoleculeAction = new MethodAction("loadMoleculeAction",boost::bind(&MoleculeListClass::loadFromXYZ,molecules,periode));
     2148  new ActionMenuItem('l',"load molecule from xyz file",editMoleculesMenu,loadMoleculeAction);
     2149
     2150  Action *changeFilenameAction = new ChangeMoleculeNameAction(molecules);
     2151  new ActionMenuItem('n',"change molecule's name",editMoleculesMenu,changeFilenameAction);
     2152
     2153  Action *giveFilenameAction = new MethodAction("giveFilenameAction",boost::bind(&MoleculeListClass::setMoleculeFilename,molecules));
     2154  new ActionMenuItem('N',"give molecules filename",editMoleculesMenu,giveFilenameAction);
     2155
     2156  Action *parseAtomsAction = new MethodAction("parseAtomsAction",boost::bind(&MoleculeListClass::parseXYZIntoMolecule,molecules));
     2157  new ActionMenuItem('p',"parse atoms in xyz file into molecule",editMoleculesMenu,parseAtomsAction);
     2158
     2159  Action *eraseMoleculeAction = new MethodAction("eraseMoleculeAction",boost::bind(&MoleculeListClass::eraseMolecule,molecules));
     2160  new ActionMenuItem('r',"remove a molecule",editMoleculesMenu,eraseMoleculeAction);
     2161}
     2162
     2163
    22542164/********************************************** Main routine **************************************/
    22552165
    22562166int main(int argc, char **argv)
    22572167{
    2258   periodentafel *periode = new periodentafel; // and a period table of all elements
    2259   MoleculeListClass *molecules = new MoleculeListClass;  // list of all molecules
    2260   molecule *mol = NULL;
    2261   config *configuration = new config;
    2262   char choice;  // menu choice char
    2263   Vector x,y,z,n;  // coordinates for absolute point in cell volume
    2264   ifstream test;
    2265   ofstream output;
    2266   string line;
    2267   char *ConfigFileName = NULL;
    2268   int j;
    2269 
    2270   cout << ESPACKVersion << endl;
    2271 
    2272   setVerbosity(0);
    2273 
    2274   // =========================== PARSE COMMAND LINE OPTIONS ====================================
    2275   j = ParseCommandLineOptions(argc, argv, molecules, periode, *configuration, ConfigFileName);
    2276   switch(j) {
    2277     case 255:  // something went wrong
    2278     case 2:  // just for -f option
    2279     case 1:  // just for -v and -h options
    2280       delete(molecules); // also free's all molecules contained
    2281       delete(periode);
    2282       delete(configuration);
    2283       Log() << Verbose(0) <<  "Maximum of allocated memory: "
    2284         << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
    2285       Log() << Verbose(0) <<  "Remaining non-freed memory: "
    2286         << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
    2287       MemoryUsageObserver::getInstance()->purgeInstance();
    2288       logger::purgeInstance();
    2289       errorLogger::purgeInstance();
    2290      return (j == 1 ? 0 : j);
    2291     default:
    2292       break;
    2293   }
    2294 
    2295   // General stuff
    2296   if (molecules->ListOfMolecules.size() == 0) {
    2297     mol = new molecule(periode);
    2298     if (mol->cell_size[0] == 0.) {
    2299       Log() << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl;
    2300       for (int i=0;i<6;i++) {
    2301         Log() << Verbose(1) << "Cell size" << i << ": ";
    2302         cin >> mol->cell_size[i];
    2303       }
     2168  periodentafel *periode = new periodentafel;
     2169    MoleculeListClass *molecules = new MoleculeListClass;
     2170    molecule *mol = NULL;
     2171    config *configuration = new config;
     2172    Vector x, y, z, n;
     2173    ifstream test;
     2174    ofstream output;
     2175    string line;
     2176    char *ConfigFileName = NULL;
     2177    int j;
     2178    setVerbosity(0);
     2179    /* structure of ParseCommandLineOptions will be refactored later */
     2180    j = ParseCommandLineOptions(argc, argv, molecules, periode, *configuration, ConfigFileName);
     2181    switch (j){
     2182        case 255:
     2183        case 2:
     2184        case 1:
     2185            delete (molecules);
     2186            delete (periode);
     2187            delete (configuration);
     2188            Log() << Verbose(0) << "Maximum of allocated memory: " << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
     2189            Log() << Verbose(0) << "Remaining non-freed memory: " << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
     2190            MemoryUsageObserver::getInstance()->purgeInstance();
     2191            logger::purgeInstance();
     2192            errorLogger::purgeInstance();
     2193            return (j == 1 ? 0 : j);
     2194        default:
     2195            break;
    23042196    }
    2305     mol->ActiveFlag = true;
    2306     molecules->insert(mol);
    2307   }
    2308 
    2309   // =========================== START INTERACTIVE SESSION ====================================
    2310 
    2311   // now the main construction loop
    2312   Log() << Verbose(0) << endl << "Now comes the real construction..." << endl;
    2313   do {
    2314     Log() << Verbose(0) << endl << endl;
    2315     Log() << Verbose(0) << "============Molecule list=======================" << endl;
    2316     molecules->Enumerate((ofstream *)&cout);
    2317     Log() << Verbose(0) << "============Menu===============================" << endl;
    2318     Log() << Verbose(0) << "a - set molecule (in)active" << endl;
    2319     Log() << Verbose(0) << "e - edit molecules (load, parse, save)" << endl;
    2320     Log() << Verbose(0) << "g - globally manipulate atoms in molecule" << endl;
    2321     Log() << Verbose(0) << "M - Merge molecules" << endl;
    2322     Log() << Verbose(0) << "m - manipulate atoms" << endl;
    2323     Log() << Verbose(0) << "-----------------------------------------------" << endl;
    2324     Log() << Verbose(0) << "c - edit the current configuration" << endl;
    2325     Log() << Verbose(0) << "-----------------------------------------------" << endl;
    2326     Log() << Verbose(0) << "s - save current setup to config file" << endl;
    2327     Log() << Verbose(0) << "T - call the current test routine" << endl;
    2328     Log() << Verbose(0) << "q - quit" << endl;
    2329     Log() << Verbose(0) << "===============================================" << endl;
    2330     Log() << Verbose(0) << "Input: ";
    2331     cin >> choice;
    2332 
    2333     switch (choice) {
    2334       case 'a':  // (in)activate molecule
    2335         {
    2336           Log() << Verbose(0) << "Enter index of molecule: ";
    2337           cin >> j;
    2338           for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
    2339             if ((*ListRunner)->IndexNr == j)
    2340               (*ListRunner)->ActiveFlag = !(*ListRunner)->ActiveFlag;
     2197    if(molecules->ListOfMolecules.size() == 0){
     2198        mol = new molecule(periode);
     2199        if(mol->cell_size[0] == 0.){
     2200            Log() << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl;
     2201            for(int i = 0;i < 6;i++){
     2202                Log() << Verbose(1) << "Cell size" << i << ": ";
     2203                cin >> mol->cell_size[i];
     2204            }
    23412205        }
    2342         break;
    2343 
    2344       case 'c': // edit each field of the configuration
    2345        configuration->Edit();
    2346        break;
    2347 
    2348       case 'e': // create molecule
    2349         EditMolecules(periode, molecules);
    2350         break;
    2351 
    2352       case 'g': // manipulate molecules
    2353         ManipulateMolecules(periode, molecules, configuration);
    2354         break;
    2355 
    2356       case 'M':  // merge molecules
    2357         MergeMolecules(periode, molecules);
    2358         break;
    2359 
    2360       case 'm': // manipulate atoms
    2361         ManipulateAtoms(periode, molecules, configuration);
    2362         break;
    2363 
    2364       case 'q': // quit
    2365         break;
    2366 
    2367       case 's': // save to config file
    2368         SaveConfig(ConfigFileName, configuration, periode, molecules);
    2369         break;
    2370 
    2371       case 'T':
    2372         testroutine(molecules);
    2373         break;
    2374 
    2375       default:
    2376         break;
    2377     };
    2378   } while (choice != 'q');
    2379 
    2380   // save element data base
    2381   if (periode->StorePeriodentafel(configuration->databasepath)) //ElementsFileName
    2382     Log() << Verbose(0) << "Saving of elements.db successful." << endl;
    2383   else
    2384     Log() << Verbose(0) << "Saving of elements.db failed." << endl;
    2385 
    2386   delete(molecules); // also free's all molecules contained
    2387   delete(periode);
     2206
     2207        mol->ActiveFlag = true;
     2208        molecules->insert(mol);
     2209    }
     2210
     2211    {
     2212      cout << ESPACKVersion << endl;
     2213
     2214      setVerbosity(0);
     2215
     2216      menuPopulaters populaters;
     2217      populaters.MakeEditMoleculesMenu = populateEditMoleculesMenu;
     2218
     2219      UIFactory::makeUserInterface(UIFactory::Text);
     2220      MainWindow *mainWindow = UIFactory::get()->makeMainWindow(populaters,molecules, configuration, periode, ConfigFileName);
     2221      mainWindow->display();
     2222      delete mainWindow;
     2223    }
     2224
     2225    if(periode->StorePeriodentafel(configuration->databasepath))
     2226        Log() << Verbose(0) << "Saving of elements.db successful." << endl;
     2227
     2228    else
     2229        Log() << Verbose(0) << "Saving of elements.db failed." << endl;
     2230
     2231    delete (molecules);
     2232    delete(periode);
    23882233  delete(configuration);
     2234
     2235
    23892236
    23902237  Log() << Verbose(0) <<  "Maximum of allocated memory: "
     
    23952242  logger::purgeInstance();
    23962243  errorLogger::purgeInstance();
    2397 
     2244  UIFactory::purgeInstance();
     2245  ActionRegistry::purgeRegistry();
    23982246  return (0);
    23992247}
  • src/config.cpp

    r1f1b23 ra25aae  
    17771777};
    17781778
     1779
     1780/** Tries given filename or standard on saving the config file.
     1781 * \param *ConfigFileName name of file
     1782 * \param *periode pointer to periodentafel structure with all the elements
     1783 * \param *molecules list of molecules structure with all the atoms and coordinates
     1784 */
     1785void config::SaveAll(char *ConfigFileName, periodentafel *periode, MoleculeListClass *molecules)
     1786{
     1787  char filename[MAXSTRINGSIZE];
     1788  ofstream output;
     1789  molecule *mol = new molecule(periode);
     1790  mol->SetNameFromFilename(ConfigFileName);
     1791
     1792  if (!strcmp(configpath, GetDefaultPath())) {
     1793    eLog() << Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl;
     1794  }
     1795
     1796
     1797  // first save as PDB data
     1798  if (ConfigFileName != NULL)
     1799    strcpy(filename, ConfigFileName);
     1800  if (output == NULL)
     1801    strcpy(filename,"main_pcp_linux");
     1802  Log() << Verbose(0) << "Saving as pdb input ";
     1803  if (SavePDB(filename, molecules))
     1804    Log() << Verbose(0) << "done." << endl;
     1805  else
     1806    Log() << Verbose(0) << "failed." << endl;
     1807
     1808  // then save as tremolo data file
     1809  if (ConfigFileName != NULL)
     1810    strcpy(filename, ConfigFileName);
     1811  if (output == NULL)
     1812    strcpy(filename,"main_pcp_linux");
     1813  Log() << Verbose(0) << "Saving as tremolo data input ";
     1814  if (SaveTREMOLO(filename, molecules))
     1815    Log() << Verbose(0) << "done." << endl;
     1816  else
     1817    Log() << Verbose(0) << "failed." << endl;
     1818
     1819  // translate each to its center and merge all molecules in MoleculeListClass into this molecule
     1820  int N = molecules->ListOfMolecules.size();
     1821  int *src = new int[N];
     1822  N=0;
     1823  for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
     1824    src[N++] = (*ListRunner)->IndexNr;
     1825    (*ListRunner)->Translate(&(*ListRunner)->Center);
     1826  }
     1827  molecules->SimpleMultiAdd(mol, src, N);
     1828  delete[](src);
     1829
     1830  // ... and translate back
     1831  for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
     1832    (*ListRunner)->Center.Scale(-1.);
     1833    (*ListRunner)->Translate(&(*ListRunner)->Center);
     1834    (*ListRunner)->Center.Scale(-1.);
     1835  }
     1836
     1837  Log() << Verbose(0) << "Storing configuration ... " << endl;
     1838  // get correct valence orbitals
     1839  mol->CalculateOrbitals(*this);
     1840  InitMaxMinStopStep = MaxMinStopStep = MaxPsiDouble;
     1841  if (ConfigFileName != NULL) { // test the file name
     1842    strcpy(filename, ConfigFileName);
     1843    output.open(filename, ios::trunc);
     1844  } else if (strlen(configname) != 0) {
     1845    strcpy(filename, configname);
     1846    output.open(configname, ios::trunc);
     1847    } else {
     1848      strcpy(filename, DEFAULTCONFIG);
     1849      output.open(DEFAULTCONFIG, ios::trunc);
     1850    }
     1851  output.close();
     1852  output.clear();
     1853  Log() << Verbose(0) << "Saving of config file ";
     1854  if (Save(filename, periode, mol))
     1855    Log() << Verbose(0) << "successful." << endl;
     1856  else
     1857    Log() << Verbose(0) << "failed." << endl;
     1858
     1859  // and save to xyz file
     1860  if (ConfigFileName != NULL) {
     1861    strcpy(filename, ConfigFileName);
     1862    strcat(filename, ".xyz");
     1863    output.open(filename, ios::trunc);
     1864  }
     1865  if (output == NULL) {
     1866    strcpy(filename,"main_pcp_linux");
     1867    strcat(filename, ".xyz");
     1868    output.open(filename, ios::trunc);
     1869  }
     1870  Log() << Verbose(0) << "Saving of XYZ file ";
     1871  if (mol->MDSteps <= 1) {
     1872    if (mol->OutputXYZ(&output))
     1873      Log() << Verbose(0) << "successful." << endl;
     1874    else
     1875      Log() << Verbose(0) << "failed." << endl;
     1876  } else {
     1877    if (mol->OutputTrajectoriesXYZ(&output))
     1878      Log() << Verbose(0) << "successful." << endl;
     1879    else
     1880      Log() << Verbose(0) << "failed." << endl;
     1881  }
     1882  output.close();
     1883  output.clear();
     1884
     1885  // and save as MPQC configuration
     1886  if (ConfigFileName != NULL)
     1887    strcpy(filename, ConfigFileName);
     1888  if (output == NULL)
     1889    strcpy(filename,"main_pcp_linux");
     1890  Log() << Verbose(0) << "Saving as mpqc input ";
     1891  if (SaveMPQC(filename, mol))
     1892    Log() << Verbose(0) << "done." << endl;
     1893  else
     1894    Log() << Verbose(0) << "failed." << endl;
     1895
     1896  if (!strcmp(configpath, GetDefaultPath())) {
     1897    eLog() << Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl;
     1898  }
     1899
     1900  delete(mol);
     1901};
     1902
    17791903/** Reads parameter from a parsed file.
    17801904 * The file is either parsed for a certain keyword or if null is given for
  • src/config.hpp

    r1f1b23 ra25aae  
    146146  bool SaveTREMOLO(const char * const filename, const MoleculeListClass * const MolList) const;
    147147
     148  void SaveAll(char *ConfigFileName, periodentafel *periode, MoleculeListClass *molecules);
     149
    148150  void Edit();
    149151  bool GetIsAngstroem() const;
  • src/defs.hpp

    r1f1b23 ra25aae  
    7777#define UPDATECOUNT 10  //!< update ten sites per BOSSANOVA interval
    7878
     79#define STD_MENU_LENGTH 60
     80#define STD_MENU_TITLE_SPACER '='
     81#define STD_SEPERATOR_SPACER '-'
     82
    7983#endif /*DEFS_HPP_*/
  • src/molecule.cpp

    r1f1b23 ra25aae  
    6161  delete(start);
    6262};
     63
     64
     65// getter and setter
     66const std::string molecule::getName(){
     67  return std::string(name);
     68}
     69
     70void molecule::setName(const std::string _name){
     71  START_OBSERVER;
     72  strncpy(name,_name.c_str(),MAXSTRINGSIZE);
     73  FINISH_OBSERVER;
     74}
    6375
    6476
     
    10831095  }
    10841096};
     1097
     1098void molecule::flipActiveFlag(){
     1099  ActiveFlag = !ActiveFlag;
     1100}
  • src/molecule.hpp

    r1f1b23 ra25aae  
    2727#include <vector>
    2828
     29#include <string>
     30
    2931#include "graph.hpp"
    3032#include "stackclass.hpp"
    3133#include "tesselation.hpp"
     34#include "Patterns/Observer.hpp"
    3235
    3336/****************************************** forward declarations *****************************/
     
    8083 * Class incorporates number of types
    8184 */
    82 class molecule : public PointCloud {
     85class molecule : public PointCloud , public Observable {
    8386  public:
    8487    double cell_size[6];//!< cell size
     
    99102    bool ActiveFlag;    //!< in a MoleculeListClass used to discern active from inactive molecules
    100103    Vector Center;      //!< Center of molecule in a global box
     104    int IndexNr;        //!< index of molecule in a MoleculeListClass
    101105    char name[MAXSTRINGSIZE];         //!< arbitrary name
    102     int IndexNr;        //!< index of molecule in a MoleculeListClass
    103 
     106
     107public:
    104108  molecule(const periodentafel * const teil);
    105109  virtual ~molecule();
     110
     111  //getter and setter
     112  const std::string getName();
     113  void setName(const std::string);
    106114
    107115  // re-definition of virtual functions from PointCloud
     
    299307  bool OutputTemperatureFromTrajectories(ofstream * const output, int startstep, int endstep);
    300308
     309  // Manipulation routines
     310  void flipActiveFlag();
     311
    301312  private:
    302313  int last_atom;      //!< number given to last atom
     
    308319/** A list of \a molecule classes.
    309320 */
    310 class MoleculeListClass {
     321class MoleculeListClass : public Observable {
    311322  public:
    312323    MoleculeList ListOfMolecules; //!< List of the contained molecules
     
    327338  int CountAllAtoms() const;
    328339
     340  // Methods moved here from the menus
     341  // TODO: more refactoring needed on these methods
     342  void flipChosen();
     343  void createNewMolecule(periodentafel *periode);
     344  void loadFromXYZ(periodentafel *periode);
     345  void setMoleculeFilename();
     346  void parseXYZIntoMolecule();
     347  void eraseMolecule();
     348
     349
    329350  // merging of molecules
    330351  bool SimpleMerge(molecule *mol, molecule *srcmol);
  • src/moleculelist.cpp

    r1f1b23 ra25aae  
    5050void MoleculeListClass::insert(molecule *mol)
    5151{
     52  START_OBSERVER;
    5253  mol->IndexNr = MaxIndex++;
    5354  ListOfMolecules.push_back(mol);
     55  mol->signOn(this);
     56  FINISH_OBSERVER;
    5457};
    5558
     
    144147
    145148  // header
    146   Log() << Verbose(0) << "Index\tName\t\tAtoms\tFormula\tCenter\tSize" << endl;
    147   Log() << Verbose(0) << "-----------------------------------------------" << endl;
     149  (*out) << "Index\tName\t\tAtoms\tFormula\tCenter\tSize" << endl;
     150  (*out) << "-----------------------------------------------" << endl;
    148151  if (ListOfMolecules.size() == 0)
    149     Log() << Verbose(0) << "\tNone" << endl;
     152    (*out) << "\tNone" << endl;
    150153  else {
    151154    Origin.Zero();
     
    164167      }
    165168      // output Index, Name, number of atoms, chemical formula
    166       Log() << Verbose(0) << ((*ListRunner)->ActiveFlag ? "*" : " ") << (*ListRunner)->IndexNr << "\t" << (*ListRunner)->name << "\t\t" << (*ListRunner)->AtomCount << "\t";
     169      (*out) << ((*ListRunner)->ActiveFlag ? "*" : " ") << (*ListRunner)->IndexNr << "\t" << (*ListRunner)->name << "\t\t" << (*ListRunner)->AtomCount << "\t";
    167170      Elemental = (*ListRunner)->elemente->end;
    168171      while(Elemental->previous != (*ListRunner)->elemente->start) {
    169172        Elemental = Elemental->previous;
    170173        if (Counts[Elemental->Z] != 0)
    171           Log() << Verbose(0) << Elemental->symbol << Counts[Elemental->Z];
     174          (*out) << Elemental->symbol << Counts[Elemental->Z];
    172175      }
    173176      // Center and size
    174       Log() << Verbose(0) << "\t" << (*ListRunner)->Center << "\t" << sqrt(size) << endl;
     177      (*out) << "\t" << (*ListRunner)->Center << "\t" << sqrt(size) << endl;
    175178    }
    176179  }
     
    875878}
    876879
     880/***********
     881 * Methods Moved here from the menus
     882 */
     883
     884void MoleculeListClass::flipChosen() {
     885  int j;
     886  Log() << Verbose(0) << "Enter index of molecule: ";
     887  cin >> j;
     888  for(MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++)
     889    if ((*ListRunner)->IndexNr == j)
     890      (*ListRunner)->ActiveFlag = !(*ListRunner)->ActiveFlag;
     891}
     892
     893void MoleculeListClass::createNewMolecule(periodentafel *periode) {
     894  START_OBSERVER;
     895  molecule *mol = NULL;
     896  mol = new molecule(periode);
     897  insert(mol);
     898  FINISH_OBSERVER;
     899};
     900
     901void MoleculeListClass::loadFromXYZ(periodentafel *periode){
     902  molecule *mol = NULL;
     903  Vector center;
     904  char filename[MAXSTRINGSIZE];
     905  Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
     906  mol = new molecule(periode);
     907  do {
     908    Log() << Verbose(0) << "Enter file name: ";
     909    cin >> filename;
     910  } while (!mol->AddXYZFile(filename));
     911  mol->SetNameFromFilename(filename);
     912  // center at set box dimensions
     913  mol->CenterEdge(&center);
     914  mol->cell_size[0] = center.x[0];
     915  mol->cell_size[1] = 0;
     916  mol->cell_size[2] = center.x[1];
     917  mol->cell_size[3] = 0;
     918  mol->cell_size[4] = 0;
     919  mol->cell_size[5] = center.x[2];
     920  insert(mol);
     921}
     922
     923void MoleculeListClass::setMoleculeFilename() {
     924  char filename[MAXSTRINGSIZE];
     925  int nr;
     926  molecule *mol = NULL;
     927  do {
     928    Log() << Verbose(0) << "Enter index of molecule: ";
     929    cin >> nr;
     930    mol = ReturnIndex(nr);
     931  } while (mol == NULL);
     932  Log() << Verbose(0) << "Enter name: ";
     933  cin >> filename;
     934  mol->SetNameFromFilename(filename);
     935}
     936
     937void MoleculeListClass::parseXYZIntoMolecule(){
     938  char filename[MAXSTRINGSIZE];
     939  int nr;
     940  molecule *mol = NULL;
     941  mol = NULL;
     942  do {
     943   Log() << Verbose(0) << "Enter index of molecule: ";
     944   cin >> nr;
     945   mol = ReturnIndex(nr);
     946  } while (mol == NULL);
     947  Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
     948  do {
     949   Log() << Verbose(0) << "Enter file name: ";
     950   cin >> filename;
     951  } while (!mol->AddXYZFile(filename));
     952  mol->SetNameFromFilename(filename);
     953};
     954
     955void MoleculeListClass::eraseMolecule(){
     956  int nr;
     957  molecule *mol = NULL;
     958  Log() << Verbose(0) << "Enter index of molecule: ";
     959  cin >> nr;
     960  for(MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++)
     961    if (nr == (*ListRunner)->IndexNr) {
     962      mol = *ListRunner;
     963      ListOfMolecules.erase(ListRunner);
     964      delete(mol);
     965      break;
     966    }
     967};
     968
    877969
    878970/******************************************* Class MoleculeLeafClass ************************************************/
  • src/unittests/Makefile.am

    r1f1b23 ra25aae  
    33AM_LDFLAGS = $(CPPUNIT_LIBS) -ldl
    44AM_CXXFLAGS = $(CPPUNIT_CFLAGS)
     5
     6MENUTESTS = ActionSequenceTest
    57
    68TESTS = \
     
    2426  Tesselation_BoundaryTriangleUnitTest \
    2527  Tesselation_InOutsideUnitTest \
    26   VectorUnitTest
     28  VectorUnitTest \
     29  ObserverTest \
     30  ${MENUTESTS} 
     31   
    2732 
    28 check_PROGRAMS = $(TESTS)
     33check_PROGRAMS = $(TESTS) 
    2934noinst_PROGRAMS = $(TESTS)
    3035
     
    8994VectorUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    9095
     96ActionSequenceTest_SOURCES = ActionSequenceTest.cpp ActionSequenceTest.hpp
     97ActionSequenceTest_LDADD = ../libmolecuilder.a
     98
     99ObserverTest_SOURCES = ObserverTest.cpp ObserverTest.hpp
     100ObserverTest_LDADD = ../libmolecuilder.a
    91101
    92102#AUTOMAKE_OPTIONS = parallel-tests
  • src/vector.cpp

    r1f1b23 ra25aae  
    663663};
    664664
     665Vector& Vector::operator=(const Vector& src) {
     666  CopyVector(src);
     667  return *this;
     668}
     669
    665670/** Prints a 3dim vector.
    666671 * prints no end of line.
     
    10761081void Vector::CopyVector(const Vector * const y)
    10771082{
    1078   for (int i=NDIM;i--;)
    1079     this->x[i] = y->x[i];
     1083  // check for self assignment
     1084  if(y!=this){
     1085    for (int i=NDIM;i--;)
     1086      this->x[i] = y->x[i];
     1087  }
    10801088}
    10811089
     
    10851093void Vector::CopyVector(const Vector &y)
    10861094{
    1087   for (int i=NDIM;i--;)
    1088     this->x[i] = y.x[i];
     1095  // check for self assignment
     1096  if(&y!=this) {
     1097    for (int i=NDIM;i--;)
     1098      this->x[i] = y.x[i];
     1099  }
    10891100}
    10901101
  • src/vector.hpp

    r1f1b23 ra25aae  
    7979  bool IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const;
    8080  void WrapPeriodically(const double * const M, const double * const Minv);
     81
     82  Vector& operator=(const Vector &src);
     83
    8184};
    8285
Note: See TracChangeset for help on using the changeset viewer.