Ignore:
File:
1 edited

Legend:

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

    ra2a2f7 r98a293b  
    5858  const Graph &_graph,
    5959  const enum HydrogenTreatment _treatment,
    60   const enum HydrogenSaturation _saturation) :
     60  const enum HydrogenSaturation _saturation,
     61  const SaturatedFragment::GlobalSaturationPositions_t &_globalsaturationpositions) :
    6162  TotalGraph(_graph),
    6263  BondFragments(World::getPointer()),
    6364  treatment(_treatment),
    6465  saturation(_saturation),
     66  globalsaturationpositions(_globalsaturationpositions),
    6567  CurrentKeySet(TotalGraph.begin())
    6668{
     
    115117          hydrogens,
    116118          treatment,
    117           saturation)
     119          saturation,
     120          globalsaturationpositions)
    118121  );
    119122  // and return
     
    137140}
    138141
    139 /** Internal helper to create from each keyset a molecule
    140  *
    141  */
    142 void ExportGraph::prepareMolecule()
    143 {
    144   size_t count = 0;
    145   for(Graph::const_iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
    146     KeySet test = (*runner).first;
    147     LOG(2, "DEBUG: Fragment No." << (*runner).second.first << " with TEFactor "
    148         << (*runner).second.second << ".");
    149     BondFragments.insert(StoreFragmentFromKeySet(test, World::getInstance().getConfig()));
    150     ++count;
    151   }
    152   LOG(1, "INFO: " << count << "/" << BondFragments.ListOfMolecules.size()
    153       << " fragments generated from the keysets.");
    154 }
    155 
    156 /** Stores a fragment from \a KeySet into \a molecule.
    157  * First creates the minimal set of atoms from the KeySet, then creates the bond structure from the complete
    158  * molecule and adds missing hydrogen where bonds were cut.
    159  * \param &Leaflet pointer to KeySet structure
    160  * \param IsAngstroem whether we have Ansgtroem or bohrradius
    161  * \return pointer to constructed molecule
    162  */
    163 molecule * ExportGraph::StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem)
    164 {
    165   Info info(__func__);
    166   ListOfLocalAtoms_t SonList;
    167   molecule *Leaf = World::getInstance().createMolecule();
    168 
    169   StoreFragmentFromKeySet_Init(Leaf, Leaflet, SonList);
    170   // create the bonds between all: Make it an induced subgraph and add hydrogen
    171 //  LOG(2, "Creating bonds from father graph (i.e. induced subgraph creation).");
    172   CreateInducedSubgraphOfFragment(Leaf, SonList, IsAngstroem);
    173 
    174   //Leaflet->Leaf->ScanForPeriodicCorrection(out);
    175   return Leaf;
    176 }
    177 
    178 /** Initializes some value for putting fragment of \a *mol into \a *Leaf.
    179  * \param *Leaf fragment molecule
    180  * \param &Leaflet pointer to KeySet structure
    181  * \param SonList calloc'd list which atom of \a *Leaf is a son of which atom in \a *mol
    182  * \return number of atoms in fragment
    183  */
    184 int ExportGraph::StoreFragmentFromKeySet_Init(molecule *Leaf, KeySet &Leaflet, ListOfLocalAtoms_t &SonList)
    185 {
    186   atom *FatherOfRunner = NULL;
    187 
    188   // first create the minimal set of atoms from the KeySet
    189   World &world = World::getInstance();
    190   int size = 0;
    191   for(KeySet::const_iterator runner = Leaflet.begin(); runner != Leaflet.end(); runner++) {
    192     FatherOfRunner = world.getAtom(AtomById(*runner));  // find the id
    193     SonList.insert( std::make_pair(FatherOfRunner->getNr(), Leaf->AddCopyAtom(FatherOfRunner) ) );
    194     size++;
    195   }
    196   return size;
    197 }
    198 
    199 /** Creates an induced subgraph out of a fragmental key set, adding bonds and hydrogens (if treated specially).
    200  * \param *Leaf fragment molecule
    201  * \param IsAngstroem whether we have Ansgtroem or bohrradius
    202  * \param SonList list which atom of \a *Leaf is another atom's son
    203  */
    204 void ExportGraph::CreateInducedSubgraphOfFragment(molecule *Leaf, ListOfLocalAtoms_t &SonList, bool IsAngstroem)
    205 {
    206   bool LonelyFlag = false;
    207   atom *OtherFather = NULL;
    208   atom *FatherOfRunner = NULL;
    209 
    210   // we increment the iter just before skipping the hydrogen
    211   // as we use AddBond, we cannot have a const_iterator here
    212   for (molecule::iterator iter = Leaf->begin(); iter != Leaf->end();) {
    213     LonelyFlag = true;
    214     FatherOfRunner = (*iter)->father;
    215     ASSERT(FatherOfRunner,"Atom without father found");
    216     if (SonList.find(FatherOfRunner->getNr()) != SonList.end())  {  // check if this, our father, is present in list
    217       // create all bonds
    218       const BondList& ListOfBonds = FatherOfRunner->getListOfBonds();
    219       for (BondList::const_iterator BondRunner = ListOfBonds.begin();
    220           BondRunner != ListOfBonds.end();
    221           ++BondRunner) {
    222         OtherFather = (*BondRunner)->GetOtherAtom(FatherOfRunner);
    223         if (SonList.find(OtherFather->getNr()) != SonList.end()) {
    224 //          LOG(2, "INFO: Father " << *FatherOfRunner << " of son " << *SonList[FatherOfRunner->getNr()]
    225 //              << " is bound to " << *OtherFather << ", whose son is "
    226 //              << *SonList[OtherFather->getNr()] << ".");
    227           if (OtherFather->getNr() > FatherOfRunner->getNr()) { // add bond (Nr check is for adding only one of both variants: ab, ba)
    228             std::stringstream output;
    229 //            output << "ACCEPT: Adding Bond: "
    230             output << Leaf->AddBond((*iter), SonList[OtherFather->getNr()], (*BondRunner)->getDegree());
    231 //            LOG(3, output.str());
    232             //NumBonds[(*iter)->getNr()]++;
    233           } else {
    234 //            LOG(3, "REJECY: Not adding bond, labels in wrong order.");
    235           }
    236           LonelyFlag = false;
    237         } else {
    238 //          LOG(2, "INFO: Father " << *FatherOfRunner << " of son " << *SonList[FatherOfRunner->getNr()]
    239 //              << " is bound to " << *OtherFather << ", who has no son in this fragment molecule.");
    240           if (saturation == DoSaturate) {
    241 //          LOG(3, "ACCEPT: Adding Hydrogen to " << (*iter)->Name << " and a bond in between.");
    242             if (!Leaf->AddHydrogenReplacementAtom((*BondRunner), (*iter), FatherOfRunner, OtherFather, IsAngstroem))
    243               exit(1);
    244           } else if ((treatment == ExcludeHydrogen) && (OtherFather->getElementNo() == (atomicNumber_t)1)) {
    245             // just copy the atom if it's a hydrogen
    246             atom * const OtherWalker = Leaf->AddCopyAtom(OtherFather);
    247             Leaf->AddBond((*iter), OtherWalker, (*BondRunner)->getDegree());
    248           }
    249           //NumBonds[(*iter)->getNr()] += Binder->getDegree();
    250         }
    251       }
    252     } else {
    253       ELOG(1, "Son " << (*iter)->getName() << " has father " << FatherOfRunner->getName() << " but its entry in SonList is " << SonList[FatherOfRunner->getNr()] << "!");
    254     }
    255     if ((LonelyFlag) && (Leaf->getAtomCount() > 1)) {
    256       LOG(0, **iter << "has got bonds only to hydrogens!");
    257     }
    258     ++iter;
    259     if (saturation == DoSaturate) {
    260       while ((iter != Leaf->end()) && ((*iter)->getType()->getAtomicNumber() == 1)){ // skip added hydrogen
    261         iter++;
    262       }
    263     }
    264   }
    265 }
     142///** Internal helper to create from each keyset a molecule
     143// *
     144// */
     145//void ExportGraph::prepareMolecule()
     146//{
     147//  size_t count = 0;
     148//  for(Graph::const_iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
     149//    KeySet test = (*runner).first;
     150//    LOG(2, "DEBUG: Fragment No." << (*runner).second.first << " with TEFactor "
     151//        << (*runner).second.second << ".");
     152//    BondFragments.insert(StoreFragmentFromKeySet(test, World::getInstance().getConfig()));
     153//    ++count;
     154//  }
     155//  LOG(1, "INFO: " << count << "/" << BondFragments.ListOfMolecules.size()
     156//      << " fragments generated from the keysets.");
     157//}
     158//
     159///** Stores a fragment from \a KeySet into \a molecule.
     160// * First creates the minimal set of atoms from the KeySet, then creates the bond structure from the complete
     161// * molecule and adds missing hydrogen where bonds were cut.
     162// * \param &Leaflet pointer to KeySet structure
     163// * \param IsAngstroem whether we have Ansgtroem or bohrradius
     164// * \return pointer to constructed molecule
     165// */
     166//molecule * ExportGraph::StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem)
     167//{
     168//  Info info(__func__);
     169//  ListOfLocalAtoms_t SonList;
     170//  molecule *Leaf = World::getInstance().createMolecule();
     171//
     172//  StoreFragmentFromKeySet_Init(Leaf, Leaflet, SonList);
     173//  // create the bonds between all: Make it an induced subgraph and add hydrogen
     174////  LOG(2, "Creating bonds from father graph (i.e. induced subgraph creation).");
     175//  CreateInducedSubgraphOfFragment(Leaf, SonList, IsAngstroem);
     176//
     177//  //Leaflet->Leaf->ScanForPeriodicCorrection(out);
     178//  return Leaf;
     179//}
     180//
     181///** Initializes some value for putting fragment of \a *mol into \a *Leaf.
     182// * \param *Leaf fragment molecule
     183// * \param &Leaflet pointer to KeySet structure
     184// * \param SonList calloc'd list which atom of \a *Leaf is a son of which atom in \a *mol
     185// * \return number of atoms in fragment
     186// */
     187//int ExportGraph::StoreFragmentFromKeySet_Init(molecule *Leaf, KeySet &Leaflet, ListOfLocalAtoms_t &SonList)
     188//{
     189//  atom *FatherOfRunner = NULL;
     190//
     191//  // first create the minimal set of atoms from the KeySet
     192//  World &world = World::getInstance();
     193//  int size = 0;
     194//  for(KeySet::const_iterator runner = Leaflet.begin(); runner != Leaflet.end(); runner++) {
     195//    FatherOfRunner = world.getAtom(AtomById(*runner));  // find the id
     196//    SonList.insert( std::make_pair(FatherOfRunner->getNr(), Leaf->AddCopyAtom(FatherOfRunner) ) );
     197//    size++;
     198//  }
     199//  return size;
     200//}
     201//
     202///** Creates an induced subgraph out of a fragmental key set, adding bonds and hydrogens (if treated specially).
     203// * \param *Leaf fragment molecule
     204// * \param IsAngstroem whether we have Ansgtroem or bohrradius
     205// * \param SonList list which atom of \a *Leaf is another atom's son
     206// */
     207//void ExportGraph::CreateInducedSubgraphOfFragment(molecule *Leaf, ListOfLocalAtoms_t &SonList, bool IsAngstroem)
     208//{
     209//  bool LonelyFlag = false;
     210//  atom *OtherFather = NULL;
     211//  atom *FatherOfRunner = NULL;
     212//
     213//  // we increment the iter just before skipping the hydrogen
     214//  // as we use AddBond, we cannot have a const_iterator here
     215//  for (molecule::iterator iter = Leaf->begin(); iter != Leaf->end();) {
     216//    LonelyFlag = true;
     217//    FatherOfRunner = (*iter)->father;
     218//    ASSERT(FatherOfRunner,"Atom without father found");
     219//    if (SonList.find(FatherOfRunner->getNr()) != SonList.end())  {  // check if this, our father, is present in list
     220//      // create all bonds
     221//      const BondList& ListOfBonds = FatherOfRunner->getListOfBonds();
     222//      for (BondList::const_iterator BondRunner = ListOfBonds.begin();
     223//          BondRunner != ListOfBonds.end();
     224//          ++BondRunner) {
     225//        OtherFather = (*BondRunner)->GetOtherAtom(FatherOfRunner);
     226//        if (SonList.find(OtherFather->getNr()) != SonList.end()) {
     227////          LOG(2, "INFO: Father " << *FatherOfRunner << " of son " << *SonList[FatherOfRunner->getNr()]
     228////              << " is bound to " << *OtherFather << ", whose son is "
     229////              << *SonList[OtherFather->getNr()] << ".");
     230//          if (OtherFather->getNr() > FatherOfRunner->getNr()) { // add bond (Nr check is for adding only one of both variants: ab, ba)
     231//            std::stringstream output;
     232////            output << "ACCEPT: Adding Bond: "
     233//            output << Leaf->AddBond((*iter), SonList[OtherFather->getNr()], (*BondRunner)->getDegree());
     234////            LOG(3, output.str());
     235//            //NumBonds[(*iter)->getNr()]++;
     236//          } else {
     237////            LOG(3, "REJECY: Not adding bond, labels in wrong order.");
     238//          }
     239//          LonelyFlag = false;
     240//        } else {
     241////          LOG(2, "INFO: Father " << *FatherOfRunner << " of son " << *SonList[FatherOfRunner->getNr()]
     242////              << " is bound to " << *OtherFather << ", who has no son in this fragment molecule.");
     243//          if (saturation == DoSaturate) {
     244////          LOG(3, "ACCEPT: Adding Hydrogen to " << (*iter)->Name << " and a bond in between.");
     245//            if (!Leaf->AddHydrogenReplacementAtom((*BondRunner), (*iter), FatherOfRunner, OtherFather, IsAngstroem))
     246//              exit(1);
     247//          } else if ((treatment == ExcludeHydrogen) && (OtherFather->getElementNo() == (atomicNumber_t)1)) {
     248//            // just copy the atom if it's a hydrogen
     249//            atom * const OtherWalker = Leaf->AddCopyAtom(OtherFather);
     250//            Leaf->AddBond((*iter), OtherWalker, (*BondRunner)->getDegree());
     251//          }
     252//          //NumBonds[(*iter)->getNr()] += Binder->getDegree();
     253//        }
     254//      }
     255//    } else {
     256//      ELOG(1, "Son " << (*iter)->getName() << " has father " << FatherOfRunner->getName() << " but its entry in SonList is " << SonList[FatherOfRunner->getNr()] << "!");
     257//    }
     258//    if ((LonelyFlag) && (Leaf->getAtomCount() > 1)) {
     259//      LOG(0, **iter << "has got bonds only to hydrogens!");
     260//    }
     261//    ++iter;
     262//    if (saturation == DoSaturate) {
     263//      while ((iter != Leaf->end()) && ((*iter)->getType()->getAtomicNumber() == 1)){ // skip added hydrogen
     264//        iter++;
     265//      }
     266//    }
     267//  }
     268//}
Note: See TracChangeset for help on using the changeset viewer.