Ignore:
Timestamp:
May 8, 2008, 3:22:41 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:
df2fca
Parents:
fc1309
Message:

new function FillListOfLocalAtoms() checks whether List needs filling or is already present, Count() const

Count() is now Count() const
new function FillListOfLocalAtoms() checks for NULL pointers and if found fills the list by calling CreateFatherLookupTable()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/moleculelist.cpp

    rfc1309 rd2a294  
    364364  int AtomNo;
    365365
    366   if (ListOfLocalAtoms == NULL) { // allocated initial pointer
    367     // count the number of fragments
    368     MoleculeLeafClass *MolecularWalker = this;
    369     while (MolecularWalker->next != NULL) {
    370       MolecularWalker = MolecularWalker->next;
    371       FragmentCounter++;
    372     }
    373     // allocate and set each field to NULL
    374     ListOfLocalAtoms = (atom ***) Malloc(sizeof(atom **)*(FragmentCounter+1), "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");
    375     if (ListOfLocalAtoms == NULL)
    376       return false;
    377     for (int i=0;i<=FragmentCounter;i++)
    378       ListOfLocalAtoms[i] = NULL;
    379     FragmentCounter = 0;
    380     FreeList = FreeList && true;
    381   }
    382   if (ListOfLocalAtoms[FragmentCounter] == NULL) { // allocate and fill list of this fragment/subgraph
    383     status = status && CreateFatherLookupTable(out, Leaf->start, Leaf->end, ListOfLocalAtoms[FragmentCounter], reference->AtomCount);
    384     FreeList = FreeList && true;
     366  // fill ListOfLocalAtoms if NULL was given
     367  if (!FillListOfLocalAtoms(out, ListOfLocalAtoms, FragmentCounter, reference->AtomCount, FreeList)) {
     368    *out << Verbose(1) << "Filling of ListOfLocalAtoms failed." << endl;
     369    return false;
    385370  }
    386371 
     
    449434        if (next != NULL)
    450435          next->FillRootStackForSubgraphs(out, RootStack, Order, ++FragmentCounter);
    451       } else
     436      }  else {
     437        *out << Verbose(1) << "Rootstack[" << FragmentCounter  << "] is NULL." << endl;
    452438        return false;
    453     }
     439      }
     440    }
     441    FragmentCounter--;
    454442    return true;
     443  } else {
     444    *out << Verbose(1) << "Rootstack is NULL." << endl;
     445    return false;
     446  }
     447};
     448
     449/** Fills a lookup list of father's Atom::nr -> atom for each subgraph.
     450 * \param *out output stream fro debugging
     451 * \param ***ListOfLocalAtoms Lookup table for each subgraph and index of each atom in global molecule, may be NULL on start, then it is filled
     452 * \param &FragmentCounter counts the fragments as we move along the list
     453 * \param GlobalAtomCount number of atoms in the complete molecule
     454 * \param &FreeList true - ***ListOfLocalAtoms is free'd before return, false - it is not
     455 * \return true - succes, false - failure
     456 */
     457bool MoleculeLeafClass::FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, int &FragmentCounter, int GlobalAtomCount, bool &FreeList)
     458{
     459  bool status = true;
     460 
     461  int Counter = Count();
     462  if (ListOfLocalAtoms == NULL) { // allocated initial pointer
     463    // allocate and set each field to NULL
     464    ListOfLocalAtoms = (atom ***) Malloc(sizeof(atom **)*Counter, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");
     465    if (ListOfLocalAtoms != NULL) {
     466      for (int i=0;i<Counter;i++)
     467        ListOfLocalAtoms[i] = NULL;
     468      FreeList = FreeList && true;
     469    } else
     470      status = false;
     471  }
     472 
     473  if ((ListOfLocalAtoms != NULL) && (ListOfLocalAtoms[FragmentCounter] == NULL)) { // allocate and fill list of this fragment/subgraph
     474    status = status && CreateFatherLookupTable(out, Leaf->start, Leaf->end, ListOfLocalAtoms[FragmentCounter], GlobalAtomCount);
     475    FreeList = FreeList && true;
     476  }
     477 
     478  return status;
     479};
     480
     481/** The indices per keyset are compared to the respective father's Atom::nr in each subgraph and thus put into \a **&FragmentList.
     482 * \param *out output stream fro debugging
     483 * \param *reference reference molecule with the bond structure to be copied
     484 * \param *KeySetList list with all keysets
     485 * \param ***ListOfLocalAtoms Lookup table for each subgraph and index of each atom in global molecule, may be NULL on start, then it is filled
     486 * \param **&FragmentList list to be allocated and returned
     487 * \param &FragmentCounter counts the fragments as we move along the list
     488 * \param FreeList true - ***ListOfLocalAtoms is free'd before return, false - it is not
     489 * \retuen true - success, false - failure
     490 */
     491bool MoleculeLeafClass::AssignKeySetsToFragment(ofstream *out, molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList)
     492{
     493  bool status = true;
     494  int KeySetCounter = 0;
     495 
     496  // fill ListOfLocalAtoms if NULL was given
     497  if (!FillListOfLocalAtoms(out, ListOfLocalAtoms, FragmentCounter, reference->AtomCount, FreeList)) {
     498    *out << Verbose(1) << "Filling of ListOfLocalAtoms failed." << endl;
     499    return false;
     500  }
     501
     502  // allocate fragment list
     503  if (FragmentList == NULL) {
     504    KeySetCounter = Count();
     505    FragmentList = (Graph **) Malloc(sizeof(Graph *)*KeySetCounter, "molecule::FragmentMolecule - **BondFragments");
     506    for(int i=0;i<KeySetCounter;i++)
     507      FragmentList[i] = NULL;
     508    KeySetCounter = 0;
     509  }
     510 
     511  if ((KeySetList != NULL) && (KeySetList->size() != 0)) { // if there are some scanned keysets at all
     512    // assign scanned keysets
     513    if (FragmentList[FragmentCounter] == NULL)
     514      FragmentList[FragmentCounter] = new Graph;
     515    KeySet *TempSet = new KeySet;
     516    for(Graph::iterator runner = KeySetList->begin();runner != KeySetList->end(); runner++) { // key sets contain global numbers!
     517      if ( ListOfLocalAtoms[FragmentCounter][reference->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
     518        // translate keyset to local numbers
     519        for(KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++)
     520          TempSet->insert(ListOfLocalAtoms[FragmentCounter][reference->FindAtom(*sprinter)->nr]->nr);
     521        // insert into FragmentList
     522        FragmentList[FragmentCounter]->insert(GraphPair (*TempSet, pair<int,double>(KeySetCounter++, (*runner).second.second)));
     523      }
     524      TempSet->clear();
     525    }
     526    delete(TempSet);
     527    if (KeySetCounter == 0) {// if there are no keysets, delete the list
     528      *out << Verbose(1) << "KeySetCounter is zero, deleting FragmentList." << endl;
     529      delete(FragmentList[FragmentCounter]);
     530    } else
     531      *out << Verbose(1) << KeySetCounter << " keysets were assigned to subgraph " << FragmentCounter << "." << endl;
     532    FragmentCounter++;
     533    if (next != NULL)
     534      next->AssignKeySetsToFragment(out, reference, KeySetList, ListOfLocalAtoms, FragmentList, FragmentCounter, FreeList);
     535    FragmentCounter--;
    455536  } else
    456     return false;
     537    *out << Verbose(1) << "KeySetList is NULL or empty." << endl;
     538 
     539  return status;
    457540};
    458541
     
    460543 * \return number of items
    461544 */
    462 int MoleculeLeafClass::Count()
     545int MoleculeLeafClass::Count() const
    463546{
    464547  if (next != NULL)
Note: See TracChangeset for help on using the changeset viewer.