5 #ifndef BALL_STRUCTURE_SIMPLEMOLECULARGRAPH_H
6 #define BALL_STRUCTURE_SIMPLEMOLECULARGRAPH_H
8 #ifndef BALL_KERNEL_ATOM_H
12 #ifndef BALL_KERNEL_BOND_H
16 #ifndef BALL_STRUCTURE_MOLECULE_H
20 #ifndef BALL_STRUCTURE_FRAGMENT_H
31 template <
typename Node,
typename Edge>
34 template <
typename Node,
typename Edge>
40 template <
typename Node,
typename Edge>
54 typedef typename std::list<EdgeItem<Node, Edge>*>::iterator
Iterator;
56 typedef typename std::list<EdgeItem<Node, Edge>*>::const_iterator
ConstIterator;
66 void setData(
const Node& data) ;
92 template <
typename Node,
typename Edge>
98 typedef typename std::list<NodeItem<Node, Edge>*>::iterator
Iterator;
99 typedef typename std::list<NodeItem<Node, Edge>*>::const_iterator
ConstIterator;
130 template <
typename Node,
typename Edge>
132 : bond_(const_cast<
Bond*>(&bond))
136 template <
typename Node,
typename Edge>
138 : bond_(const_cast<
Bond*>(&bond)),
144 template <
typename Node,
typename Edge>
204 template <
typename Node,
typename Edge>
214 template <
typename Node,
typename Edge>
228 for (ai = molecule.beginAtom(); +ai; ++ai)
230 for (bi = ai->beginBond(); +bi; ++bi)
232 if (bi->getFirstAtom() == &*ai)
240 template <
typename Node,
typename Edge>
244 Atom* atom_ptr =
const_cast<Atom*
>(&atom);
246 if (atom_to_node_.has(atom_ptr))
252 atom_to_node_.insert(std::pair<Atom*, NodeItemType*>(atom_ptr, &(nodes_.back())));
257 template <
typename Node,
typename Edge>
266 if (!atom_to_node_.has(first) || !atom_to_node_.has(second))
272 if (bond_to_edge_.has(const_cast<Bond*>(&bond)))
281 edges_.push_back(
EdgeItemType(bond, first_item, second_item));
282 bond_to_edge_.insert(std::pair<Bond*, EdgeItemType*>(const_cast<Bond*>(&bond), &edges_.back()));
289 template <
typename Node,
typename Edge>
290 std::ostream& operator << (std::ostream& os, const TSimpleMolecularGraph<Node, Edge>& G)
292 os <<
"Nodes:" << std::endl;
296 for (; node != G.
endNode(); ++node)
298 os << count++ <<
": " << node->getAtom()->getFullName() <<
" [" << node->getDegree() <<
"] '" << node->getAtom() <<
"'" << std::endl;
301 os <<
"Edges:" << std::endl;
305 for (; edge != G.
endEdge(); ++edge)
307 os << count++ <<
": " << edge->getSource().getAtom() <<
"-" << edge->getTarget().getAtom() <<
" '" << edge->getBond() <<
"'" << std::endl;
313 template <
typename Node,
typename Edge>
316 if (!atom_to_node_.has(const_cast<Atom*>(&atom)))
321 return deleteNode(*atom_to_node_[const_cast<Atom*>(&atom)]);
324 template <
typename Node,
typename Edge>
327 if (!bond_to_edge_.has(const_cast<Bond*>(&bond)))
332 return deleteEdge(*bond_to_edge_[const_cast<Bond*>(&bond)]);
335 template <
typename Node,
typename Edge>
338 NodeIterator node_it = std::find(nodes_.begin(), nodes_.end(), node);
339 if (node_it == nodes_.end())
348 typename NodeItemType::Iterator edge(node.
begin());
349 for (; edge != node.
end(); ++edge)
356 atom_to_node_.erase(node_it->getAtom());
357 nodes_.erase(node_it);
362 template <
typename Node,
typename Edge>
365 typename std::list<EdgeItemType>::iterator edge_it = std::find(edges_.begin(), edges_.end(), edge);
366 if (edge_it == edges_.end())
370 edge.getSource().deleteEdge_(&edge);
371 edge.getTarget().deleteEdge_(&edge);
372 bond_to_edge_.erase(edge_it->getBond());
373 edges_.erase(edge_it);
379 template <
typename Node,
typename Edge>
386 template <
typename Node,
typename Edge>
389 : atom_(const_cast<
Atom*>(&atom))
393 template <
typename Node,
typename Edge>
400 template <
typename Node,
typename Edge>
408 template <
typename Node,
typename Edge>
416 template <
typename Node,
typename Edge>
423 template <
typename Node,
typename Edge>
430 template <
typename Node,
typename Edge>
434 return adjacent_edges_.begin();
437 template <
typename Node,
typename Edge>
441 return adjacent_edges_.begin();
444 template <
typename Node,
typename Edge>
448 return adjacent_edges_.end();
451 template <
typename Node,
typename Edge>
455 return adjacent_edges_.end();
458 template <
typename Node,
typename Edge>
462 return (
Size)adjacent_edges_.size();
465 template <
typename Node,
typename Edge>
469 return (atom_ == item.
atom_);
472 template <
typename Node,
typename Edge>
476 return (atom_ != item.
atom_);
479 template <
typename Node,
typename Edge>
483 Iterator it(std::find(adjacent_edges_.begin(), adjacent_edges_.end(), item));
484 if (it != adjacent_edges_.end())
486 adjacent_edges_.erase(it);
490 template <
typename Node,
typename Edge>
495 return nodes_.size();
498 template <
typename Node,
typename Edge>
503 return edges_.size();
509 #endif // BALL_STRUCTURE_MOLECULARGRAPH_H
const Node & getData() const
NodeItem< Node, Edge > NodeItemType
NodeItemType & getSource()
NodeConstIterator endNode() const
EdgeConstIterator beginEdge() const
EdgeConstIterator endEdge() const
bool deleteNode(NodeItemType &node)
const Atom * getFirstAtom() const
Return a pointer to the first atom.
EdgeItemType & getEdge(Position index)
void setData(const Edge &data)
void setData(const Node &data)
bool operator!=(const EdgeItem &item) const
std::list< EdgeItemType * > adjacent_edges_
Size getNumberOfEdges() const
EdgeItem< Node, Edge > EdgeItemType
void deleteEdge_(EdgeItemType *item)
NodeItem< Node, Edge > NodeItemType
std::list< NodeItem< Node, Edge > * >::const_iterator ConstIterator
HashMap< Bond *, EdgeItemType * > bond_to_edge_
std::list< EdgeItemType > edges_
const Bond * getBond() const
bool has(const Bond &bond) const
std::list< NodeItem< Node, Edge > * >::iterator Iterator
EdgeItem< Node, Edge > EdgeItemType
NodeItemType & getNode(Position index)
const NodeItemType & getTarget() const
const Atom * getAtom() const
const NodeItemType & getSource() const
HashMap< Atom *, NodeItemType * > atom_to_node_
std::list< EdgeItem< Node, Edge > * >::const_iterator ConstIterator
bool operator==(const EdgeItem &item) const
NodeItemType & getTarget()
bool deleteEdge(EdgeItemType &edge)
std::list< NodeItemType > nodes_
const Atom * getSecondAtom() const
Return a pointer to the second atom.
EdgeItem< Node, Edge > EdgeItemType
std::list< NodeItemType >::iterator NodeIterator
bool operator==(const NodeItem &item) const
std::list< NodeItemType >::const_iterator NodeConstIterator
std::list< EdgeItemType >::iterator EdgeIterator
NodeItem< Node, Edge > NodeItemType
NodeConstIterator beginNode() const
bool newEdge(const Bond &bond)
TSimpleMolecularGraph< Index, Index > SimpleMolecularGraph
std::list< EdgeItem< Node, Edge > * >::iterator Iterator
std::list< EdgeItemType >::const_iterator EdgeConstIterator
bool has(const Atom &atom) const
const NodeItemType & getNode(Position index) const
HashMap class based on the STL map (containing serveral convenience functions)
bool operator!=(const NodeItem &item) const
Size getNumberOfNodes() const
bool newNode(const Atom &atom)
const EdgeItemType & getEdge(Position index) const