Changeset df2fca for src


Ignore:
Timestamp:
May 8, 2008, 3:25:00 PM (17 years ago)
Author:
Frederik Heber <heber@…>
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:
da5355
Parents:
d2a294
Message:

FragmentMolecule(): abstractized AssignKeySetsToFragments() and shifted some memory deallocation around

MoleculeLeafClass::AssignKeySetsToFragments() now does the splitting up of the keysets into FragmentList[] array
some memory dealloaction (ListOfLocalAtoms) was shifted up a bit, closer to where it's not needed anymore.
some comments changed and some more output included

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecules.cpp

    rd2a294 rdf2fca  
    10561056    return true;
    10571057  }
     1058};
     1059
     1060/** Outputs contents of molecule::ListOfBondsPerAtom.
     1061 * \param *out output stream
     1062 */
     1063void molecule::OutputListOfBonds(ofstream *out) const
     1064{
     1065  *out << Verbose(2) << endl << "From Contents of ListOfBondsPerAtom, all non-hydrogen atoms:" << endl;
     1066  atom *Walker = start;
     1067  while (Walker->next != end) {
     1068    Walker = Walker->next;
     1069#ifdef ADDHYDROGEN
     1070    if (Walker->type->Z != 1) {   // regard only non-hydrogen
     1071#endif
     1072      *out << Verbose(2) << "Atom " << Walker->Name << " has Bonds: "<<endl;
     1073      for(int j=0;j<NumberOfBondsPerAtom[Walker->nr];j++) {
     1074        *out << Verbose(3) << *(ListOfBondsPerAtom)[Walker->nr][j] << endl;
     1075      }
     1076#ifdef ADDHYDROGEN
     1077    }
     1078#endif
     1079  }
     1080  *out << endl;
    10581081};
    10591082
     
    19401963  }
    19411964
     1965  // free memory
    19421966  Free((void **)&filename, "molecule::ParseKeySetFile - filename");
    19431967
     
    21312155          FragmentationToDo = true;
    21322156    }
     2157    if (!FragmentationToDo)
     2158      *out << Verbose(1) << "Order at every site is already equal or above desired order " << Order << "." << endl;
    21332159  } else
    21342160    *out << Verbose(1) << "Parsing order at site file failed" << endl;
    2135 
    2136   if (!FragmentationToDo)
    2137     *out << Verbose(0) << "Order at every site is already equal or above desired order " << Order << "." << endl;
    21382161};
    21392162
     
    21692192  bool FragmentationToDo = true;
    21702193  Graph **FragmentList = NULL;
    2171   Graph *TempFragmentList = NULL;
     2194  Graph *ParsedFragmentList = NULL;
    21722195  Graph TotalGraph;     // graph with all keysets however local numbers
    2173   KeySet *TempSet = NULL;
    21742196  int TotalNumberOfKeySets = 0;
    2175   int KeySetCounter = 0;
    21762197  atom **ListOfAtoms = NULL;
    21772198  atom ***ListOfLocalAtoms = NULL;
     
    21992220
    22002221  // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs =====
    2201   Subgraphs = DepthFirstSearchAnalysis((ofstream *)&*out, false, MinimumRingSize);
    2202  
     2222  Subgraphs = DepthFirstSearchAnalysis(out, false, MinimumRingSize);
    22032223  // fill the bond structure of the individually stored subgraphs
    2204   FragmentationToDo = FragmentationToDo && Subgraphs->next->FillBondStructureFromReference(out, this, FragmentCounter, ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
     2224  Subgraphs->next->FillBondStructureFromReference(out, this, (FragmentCounter = 0), ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
    22052225
    22062226  // ===== 3. if structure still valid, parse key set file and others =====
    2207   TempFragmentList = new Graph;
    2208   FragmentationToDo = FragmentationToDo && ParseKeySetFile(out, configuration->configpath, TempFragmentList, configuration->GetIsAngstroem());
     2227  FragmentationToDo = FragmentationToDo && ParseKeySetFile(out, configuration->configpath, ParsedFragmentList, configuration->GetIsAngstroem());
    22092228
    22102229  // ===== 4. check globally whether there's something to do actually (first adaptivity check)
     
    22172236    *out << Verbose(0) << "Bond order " << Order << " greater than or equal to Minimum Ring size of " << MinimumRingSize << " found is not allowed." << endl;
    22182237  } else {
    2219     FragmentList = (Graph **) Malloc(sizeof(Graph *)*Subgraphs->next->Count(), "molecule::FragmentMolecule - **BondFragments");
    2220    
    22212238    // ===== 6a. fill RootStack for each subgraph (second adaptivity check) =====
    22222239    // NOTE: (keep this extern of following while loop, as lateron we may here look for which site to add to which subgraph)
     
    22262243
    22272244   // ===== 6b. assign each keyset to its respective subgraph =====
    2228     if ((TempFragmentList != NULL) && (TempFragmentList->size() != 0)) { // if there are some scanned keysets at all
    2229       // spread the keysets
    2230       FragmentCounter = 0;
    2231       MolecularWalker = Subgraphs;
    2232       while (MolecularWalker->next != NULL) {
    2233         MolecularWalker = MolecularWalker->next;
    2234         // assign scanned keysets
    2235         FragmentList[FragmentCounter] = new Graph;
    2236         TempSet = new KeySet;
    2237         KeySetCounter = 0;
    2238         for(Graph::iterator runner = TempFragmentList->begin();runner != TempFragmentList->end(); runner++) { // key sets contain global numbers!
    2239           if ( ListOfLocalAtoms[FragmentCounter][FindAtom(*((*runner).first.begin()))->nr]->nr != -1) {// as we may assume that that bond structure is unchanged, we only test the first key in each set
    2240             // translate keyset to local numbers
    2241             for(KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++)
    2242               TempSet->insert(ListOfLocalAtoms[FragmentCounter][FindAtom(*sprinter)->nr]->nr);
    2243             // insert into FragmentList
    2244             FragmentList[FragmentCounter]->insert(GraphPair (*TempSet, pair<int,double>(KeySetCounter++, (*runner).second.second)));
    2245           }
    2246           TempSet->clear();
    2247         }
    2248         delete(TempSet);
    2249         if (KeySetCounter == 0)
    2250           delete(FragmentList[FragmentCounter]);
    2251         else
    2252           *out << Verbose(1) << KeySetCounter << " keysets were assigned to subgraph " << FragmentCounter << "." << endl;
    2253         FragmentCounter++;
    2254       }
    2255     } else  // otherwise make sure all lists are initialised to NULL
    2256       for(int i=0;i<FragmentCounter;i++)
    2257         FragmentList[i] = NULL;
    2258    
     2245    Subgraphs->next->AssignKeySetsToFragment(out, this, ParsedFragmentList, ListOfLocalAtoms, FragmentList, (FragmentCounter = 0), false);
    22592246
    22602247   // ===== 7. fill the bond fragment list =====
    22612248    FragmentCounter = 0;
    2262     TotalNumberOfKeySets = 0;
    22632249    MolecularWalker = Subgraphs;
    22642250    while (MolecularWalker->next != NULL) {
    22652251      MolecularWalker = MolecularWalker->next;
    22662252      *out << Verbose(1) << "Fragmenting subgraph " << MolecularWalker << "." << endl;
     2253      // output ListOfBondsPerAtom for debugging
     2254      MolecularWalker->Leaf->OutputListOfBonds(out);
    22672255      if (MolecularWalker->Leaf->first->next != MolecularWalker->Leaf->last) {
    2268           // output ListOfBondsPerAtom for debugging
    2269         *out << Verbose(0) << endl << "From Contents of ListOfBondsPerAtom, all non-hydrogen atoms:" << endl;
    2270         Walker = MolecularWalker->Leaf->start;
    2271         while (Walker->next != MolecularWalker->Leaf->end) {
    2272           Walker = Walker->next;
    2273 #ifdef ADDHYDROGEN
    2274           if (Walker->type->Z != 1) {   // regard only non-hydrogen
    2275 #endif
    2276             *out << Verbose(0) << "Atom " << Walker->Name << " has Bonds: "<<endl;
    2277             for(int j=0;j<MolecularWalker->Leaf->NumberOfBondsPerAtom[Walker->nr];j++) {
    2278               *out << Verbose(1) << *(MolecularWalker->Leaf->ListOfBondsPerAtom)[Walker->nr][j] << endl;
    2279             }
    2280 #ifdef ADDHYDROGEN
    2281           }
    2282 #endif
    2283         }
    2284         *out << endl;
    22852256     
     2257        // call BOSSANOVA method
    22862258        *out << Verbose(0) << endl << " ========== BOND ENERGY of subgraph " << FragmentCounter << " ========================= " << endl;
    2287         *out << Verbose(0) << "Begin of bond fragmentation." << endl;
    2288        
    2289         // call BOSSANOVA method
    22902259        MolecularWalker->Leaf->FragmentBOSSANOVA(out, FragmentList[FragmentCounter], RootStack[FragmentCounter]);
    2291        
    22922260      } else {
    22932261        cerr << "Subgraph " << MolecularWalker << " has no atoms!" << endl;
     
    22962264    }
    22972265  }
     2266 
     2267  // free the index lookup list
     2268  for (int i=0;i<FragmentCounter;i++)
     2269    Free((void **)&ListOfLocalAtoms[i], "molecule::FragmentMolecule - *ListOfLocalAtoms[]");
     2270  Free((void **)&ListOfLocalAtoms, "molecule::FragmentMolecule - **ListOfLocalAtoms");
    22982271
    22992272  // ==================================== End of FRAGMENTATION ============================================
    23002273
    2301   // ===== 8a. translate list into global numbers (i.e. valid in "this" molecule, not in MolecularWalker->Leaf)
     2274  // ===== 8a. translate list into global numbers (i.e. ones that are valid in "this" molecule, not in MolecularWalker->Leaf)
    23022275  MolecularWalker = Subgraphs;
    23032276  FragmentCounter = 0;
     
    23162289  }
    23172290  Free((void **)&FragmentList, "molecule::FragmentMolecule - **FragmentList");
     2291  // free subgraph memory again
     2292  delete(ParsedFragmentList);
     2293  if (Subgraphs != NULL) {
     2294    while (Subgraphs->next != NULL) {
     2295      Subgraphs = Subgraphs->next;
     2296      delete(Subgraphs->previous);
     2297    }
     2298    delete(Subgraphs);
     2299  }
    23182300
    23192301  // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass =====
     
    23292311  *out << k << "/" << BondFragments->NumberOfMolecules << " fragments generated from the keysets." << endl;
    23302312 
    2331   // ===== 10. Save fragments' configuration and keyset files et al to disk ===
     2313  // ===== 9. Save fragments' configuration and keyset files et al to disk ===
    23322314  if (BondFragments->NumberOfMolecules != 0) {
    23332315    // create a SortIndex to map from BFS labels to the sequence in which the atoms are given in the config file
     
    23772359    *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl;
    23782360 
    2379   // free the index lookup list
    2380   for (int i=0;i<FragmentCounter;i++)
    2381     Free((void **)&ListOfLocalAtoms[i], "molecule::FragmentMolecule - *ListOfLocalAtoms[]");
    2382   Free((void **)&ListOfLocalAtoms, "molecule::FragmentMolecule - **ListOfLocalAtoms");
    2383   // free subgraph memory again
    2384   delete(TempFragmentList);
    2385   if (Subgraphs != NULL) {
    2386     while (Subgraphs->next != NULL) {
    2387       Subgraphs = Subgraphs->next;
    2388       delete(Subgraphs->previous);
    2389     }
    2390     delete(Subgraphs);
    2391   }
    2392 
    23932361  *out << Verbose(0) << "End of bond fragmentation." << endl;
    23942362};
Note: See TracChangeset for help on using the changeset viewer.