/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010-2012 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * KeySetsContainer.cpp * * Created on: Sep 15, 2011 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include #include #include "CodePatterns/Log.hpp" #include "Fragmentation/defs.hpp" #include "Fragmentation/helpers.hpp" #include "Helpers/defs.hpp" #include "KeySetsContainer.hpp" /** Constructor of KeySetsContainer class. */ KeySetsContainer::KeySetsContainer() : FragmentCounter(0), Order(0), FragmentsPerOrder(0) {}; /** Destructor of KeySetsContainer class. */ KeySetsContainer::~KeySetsContainer() { // for(int i=FragmentCounter;i--;) // delete[](KeySets[i]); // for(int i=Order;i--;) // delete[](OrderSet[i]); // delete[](KeySets); // delete[](OrderSet); // delete[](AtomCounter); // delete[](FragmentsPerOrder); }; /** Parsing KeySets into array. * \param *name directory with keyset file * \param *ACounter number of atoms per fragment * \param FCounter number of fragments * \return parsing succesful */ bool KeySetsContainer::ParseKeySets(const std::string name, const IntVector ACounter, const int FCounter) { ifstream input; char *FragmentNumber = NULL; stringstream file; char filename[1023]; FragmentCounter = FCounter; LOG(0, "Parsing key sets."); KeySets.resize(FragmentCounter); file << name << FRAGMENTPREFIX << KEYSETFILE; input.open(file.str().c_str(), ios::in); if (input.fail()) { LOG(0, endl << "KeySetsContainer::ParseKeySets: Unable to open " << file.str() << ", is the directory correct?"); return false; } AtomCounter.resize(FragmentCounter); for(int i=0;(i> KeySets[i][j]; //output << " " << KeySets[i][j]; } //LOG(0, output.str()); } input.close(); return true; }; /** Parse many body terms, associating each fragment to a certain bond order. * \return parsing succesful */ bool KeySetsContainer::ParseManyBodyTerms() { int Counter; LOG(0, "Creating Fragment terms."); // scan through all to determine maximum order Order=0; for(int i=FragmentCounter;i--;) { Counter=0; for(int j=AtomCounter[i];j--;) if (KeySets[i][j] != -1) Counter++; if (Counter > Order) Order = Counter; } LOG(0, "Found Order is " << Order << "."); // scan through all to determine fragments per order FragmentsPerOrder.resize(Order); // for(int i=Order;i--;) // FragmentsPerOrder[i] = 0; for(int i=FragmentCounter;i--;) { Counter=0; for(int j=AtomCounter[i];j--;) if (KeySets[i][j] != -1) Counter++; FragmentsPerOrder[Counter-1]++; } for(int i=0;i FragmentCounter) || (SmallerSet > FragmentCounter)) // index out of bounds return false; for(int i=AtomCounter[SmallerSet];i--;) { intermediate = false; for (int j=AtomCounter[GreaterSet];j--;) intermediate = (intermediate || ((KeySets[SmallerSet][i] == KeySets[GreaterSet][j]) || (KeySets[SmallerSet][i] == -1))); result = result && intermediate; } return result; }; /** Comparison operator for class KeySetsContainer. * * @param other instance to compare to * @return true - both instances are the same in each member variable. */ bool KeySetsContainer::operator==(const KeySetsContainer &other) const { // compare KeySets if (KeySets != other.KeySets) return false; // compare OrderSet if (OrderSet != other.OrderSet) return false; // compare AtomCounter if (AtomCounter != other.AtomCounter) return false; // compare FragmentCounter if (FragmentCounter != other.FragmentCounter) return false; // compare Order if (Order != other.Order) return false; // compare FragmentsPerOrder if (FragmentsPerOrder != other.FragmentsPerOrder) return false; return true; }