Changeset f5fa48 for src/Fragmentation/Exporters/SaturatedFragment.cpp
- Timestamp:
- Aug 20, 2014, 1:06:47 PM (11 years ago)
- Children:
- d635829
- Parents:
- ce0ca4
- git-author:
- Frederik Heber <heber@…> (07/18/14 17:08:09)
- git-committer:
- Frederik Heber <heber@…> (08/20/14 13:06:47)
- File:
- 
      - 1 edited
 
 - 
          
  src/Fragmentation/Exporters/SaturatedFragment.cpp (modified) (8 diffs)
 
Legend:
- Unmodified
- Added
- Removed
- 
      src/Fragmentation/Exporters/SaturatedFragment.cpprce0ca4 rf5fa48 65 65 HydrogenPool &_hydrogens, 66 66 const enum HydrogenTreatment _treatment, 67 const enum HydrogenSaturation _saturation) : 67 const enum HydrogenSaturation _saturation, 68 const GlobalSaturationPositions_t &_globalsaturationpositions) : 68 69 container(_container), 69 70 set(_set), … … 79 80 container.insert(set); 80 81 81 // prepare saturation hydrogens 82 saturate(); 82 // prepare saturation hydrogens, either using global information 83 // or if not given, local information (created in the function) 84 if (_globalsaturationpositions.empty()) 85 saturate(); 86 else 87 saturate(_globalsaturationpositions); 83 88 } 84 89 … … 101 106 } 102 107 103 void SaturatedFragment::saturate() 104 { 105 // so far, we just have a set of keys. Hence, convert to atom refs 106 // and gather all atoms in a vector 107 std::vector<atom *>atoms;108 for (KeySet::const_iterator iter = FullMolecule.begin();109 iter != FullMolecule.end();108 typedef std::vector<atom *> atoms_t; 109 110 atoms_t gatherAllAtoms(const KeySet &_FullMolecule) 111 { 112 atoms_t atoms; 113 for (KeySet::const_iterator iter = _FullMolecule.begin(); 114 iter != _FullMolecule.end(); 110 115 ++iter) { 111 116 atom * const Walker = World::getInstance().getAtom(AtomById(*iter)); 112 117 ASSERT( Walker != NULL, 113 " SaturatedFragment::OutputConfig() - id "118 "gatherAllAtoms() - id " 114 119 +toString(*iter)+" is unknown to World."); 115 120 atoms.push_back(Walker); … … 117 122 LOG(4, "DEBUG: We have gathered the following atoms: " << atoms); 118 123 119 // bool LonelyFlag = false; 120 // go through each atom of the fragment and gather all cut bonds in list 121 typedef std::map<atom *, BondList > CutBonds_t; 124 return atoms; 125 } 126 127 typedef std::map<atom *, BondList > CutBonds_t; 128 129 CutBonds_t gatherCutBonds( 130 const atoms_t &_atoms, 131 const KeySet &_set, 132 const enum HydrogenTreatment _treatment, 133 KeySet &_FullMolecule) 134 { 135 // bool LonelyFlag = false; 122 136 CutBonds_t CutBonds; 123 for ( std::vector<atom *>::const_iterator iter =atoms.begin();124 iter != atoms.end();137 for (atoms_t::const_iterator iter = _atoms.begin(); 138 iter != _atoms.end(); 125 139 ++iter) { 126 140 atom * const Walker = *iter; … … 135 149 atom * const OtherWalker = (*BondRunner)->GetOtherAtom(Walker); 136 150 // if other atom is in key set 137 if ( set.find(OtherWalker->getId()) !=set.end()) {151 if (_set.find(OtherWalker->getId()) != _set.end()) { 138 152 LOG(4, "DEBUG: Walker " << *Walker << " is bound to " << *OtherWalker << "."); 139 153 // if (OtherWalker->getId() > Walker->getId()) { // add bond (Nr check is for adding only one of both variants: ab, ba) … … 150 164 LOG(4, "DEBUG: Walker " << *Walker << " is bound to " 151 165 << *OtherWalker << ", who is not in this fragment molecule."); 152 if (( treatment == ExcludeHydrogen) && (OtherWalker->getElementNo() == (atomicNumber_t)1)) {166 if ((_treatment == ExcludeHydrogen) && (OtherWalker->getElementNo() == (atomicNumber_t)1)) { 153 167 LOG(4, "REJECT: " << *OtherWalker << " is a hydrogen, that are excluded from the set."); 154 FullMolecule.insert(OtherWalker->getId());168 _FullMolecule.insert(OtherWalker->getId()); 155 169 } else { 156 170 LOG(3, "ACCEPT: Adding " << **BondRunner << " as a cut bond."); … … 162 176 } 163 177 LOG(4, "DEBUG: We have gathered the following CutBonds: " << CutBonds); 178 179 return CutBonds; 180 } 181 182 void SaturatedFragment::saturate() 183 { 184 // so far, we just have a set of keys. Hence, convert to atom refs 185 // and gather all atoms in a vector 186 std::vector<atom *> atoms = gatherAllAtoms(FullMolecule); 187 188 // go through each atom of the fragment and gather all cut bonds in list 189 CutBonds_t CutBonds = gatherCutBonds(atoms, set, treatment, FullMolecule); 164 190 165 191 // go through all cut bonds and replace with a hydrogen … … 172 198 if (!saturateAtom(Walker, atomiter->second)) 173 199 exit(1); 200 } 201 } else 202 LOG(3, "INFO: We are not saturating cut bonds."); 203 } 204 205 void SaturatedFragment::saturate( 206 const GlobalSaturationPositions_t &_globalsaturationpositions) 207 { 208 // so far, we just have a set of keys. Hence, convert to atom refs 209 // and gather all atoms in a vector 210 std::vector<atom *> atoms = gatherAllAtoms(FullMolecule); 211 212 // go through each atom of the fragment and gather all cut bonds in list 213 CutBonds_t CutBonds = gatherCutBonds(atoms, set, treatment, FullMolecule); 214 215 // go through all cut bonds and replace with a hydrogen 216 if (saturation == DoSaturate) { 217 for (CutBonds_t::const_iterator atomiter = CutBonds.begin(); 218 atomiter != CutBonds.end(); ++atomiter) { 219 atom * const Walker = atomiter->first; 220 LOG(4, "DEBUG: We are now saturating dangling bonds of " << *Walker); 221 222 // gather set of positions for this atom from global map 223 GlobalSaturationPositions_t::const_iterator mapiter = 224 _globalsaturationpositions.find(Walker->getId()); 225 ASSERT( mapiter != _globalsaturationpositions.end(), 226 "SaturatedFragment::saturate() - no global information for " 227 +toString(*Walker)); 228 const SaturationsPositionsPerNeighbor_t &saturationpositions = 229 mapiter->second; 230 231 // go through all cut bonds for this atom 232 for (BondList::const_iterator bonditer = atomiter->second.begin(); 233 bonditer != atomiter->second.end(); ++bonditer) { 234 atom * const OtherWalker = (*bonditer)->GetOtherAtom(Walker); 235 236 // get positions from global map 237 SaturationsPositionsPerNeighbor_t::const_iterator positionsiter = 238 saturationpositions.find(OtherWalker->getId()); 239 ASSERT(positionsiter != saturationpositions.end(), 240 "SaturatedFragment::saturate() - no information on bond neighbor " 241 +toString(*OtherWalker)+" to atom "+toString(*Walker)); 242 ASSERT(!positionsiter->second.empty(), 243 "SaturatedFragment::saturate() - no positions for saturating bond to" 244 +toString(*OtherWalker)+" to atom "+toString(*Walker)); 245 246 // get typical bond distance from elements database 247 double BondDistance = Walker->getType()->getHBondDistance(positionsiter->second.size()-1); 248 if (BondDistance < 0.) { 249 ELOG(2, "saturateAtoms() - no typical hydrogen bond distance of degree " 250 +toString(positionsiter->second.size())+" for element " 251 +toString(Walker->getType()->getName())); 252 // try bond degree 1 distance 253 BondDistance = Walker->getType()->getHBondDistance(1-1); 254 if (BondDistance < 0.) { 255 ELOG(1, "saturateAtoms() - no typical hydrogen bond distance for element " 256 +toString(Walker->getType()->getName())); 257 BondDistance = 1.; 258 } 259 } 260 ASSERT( BondDistance > 0., 261 "SaturatedFragment::saturate() - negative bond distance"); 262 263 // place hydrogen at each point 264 LOG(4, "DEBUG: Places to saturate for atom " << *OtherWalker 265 << " are " << positionsiter->second); 266 atom * const father = Walker; 267 for (SaturationsPositions_t::const_iterator positer = positionsiter->second.begin(); 268 positer != positionsiter->second.end(); ++positer) { 269 const atom& hydrogen = 270 setHydrogenReplacement(Walker, *positer, BondDistance, father); 271 FullMolecule.insert(hydrogen.getId()); 272 } 273 } 174 274 } 175 275 } else 
  Note:
 See   TracChangeset
 for help on using the changeset viewer.
  
