Changeset 1c0b0b
- Timestamp:
- Oct 23, 2022, 9:08:55 AM (3 years ago)
- Branches:
- Candidate_v1.7.0, stable
- Children:
- 894040
- Parents:
- 0daef6
- git-author:
- Frederik Heber <frederik.heber@…> (10/19/22 19:38:02)
- git-committer:
- Frederik Heber <frederik.heber@…> (10/23/22 09:08:55)
- Location:
- src/Graph
- Files:
-
- 5 edited
-
BoostGraphCreator.cpp (modified) (2 diffs)
-
BoostGraphCreator.hpp (modified) (1 diff)
-
Graph6Writer.cpp (modified) (2 diffs)
-
Graph6Writer.hpp (modified) (2 diffs)
-
unittests/BoostGraphCreatorUnitTest.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/Graph/BoostGraphCreator.cpp
r0daef6 r1c0b0b 75 75 76 76 void BoostGraphCreator::createFromAtoms( 77 const std::vector< atom *> &_atoms,77 const std::vector<const atom *> &_atoms, 78 78 const predicate_t &_pred) 79 79 { … … 88 88 std::sort(atomids.begin(), atomids.end()); 89 89 const predicate_t predicate = boost::bind(inSetPredicate, boost::ref(atomids), _1); 90 createFromRange<std::vector< atom *>::const_iterator>(91 const_cast<const std::vector< atom *> &>(_atoms).begin(),92 const_cast<const std::vector< atom *> &>(_atoms).end(),90 createFromRange<std::vector<const atom *>::const_iterator>( 91 const_cast<const std::vector<const atom *> &>(_atoms).begin(), 92 const_cast<const std::vector<const atom *> &>(_atoms).end(), 93 93 _atoms.size(), 94 94 boost::bind(predicateAnd, _pred, predicate, _1)); -
src/Graph/BoostGraphCreator.hpp
r0daef6 r1c0b0b 87 87 */ 88 88 void createFromAtoms( 89 const std::vector< atom *> &_atoms,89 const std::vector<const atom *> &_atoms, 90 90 const predicate_t &_pred); 91 91 -
src/Graph/Graph6Writer.cpp
r0daef6 r1c0b0b 44 44 45 45 #include "Atom/atom.hpp" 46 #include "Descriptors/AtomIdDescriptor.hpp" 46 47 #include "Element/element.hpp" 48 #include "Graph/BoostGraphCreator.hpp" 49 #include "Graph/BreadthFirstSearchGatherer.hpp" 50 #include "World.hpp" 47 51 48 52 //#include "CodePatterns/MemDebug.hpp" … … 116 120 ASSERT( value==0, 117 121 "Graph6Writer::write_graph6() - byte is not null, i.e. chars left to write?"); 118 ASSERT( bytes_written == ( int)ceil(n*(n-1)/12.0f),122 ASSERT( bytes_written == (unsigned int)ceil(n*(n-1)/12.0f), 119 123 "Graph6Writer::write_graph6() - unexpected number of bytes written"); 120 124 } 121 125 126 /** 127 * Picks a non-hydrogen from all hydrogen atoms in the current set 128 * of atoms. 129 * 130 * Returns -1 if none could be found. 131 */ 132 atomId_t Graph6Writer::getBoundaryNonHydrogen() const { 133 atomId_t start_atom_id = -1; 134 int bond_degree = 16; 135 for(std::vector<const atom *>::const_iterator iter = _atoms.begin(); 136 iter != _atoms.end(); ++iter) { 137 const atom *walker = *iter; 138 if (walker->getElement().getSymbol() == "H") { 139 const BondList& bond_list = walker->getListOfBonds(); 140 assert(bond_list.size() == 1); 141 const atom *other = bond_list.front().get()->GetOtherAtom(walker); 142 const int number_of_bonds = other->getListOfBonds().size(); 143 if ((other->getElement().getSymbol() != "H") && (bond_degree > number_of_bonds)) { 144 start_atom_id = other->getId(); 145 bond_degree = number_of_bonds; 146 } 147 } 148 } 149 return start_atom_id; 150 } 151 152 bool OnlyNonHydrogens(const bond &_bond) { 153 return _bond.HydrogenBond == 0; 154 } 155 122 156 void Graph6Writer::write_elementlist(std::ostream& out) { 123 for (std::vector<const atom *>::const_iterator iter = _atoms.begin(); 124 iter != _atoms.end(); ++iter) { 125 if (iter != _atoms.begin()) 157 /** Execute a Breadth-First Search discovery from one terminal atom (e.g., 158 * pick random hydrogen and then it's bond-neighbor if it is non-hydrogen). 159 * Then return the element list in that ordering. 160 * 161 * The graph6 string does not account for the inherent graph symmetries 162 * (e.g., BW having 123<->321 but not 123<->132 symmetry). 163 */ 164 // pick bond neighbor of a hydrogen atom 165 atomId_t start_atom_id = getBoundaryNonHydrogen(); 166 if (start_atom_id == (unsigned int)-1) { 167 // fall back to first atom in list 168 start_atom_id = _atoms.front()->getId(); 169 } 170 171 // do an unlimited BFS and get set of nodes, ordered by discovery level 172 BoostGraphCreator graphCreator; 173 graphCreator.createFromAtoms(_atoms, OnlyNonHydrogens); 174 BreadthFirstSearchGatherer gatherer(graphCreator); 175 const std::vector<atomId_t> gathered_atoms = gatherer(start_atom_id); 176 177 // print all nodes 178 const World& world = World::getConstInstance(); 179 for (std::vector<atomId_t>::const_iterator iter = gathered_atoms.begin(); 180 iter != gathered_atoms.end(); ++iter) { 181 if (iter != gathered_atoms.begin()) 126 182 out << ' '; 127 out << (*iter)->getElement().getSymbol(); 183 const atom* walker = world.getAtom(AtomById(*iter)); 184 assert(walker != NULL); 185 out << walker->getElement().getSymbol(); 128 186 } 129 187 } -
src/Graph/Graph6Writer.hpp
r0daef6 r1c0b0b 17 17 #include <iosfwd> 18 18 #include <vector> 19 20 #include "types.hpp" 19 21 20 22 class atom; … … 41 43 42 44 void write_elementlist(std::ostream& out); 45 46 private: 47 atomId_t getBoundaryNonHydrogen() const; 43 48 }; 44 49 -
src/Graph/unittests/BoostGraphCreatorUnitTest.cpp
r0daef6 r1c0b0b 164 164 void BoostGraphCreatorTest::createFromAtomsTest() 165 165 { 166 std::vector< atom *> atoms;166 std::vector<const atom *> atoms; 167 167 std::copy(TestMolecule->begin(), TestMolecule->end(), std::back_inserter(atoms)); 168 168 BGCreator->createFromAtoms(atoms, BreadthFirstSearchGatherer::AlwaysTruePredicate);
Note:
See TracChangeset
for help on using the changeset viewer.
