Changeset 9fcf47 for src


Ignore:
Timestamp:
May 8, 2008, 12:04:42 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:
386aa2
Parents:
c82f3d
Message:

new function molecule::CheckOrderAtSite and molecule::FragmentMolecule() abstractized

molecule::CheckOrderAtSite() just checks a given order against atom:AdaptiveOrder and whether there's still something to do for the fragmentation.
MoleculeLeafClass::FillBondStructureFromReference, CreateFatherLookupTable, along with the molecule::CheckOrderAtSite are used to make the structure of molecule::FragmentMolecule clearer

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/molecules.cpp

    rc82f3d r9fcf47  
    21112111};
    21122112
     2113/** Checks whether the OrderAtSite is still bewloe \a Order at some site.
     2114 * \param *out output stream for debugging
     2115 * \param &FragmentationToDo return boolean
     2116 * \param Order desired Order
     2117 */
     2118void molecule::CheckOrderAtSite(ofstream *out, bool &FragmentationToDo, int Order)
     2119{
     2120  atom *Walker = NULL;
     2121 
     2122  if (FragmentationToDo) { // check whether OrderAtSite is above Order everywhere
     2123    FragmentationToDo = false;
     2124    Walker = start;
     2125    while (Walker->next != end) {
     2126      Walker = Walker->next;
     2127#ifdef ADDHYDROGEN
     2128      if (Walker->type->Z != 1) // skip hydrogen
     2129#endif
     2130        if (Walker->AdaptiveOrder < Order)
     2131          FragmentationToDo = true;
     2132    }
     2133  } else
     2134    *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;
     2138};
     2139
    21132140/** Performs a many-body bond order analysis for a given bond order.
    21142141 * -# parses adjacency, keysets and orderatsite files
     
    21322159        MoleculeListClass *BondFragments = NULL;
    21332160  atom *Walker = NULL;
    2134   atom *OtherWalker = NULL;
    2135   bond *Binder = NULL;
    21362161  int *SortIndex = NULL;
    21372162  element *runner = NULL;
     
    21492174  int TotalNumberOfKeySets = 0;
    21502175  int KeySetCounter = 0;
     2176  atom **ListOfAtoms = NULL;
    21512177  atom ***ListOfLocalAtoms = NULL;
    21522178 
     
    21582184#endif
    21592185
     2186  // ++++++++++++++++++++++++++++ INITIAL STUFF: Bond structure analysis, ... ++++++++++++++++++++++++++++++++++++++++++
     2187 
    21602188  // ===== 1. Check whether bond structure is same as stored in files ====
    21612189 
     
    21642192
    21652193  // create lookup table for Atom::nr
    2166   atom **ListOfAtoms = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::FragmentMolecule - **ListOfAtoms");
    2167   Walker = start;
    2168   while (Walker->next != end) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron
    2169     Walker = Walker->next;
    2170     if ((Walker->nr >= 0) && (Walker->nr < AtomCount)) {
    2171       ListOfAtoms[Walker->nr] = Walker;
    2172     } else
    2173       break;
    2174   }
    2175   if (Walker->next != end) {  // everything went alright
    2176     *out << " range of nuclear ids exceeded [0, AtomCount)." << endl;
    2177     FragmentationToDo = false;
    2178   }
     2194  FragmentationToDo = FragmentationToDo && CreateFatherLookupTable(out, start, end, ListOfAtoms, AtomCount);
     2195 
    21792196  // === compare it with adjacency file ===
    21802197  FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(out, configuration->configpath, ListOfAtoms);
     
    21842201  Subgraphs = DepthFirstSearchAnalysis((ofstream *)&*out, false, MinimumRingSize);
    21852202 
    2186   // fill index lookup list for each subgraph from global nr to local pointer
    2187   ListOfLocalAtoms = (atom ***) Malloc(sizeof(atom **)*FragmentCounter, "molecule::FragmentMolecule - **ListOfLocalAtoms");
    2188   for (int i=0;i<FragmentCounter;i++) {
    2189     ListOfLocalAtoms[i] = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::FragmentMolecule - *ListOfLocalAtoms[]");
    2190     for(int j=0;j<AtomCount;j++)
    2191       ListOfLocalAtoms[i][j] = NULL;
    2192   }
    2193   FragmentCounter = 0;
    2194   MolecularWalker = Subgraphs;
    2195   while (MolecularWalker->next != NULL) {
    2196     MolecularWalker = MolecularWalker->next;
    2197     Walker = MolecularWalker->Leaf->start;
    2198     while (Walker->next != MolecularWalker->Leaf->end) {
    2199       Walker = Walker->next;
    2200 #ifdef ADDHYDROGEN
    2201       if (Walker->type->Z != 1) // skip hydrogen
    2202 #endif
    2203         ListOfLocalAtoms[FragmentCounter][Walker->GetTrueFather()->nr] = Walker;  // set present global id index to the local pointer
    2204     }
    2205     FragmentCounter++;
    2206   }
    2207 
    22082203  // fill the bond structure of the individually stored subgraphs
    2209   FragmentCounter = 0;
    2210   MolecularWalker = Subgraphs;
    2211   while (MolecularWalker->next != NULL) {
    2212     MolecularWalker = MolecularWalker->next;
    2213     *out << Verbose(1) << "Creating adjacency list for subgraph " << MolecularWalker << "." << endl;
    2214     Walker = MolecularWalker->Leaf->start;
    2215     while (Walker->next != MolecularWalker->Leaf->end) {
    2216       Walker = Walker->next;
    2217       AtomNo = Walker->father->nr;  // global id of the current walker
    2218       for(int i=0;i<NumberOfBondsPerAtom[AtomNo];i++) { // go through father's bonds and copy them all
    2219         Binder = ListOfBondsPerAtom[AtomNo][i];
    2220         OtherWalker = ListOfLocalAtoms[FragmentCounter][Binder->GetOtherAtom(Walker->father)->nr];    // local copy of current bond partner of walker
    2221         if ((OtherWalker != NULL) && (OtherWalker->nr > Walker->nr))
    2222           MolecularWalker->Leaf->AddBond(Walker, OtherWalker, Binder->BondDegree);
    2223       }
    2224     }
    2225     //MolecularWalker->Leaf->CreateAdjacencyList(out, BondDistance);
    2226     MolecularWalker->Leaf->CreateListOfBondsPerAtom(out);
    2227     FragmentCounter++;
    2228   }
     2204  FragmentationToDo = FragmentationToDo && Subgraphs->next->FillBondStructureFromReference(out, this, FragmentCounter, ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
    22292205
    22302206  // ===== 3. if structure still valid, parse key set file and others =====
    2231   if (FragmentationToDo) {
    2232     // parse key sets into new graph
    2233     TempFragmentList = new Graph;
    2234     FragmentationToDo = FragmentationToDo && ParseKeySetFile(out, configuration->configpath, TempFragmentList, configuration->GetIsAngstroem());
    2235   } else
    2236     *out << Verbose(1) << "Creation of lookup table Atom::nr <-> Atom failed!" << endl;
    2237   if (FragmentationToDo)  // parse the adaptive order per atom/site/vertex
    2238     FragmentationToDo = FragmentationToDo && ParseOrderAtSiteFromFile(out, configuration->configpath);
    2239   else
    2240      *out << Verbose(1) << "Parsing keyset file failed" << endl;
    2241  
     2207  TempFragmentList = new Graph;
     2208  FragmentationToDo = FragmentationToDo && ParseKeySetFile(out, configuration->configpath, TempFragmentList, configuration->GetIsAngstroem());
     2209
    22422210  // ===== 4. check globally whether there's something to do actually (first adaptivity check)
    2243   if (FragmentationToDo) { // check whether OrderAtSite is above Order everywhere
    2244     FragmentationToDo = false;
    2245     Walker = start;
    2246     while (Walker->next != end) {
    2247       Walker = Walker->next;
    2248 #ifdef ADDHYDROGEN
    2249       if (Walker->type->Z != 1) // skip hydrogen
    2250 #endif
    2251         if (Walker->AdaptiveOrder < Order)
    2252           FragmentationToDo = true;
    2253     }
    2254   } else
    2255     *out << Verbose(1) << "Parsing order at site file failed" << endl;
    2256  
    2257   if (!FragmentationToDo)
    2258     *out << Verbose(0) << "Order at every site is already equal or above desired order " << Order << "." << endl;
    2259 
     2211  FragmentationToDo = FragmentationToDo && ParseOrderAtSiteFromFile(out, configuration->configpath);
     2212  CheckOrderAtSite(out, FragmentationToDo, Order);
     2213 
    22602214  // =================================== Begin of FRAGMENTATION ===============================
    22612215  // check cyclic lengths
     
    22632217    *out << Verbose(0) << "Bond order " << Order << " greater than or equal to Minimum Ring size of " << MinimumRingSize << " found is not allowed." << endl;
    22642218  } else {
    2265     FragmentCounter = 0;
    2266     MolecularWalker = Subgraphs;
    2267     // count subgraphs and allocate fragments
    2268     while (MolecularWalker->next != NULL) {
    2269       MolecularWalker = MolecularWalker->next;
    2270       FragmentCounter++;
    2271     }
    22722219    FragmentList = (Graph **) Malloc(sizeof(Graph *)*FragmentCounter, "molecule::FragmentMolecule - **BondFragments");
    22732220   
     
    23252272          delete(FragmentList[FragmentCounter]);
    23262273        else
    2327           *out << Verbose(1) << KeySetCounter << " atoms were put into subgraph " << FragmentCounter << "." << endl;
     2274          *out << Verbose(1) << KeySetCounter << " keysets were assigned to subgraph " << FragmentCounter << "." << endl;
    23282275        FragmentCounter++;
    23292276      }
     
    23652312        MolecularWalker->Leaf->FragmentBOSSANOVA(out, FragmentList[FragmentCounter], RootStack[FragmentCounter]);
    23662313       
    2367         // translate list into global numbers (i.e. valid in "this" molecule, not in MolecularWalker->Leaf)
    2368         KeySet *TempSet = new KeySet;
    2369         for(Graph::iterator runner = FragmentList[FragmentCounter]->begin(); runner != FragmentList[FragmentCounter]->end(); runner++) {
    2370           for(KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++)
    2371             TempSet->insert((MolecularWalker->Leaf->FindAtom(*sprinter))->GetTrueFather()->nr);
    2372           TotalGraph.insert(GraphPair(*TempSet, pair<int,double>(TotalNumberOfKeySets++, (*runner).second.second)));
    2373           TempSet->clear();
    2374         }
    2375         delete(TempSet);
    2376         delete(FragmentList[FragmentCounter]);
    23772314      } else {
    23782315        cerr << "Subgraph " << MolecularWalker << " has no atoms!" << endl;
     
    23812318    }
    23822319  }
     2320
     2321  // ==================================== End of FRAGMENTATION ============================================
     2322
     2323  // ===== 8a. translate list into global numbers (i.e. valid in "this" molecule, not in MolecularWalker->Leaf)
     2324  MolecularWalker = Subgraphs;
     2325  FragmentCounter = 0;
     2326  while (MolecularWalker->next != NULL) {
     2327    MolecularWalker = MolecularWalker->next;
     2328    KeySet *TempSet = new KeySet;
     2329    for(Graph::iterator runner = FragmentList[FragmentCounter]->begin(); runner != FragmentList[FragmentCounter]->end(); runner++) {
     2330      for(KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++)
     2331        TempSet->insert((MolecularWalker->Leaf->FindAtom(*sprinter))->GetTrueFather()->nr);
     2332      TotalGraph.insert(GraphPair(*TempSet, pair<int,double>(TotalNumberOfKeySets++, (*runner).second.second)));
     2333      TempSet->clear();
     2334    }
     2335    delete(TempSet);
     2336    delete(FragmentList[FragmentCounter]);
     2337    FragmentCounter++;
     2338  }
    23832339  Free((void **)&FragmentList, "molecule::FragmentMolecule - **FragmentList");
    23842340
    2385   // ===== 8. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass =====
     2341  // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass =====
    23862342  // allocate memory for the pointer array and transmorph graphs into full molecular fragments
    23872343  BondFragments = new MoleculeListClass(TotalGraph.size(), AtomCount);
     
    23942350  }
    23952351  *out << k << "/" << BondFragments->NumberOfMolecules << " fragments generated from the keysets." << endl;
    2396 
    2397  // ==================================== End of FRAGMENTATION ================================
    23982352 
    23992353  // ===== 10. Save fragments' configuration and keyset files et al to disk ===
  • src/molecules.hpp

    rc82f3d r9fcf47  
    340340  /// Fragment molecule by two different approaches:
    341341  void FragmentMolecule(ofstream *out, int Order, config *configuration);
     342  void CheckOrderAtSite(ofstream *out, bool &FragmentationToDo, int Order);
    342343  bool StoreAdjacencyToFile(ofstream *out, char *path);
    343344  bool CheckAdjacencyFileAgainstMolecule(ofstream *out, char *path, atom **ListOfAtoms);
     
    408409
    409410  bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous);
     411  bool FillBondStructureFromReference(ofstream *out, molecule *reference, int &FragmentCounter, atom ***&ListOfLocalAtoms, bool FreeList = false);
    410412};
    411413
Note: See TracChangeset for help on using the changeset viewer.