Changeset ca8bea for src/Fragmentation
- 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)
- Location:
- src/Fragmentation
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/Exporters/ExportGraph.cpp
rde0af2 rca8bea 42 42 */ 43 43 ExportGraph::ExportGraph(const Graph &_graph) : 44 TotalGraph( graph)44 TotalGraph(_graph) 45 45 { 46 46 47 47 } 48 49 /** Destructor for class ExportGraph. 50 * 51 */ 52 ExportGraph::~ExportGraph() 53 {} -
src/Fragmentation/Exporters/ExportGraph.hpp
rde0af2 rca8bea 18 18 /** ExportGraph is an interface definition of a class that takes a fragmented 19 19 * system contained in an instance of Graph and exports it to some place else. 20 * 21 * Guidelines are as follows: 22 * - all derived classes should have their specific properties set by extra 23 * setters and not by passing them through the cstor 24 * - operator() is called without arguments. 20 25 */ 21 26 class ExportGraph … … 23 28 public: 24 29 ExportGraph(const Graph &_graph); 25 ~ExportGraph();30 virtual ~ExportGraph(); 26 31 27 32 virtual void operator()()=0; 28 33 29 pr ivate:34 protected: 30 35 const Graph &TotalGraph; 31 36 }; -
src/Fragmentation/Exporters/ExportGraph_ToFiles.cpp
rde0af2 rca8bea 37 37 #include "ExportGraph_ToFiles.hpp" 38 38 39 #include "CodePatterns/Info.hpp" 39 40 #include "CodePatterns/Log.hpp" 41 42 #include "Bond/bond.hpp" 43 #include "Element/element.hpp" 40 44 #include "Fragmentation/Graph.hpp" 41 45 #include "Fragmentation/KeySet.hpp" 46 #include "Graph/ListOfLocalAtoms.hpp" 47 #include "molecule.hpp" 42 48 #include "MoleculeListClass.hpp" 49 #include "Parser/FormatParserStorage.hpp" 43 50 #include "World.hpp" 44 51 … … 46 53 * 47 54 * @param _graph instance of Graph containing keyset of each fragment 48 */ 49 ExportGraph_ToFiles::ExportGraph_ToFiles(const Graph &_graph) : 50 ExportGraph(_graph) 55 * @param _mol molecule as reference 56 */ 57 ExportGraph_ToFiles::ExportGraph_ToFiles(const Graph &_graph, molecule *&_mol, const enum HydrogenSaturation _saturation) : 58 ExportGraph(_graph), 59 mol(_mol), 60 BondFragments(World::getPointer()), 61 saturation(_saturation) 51 62 {} 52 63 64 /** Destructor of class ExportGraph_ToFiles. 65 * 66 * We free all created molecules again and also removed their copied atoms. 67 */ 68 ExportGraph_ToFiles::~ExportGraph_ToFiles() 69 { 70 // remove all create molecules again from the World including their atoms 71 for (MoleculeList::iterator iter = BondFragments.ListOfMolecules.begin(); 72 !BondFragments.ListOfMolecules.empty(); 73 iter = BondFragments.ListOfMolecules.begin()) { 74 // remove copied atoms and molecule again 75 molecule *mol = *iter; 76 mol->removeAtomsinMolecule(); 77 World::getInstance().destroyMolecule(mol); 78 BondFragments.ListOfMolecules.erase(iter); 79 } 80 } 81 53 82 /** Actual implementation of the export to files function. 54 * 55 */ 56 void ExportGraph_ToFiles::operator ()() 57 { 83 */ 84 void ExportGraph_ToFiles::operator()() 85 { 86 if (BondFragments.ListOfMolecules.size() == 0) 87 prepareMolecule(); 88 89 // ===== 9. Save fragments' configuration and keyset files et al to disk === 90 // create the SortIndex from BFS labels to order in the config file 91 std::map<atomId_t, int> SortIndex; 92 CreateMappingLabelsToConfigSequence(SortIndex); 93 94 LOG(1, "Writing " << BondFragments.ListOfMolecules.size() << " possible bond fragmentation configs"); 95 bool write_status = true; 96 for (std::vector<std::string>::const_iterator iter = typelist.begin(); 97 iter != typelist.end(); 98 ++iter) { 99 LOG(2, "INFO: Writing bond fragments for type " << (*iter) << "."); 100 write_status = write_status 101 && BondFragments.OutputConfigForListOfFragments( 102 prefix, 103 FormatParserStorage::getInstance().getTypeFromName(*iter)); 104 } 105 if (write_status) 106 LOG(1, "All configs written."); 107 else 108 LOG(1, "Some config writing failed."); 109 110 // store force index reference file 111 BondFragments.StoreForcesFile(prefix, SortIndex); 112 113 // store keysets file 114 TotalGraph.StoreKeySetFile(prefix); 115 116 { 117 // store Adjacency file 118 std::string filename = prefix + ADJACENCYFILE; 119 mol->StoreAdjacencyToFile(filename); 120 } 121 122 // store Hydrogen saturation correction file 123 BondFragments.AddHydrogenCorrection(prefix); 124 125 // restore orbital and Stop values 126 //CalculateOrbitals(*configuration); 58 127 } 59 128 … … 63 132 void ExportGraph_ToFiles::prepareMolecule() 64 133 { 65 // allocate memory for the pointer array and transmorph graphs into full molecular fragments66 MoleculeListClass *BondFragments = new MoleculeListClass(World::getPointer());67 134 size_t count = 0; 68 for(Graph:: iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {135 for(Graph::const_iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) { 69 136 KeySet test = (*runner).first; 70 137 LOG(2, "DEBUG: Fragment No." << (*runner).second.first << " with TEFactor " 71 138 << (*runner).second.second << "."); 72 BondFragments ->insert(StoreFragmentFromKeySet(test, World::getInstance().getConfig()));139 BondFragments.insert(StoreFragmentFromKeySet(mol, test, World::getInstance().getConfig())); 73 140 ++count; 74 141 } 75 LOG(1, "INFO: " << count << "/" << BondFragments ->ListOfMolecules.size()142 LOG(1, "INFO: " << count << "/" << BondFragments.ListOfMolecules.size() 76 143 << " fragments generated from the keysets."); 77 144 } 145 146 /** Stores a fragment from \a KeySet into \a molecule. 147 * First creates the minimal set of atoms from the KeySet, then creates the bond structure from the complete 148 * molecule and adds missing hydrogen where bonds were cut. 149 * \param *mol reference molecule 150 * \param &Leaflet pointer to KeySet structure 151 * \param IsAngstroem whether we have Ansgtroem or bohrradius 152 * \return pointer to constructed molecule 153 */ 154 molecule * ExportGraph_ToFiles::StoreFragmentFromKeySet(molecule *mol, KeySet &Leaflet, bool IsAngstroem) 155 { 156 Info info(__func__); 157 ListOfLocalAtoms_t SonList; 158 molecule *Leaf = World::getInstance().createMolecule(); 159 160 StoreFragmentFromKeySet_Init(mol, Leaf, Leaflet, SonList); 161 // create the bonds between all: Make it an induced subgraph and add hydrogen 162 // LOG(2, "Creating bonds from father graph (i.e. induced subgraph creation)."); 163 CreateInducedSubgraphOfFragment(mol, Leaf, SonList, IsAngstroem); 164 165 //Leaflet->Leaf->ScanForPeriodicCorrection(out); 166 return Leaf; 167 } 168 169 /** Initializes some value for putting fragment of \a *mol into \a *Leaf. 170 * \param *mol total molecule 171 * \param *Leaf fragment molecule 172 * \param &Leaflet pointer to KeySet structure 173 * \param SonList calloc'd list which atom of \a *Leaf is a son of which atom in \a *mol 174 * \return number of atoms in fragment 175 */ 176 int ExportGraph_ToFiles::StoreFragmentFromKeySet_Init(molecule *mol, molecule *Leaf, KeySet &Leaflet, ListOfLocalAtoms_t &SonList) 177 { 178 atom *FatherOfRunner = NULL; 179 180 // first create the minimal set of atoms from the KeySet 181 int size = 0; 182 for(KeySet::const_iterator runner = Leaflet.begin(); runner != Leaflet.end(); runner++) { 183 FatherOfRunner = mol->FindAtom((*runner)); // find the id 184 SonList.insert( std::make_pair(FatherOfRunner->getNr(), Leaf->AddCopyAtom(FatherOfRunner) ) ); 185 size++; 186 } 187 return size; 188 } 189 190 /** Creates an induced subgraph out of a fragmental key set, adding bonds and hydrogens (if treated specially). 191 * \param *out output stream for debugging messages 192 * \param *mol total molecule 193 * \param *Leaf fragment molecule 194 * \param IsAngstroem whether we have Ansgtroem or bohrradius 195 * \param SonList list which atom of \a *Leaf is a son of which atom in \a *mol 196 */ 197 void ExportGraph_ToFiles::CreateInducedSubgraphOfFragment(molecule *mol, molecule *Leaf, ListOfLocalAtoms_t &SonList, bool IsAngstroem) 198 { 199 bool LonelyFlag = false; 200 atom *OtherFather = NULL; 201 atom *FatherOfRunner = NULL; 202 203 // we increment the iter just before skipping the hydrogen 204 // as we use AddBond, we cannot have a const_iterator here 205 for (molecule::iterator iter = Leaf->begin(); iter != Leaf->end();) { 206 LonelyFlag = true; 207 FatherOfRunner = (*iter)->father; 208 ASSERT(FatherOfRunner,"Atom without father found"); 209 if (SonList.find(FatherOfRunner->getNr()) != SonList.end()) { // check if this, our father, is present in list 210 // create all bonds 211 const BondList& ListOfBonds = FatherOfRunner->getListOfBonds(); 212 for (BondList::const_iterator BondRunner = ListOfBonds.begin(); 213 BondRunner != ListOfBonds.end(); 214 ++BondRunner) { 215 OtherFather = (*BondRunner)->GetOtherAtom(FatherOfRunner); 216 if (SonList.find(OtherFather->getNr()) != SonList.end()) { 217 // LOG(2, "INFO: Father " << *FatherOfRunner << " of son " << *SonList[FatherOfRunner->getNr()] 218 // << " is bound to " << *OtherFather << ", whose son is " 219 // << *SonList[OtherFather->getNr()] << "."); 220 if (OtherFather->getNr() > FatherOfRunner->getNr()) { // add bond (Nr check is for adding only one of both variants: ab, ba) 221 std::stringstream output; 222 // output << "ACCEPT: Adding Bond: " 223 output << Leaf->AddBond((*iter), SonList[OtherFather->getNr()], (*BondRunner)->BondDegree); 224 // LOG(3, output.str()); 225 //NumBonds[(*iter)->getNr()]++; 226 } else { 227 // LOG(3, "REJECY: Not adding bond, labels in wrong order."); 228 } 229 LonelyFlag = false; 230 } else { 231 // LOG(2, "INFO: Father " << *FatherOfRunner << " of son " << *SonList[FatherOfRunner->getNr()] 232 // << " is bound to " << *OtherFather << ", who has no son in this fragment molecule."); 233 if (saturation == DoSaturate) { 234 // LOG(3, "ACCEPT: Adding Hydrogen to " << (*iter)->Name << " and a bond in between."); 235 if (!Leaf->AddHydrogenReplacementAtom((*BondRunner), (*iter), FatherOfRunner, OtherFather, IsAngstroem)) 236 exit(1); 237 } 238 //NumBonds[(*iter)->getNr()] += Binder->BondDegree; 239 } 240 } 241 } else { 242 ELOG(1, "Son " << (*iter)->getName() << " has father " << FatherOfRunner->getName() << " but its entry in SonList is " << SonList[FatherOfRunner->getNr()] << "!"); 243 } 244 if ((LonelyFlag) && (Leaf->getAtomCount() > 1)) { 245 LOG(0, **iter << "has got bonds only to hydrogens!"); 246 } 247 ++iter; 248 if (saturation == DoSaturate) { 249 while ((iter != Leaf->end()) && ((*iter)->getType()->getAtomicNumber() == 1)){ // skip added hydrogen 250 iter++; 251 } 252 } 253 } 254 } 255 256 /** Create a SortIndex to map from atomic labels to the sequence in which the atoms are given in the config file. 257 * \param &SortIndex Mapping array of size molecule::AtomCount 258 * \return true - success, false - failure of SortIndex alloc 259 */ 260 bool ExportGraph_ToFiles::CreateMappingLabelsToConfigSequence(std::map<atomId_t, int> &SortIndex) 261 { 262 if (!SortIndex.empty()) { 263 LOG(1, "SortIndex has " << SortIndex.size() << " entries and is not empty as expected."); 264 return false; 265 } 266 267 int AtomNo = 0; 268 for(molecule::const_iterator iter=mol->begin();iter!=mol->end();++iter){ 269 const int id = (*iter)->getNr(); 270 #ifndef NDEBUG 271 std::pair<std::map<atomId_t, int>::const_iterator, bool> inserter = 272 #endif 273 SortIndex.insert( std::make_pair(id, AtomNo++) ); 274 ASSERT( inserter.second , 275 "ExportGraph_ToFiles::CreateMappingLabelsToConfigSequence() - same SortIndex set twice."); 276 } 277 278 return true; 279 } 280 -
src/Fragmentation/Exporters/ExportGraph_ToFiles.hpp
rde0af2 rca8bea 14 14 #endif 15 15 16 #include <string> 17 #include <vector> 18 19 #include "Fragmentation/HydrogenSaturation_enum.hpp" 16 20 #include "Fragmentation/Exporters/ExportGraph.hpp" 21 #include "MoleculeListClass.hpp" 22 23 class ListOfLocalAtoms_t; 17 24 18 25 /** ExportGraph_ToFiles implements an ExportGraph as storing all fragmentary … … 22 29 { 23 30 public: 24 ExportGraph_ToFiles(); 31 ExportGraph_ToFiles(const Graph &_graph, molecule *&_mol, const enum HydrogenSaturation _saturation); 32 virtual ~ExportGraph_ToFiles(); 25 33 26 34 void operator()(); 35 36 void setPrefix(const std::string &_prefix) { 37 prefix = _prefix; 38 } 39 40 void setOutputTypes(const std::vector<std::string> &_typelist) { 41 typelist = _typelist; 42 } 43 44 private: 45 46 void prepareMolecule(); 47 molecule * StoreFragmentFromKeySet(molecule *mol, KeySet &Leaflet, bool IsAngstroem); 48 int StoreFragmentFromKeySet_Init(molecule *mol, molecule *Leaf, KeySet &Leaflet, ListOfLocalAtoms_t &SonList); 49 void CreateInducedSubgraphOfFragment(molecule *mol, molecule *Leaf, ListOfLocalAtoms_t &SonList, bool IsAngstroem); 50 bool CreateMappingLabelsToConfigSequence(std::map<atomId_t, int> &SortIndex); 51 52 53 private: 54 //!> molecule as reference 55 molecule *mol; 56 //!> internal list of created molecules 57 MoleculeListClass BondFragments; 58 //!> prefix for fragment files 59 std::string prefix; 60 //!> list of parser types for which a configuration file per fragment is stored 61 std::vector<std::string> typelist; 62 //!> whether to saturate dangling bonds or not 63 const enum HydrogenSaturation saturation; 27 64 }; 28 65 -
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. -
src/Fragmentation/Fragmentation.hpp
rde0af2 rca8bea 16 16 #include "Graph/DepthFirstSearchAnalysis.hpp" 17 17 18 #include "Fragmentation/fragmentation_helpers.hpp" 19 #include "Fragmentation/Graph.hpp" 18 20 #include "Fragmentation/HydrogenSaturation_enum.hpp" 19 #include "Fragmentation/fragmentation_helpers.hpp"20 21 #include "types.hpp" 21 22 … … 27 28 class AtomMask_t; 28 29 class CheckAgainstAdjacencyFile; 29 class Graph;30 30 class KeySet; 31 31 class molecule; … … 39 39 int FragmentMolecule(const std::vector<atomId_t> &atomids, int Order, std::string prefix, DepthFirstSearchAnalysis &DFS); 40 40 41 void setOutputTypes(const std::vector<std::string> &types); 41 const Graph& getGraph() const { 42 return TotalGraph; 43 } 42 44 43 45 private: … … 45 47 void FragmentBOSSANOVA(molecule *mol, Graph &FragmentList, KeyStack &RootStack); 46 48 int GuesstimateFragmentCount(int order); 47 48 bool CreateMappingLabelsToConfigSequence(std::map<atomId_t, int> &SortIndex);49 49 50 50 // order at site … … 54 54 55 55 // storing fragments 56 molecule * StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem);57 int StoreFragmentFromKeySet_Init(molecule *mol, molecule *Leaf, KeySet &Leaflet, ListOfLocalAtoms_t &SonList);58 void CreateInducedSubgraphOfFragment(molecule *mol, molecule *Leaf, ListOfLocalAtoms_t &SonList, bool IsAngstroem);59 56 void FillRootStackForSubgraphs(KeyStack &RootStack, const AtomMask_t &AtomMask); 60 57 bool AssignKeySetsToFragment(Graph &KeySetList, ListOfLocalAtoms_t &ListOfLocalAtoms, Graph &FragmentList, bool FreeList = false); … … 66 63 //!> whether to saturate dangling bonds with hydrogen and hence treat hydrogen special 67 64 const enum HydrogenSaturation saturation; 68 //!> list of parser types for which a configuration file per fragment is stored69 std::vector<std::string> typelist;70 65 //!> reference to an external adjacency for comparison 71 66 CheckAgainstAdjacencyFile &FileChecker; 67 //!> Resulting Graph with all keysets 68 Graph TotalGraph; 72 69 }; 73 70 -
src/Fragmentation/Graph.cpp
rde0af2 rca8bea 132 132 * \return true - file written successfully, false - writing failed 133 133 */ 134 bool Graph::StoreKeySetFile(std::string &path) 134 bool Graph::StoreKeySetFile(std::string &path) const 135 135 { 136 136 bool status = true; … … 141 141 LOG(1, "INFO: Saving key sets of the total graph ... "); 142 142 if(output.good()) { 143 for(Graph:: iterator runner = begin(); runner != end(); runner++) {144 for (KeySet:: iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++) {143 for(Graph::const_iterator runner = begin(); runner != end(); runner++) { 144 for (KeySet::const_iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++) { 145 145 if (sprinter != (*runner).first.begin()) 146 146 output << "\t"; … … 210 210 * \return true - file written successfully, false - writing failed 211 211 */ 212 bool Graph::StoreTEFactorsFile(char *path) 212 bool Graph::StoreTEFactorsFile(char *path) const 213 213 { 214 214 ofstream output; … … 224 224 LOG(1, "INFO: Saving TEFactors of the total graph ... "); 225 225 if(output != NULL) { 226 for(Graph:: iterator runner = begin(); runner != end(); runner++)226 for(Graph::const_iterator runner = begin(); runner != end(); runner++) 227 227 output << (*runner).second.second << endl; 228 228 LOG(1, "INFO: done." << endl); -
src/Fragmentation/Graph.hpp
rde0af2 rca8bea 33 33 34 34 bool ParseKeySetFile(std::string &path); 35 bool StoreKeySetFile(std::string &path) ;35 bool StoreKeySetFile(std::string &path) const; 36 36 bool ParseTEFactorsFile(char *path); 37 bool StoreTEFactorsFile(char *path) ;37 bool StoreTEFactorsFile(char *path) const; 38 38 39 39 AdaptivityMap * GraphToAdaptivityMap() const; -
src/Fragmentation/Makefile.am
rde0af2 rca8bea 3 3 4 4 FRAGMENTATIONSOURCE = \ 5 Fragmentation/Exporters/ExportGraph_ToFiles.cpp \ 6 Fragmentation/Exporters/ExportGraph.cpp \ 5 7 Fragmentation/AdaptivityMap.cpp \ 6 8 Fragmentation/BondsPerShortestPath.cpp \ … … 19 21 20 22 FRAGMENTATIONHEADER = \ 23 Fragmentation/Exporters/ExportGraph_ToFiles.hpp \ 24 Fragmentation/Exporters/ExportGraph.hpp \ 21 25 Fragmentation/AdaptivityMap.hpp \ 22 26 Fragmentation/AtomMask.hpp \
Note:
See TracChangeset
for help on using the changeset viewer.