Changeset ca8bea for src/Fragmentation/Fragmentation.cpp
- Timestamp:
- Dec 3, 2012, 9:49:59 AM (12 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- dcbb5d
- Parents:
- de0af2
- git-author:
- Frederik Heber <heber@…> (09/20/12 12:37:12)
- git-committer:
- Frederik Heber <heber@…> (12/03/12 09:49:59)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/Fragmentation.cpp
rde0af2 rca8bea 57 57 #include "Graph/ListOfLocalAtoms.hpp" 58 58 #include "molecule.hpp" 59 #include "MoleculeLeafClass.hpp"60 #include "MoleculeListClass.hpp"61 #include "Parser/FormatParserStorage.hpp"62 59 #include "World.hpp" 63 60 … … 102 99 int Fragmentation::FragmentMolecule(const std::vector<atomId_t> &atomids, int Order, std::string prefix, DepthFirstSearchAnalysis &DFS) 103 100 { 104 MoleculeListClass *BondFragments = NULL;105 101 std::fstream File; 106 102 bool FragmentationToDo = true; 107 103 bool CheckOrder = false; 108 Graph TotalGraph; // graph with all keysets however local numbers109 104 int TotalNumberOfKeySets = 0; 110 105 AtomMask_t AtomMask(atomids); … … 166 161 TranslateIndicesToGlobalIDs(FragmentList, TotalNumberOfKeySets, TotalGraph); 167 162 168 // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass ===== 169 //if (FragmentationToDo) { // we should always store the fragments again as coordination might have changed slightly without changing bond structure 170 // allocate memory for the pointer array and transmorph graphs into full molecular fragments 171 BondFragments = new MoleculeListClass(World::getPointer()); 172 int k=0; 173 for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) { 174 KeySet test = (*runner).first; 175 LOG(0, "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "."); 176 BondFragments->insert(StoreFragmentFromKeySet(test, World::getInstance().getConfig())); 177 k++; 178 } 179 LOG(0, k << "/" << BondFragments->ListOfMolecules.size() << " fragments generated from the keysets."); 180 181 // ===== 9. Save fragments' configuration and keyset files et al to disk === 182 if (BondFragments->ListOfMolecules.size() != 0) { 183 // create the SortIndex from BFS labels to order in the config file 184 std::map<atomId_t, int> SortIndex; 185 CreateMappingLabelsToConfigSequence(SortIndex); 186 187 LOG(1, "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs"); 188 bool write_status = true; 189 for (std::vector<std::string>::const_iterator iter = typelist.begin(); 190 iter != typelist.end(); 191 ++iter) { 192 LOG(2, "INFO: Writing bond fragments for type " << (*iter) << "."); 193 write_status = write_status 194 && BondFragments->OutputConfigForListOfFragments( 195 prefix, 196 FormatParserStorage::getInstance().getTypeFromName(*iter)); 197 } 198 if (write_status) 199 LOG(1, "All configs written."); 200 else 201 LOG(1, "Some config writing failed."); 202 203 // store force index reference file 204 BondFragments->StoreForcesFile(prefix, SortIndex); 205 206 // store keysets file 207 TotalGraph.StoreKeySetFile(prefix); 208 209 { 210 // store Adjacency file 211 std::string filename = prefix + ADJACENCYFILE; 212 mol->StoreAdjacencyToFile(filename); 213 } 214 215 // store Hydrogen saturation correction file 216 BondFragments->AddHydrogenCorrection(prefix); 217 218 // store adaptive orders into file 219 StoreOrderAtSiteFile(prefix); 220 221 // restore orbital and Stop values 222 //CalculateOrbitals(*configuration); 223 } else { 224 LOG(1, "FragmentList is zero on return, splitting failed."); 225 } 226 // remove all create molecules again from the World including their atoms 227 for (MoleculeList::iterator iter = BondFragments->ListOfMolecules.begin(); 228 !BondFragments->ListOfMolecules.empty(); 229 iter = BondFragments->ListOfMolecules.begin()) { 230 // remove copied atoms and molecule again 231 molecule *mol = *iter; 232 mol->removeAtomsinMolecule(); 233 World::getInstance().destroyMolecule(mol); 234 BondFragments->ListOfMolecules.erase(iter); 235 } 236 delete(BondFragments); 163 LOG(1, "STATUS: We have created " << TotalGraph.size() << " fragments."); 164 165 // store adaptive orders into file 166 StoreOrderAtSiteFile(prefix); 167 237 168 LOG(0, "End of bond fragmentation."); 238 239 169 return ((int)(!FragmentationToDo)+1); // 1 - continue, 2 - stop (no fragmentation occured) 240 170 }; … … 361 291 }; 362 292 363 /** Stores a fragment from \a KeySet into \a molecule.364 * First creates the minimal set of atoms from the KeySet, then creates the bond structure from the complete365 * molecule and adds missing hydrogen where bonds were cut.366 * \param *out output stream for debugging messages367 * \param &Leaflet pointer to KeySet structure368 * \param IsAngstroem whether we have Ansgtroem or bohrradius369 * \return pointer to constructed molecule370 */371 molecule * Fragmentation::StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem)372 {373 Info info(__func__);374 ListOfLocalAtoms_t SonList;375 molecule *Leaf = World::getInstance().createMolecule();376 377 StoreFragmentFromKeySet_Init(mol, Leaf, Leaflet, SonList);378 // create the bonds between all: Make it an induced subgraph and add hydrogen379 // LOG(2, "Creating bonds from father graph (i.e. induced subgraph creation).");380 CreateInducedSubgraphOfFragment(mol, Leaf, SonList, IsAngstroem);381 382 //Leaflet->Leaf->ScanForPeriodicCorrection(out);383 return Leaf;384 };385 386 387 293 /** Estimates by educated guessing (using upper limit) the expected number of fragments. 388 294 * The upper limit is … … 556 462 }; 557 463 558 /** Create a SortIndex to map from atomic labels to the sequence in which the atoms are given in the config file.559 * \param &SortIndex Mapping array of size molecule::AtomCount560 * \return true - success, false - failure of SortIndex alloc561 */562 bool Fragmentation::CreateMappingLabelsToConfigSequence(std::map<atomId_t, int> &SortIndex)563 {564 if (!SortIndex.empty()) {565 LOG(1, "SortIndex has " << SortIndex.size() << " entries and is not empty as expected.");566 return false;567 }568 569 int AtomNo = 0;570 for(molecule::const_iterator iter=mol->begin();iter!=mol->end();++iter){571 const int id = (*iter)->getNr();572 #ifndef NDEBUG573 std::pair<std::map<atomId_t, int>::const_iterator, bool> inserter =574 #endif575 SortIndex.insert( std::make_pair(id, AtomNo++) );576 ASSERT( inserter.second ,577 "Fragmentation::CreateMappingLabelsToConfigSequence() - same SortIndex set twice.");578 }579 580 return true;581 };582 583 584 /** Initializes some value for putting fragment of \a *mol into \a *Leaf.585 * \param *mol total molecule586 * \param *Leaf fragment molecule587 * \param &Leaflet pointer to KeySet structure588 * \param SonList calloc'd list which atom of \a *Leaf is a son of which atom in \a *mol589 * \return number of atoms in fragment590 */591 int Fragmentation::StoreFragmentFromKeySet_Init(molecule *mol, molecule *Leaf, KeySet &Leaflet, ListOfLocalAtoms_t &SonList)592 {593 atom *FatherOfRunner = NULL;594 595 // first create the minimal set of atoms from the KeySet596 int size = 0;597 for(KeySet::iterator runner = Leaflet.begin(); runner != Leaflet.end(); runner++) {598 FatherOfRunner = mol->FindAtom((*runner)); // find the id599 SonList.insert( std::make_pair(FatherOfRunner->getNr(), Leaf->AddCopyAtom(FatherOfRunner) ) );600 size++;601 }602 return size;603 };604 605 606 /** Creates an induced subgraph out of a fragmental key set, adding bonds and hydrogens (if treated specially).607 * \param *out output stream for debugging messages608 * \param *mol total molecule609 * \param *Leaf fragment molecule610 * \param IsAngstroem whether we have Ansgtroem or bohrradius611 * \param SonList list which atom of \a *Leaf is a son of which atom in \a *mol612 */613 void Fragmentation::CreateInducedSubgraphOfFragment(molecule *mol, molecule *Leaf, ListOfLocalAtoms_t &SonList, bool IsAngstroem)614 {615 bool LonelyFlag = false;616 atom *OtherFather = NULL;617 atom *FatherOfRunner = NULL;618 619 // we increment the iter just before skipping the hydrogen620 // as we use AddBond, we cannot have a const_iterator here621 for (molecule::iterator iter = Leaf->begin(); iter != Leaf->end();) {622 LonelyFlag = true;623 FatherOfRunner = (*iter)->father;624 ASSERT(FatherOfRunner,"Atom without father found");625 if (SonList.find(FatherOfRunner->getNr()) != SonList.end()) { // check if this, our father, is present in list626 // create all bonds627 const BondList& ListOfBonds = FatherOfRunner->getListOfBonds();628 for (BondList::const_iterator BondRunner = ListOfBonds.begin();629 BondRunner != ListOfBonds.end();630 ++BondRunner) {631 OtherFather = (*BondRunner)->GetOtherAtom(FatherOfRunner);632 if (SonList.find(OtherFather->getNr()) != SonList.end()) {633 // LOG(2, "INFO: Father " << *FatherOfRunner << " of son " << *SonList[FatherOfRunner->getNr()]634 // << " is bound to " << *OtherFather << ", whose son is "635 // << *SonList[OtherFather->getNr()] << ".");636 if (OtherFather->getNr() > FatherOfRunner->getNr()) { // add bond (Nr check is for adding only one of both variants: ab, ba)637 std::stringstream output;638 // output << "ACCEPT: Adding Bond: "639 output << Leaf->AddBond((*iter), SonList[OtherFather->getNr()], (*BondRunner)->BondDegree);640 // LOG(3, output.str());641 //NumBonds[(*iter)->getNr()]++;642 } else {643 // LOG(3, "REJECY: Not adding bond, labels in wrong order.");644 }645 LonelyFlag = false;646 } else {647 // LOG(2, "INFO: Father " << *FatherOfRunner << " of son " << *SonList[FatherOfRunner->getNr()]648 // << " is bound to " << *OtherFather << ", who has no son in this fragment molecule.");649 if (saturation == DoSaturate) {650 // LOG(3, "ACCEPT: Adding Hydrogen to " << (*iter)->Name << " and a bond in between.");651 if (!Leaf->AddHydrogenReplacementAtom((*BondRunner), (*iter), FatherOfRunner, OtherFather, IsAngstroem))652 exit(1);653 }654 //NumBonds[(*iter)->getNr()] += Binder->BondDegree;655 }656 }657 } else {658 ELOG(1, "Son " << (*iter)->getName() << " has father " << FatherOfRunner->getName() << " but its entry in SonList is " << SonList[FatherOfRunner->getNr()] << "!");659 }660 if ((LonelyFlag) && (Leaf->getAtomCount() > 1)) {661 LOG(0, **iter << "has got bonds only to hydrogens!");662 }663 ++iter;664 if (saturation == DoSaturate) {665 while ((iter != Leaf->end()) && ((*iter)->getType()->getAtomicNumber() == 1)){ // skip added hydrogen666 iter++;667 }668 }669 }670 };671 672 /** Sets the desired output types of the fragment configurations.673 *674 * @param types vector of desired types.675 */676 void Fragmentation::setOutputTypes(const std::vector<std::string> &types)677 {678 typelist = types;679 }680 681 464 /** Fills the root stack for sites to be used as root in fragmentation depending on order or adaptivity criteria 682 465 * Again, as in \sa FillBondStructureFromReference steps recursively through each Leaf in this chain list of molecule's.
Note:
See TracChangeset
for help on using the changeset viewer.