- Timestamp:
- Oct 12, 2009, 1:05:46 PM (16 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:
- 407536
- Parents:
- d2943b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecule_fragmentation.cpp
rd2943b r14e73a 1156 1156 }; 1157 1157 1158 1159 1160 /** Creates a list of all unique fragments of certain vertex size from a given graph \a Fragment for a given root vertex in the context of \a this molecule. 1161 * -# initialises UniqueFragments structure 1162 * -# fills edge list via BFS 1163 * -# creates the fragment by calling recursive function SPFragmentGenerator with UniqueFragments structure, 0 as 1164 root distance, the edge set, its dimension and the current suborder 1165 * -# Free'ing structure 1166 * Note that we may use the fact that the atoms are SP-ordered on the atomstack. I.e. when popping always the last, we first get all 1167 * with SP of 2, then those with SP of 3, then those with SP of 4 and so on. 1168 * \param *out output stream for debugging 1158 /** Initializes FragmenSearch. 1159 * Sets UniqueFragments::ShortestPathList entries to zero, UniqueFragments::BondsPerSPCount to zero (except zero level to 1) and 1160 * adds initial bond UniqueFragments::Root to UniqueFragments::Root to UniqueFragments::BondsPerSPList 1161 * \param *out output stream 1169 1162 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation 1170 * \param FragmentSearch UniqueFragments structure containing TEFactor, root atom and so on 1171 * \param RestrictedKeySet Restricted vertex set to use in context of molecule 1172 * \return number of inserted fragments 1173 * \note ShortestPathList in FragmentSearch structure is probably due to NumberOfAtomsSPLevel and SP not needed anymore 1174 */ 1175 int molecule::PowerSetGenerator(ofstream *out, int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet) 1176 { 1177 int SP, AtomKeyNr; 1178 atom *Walker = NULL, *OtherWalker = NULL, *Predecessor = NULL; 1179 bond *Binder = NULL; 1180 bond *CurrentEdge = NULL; 1181 bond **BondsList = NULL; 1182 int RootKeyNr = FragmentSearch.Root->GetTrueFather()->nr; 1183 int Counter = FragmentSearch.FragmentCounter; 1184 int RemainingWalkers; 1185 1186 *out << endl; 1187 *out << Verbose(0) << "Begin of PowerSetGenerator with order " << Order << " at Root " << *FragmentSearch.Root << "." << endl; 1188 1163 * \param FragmentSearch UniqueFragments 1164 * \sa FreeSPList() 1165 */ 1166 void InitialiseSPList(ofstream *out, int Order, struct UniqueFragments &FragmentSearch) 1167 { 1189 1168 // prepare Label and SP arrays of the BFS search 1190 1169 FragmentSearch.ShortestPathList[FragmentSearch.Root->nr] = 0; … … 1194 1173 FragmentSearch.BondsPerSPCount[i] = 0; 1195 1174 FragmentSearch.BondsPerSPCount[0] = 1; 1196 Binder = new bond(FragmentSearch.Root, FragmentSearch.Root);1175 bond *Binder = new bond(FragmentSearch.Root, FragmentSearch.Root); 1197 1176 add(Binder, FragmentSearch.BondsPerSPList[1]); 1198 1199 // do a BFS search to fill the SP lists and label the found vertices 1177 }; 1178 1179 /** Resets UniqueFragments::ShortestPathList and cleans bonds from UniqueFragments::BondsPerSPList. 1180 * \param *out output stream 1181 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation 1182 * \param FragmentSearch UniqueFragments 1183 * \sa InitialiseSPList() 1184 */ 1185 void FreeSPList(ofstream *out, int Order, struct UniqueFragments &FragmentSearch) 1186 { 1187 bond *Binder = NULL; 1188 *out << Verbose(0) << "Free'ing all found lists. and resetting index lists" << endl; 1189 for(int i=Order;i--;) { 1190 *out << Verbose(1) << "Current SP level is " << i << ": "; 1191 Binder = FragmentSearch.BondsPerSPList[2*i]; 1192 while (Binder->next != FragmentSearch.BondsPerSPList[2*i+1]) { 1193 Binder = Binder->next; 1194 // *out << "Removing atom " << Binder->leftatom->nr << " and " << Binder->rightatom->nr << "." << endl; // make sure numbers are local 1195 FragmentSearch.ShortestPathList[Binder->leftatom->nr] = -1; 1196 FragmentSearch.ShortestPathList[Binder->rightatom->nr] = -1; 1197 } 1198 // delete added bonds 1199 cleanup(FragmentSearch.BondsPerSPList[2*i], FragmentSearch.BondsPerSPList[2*i+1]); 1200 // also start and end node 1201 *out << "cleaned." << endl; 1202 } 1203 }; 1204 1205 1206 /** Fills the Bonds per Shortest Path List and set the vertex labels. 1207 * \param *out output stream 1208 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation 1209 * \param FragmentSearch UniqueFragments 1210 * \param *mol molecule with atoms and bonds 1211 * \param RestrictedKeySet Restricted vertex set to use in context of molecule 1212 */ 1213 void FillSPListandLabelVertices(ofstream *out, int Order, struct UniqueFragments &FragmentSearch, molecule *mol, KeySet RestrictedKeySet) 1214 { 1200 1215 // Actually, we should construct a spanning tree vom the root atom and select all edges therefrom and put them into 1201 1216 // according shortest path lists. However, we don't. Rather we fill these lists right away, as they do form a spanning … … 1204 1219 // In another picture, the bonds always contain a direction by rightatom being the one more distant from root and hence 1205 1220 // naturally leftatom forming its predecessor, preventing the BFS"seeker" from continuing in the wrong direction. 1206 *out << endl; 1221 int AtomKeyNr = -1; 1222 atom *Walker = NULL; 1223 atom *OtherWalker = NULL; 1224 atom *Predecessor = NULL; 1225 bond *Binder = NULL; 1226 bond *CurrentEdge = NULL; 1227 int RootKeyNr = FragmentSearch.Root->GetTrueFather()->nr; 1228 int RemainingWalkers = -1; 1229 int SP = -1; 1230 1207 1231 *out << Verbose(0) << "Starting BFS analysis ..." << endl; 1208 1232 for (SP = 0; SP < (Order-1); SP++) { … … 1226 1250 // go through all its bonds 1227 1251 *out << Verbose(1) << "Going through all bonds of Walker." << endl; 1228 for (int i=0;i< NumberOfBondsPerAtom[AtomKeyNr];i++) {1229 Binder = ListOfBondsPerAtom[AtomKeyNr][i];1252 for (int i=0;i<mol->NumberOfBondsPerAtom[AtomKeyNr];i++) { 1253 Binder = mol->ListOfBondsPerAtom[AtomKeyNr][i]; 1230 1254 OtherWalker = Binder->GetOtherAtom(Walker); 1231 1255 if ((RestrictedKeySet.find(OtherWalker->nr) != RestrictedKeySet.end()) … … 1254 1278 } 1255 1279 } 1256 1257 // outputting all list for debugging 1280 }; 1281 1282 /** prints the Bonds per Shortest Path list in UniqueFragments. 1283 * \param *out output stream 1284 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation 1285 * \param FragmentSearch UniqueFragments 1286 */ 1287 void OutputSPList(ofstream *out, int Order, struct UniqueFragments &FragmentSearch) 1288 { 1289 bond *Binder = NULL; 1258 1290 *out << Verbose(0) << "Printing all found lists." << endl; 1259 1291 for(int i=1;i<Order;i++) { // skip the root edge in the printing … … 1265 1297 } 1266 1298 } 1267 1268 // creating fragments with the found edge sets (may be done in reverse order, faster) 1269 SP = -1; // the Root <-> Root edge must be subtracted! 1299 }; 1300 1301 /** Simply counts all bonds in all UniqueFragments::BondsPerSPList lists. 1302 * \param *out output stream 1303 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation 1304 * \param FragmentSearch UniqueFragments 1305 */ 1306 int CountNumbersInBondsList(ofstream *out, int Order, struct UniqueFragments &FragmentSearch) 1307 { 1308 bond *Binder = NULL; 1309 int SP = -1; // the Root <-> Root edge must be subtracted! 1270 1310 for(int i=Order;i--;) { // sum up all found edges 1271 1311 Binder = FragmentSearch.BondsPerSPList[2*i]; … … 1275 1315 } 1276 1316 } 1317 return SP; 1318 }; 1319 1320 /** Creates a list of all unique fragments of certain vertex size from a given graph \a Fragment for a given root vertex in the context of \a this molecule. 1321 * -# initialises UniqueFragments structure 1322 * -# fills edge list via BFS 1323 * -# creates the fragment by calling recursive function SPFragmentGenerator with UniqueFragments structure, 0 as 1324 root distance, the edge set, its dimension and the current suborder 1325 * -# Free'ing structure 1326 * Note that we may use the fact that the atoms are SP-ordered on the atomstack. I.e. when popping always the last, we first get all 1327 * with SP of 2, then those with SP of 3, then those with SP of 4 and so on. 1328 * \param *out output stream for debugging 1329 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation 1330 * \param FragmentSearch UniqueFragments structure containing TEFactor, root atom and so on 1331 * \param RestrictedKeySet Restricted vertex set to use in context of molecule 1332 * \return number of inserted fragments 1333 * \note ShortestPathList in FragmentSearch structure is probably due to NumberOfAtomsSPLevel and SP not needed anymore 1334 */ 1335 int molecule::PowerSetGenerator(ofstream *out, int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet) 1336 { 1337 bond **BondsList = NULL; 1338 int Counter = FragmentSearch.FragmentCounter; // mark current value of counter 1339 1340 *out << endl; 1341 *out << Verbose(0) << "Begin of PowerSetGenerator with order " << Order << " at Root " << *FragmentSearch.Root << "." << endl; 1342 1343 InitialiseSPList(out, Order, FragmentSearch); 1344 1345 // do a BFS search to fill the SP lists and label the found vertices 1346 FillSPListandLabelVertices(out, Order, FragmentSearch, this, RestrictedKeySet); 1347 1348 // outputting all list for debugging 1349 OutputSPList(out, Order, FragmentSearch); 1350 1351 // creating fragments with the found edge sets (may be done in reverse order, faster) 1352 int SP = CountNumbersInBondsList(out, Order, FragmentSearch); 1277 1353 *out << Verbose(0) << "Total number of edges is " << SP << "." << endl; 1278 1354 if (SP >= (Order-1)) { … … 1281 1357 FragmentSearch.FragmentSet->clear(); 1282 1358 *out << Verbose(0) << "Preparing subset for this root and calling generator." << endl; 1359 1283 1360 // prepare the subset and call the generator 1284 1361 BondsList = Malloc<bond*>(FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList"); … … 1298 1375 1299 1376 // free'ing the bonds lists 1300 *out << Verbose(0) << "Free'ing all found lists. and resetting index lists" << endl; 1301 for(int i=Order;i--;) { 1302 *out << Verbose(1) << "Current SP level is " << i << ": "; 1303 Binder = FragmentSearch.BondsPerSPList[2*i]; 1304 while (Binder->next != FragmentSearch.BondsPerSPList[2*i+1]) { 1305 Binder = Binder->next; 1306 // *out << "Removing atom " << Binder->leftatom->nr << " and " << Binder->rightatom->nr << "." << endl; // make sure numbers are local 1307 FragmentSearch.ShortestPathList[Binder->leftatom->nr] = -1; 1308 FragmentSearch.ShortestPathList[Binder->rightatom->nr] = -1; 1309 } 1310 // delete added bonds 1311 cleanup(FragmentSearch.BondsPerSPList[2*i], FragmentSearch.BondsPerSPList[2*i+1]); 1312 // also start and end node 1313 *out << "cleaned." << endl; 1314 } 1377 FreeSPList(out, Order, FragmentSearch); 1315 1378 1316 1379 // return list
Note:
See TracChangeset
for help on using the changeset viewer.