Ignore:
Timestamp:
Nov 3, 2009, 12:37:55 PM (16 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, Candidate_v1.7.0, 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:
2aeefd
Parents:
fa649a
git-author:
Frederik Heber <heber@…> (11/03/09 08:41:45)
git-committer:
Frederik Heber <heber@…> (11/03/09 12:37:55)
Message:

Several memory bugfixes (thx valgrind).

Fixed Calloc:

Signed-off-by: Frederik Heber <heber@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule_fragmentation.cpp

    rfa649a r7218f8  
    123123  }
    124124
     125  Free(&filename);
    125126  return status;
    126127};
     
    574575  // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs =====
    575576  Subgraphs = DepthFirstSearchAnalysis(out, BackEdgeStack);
    576   // fill the bond structure of the individually stored subgraphs
    577   Subgraphs->next->FillBondStructureFromReference(out, this, (FragmentCounter = 0), ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
     577
    578578  // analysis of the cycles (print rings, get minimum cycle length) for each subgraph
    579579  for(int i=AtomCount;i--;)
     
    583583  while (MolecularWalker->next != NULL) {
    584584    MolecularWalker = MolecularWalker->next;
     585    // fill the bond structure of the individually stored subgraphs
     586  MolecularWalker->FillBondStructureFromReference(out, this, FragmentCounter, ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
    585587    *out << Verbose(0) << "Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl;
    586588    LocalBackEdgeStack = new StackClass<bond *> (MolecularWalker->Leaf->BondCount);
     
    599601    delete(LocalBackEdgeStack);
    600602  }
     603  delete(BackEdgeStack);
    601604
    602605  // ===== 3. if structure still valid, parse key set file and others =====
     
    663666  // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass =====
    664667  //if (FragmentationToDo) {    // we should always store the fragments again as coordination might have changed slightly without changing bond structure
    665     // allocate memory for the pointer array and transmorph graphs into full molecular fragments
    666     BondFragments = new MoleculeListClass();
    667     int k=0;
    668     for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
    669       KeySet test = (*runner).first;
    670       *out << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl;
    671       BondFragments->insert(StoreFragmentFromKeySet(out, test, configuration));
    672       k++;
    673     }
    674     *out << k << "/" << BondFragments->ListOfMolecules.size() << " fragments generated from the keysets." << endl;
    675 
    676     // ===== 9. Save fragments' configuration and keyset files et al to disk ===
    677     if (BondFragments->ListOfMolecules.size() != 0) {
    678       // create the SortIndex from BFS labels to order in the config file
    679       CreateMappingLabelsToConfigSequence(out, SortIndex);
    680 
    681       *out << Verbose(1) << "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs" << endl;
    682       if (BondFragments->OutputConfigForListOfFragments(out, configuration, SortIndex))
    683         *out << Verbose(1) << "All configs written." << endl;
    684       else
    685         *out << Verbose(1) << "Some config writing failed." << endl;
    686 
    687       // store force index reference file
    688       BondFragments->StoreForcesFile(out, configuration->configpath, SortIndex);
    689 
    690       // store keysets file
    691       StoreKeySetFile(out, TotalGraph, configuration->configpath);
    692 
    693       // store Adjacency file
    694       StoreAdjacencyToFile(out, configuration->configpath);
    695 
    696       // store Hydrogen saturation correction file
    697       BondFragments->AddHydrogenCorrection(out, configuration->configpath);
    698 
    699       // store adaptive orders into file
    700       StoreOrderAtSiteFile(out, configuration->configpath);
    701 
    702       // restore orbital and Stop values
    703       CalculateOrbitals(*configuration);
    704 
    705       // free memory for bond part
    706       *out << Verbose(1) << "Freeing bond memory" << endl;
    707       delete(FragmentList); // remove bond molecule from memory
    708       Free(&SortIndex);
    709     } else
    710       *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl;
    711   //} else
    712   //  *out << Verbose(1) << "No fragments to store." << endl;
     668  // allocate memory for the pointer array and transmorph graphs into full molecular fragments
     669  BondFragments = new MoleculeListClass();
     670  int k=0;
     671  for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
     672    KeySet test = (*runner).first;
     673    *out << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl;
     674    BondFragments->insert(StoreFragmentFromKeySet(out, test, configuration));
     675    k++;
     676  }
     677  *out << k << "/" << BondFragments->ListOfMolecules.size() << " fragments generated from the keysets." << endl;
     678
     679  // ===== 9. Save fragments' configuration and keyset files et al to disk ===
     680  if (BondFragments->ListOfMolecules.size() != 0) {
     681    // create the SortIndex from BFS labels to order in the config file
     682    CreateMappingLabelsToConfigSequence(out, SortIndex);
     683
     684    *out << Verbose(1) << "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs" << endl;
     685    if (BondFragments->OutputConfigForListOfFragments(out, configuration, SortIndex))
     686      *out << Verbose(1) << "All configs written." << endl;
     687    else
     688      *out << Verbose(1) << "Some config writing failed." << endl;
     689
     690    // store force index reference file
     691    BondFragments->StoreForcesFile(out, configuration->configpath, SortIndex);
     692
     693    // store keysets file
     694    StoreKeySetFile(out, TotalGraph, configuration->configpath);
     695
     696    // store Adjacency file
     697    StoreAdjacencyToFile(out, configuration->configpath);
     698
     699    // store Hydrogen saturation correction file
     700    BondFragments->AddHydrogenCorrection(out, configuration->configpath);
     701
     702    // store adaptive orders into file
     703    StoreOrderAtSiteFile(out, configuration->configpath);
     704
     705    // restore orbital and Stop values
     706    CalculateOrbitals(*configuration);
     707
     708    // free memory for bond part
     709    *out << Verbose(1) << "Freeing bond memory" << endl;
     710    delete(FragmentList); // remove bond molecule from memory
     711    Free(&SortIndex);
     712  } else {
     713    *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl;
     714  }
     715  delete(BondFragments);
    713716  *out << Verbose(0) << "End of bond fragmentation." << endl;
    714717
     
    751754bool molecule::ParseOrderAtSiteFromFile(ofstream *out, char *path)
    752755{
    753   unsigned char *OrderArray = Malloc<unsigned char>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
    754   bool *MaxArray = Malloc<bool>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
     756  unsigned char *OrderArray = Calloc<unsigned char>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
     757  bool *MaxArray = Calloc<bool>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
    755758  bool status;
    756759  int AtomNr, value;
     
    759762
    760763  *out << Verbose(1) << "Begin of ParseOrderAtSiteFromFile" << endl;
    761   for(int i=AtomCount;i--;)
    762     OrderArray[i] = 0;
    763764  line << path << "/" << FRAGMENTPREFIX << ORDERATSITEFILE;
    764765  file.open(line.str().c_str());
    765766  if (file != NULL) {
    766     for (int i=AtomCount;i--;) { // initialise with 0
    767       OrderArray[i] = 0;
    768       MaxArray[i] = 0;
    769     }
    770767    while (!file.eof()) { // parse from file
    771768      AtomNr = -1;
     
    830827 * \param *Leaf fragment molecule
    831828 * \param &Leaflet pointer to KeySet structure
    832  * \param **SonList list which atom of \a *Leaf is a son of which atom in \a *mol
     829 * \param **SonList calloc'd list which atom of \a *Leaf is a son of which atom in \a *mol
    833830 * \return number of atoms in fragment
    834831 */
     
    840837  for(int i=NDIM*2;i--;)
    841838    Leaf->cell_size[i] = mol->cell_size[i];
    842 
    843   // initialise SonList (indicates when we need to replace a bond with hydrogen instead)
    844   for(int i=mol->AtomCount;i--;)
    845     SonList[i] = NULL;
    846839
    847840  // first create the minimal set of atoms from the KeySet
     
    924917molecule * molecule::StoreFragmentFromKeySet(ofstream *out, KeySet &Leaflet, bool IsAngstroem)
    925918{
    926   atom **SonList = Malloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");
     919  atom **SonList = Calloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");
    927920  molecule *Leaf = new molecule(elemente);
    928921
     
    13891382
    13901383    // prepare the subset and call the generator
    1391     BondsList = Malloc<bond*>(FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");
     1384    BondsList = Calloc<bond*>(FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");
    13921385    BondsList[0] = FragmentSearch.BondsPerSPList[0]->next;  // on SP level 0 there's only the root bond
    13931386
     
    15441537  // FragmentLowerOrdersList is a 2D-array of pointer to MoleculeListClass objects, one dimension represents the ANOVA expansion of a single order (i.e. 5)
    15451538  // with all needed lower orders that are subtracted, the other dimension is the BondOrder (i.e. from 1 to 5)
    1546   NumMoleculesOfOrder = Malloc<int>(UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
    1547   FragmentLowerOrdersList = Malloc<Graph**>(UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
     1539  NumMoleculesOfOrder = Calloc<int>(UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
     1540  FragmentLowerOrdersList = Calloc<Graph**>(UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
    15481541
    15491542  // initialise the fragments structure
    1550   FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
    15511543  FragmentSearch.FragmentCounter = 0;
    15521544  FragmentSearch.FragmentSet = new KeySet;
    15531545  FragmentSearch.Root = FindAtom(RootKeyNr);
     1546  FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
    15541547  for (int i=AtomCount;i--;) {
    15551548    FragmentSearch.ShortestPathList[i] = -1;
     
    15871580      // allocate memory for all lower level orders in this 1D-array of ptrs
    15881581      NumLevels = 1 << (Order-1); // (int)pow(2,Order);
    1589       FragmentLowerOrdersList[RootNr] = Malloc<Graph*>(NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
    1590       for (int i=0;i<NumLevels;i++)
    1591         FragmentLowerOrdersList[RootNr][i] = NULL;
     1582      FragmentLowerOrdersList[RootNr] = Calloc<Graph*>(NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
    15921583
    15931584      // create top order where nothing is reduced
     
    16651656  *out << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl;
    16661657
    1667   ColorList = Malloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
     1658  ColorList = Calloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
    16681659  while (flag) {
    16691660    // remove bonds that are beyond bonddistance
Note: See TracChangeset for help on using the changeset viewer.