Changeset ca8bea for src/Fragmentation


Ignore:
Timestamp:
Dec 3, 2012, 9:49:59 AM (12 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:
dcbb5d
Parents:
de0af2
git-author:
Frederik Heber <heber@…> (09/20/12 12:37:12)
git-committer:
Frederik Heber <heber@…> (12/03/12 09:49:59)
Message:

ExportGraph_ToFiles performs now the storing of the generated Graph to files.

  • FragmentMolecule now fills an internal graph.
  • ExportGraph_ToFiles gets graph in cstor and writes the contained KeySets to file on call of operator().
Location:
src/Fragmentation
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Exporters/ExportGraph.cpp

    rde0af2 rca8bea  
    4242 */
    4343ExportGraph::ExportGraph(const Graph &_graph) :
    44         TotalGraph(graph)
     44        TotalGraph(_graph)
    4545{
    4646
    4747}
     48
     49/** Destructor for class ExportGraph.
     50 *
     51 */
     52ExportGraph::~ExportGraph()
     53{}
  • src/Fragmentation/Exporters/ExportGraph.hpp

    rde0af2 rca8bea  
    1818/** ExportGraph is an interface definition of a class that takes a fragmented
    1919 * system contained in an instance of Graph and exports it to some place else.
     20 *
     21 * Guidelines are as follows:
     22 * - all derived classes should have their specific properties set by extra
     23 *   setters and not by passing them through the cstor
     24 * - operator() is called without arguments.
    2025 */
    2126class ExportGraph
     
    2328public:
    2429        ExportGraph(const Graph &_graph);
    25         ~ExportGraph();
     30        virtual ~ExportGraph();
    2631
    2732        virtual void operator()()=0;
    2833
    29 private:
     34protected:
    3035        const Graph &TotalGraph;
    3136};
  • src/Fragmentation/Exporters/ExportGraph_ToFiles.cpp

    rde0af2 rca8bea  
    3737#include "ExportGraph_ToFiles.hpp"
    3838
     39#include "CodePatterns/Info.hpp"
    3940#include "CodePatterns/Log.hpp"
     41
     42#include "Bond/bond.hpp"
     43#include "Element/element.hpp"
    4044#include "Fragmentation/Graph.hpp"
    4145#include "Fragmentation/KeySet.hpp"
     46#include "Graph/ListOfLocalAtoms.hpp"
     47#include "molecule.hpp"
    4248#include "MoleculeListClass.hpp"
     49#include "Parser/FormatParserStorage.hpp"
    4350#include "World.hpp"
    4451
     
    4653 *
    4754 * @param _graph instance of Graph containing keyset of each fragment
    48  */
    49 ExportGraph_ToFiles::ExportGraph_ToFiles(const Graph &_graph) :
    50                 ExportGraph(_graph)
     55 * @param _mol molecule as reference
     56 */
     57ExportGraph_ToFiles::ExportGraph_ToFiles(const Graph &_graph, molecule *&_mol, const enum HydrogenSaturation _saturation) :
     58                ExportGraph(_graph),
     59                mol(_mol),
     60                BondFragments(World::getPointer()),
     61                saturation(_saturation)
    5162{}
    5263
     64/** Destructor of class ExportGraph_ToFiles.
     65 *
     66 * We free all created molecules again and also removed their copied atoms.
     67 */
     68ExportGraph_ToFiles::~ExportGraph_ToFiles()
     69{
     70  // remove all create molecules again from the World including their atoms
     71  for (MoleculeList::iterator iter = BondFragments.ListOfMolecules.begin();
     72      !BondFragments.ListOfMolecules.empty();
     73      iter = BondFragments.ListOfMolecules.begin()) {
     74    // remove copied atoms and molecule again
     75    molecule *mol = *iter;
     76    mol->removeAtomsinMolecule();
     77    World::getInstance().destroyMolecule(mol);
     78    BondFragments.ListOfMolecules.erase(iter);
     79  }
     80}
     81
    5382/** Actual implementation of the export to files function.
    54  *
    55  */
    56 void ExportGraph_ToFiles::operator ()()
    57 {
     83 */
     84void ExportGraph_ToFiles::operator()()
     85{
     86  if (BondFragments.ListOfMolecules.size() == 0)
     87    prepareMolecule();
     88
     89  // ===== 9. Save fragments' configuration and keyset files et al to disk ===
     90  // create the SortIndex from BFS labels to order in the config file
     91  std::map<atomId_t, int> SortIndex;
     92  CreateMappingLabelsToConfigSequence(SortIndex);
     93
     94  LOG(1, "Writing " << BondFragments.ListOfMolecules.size() << " possible bond fragmentation configs");
     95  bool write_status = true;
     96  for (std::vector<std::string>::const_iterator iter = typelist.begin();
     97      iter != typelist.end();
     98      ++iter) {
     99    LOG(2, "INFO: Writing bond fragments for type " << (*iter) << ".");
     100    write_status = write_status
     101    && BondFragments.OutputConfigForListOfFragments(
     102        prefix,
     103        FormatParserStorage::getInstance().getTypeFromName(*iter));
     104  }
     105  if (write_status)
     106    LOG(1, "All configs written.");
     107  else
     108    LOG(1, "Some config writing failed.");
     109
     110  // store force index reference file
     111  BondFragments.StoreForcesFile(prefix, SortIndex);
     112
     113  // store keysets file
     114  TotalGraph.StoreKeySetFile(prefix);
     115
     116  {
     117    // store Adjacency file
     118    std::string filename = prefix + ADJACENCYFILE;
     119    mol->StoreAdjacencyToFile(filename);
     120  }
     121
     122  // store Hydrogen saturation correction file
     123  BondFragments.AddHydrogenCorrection(prefix);
     124
     125  // restore orbital and Stop values
     126  //CalculateOrbitals(*configuration);
    58127}
    59128
     
    63132void ExportGraph_ToFiles::prepareMolecule()
    64133{
    65   // allocate memory for the pointer array and transmorph graphs into full molecular fragments
    66   MoleculeListClass *BondFragments = new MoleculeListClass(World::getPointer());
    67134  size_t count = 0;
    68   for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
     135  for(Graph::const_iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
    69136    KeySet test = (*runner).first;
    70137    LOG(2, "DEBUG: Fragment No." << (*runner).second.first << " with TEFactor "
    71138                << (*runner).second.second << ".");
    72     BondFragments->insert(StoreFragmentFromKeySet(test, World::getInstance().getConfig()));
     139    BondFragments.insert(StoreFragmentFromKeySet(mol, test, World::getInstance().getConfig()));
    73140    ++count;
    74141  }
    75   LOG(1, "INFO: " << count << "/" << BondFragments->ListOfMolecules.size()
     142  LOG(1, "INFO: " << count << "/" << BondFragments.ListOfMolecules.size()
    76143                << " fragments generated from the keysets.");
    77144}
     145
     146/** Stores a fragment from \a KeySet into \a molecule.
     147 * First creates the minimal set of atoms from the KeySet, then creates the bond structure from the complete
     148 * molecule and adds missing hydrogen where bonds were cut.
     149 * \param *mol reference molecule
     150 * \param &Leaflet pointer to KeySet structure
     151 * \param IsAngstroem whether we have Ansgtroem or bohrradius
     152 * \return pointer to constructed molecule
     153 */
     154molecule * ExportGraph_ToFiles::StoreFragmentFromKeySet(molecule *mol, KeySet &Leaflet, bool IsAngstroem)
     155{
     156  Info info(__func__);
     157  ListOfLocalAtoms_t SonList;
     158  molecule *Leaf = World::getInstance().createMolecule();
     159
     160  StoreFragmentFromKeySet_Init(mol, Leaf, Leaflet, SonList);
     161  // create the bonds between all: Make it an induced subgraph and add hydrogen
     162//  LOG(2, "Creating bonds from father graph (i.e. induced subgraph creation).");
     163  CreateInducedSubgraphOfFragment(mol, Leaf, SonList, IsAngstroem);
     164
     165  //Leaflet->Leaf->ScanForPeriodicCorrection(out);
     166  return Leaf;
     167}
     168
     169/** Initializes some value for putting fragment of \a *mol into \a *Leaf.
     170 * \param *mol total molecule
     171 * \param *Leaf fragment molecule
     172 * \param &Leaflet pointer to KeySet structure
     173 * \param SonList calloc'd list which atom of \a *Leaf is a son of which atom in \a *mol
     174 * \return number of atoms in fragment
     175 */
     176int ExportGraph_ToFiles::StoreFragmentFromKeySet_Init(molecule *mol, molecule *Leaf, KeySet &Leaflet, ListOfLocalAtoms_t &SonList)
     177{
     178  atom *FatherOfRunner = NULL;
     179
     180  // first create the minimal set of atoms from the KeySet
     181  int size = 0;
     182  for(KeySet::const_iterator runner = Leaflet.begin(); runner != Leaflet.end(); runner++) {
     183    FatherOfRunner = mol->FindAtom((*runner));  // find the id
     184    SonList.insert( std::make_pair(FatherOfRunner->getNr(), Leaf->AddCopyAtom(FatherOfRunner) ) );
     185    size++;
     186  }
     187  return size;
     188}
     189
     190/** Creates an induced subgraph out of a fragmental key set, adding bonds and hydrogens (if treated specially).
     191 * \param *out output stream for debugging messages
     192 * \param *mol total molecule
     193 * \param *Leaf fragment molecule
     194 * \param IsAngstroem whether we have Ansgtroem or bohrradius
     195 * \param SonList list which atom of \a *Leaf is a son of which atom in \a *mol
     196 */
     197void ExportGraph_ToFiles::CreateInducedSubgraphOfFragment(molecule *mol, molecule *Leaf, ListOfLocalAtoms_t &SonList, bool IsAngstroem)
     198{
     199  bool LonelyFlag = false;
     200  atom *OtherFather = NULL;
     201  atom *FatherOfRunner = NULL;
     202
     203  // we increment the iter just before skipping the hydrogen
     204  // as we use AddBond, we cannot have a const_iterator here
     205  for (molecule::iterator iter = Leaf->begin(); iter != Leaf->end();) {
     206    LonelyFlag = true;
     207    FatherOfRunner = (*iter)->father;
     208    ASSERT(FatherOfRunner,"Atom without father found");
     209    if (SonList.find(FatherOfRunner->getNr()) != SonList.end())  {  // check if this, our father, is present in list
     210      // create all bonds
     211      const BondList& ListOfBonds = FatherOfRunner->getListOfBonds();
     212      for (BondList::const_iterator BondRunner = ListOfBonds.begin();
     213          BondRunner != ListOfBonds.end();
     214          ++BondRunner) {
     215        OtherFather = (*BondRunner)->GetOtherAtom(FatherOfRunner);
     216        if (SonList.find(OtherFather->getNr()) != SonList.end()) {
     217//          LOG(2, "INFO: Father " << *FatherOfRunner << " of son " << *SonList[FatherOfRunner->getNr()]
     218//              << " is bound to " << *OtherFather << ", whose son is "
     219//              << *SonList[OtherFather->getNr()] << ".");
     220          if (OtherFather->getNr() > FatherOfRunner->getNr()) { // add bond (Nr check is for adding only one of both variants: ab, ba)
     221            std::stringstream output;
     222//            output << "ACCEPT: Adding Bond: "
     223            output << Leaf->AddBond((*iter), SonList[OtherFather->getNr()], (*BondRunner)->BondDegree);
     224//            LOG(3, output.str());
     225            //NumBonds[(*iter)->getNr()]++;
     226          } else {
     227//            LOG(3, "REJECY: Not adding bond, labels in wrong order.");
     228          }
     229          LonelyFlag = false;
     230        } else {
     231//          LOG(2, "INFO: Father " << *FatherOfRunner << " of son " << *SonList[FatherOfRunner->getNr()]
     232//              << " is bound to " << *OtherFather << ", who has no son in this fragment molecule.");
     233          if (saturation == DoSaturate) {
     234//          LOG(3, "ACCEPT: Adding Hydrogen to " << (*iter)->Name << " and a bond in between.");
     235            if (!Leaf->AddHydrogenReplacementAtom((*BondRunner), (*iter), FatherOfRunner, OtherFather, IsAngstroem))
     236              exit(1);
     237          }
     238          //NumBonds[(*iter)->getNr()] += Binder->BondDegree;
     239        }
     240      }
     241    } else {
     242    ELOG(1, "Son " << (*iter)->getName() << " has father " << FatherOfRunner->getName() << " but its entry in SonList is " << SonList[FatherOfRunner->getNr()] << "!");
     243    }
     244    if ((LonelyFlag) && (Leaf->getAtomCount() > 1)) {
     245      LOG(0, **iter << "has got bonds only to hydrogens!");
     246    }
     247    ++iter;
     248    if (saturation == DoSaturate) {
     249      while ((iter != Leaf->end()) && ((*iter)->getType()->getAtomicNumber() == 1)){ // skip added hydrogen
     250        iter++;
     251      }
     252    }
     253  }
     254}
     255
     256/** Create a SortIndex to map from atomic labels to the sequence in which the atoms are given in the config file.
     257 * \param &SortIndex Mapping array of size molecule::AtomCount
     258 * \return true - success, false - failure of SortIndex alloc
     259 */
     260bool ExportGraph_ToFiles::CreateMappingLabelsToConfigSequence(std::map<atomId_t, int> &SortIndex)
     261{
     262  if (!SortIndex.empty()) {
     263    LOG(1, "SortIndex has " << SortIndex.size() << " entries and is not empty as expected.");
     264    return false;
     265  }
     266
     267  int AtomNo = 0;
     268  for(molecule::const_iterator iter=mol->begin();iter!=mol->end();++iter){
     269    const int id = (*iter)->getNr();
     270#ifndef NDEBUG
     271      std::pair<std::map<atomId_t, int>::const_iterator, bool> inserter =
     272#endif
     273    SortIndex.insert( std::make_pair(id, AtomNo++) );
     274    ASSERT( inserter.second ,
     275        "ExportGraph_ToFiles::CreateMappingLabelsToConfigSequence() - same SortIndex set twice.");
     276  }
     277
     278  return true;
     279}
     280
  • src/Fragmentation/Exporters/ExportGraph_ToFiles.hpp

    rde0af2 rca8bea  
    1414#endif
    1515
     16#include <string>
     17#include <vector>
     18
     19#include "Fragmentation/HydrogenSaturation_enum.hpp"
    1620#include "Fragmentation/Exporters/ExportGraph.hpp"
     21#include "MoleculeListClass.hpp"
     22
     23class ListOfLocalAtoms_t;
    1724
    1825/** ExportGraph_ToFiles implements an ExportGraph as storing all fragmentary
     
    2229{
    2330public:
    24         ExportGraph_ToFiles();
     31        ExportGraph_ToFiles(const Graph &_graph, molecule *&_mol, const enum HydrogenSaturation _saturation);
     32        virtual ~ExportGraph_ToFiles();
    2533
    2634        void operator()();
     35
     36        void setPrefix(const std::string &_prefix) {
     37          prefix = _prefix;
     38        }
     39
     40        void setOutputTypes(const std::vector<std::string> &_typelist) {
     41          typelist = _typelist;
     42        }
     43
     44private:
     45
     46        void prepareMolecule();
     47  molecule * StoreFragmentFromKeySet(molecule *mol, KeySet &Leaflet, bool IsAngstroem);
     48  int StoreFragmentFromKeySet_Init(molecule *mol, molecule *Leaf, KeySet &Leaflet, ListOfLocalAtoms_t &SonList);
     49  void CreateInducedSubgraphOfFragment(molecule *mol, molecule *Leaf, ListOfLocalAtoms_t &SonList, bool IsAngstroem);
     50  bool CreateMappingLabelsToConfigSequence(std::map<atomId_t, int> &SortIndex);
     51
     52
     53private:
     54  //!> molecule as reference
     55  molecule *mol;
     56  //!> internal list of created molecules
     57        MoleculeListClass BondFragments;
     58        //!> prefix for fragment files
     59        std::string prefix;
     60  //!> list of parser types for which a configuration file per fragment is stored
     61  std::vector<std::string> typelist;
     62  //!> whether to saturate dangling bonds or not
     63  const enum HydrogenSaturation saturation;
    2764};
    2865
  • src/Fragmentation/Fragmentation.cpp

    rde0af2 rca8bea  
    5757#include "Graph/ListOfLocalAtoms.hpp"
    5858#include "molecule.hpp"
    59 #include "MoleculeLeafClass.hpp"
    60 #include "MoleculeListClass.hpp"
    61 #include "Parser/FormatParserStorage.hpp"
    6259#include "World.hpp"
    6360
     
    10299int Fragmentation::FragmentMolecule(const std::vector<atomId_t> &atomids, int Order, std::string prefix, DepthFirstSearchAnalysis &DFS)
    103100{
    104   MoleculeListClass *BondFragments = NULL;
    105101  std::fstream File;
    106102  bool FragmentationToDo = true;
    107103  bool CheckOrder = false;
    108   Graph TotalGraph;     // graph with all keysets however local numbers
    109104  int TotalNumberOfKeySets = 0;
    110105  AtomMask_t AtomMask(atomids);
     
    166161  TranslateIndicesToGlobalIDs(FragmentList, TotalNumberOfKeySets, TotalGraph);
    167162
    168   // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass =====
    169   //if (FragmentationToDo) {    // we should always store the fragments again as coordination might have changed slightly without changing bond structure
    170   // allocate memory for the pointer array and transmorph graphs into full molecular fragments
    171   BondFragments = new MoleculeListClass(World::getPointer());
    172   int k=0;
    173   for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
    174     KeySet test = (*runner).first;
    175     LOG(0, "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << ".");
    176     BondFragments->insert(StoreFragmentFromKeySet(test, World::getInstance().getConfig()));
    177     k++;
    178   }
    179   LOG(0, k << "/" << BondFragments->ListOfMolecules.size() << " fragments generated from the keysets.");
    180 
    181   // ===== 9. Save fragments' configuration and keyset files et al to disk ===
    182   if (BondFragments->ListOfMolecules.size() != 0) {
    183     // create the SortIndex from BFS labels to order in the config file
    184     std::map<atomId_t, int> SortIndex;
    185     CreateMappingLabelsToConfigSequence(SortIndex);
    186 
    187     LOG(1, "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs");
    188     bool write_status = true;
    189     for (std::vector<std::string>::const_iterator iter = typelist.begin();
    190         iter != typelist.end();
    191         ++iter) {
    192       LOG(2, "INFO: Writing bond fragments for type " << (*iter) << ".");
    193       write_status = write_status
    194       && BondFragments->OutputConfigForListOfFragments(
    195           prefix,
    196           FormatParserStorage::getInstance().getTypeFromName(*iter));
    197     }
    198     if (write_status)
    199       LOG(1, "All configs written.");
    200     else
    201       LOG(1, "Some config writing failed.");
    202 
    203     // store force index reference file
    204     BondFragments->StoreForcesFile(prefix, SortIndex);
    205 
    206     // store keysets file
    207     TotalGraph.StoreKeySetFile(prefix);
    208 
    209     {
    210       // store Adjacency file
    211       std::string filename = prefix + ADJACENCYFILE;
    212       mol->StoreAdjacencyToFile(filename);
    213     }
    214 
    215     // store Hydrogen saturation correction file
    216     BondFragments->AddHydrogenCorrection(prefix);
    217 
    218     // store adaptive orders into file
    219     StoreOrderAtSiteFile(prefix);
    220 
    221     // restore orbital and Stop values
    222     //CalculateOrbitals(*configuration);
    223   } else {
    224     LOG(1, "FragmentList is zero on return, splitting failed.");
    225   }
    226   // remove all create molecules again from the World including their atoms
    227   for (MoleculeList::iterator iter = BondFragments->ListOfMolecules.begin();
    228       !BondFragments->ListOfMolecules.empty();
    229       iter = BondFragments->ListOfMolecules.begin()) {
    230     // remove copied atoms and molecule again
    231     molecule *mol = *iter;
    232     mol->removeAtomsinMolecule();
    233     World::getInstance().destroyMolecule(mol);
    234     BondFragments->ListOfMolecules.erase(iter);
    235   }
    236   delete(BondFragments);
     163  LOG(1, "STATUS: We have created " << TotalGraph.size() << " fragments.");
     164
     165  // store adaptive orders into file
     166  StoreOrderAtSiteFile(prefix);
     167
    237168  LOG(0, "End of bond fragmentation.");
    238 
    239169  return ((int)(!FragmentationToDo)+1);    // 1 - continue, 2 - stop (no fragmentation occured)
    240170};
     
    361291};
    362292
    363 /** Stores a fragment from \a KeySet into \a molecule.
    364  * First creates the minimal set of atoms from the KeySet, then creates the bond structure from the complete
    365  * molecule and adds missing hydrogen where bonds were cut.
    366  * \param *out output stream for debugging messages
    367  * \param &Leaflet pointer to KeySet structure
    368  * \param IsAngstroem whether we have Ansgtroem or bohrradius
    369  * \return pointer to constructed molecule
    370  */
    371 molecule * Fragmentation::StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem)
    372 {
    373   Info info(__func__);
    374   ListOfLocalAtoms_t SonList;
    375   molecule *Leaf = World::getInstance().createMolecule();
    376 
    377   StoreFragmentFromKeySet_Init(mol, Leaf, Leaflet, SonList);
    378   // create the bonds between all: Make it an induced subgraph and add hydrogen
    379 //  LOG(2, "Creating bonds from father graph (i.e. induced subgraph creation).");
    380   CreateInducedSubgraphOfFragment(mol, Leaf, SonList, IsAngstroem);
    381 
    382   //Leaflet->Leaf->ScanForPeriodicCorrection(out);
    383   return Leaf;
    384 };
    385 
    386 
    387293/** Estimates by educated guessing (using upper limit) the expected number of fragments.
    388294 * The upper limit is
     
    556462};
    557463
    558 /** Create a SortIndex to map from atomic labels to the sequence in which the atoms are given in the config file.
    559  * \param &SortIndex Mapping array of size molecule::AtomCount
    560  * \return true - success, false - failure of SortIndex alloc
    561  */
    562 bool Fragmentation::CreateMappingLabelsToConfigSequence(std::map<atomId_t, int> &SortIndex)
    563 {
    564   if (!SortIndex.empty()) {
    565     LOG(1, "SortIndex has " << SortIndex.size() << " entries and is not empty as expected.");
    566     return false;
    567   }
    568 
    569   int AtomNo = 0;
    570   for(molecule::const_iterator iter=mol->begin();iter!=mol->end();++iter){
    571     const int id = (*iter)->getNr();
    572 #ifndef NDEBUG
    573     std::pair<std::map<atomId_t, int>::const_iterator, bool> inserter =
    574 #endif
    575     SortIndex.insert( std::make_pair(id, AtomNo++) );
    576     ASSERT( inserter.second ,
    577         "Fragmentation::CreateMappingLabelsToConfigSequence() - same SortIndex set twice.");
    578   }
    579 
    580   return true;
    581 };
    582 
    583 
    584 /** Initializes some value for putting fragment of \a *mol into \a *Leaf.
    585  * \param *mol total molecule
    586  * \param *Leaf fragment molecule
    587  * \param &Leaflet pointer to KeySet structure
    588  * \param SonList calloc'd list which atom of \a *Leaf is a son of which atom in \a *mol
    589  * \return number of atoms in fragment
    590  */
    591 int Fragmentation::StoreFragmentFromKeySet_Init(molecule *mol, molecule *Leaf, KeySet &Leaflet, ListOfLocalAtoms_t &SonList)
    592 {
    593   atom *FatherOfRunner = NULL;
    594 
    595   // first create the minimal set of atoms from the KeySet
    596   int size = 0;
    597   for(KeySet::iterator runner = Leaflet.begin(); runner != Leaflet.end(); runner++) {
    598     FatherOfRunner = mol->FindAtom((*runner));  // find the id
    599     SonList.insert( std::make_pair(FatherOfRunner->getNr(), Leaf->AddCopyAtom(FatherOfRunner) ) );
    600     size++;
    601   }
    602   return size;
    603 };
    604 
    605 
    606 /** Creates an induced subgraph out of a fragmental key set, adding bonds and hydrogens (if treated specially).
    607  * \param *out output stream for debugging messages
    608  * \param *mol total molecule
    609  * \param *Leaf fragment molecule
    610  * \param IsAngstroem whether we have Ansgtroem or bohrradius
    611  * \param SonList list which atom of \a *Leaf is a son of which atom in \a *mol
    612  */
    613 void Fragmentation::CreateInducedSubgraphOfFragment(molecule *mol, molecule *Leaf, ListOfLocalAtoms_t &SonList, bool IsAngstroem)
    614 {
    615   bool LonelyFlag = false;
    616   atom *OtherFather = NULL;
    617   atom *FatherOfRunner = NULL;
    618 
    619   // we increment the iter just before skipping the hydrogen
    620   // as we use AddBond, we cannot have a const_iterator here
    621   for (molecule::iterator iter = Leaf->begin(); iter != Leaf->end();) {
    622     LonelyFlag = true;
    623     FatherOfRunner = (*iter)->father;
    624     ASSERT(FatherOfRunner,"Atom without father found");
    625     if (SonList.find(FatherOfRunner->getNr()) != SonList.end())  {  // check if this, our father, is present in list
    626       // create all bonds
    627       const BondList& ListOfBonds = FatherOfRunner->getListOfBonds();
    628       for (BondList::const_iterator BondRunner = ListOfBonds.begin();
    629           BondRunner != ListOfBonds.end();
    630           ++BondRunner) {
    631         OtherFather = (*BondRunner)->GetOtherAtom(FatherOfRunner);
    632         if (SonList.find(OtherFather->getNr()) != SonList.end()) {
    633 //          LOG(2, "INFO: Father " << *FatherOfRunner << " of son " << *SonList[FatherOfRunner->getNr()]
    634 //              << " is bound to " << *OtherFather << ", whose son is "
    635 //              << *SonList[OtherFather->getNr()] << ".");
    636           if (OtherFather->getNr() > FatherOfRunner->getNr()) { // add bond (Nr check is for adding only one of both variants: ab, ba)
    637             std::stringstream output;
    638 //            output << "ACCEPT: Adding Bond: "
    639             output << Leaf->AddBond((*iter), SonList[OtherFather->getNr()], (*BondRunner)->BondDegree);
    640 //            LOG(3, output.str());
    641             //NumBonds[(*iter)->getNr()]++;
    642           } else {
    643 //            LOG(3, "REJECY: Not adding bond, labels in wrong order.");
    644           }
    645           LonelyFlag = false;
    646         } else {
    647 //          LOG(2, "INFO: Father " << *FatherOfRunner << " of son " << *SonList[FatherOfRunner->getNr()]
    648 //              << " is bound to " << *OtherFather << ", who has no son in this fragment molecule.");
    649           if (saturation == DoSaturate) {
    650 //          LOG(3, "ACCEPT: Adding Hydrogen to " << (*iter)->Name << " and a bond in between.");
    651             if (!Leaf->AddHydrogenReplacementAtom((*BondRunner), (*iter), FatherOfRunner, OtherFather, IsAngstroem))
    652               exit(1);
    653           }
    654           //NumBonds[(*iter)->getNr()] += Binder->BondDegree;
    655         }
    656       }
    657     } else {
    658     ELOG(1, "Son " << (*iter)->getName() << " has father " << FatherOfRunner->getName() << " but its entry in SonList is " << SonList[FatherOfRunner->getNr()] << "!");
    659     }
    660     if ((LonelyFlag) && (Leaf->getAtomCount() > 1)) {
    661       LOG(0, **iter << "has got bonds only to hydrogens!");
    662     }
    663     ++iter;
    664     if (saturation == DoSaturate) {
    665       while ((iter != Leaf->end()) && ((*iter)->getType()->getAtomicNumber() == 1)){ // skip added hydrogen
    666         iter++;
    667       }
    668     }
    669   }
    670 };
    671 
    672 /** Sets the desired output types of the fragment configurations.
    673  *
    674  * @param types vector of desired types.
    675  */
    676 void Fragmentation::setOutputTypes(const std::vector<std::string> &types)
    677 {
    678   typelist = types;
    679 }
    680 
    681464/** Fills the root stack for sites to be used as root in fragmentation depending on order or adaptivity criteria
    682465 * Again, as in \sa FillBondStructureFromReference steps recursively through each Leaf in this chain list of molecule's.
  • src/Fragmentation/Fragmentation.hpp

    rde0af2 rca8bea  
    1616#include "Graph/DepthFirstSearchAnalysis.hpp"
    1717
     18#include "Fragmentation/fragmentation_helpers.hpp"
     19#include "Fragmentation/Graph.hpp"
    1820#include "Fragmentation/HydrogenSaturation_enum.hpp"
    19 #include "Fragmentation/fragmentation_helpers.hpp"
    2021#include "types.hpp"
    2122
     
    2728class AtomMask_t;
    2829class CheckAgainstAdjacencyFile;
    29 class Graph;
    3030class KeySet;
    3131class molecule;
     
    3939  int FragmentMolecule(const std::vector<atomId_t> &atomids, int Order, std::string prefix, DepthFirstSearchAnalysis &DFS);
    4040
    41   void setOutputTypes(const std::vector<std::string> &types);
     41  const Graph& getGraph() const {
     42    return TotalGraph;
     43  }
    4244
    4345private:
     
    4547  void FragmentBOSSANOVA(molecule *mol, Graph &FragmentList, KeyStack &RootStack);
    4648  int GuesstimateFragmentCount(int order);
    47 
    48   bool CreateMappingLabelsToConfigSequence(std::map<atomId_t, int> &SortIndex);
    4949
    5050  // order at site
     
    5454
    5555  // storing fragments
    56   molecule * StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem);
    57   int StoreFragmentFromKeySet_Init(molecule *mol, molecule *Leaf, KeySet &Leaflet, ListOfLocalAtoms_t &SonList);
    58   void CreateInducedSubgraphOfFragment(molecule *mol, molecule *Leaf, ListOfLocalAtoms_t &SonList, bool IsAngstroem);
    5956  void FillRootStackForSubgraphs(KeyStack &RootStack, const AtomMask_t &AtomMask);
    6057  bool AssignKeySetsToFragment(Graph &KeySetList, ListOfLocalAtoms_t &ListOfLocalAtoms, Graph &FragmentList, bool FreeList = false);
     
    6663  //!> whether to saturate dangling bonds with hydrogen and hence treat hydrogen special
    6764  const enum HydrogenSaturation saturation;
    68   //!> list of parser types for which a configuration file per fragment is stored
    69   std::vector<std::string> typelist;
    7065  //!> reference to an external adjacency for comparison
    7166  CheckAgainstAdjacencyFile &FileChecker;
     67  //!> Resulting Graph with all keysets
     68  Graph TotalGraph;
    7269};
    7370
  • src/Fragmentation/Graph.cpp

    rde0af2 rca8bea  
    132132 * \return true - file written successfully, false - writing failed
    133133 */
    134 bool Graph::StoreKeySetFile(std::string &path)
     134bool Graph::StoreKeySetFile(std::string &path) const
    135135{
    136136  bool status =  true;
     
    141141  LOG(1, "INFO: Saving key sets of the total graph ... ");
    142142  if(output.good()) {
    143     for(Graph::iterator runner = begin(); runner != end(); runner++) {
    144       for (KeySet::iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++) {
     143    for(Graph::const_iterator runner = begin(); runner != end(); runner++) {
     144      for (KeySet::const_iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++) {
    145145        if (sprinter != (*runner).first.begin())
    146146          output << "\t";
     
    210210 * \return true - file written successfully, false - writing failed
    211211 */
    212 bool Graph::StoreTEFactorsFile(char *path)
     212bool Graph::StoreTEFactorsFile(char *path) const
    213213{
    214214  ofstream output;
     
    224224  LOG(1, "INFO: Saving TEFactors of the total graph ... ");
    225225  if(output != NULL) {
    226     for(Graph::iterator runner = begin(); runner != end(); runner++)
     226    for(Graph::const_iterator runner = begin(); runner != end(); runner++)
    227227      output << (*runner).second.second << endl;
    228228    LOG(1, "INFO: done." << endl);
  • src/Fragmentation/Graph.hpp

    rde0af2 rca8bea  
    3333
    3434  bool ParseKeySetFile(std::string &path);
    35   bool StoreKeySetFile(std::string &path);
     35  bool StoreKeySetFile(std::string &path) const;
    3636  bool ParseTEFactorsFile(char *path);
    37   bool StoreTEFactorsFile(char *path);
     37  bool StoreTEFactorsFile(char *path) const;
    3838
    3939  AdaptivityMap * GraphToAdaptivityMap() const;
  • src/Fragmentation/Makefile.am

    rde0af2 rca8bea  
    33
    44FRAGMENTATIONSOURCE = \
     5        Fragmentation/Exporters/ExportGraph_ToFiles.cpp \
     6        Fragmentation/Exporters/ExportGraph.cpp \
    57        Fragmentation/AdaptivityMap.cpp \
    68        Fragmentation/BondsPerShortestPath.cpp \
     
    1921
    2022FRAGMENTATIONHEADER = \
     23        Fragmentation/Exporters/ExportGraph_ToFiles.hpp \
     24        Fragmentation/Exporters/ExportGraph.hpp \
    2125        Fragmentation/AdaptivityMap.hpp \
    2226        Fragmentation/AtomMask.hpp \
Note: See TracChangeset for help on using the changeset viewer.