/** \file MoleculeListClass.cpp * * Function implementations for the class MoleculeListClass. * */ #include "molecules.hpp" /*********************************** Functions for class MoleculeListClass *************************/ /** Constructor for MoleculeListClass. */ MoleculeListClass::MoleculeListClass() { }; /** constructor for MoleculeListClass. * \param NumMolecules number of molecules to allocate for * \param NumAtoms number of atoms to allocate for */ MoleculeListClass::MoleculeListClass(int NumMolecules, int NumAtoms) { ListOfMolecules = (molecule **) Malloc(sizeof(molecule *)*NumMolecules, "MoleculeListClass:MoleculeListClass: **ListOfMolecules"); for (int i=0;i (**(molecule **)b).AtomCount) return +1; else { Count = (**(molecule **)a).AtomCount; aList = (int *) Malloc(sizeof(int)*Count, "MolCompare: *aList"); bList = (int *) Malloc(sizeof(int)*Count, "MolCompare: *bList"); // fill the lists aWalker = (**(molecule **)a).start; bWalker = (**(molecule **)b).start; Counter = 0; aCounter = 0; bCounter = 0; while ((aWalker->next != (**(molecule **)a).end) && (bWalker->next != (**(molecule **)b).end)) { aWalker = aWalker->next; bWalker = bWalker->next; if (aWalker->GetTrueFather() == NULL) aList[Counter] = Count + (aCounter++); else aList[Counter] = aWalker->GetTrueFather()->nr; if (bWalker->GetTrueFather() == NULL) bList[Counter] = Count + (bCounter++); else bList[Counter] = bWalker->GetTrueFather()->nr; Counter++; } // check if AtomCount was for real flag = 0; if ((aWalker->next == (**(molecule **)a).end) && (bWalker->next != (**(molecule **)b).end)) { flag = -1; } else { if ((aWalker->next != (**(molecule **)a).end) && (bWalker->next == (**(molecule **)b).end)) flag = 1; } if (flag == 0) { // sort the lists gsl_heapsort(aList,Count, sizeof(int), CompareDoubles); gsl_heapsort(bList,Count, sizeof(int), CompareDoubles); // compare the lists flag = 0; for(int i=0;i bList[i]) flag = 1; } if (flag != 0) break; } } Free((void **)&aList, "MolCompare: *aList"); Free((void **)&bList, "MolCompare: *bList"); return flag; } } return -1; }; /** Simple output of the pointers in ListOfMolecules. * \param *out output stream */ void MoleculeListClass::Output(ofstream *out) { *out<< Verbose(1) << "MoleculeList: "; for (int i=0;iGetDefaultPath()); // correct periodic ListOfMolecules[i]->ScanForPeriodicCorrection(out); // output xyz file FragmentNumber = FixedDigitNumber(NumberOfMolecules, FragmentCounter++); sprintf(FragmentName, "%s/%s%s.conf.xyz", configuration->configpath, FRAGMENTPREFIX, FragmentNumber); outputFragment.open(FragmentName, ios::out); *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << " as XYZ ..."; if (intermediateResult = ListOfMolecules[i]->OutputXYZ(&outputFragment)) *out << " done." << endl; else *out << " failed." << endl; result = result && intermediateResult; outputFragment.close(); outputFragment.clear(); *out << Verbose(2) << "Contained atoms: "; Walker = ListOfMolecules[i]->start; while (Walker->next != ListOfMolecules[i]->end) { Walker = Walker->next; *out << Walker->Name << " "; } *out << endl; // prepare output of config file sprintf(FragmentName, "%s/%s%s.conf", configuration->configpath, FRAGMENTPREFIX, FragmentNumber); outputFragment.open(FragmentName, ios::out); strcpy(PathBackup, configuration->configpath); sprintf(FragmentName, "%s/%s%s/", configuration->configpath, FRAGMENTPREFIX, FragmentNumber); // center on edge ListOfMolecules[i]->CenterEdge(out, &BoxDimension); ListOfMolecules[i]->SetBoxDimension(&BoxDimension); // update Box of atoms by boundary int j = -1; for (int k=0;k<3;k++) { j += k+1; BoxDimension.x[k] = 5.; ListOfMolecules[i]->cell_size[j] += BoxDimension.x[k]*2.; } ListOfMolecules[i]->Translate(&BoxDimension); // also calculate necessary orbitals ListOfMolecules[i]->CountElements(); // this is a bugfix, atoms should should actually be added correctly to this fragment ListOfMolecules[i]->CalculateOrbitals(*configuration); // change path in config configuration->SetDefaultPath(FragmentName); *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << " as config ..."; if (intermediateResult = configuration->Save(&outputFragment, ListOfMolecules[i]->elemente, ListOfMolecules[i])) *out << " done." << endl; else *out << " failed." << endl; // restore old config configuration->SetDefaultPath(PathBackup); result = result && intermediateResult; outputFragment.close(); outputFragment.clear(); Free((void **)&FragmentNumber, "MoleculeListClass::OutputConfigForListOfFragments: *FragmentNumber"); } // open KeySet file sprintf(FragmentName, "%s/%s%s", configuration->configpath, FRAGMENTPREFIX , KEYSETFILE); output.open(FragmentName, ios::out); *out << Verbose(2) << "Saving " << FRAGMENTPREFIX << " key sets of each subgraph ..."; for(int j=0;jstart; while(Walker->next != ListOfMolecules[j]->end) { Walker = Walker->next; #ifdef ADDHYDROGEN if ((Walker->GetTrueFather() != NULL) && (Walker->type->Z != 1)) // if there is a real father, prints its index #else if ((Walker->GetTrueFather() != NULL)) // if there is a real father, prints its index #endif output << Walker->GetTrueFather()->nr << "\t"; #ifdef ADDHYDROGEN else // otherwise a -1 to indicate an added saturation hydrogen output << "-1\t"; #endif } output << endl; } output.close(); *out << " done." << endl; // printing final number *out << "Final number of fragments: " << FragmentCounter << "." << endl; return result; }; /******************************************* Class MoleculeLeafClass ************************************************/ /** Constructor for MoleculeLeafClass root leaf. * \param *Up Leaf on upper level * \param *PreviousLeaf NULL - We are the first leaf on this level, otherwise points to previous in list */ //MoleculeLeafClass::MoleculeLeafClass(MoleculeLeafClass *Up = NULL, MoleculeLeafClass *Previous = NULL) MoleculeLeafClass::MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf = NULL) { // if (Up != NULL) // if (Up->DownLeaf == NULL) // are we the first down leaf for the upper leaf? // Up->DownLeaf = this; // UpLeaf = Up; // DownLeaf = NULL; Leaf = NULL; previous = PreviousLeaf; if (previous != NULL) { MoleculeLeafClass *Walker = previous->next; previous->next = this; next = Walker; } else { next = NULL; } }; /** Destructor for MoleculeLeafClass. */ MoleculeLeafClass::~MoleculeLeafClass() { // if (DownLeaf != NULL) {// drop leaves further down // MoleculeLeafClass *Walker = DownLeaf; // MoleculeLeafClass *Next; // do { // Next = Walker->NextLeaf; // delete(Walker); // Walker = Next; // } while (Walker != NULL); // // Last Walker sets DownLeaf automatically to NULL // } // remove the leaf itself if (Leaf != NULL) { delete(Leaf); Leaf = NULL; } // remove this Leaf from level list if (previous != NULL) previous->next = next; // } else { // we are first in list (connects to UpLeaf->DownLeaf) // if ((NextLeaf != NULL) && (NextLeaf->UpLeaf == NULL)) // NextLeaf->UpLeaf = UpLeaf; // either null as we are top level or the upleaf of the first node // if (UpLeaf != NULL) // UpLeaf->DownLeaf = NextLeaf; // either null as we are only leaf or NextLeaf if we are just the first // } // UpLeaf = NULL; if (next != NULL) // are we last in list next->previous = previous; next = NULL; previous = NULL; }; /** Adds \a molecule leaf to the tree. * \param *ptr ptr to molecule to be added * \param *Previous previous MoleculeLeafClass referencing level and which on the level * \return true - success, false - something went wrong */ bool MoleculeLeafClass::AddLeaf(molecule *ptr, MoleculeLeafClass *Previous) { return false; };