BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
smartsParser.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_STRUCTURE_SMARTES_PARSER_H
6 #define BALL_STRUCTURE_SMARTES_PARSER_H
7 
8 #ifndef BALL_COMMON_H
9  # include <BALL/common.h>
10 #endif
11 
12 #include <map>
13 #include <set>
14 
15 // needed for MSVC:
16 #undef CW_DEFAULT
17 
18 namespace BALL
19 {
20  // forward declarations
21  class Bond;
22  class Atom;
23  class Element;
24 
36  {
37  public:
38 
40  {
41  ANY_ZE = 1,
43  Z,
44  E
45  };
46 
49  {
50  CHIRAL_CLASS_UNSPECIFIED = 1,
53  CW_DEFAULT, // TH
55  CCW_DEFAULT, // TH
57  CW_TH, // tetrahdral
61  CW_AL, // allene-like
65  CW_SP, // square planar
69  CW_TB, //trigonal bipyramidal
73  CW_OH, // octahedral
76  CCW_OH_OR_UNSPECIFIED
77  };
78 
87  {
88  AND,
89  OR,
91  NOOP
92  };
93 
94 
96  class SPAtom;
97 
106  {
107  public:
108 
111  {
112  SINGLE = 1,
123  ANY
124  };
125 
129  SPBond();
131 
133  SPBond(SPBondOrder bond_order);
134 
136  SPBond(SPAtom* first, SPAtom* second, SPBondOrder bond_order);
137 
139  virtual ~SPBond() ;
141 
145  ZEIsomerType getZEType() const { return ze_type_; }
147 
149  void setZEType(ZEIsomerType type) { ze_type_ = type; }
150 
152  void setBondOrder(SPBondOrder bond_order);
153 
155  SPBondOrder getBondOrder() const { return bond_order_; }
156 
158  bool isNot() const { return not_; }
159 
161  void setNot(bool is_not) { not_ = is_not; }
162 
163  // returns true if the SPBond matches the given bond
164  bool equals(const Bond* bond) const;
166 
167  protected:
168 
171 
174 
176  bool not_;
177  };
178 
189  {
190  public:
191 
194  {
195  ISOTOPE = 1,
209  SYMBOL
210  };
211 
214  {
219  };
220 
222  struct Property
223  {
224  public:
225 
229  Property(PropertyType type, int value);
231 
233  Property(PropertyType type, bool value);
234 
236  Property(PropertyType type, const Element* value);
237 
239  Property(PropertyType type, ChiralClass value);
240 
242  virtual ~Property();
244 
246  void operator = (const Property& rhs);
247 
251  PropertyType getType() const { return type_; }
253 
255  PropertyValue getValue() const { return value_; }
257 
258  private:
259 
261  Property();
262 
264  PropertyType type_;
265 
267  PropertyValue value_;
268  };
269 
307  SPAtom();
309 
311  SPAtom(const String& symbol);
312 
314  virtual ~SPAtom() ;
316 
317 
321  void setProperty(PropertyType type, int int_value);
323 
325  void setProperty(PropertyType type, bool flag);
326 
328  void setProperty(PropertyType type, const Element* element);
329 
331  void setProperty(PropertyType type, ChiralClass chirality);
332 
334  void setProperty(Property property);
335 
337  void addPropertiesFromSPAtom(SPAtom* sp_atom);
338 
340  void setNotProperty(PropertyType type);
341 
343  bool hasProperty(PropertyType type) const;
344 
346  PropertyValue getProperty(PropertyType type);
347 
349  Size countProperties() const;
350 
352  Size getDefaultValence(const Atom* atom) const;
353 
355  Size countRealValences(const Atom* atom) const;
356 
358  Size getNumberOfImplicitHydrogens(const Atom* atom) const;
360 
364  bool equals(const Atom* atom) const;
367 
368  protected:
369 
372 
374  std::map<PropertyType, PropertyValue> properties_;
375 
377  std::set<PropertyType> not_properties_;
378  };
379 
381  class SPNode;
382 
386  {
387  public:
388 
392  SPEdge();
394 
396  SPEdge(const SPEdge& sp_edge);
397 
399  virtual ~SPEdge();
401 
405  bool isInternal() const { return internal_; }
407 
409  void setInternal(bool internal) { internal_ = internal; }
410 
412  void setSPBond(SPBond* sp_bond) { bond_ = sp_bond; }
413 
415  SPBond* getSPBond() const { return bond_; }
416 
418  void setFirstSPNode(SPNode* first) { first_ = first; }
419 
421  SPNode* getFirstSPNode() const { return first_; }
422 
424  void setSecondSPNode(SPNode* second) { second_ = second; }
425 
427  SPNode* getSecondSPNode() const { return second_; }
428 
430  SPNode* getPartnerSPNode(SPNode* node) { return node == first_ ? second_ : first_; }
431 
433  bool isNot() const { return is_not_; }
434 
436  void setNot(bool is_not) { is_not_ = is_not; }
437 
439  void setFirstSPEdge(SPEdge* first) { first_edge_ = first; }
440 
442  SPEdge* getFirstSPEdge() const { return first_edge_; }
443 
445  void setSecondSPEdge(SPEdge* second) { second_edge_ = second; }
446 
448  SPEdge* getSecondSPEdge() const { return second_edge_; }
449 
451  void setLogicalOperator(LogicalOperator log_op) { log_op_ = log_op; }
452 
454  LogicalOperator getLogicalOperator() const { return log_op_; }
456 
457  protected:
458 
460  bool internal_;
461 
463  bool is_not_;
464 
467 
470 
473 
476 
479 
482  };
483 
487  {
488  public:
489 
493  typedef std::vector<SPEdge*>::iterator EdgeIterator;
495 
497  typedef std::vector<SPEdge*>::const_iterator EdgeConstIterator;
499 
500 
504  SPNode();
506 
508  SPNode(SPAtom* atom);
509 
511  SPNode(SPNode* first, LogicalOperator log_op, SPNode* second);
512 
514  SPNode(const SPNode& sp_node);
515 
517  virtual ~SPNode();
519 
520 
524  bool isInternal() const { return internal_; }
526 
528  void setInternal(bool internal) { internal_ = internal; }
529 
531  bool isRecursive() const { return recursive_; }
532 
534  void setRecursive(bool recursive);
535 
537  void setComponentNumber(int no) { component_no_ = no; }
538 
540  Size getComponentNumber() const { return component_no_; }
541 
543  SPAtom* getSPAtom() const { return sp_atom_; }
544 
546  void setSPAtom(SPAtom* sp_atom) { sp_atom_ = sp_atom; }
547 
549  SPEdge* getFirstEdge() const { return first_edge_; }
550 
552  void setFirstEdge(SPEdge* first) { first_edge_ = first; }
553 
555  SPEdge* getSecondEdge() const { return second_edge_; }
556 
558  void setSecondEdge(SPEdge* second) { second_edge_ = second; }
559 
561  bool getNot() const { return is_not_; }
562 
564  void setNot(bool is_not) { is_not_ = is_not; }
565 
566 
568  //void setInBrackets() { in_brackets_ = true; }
569 
571  void addSPEdge(SPEdge* sp_edge) { edges_.push_back(sp_edge); }
572 
574  void setLogicalOperator(LogicalOperator log_op) { log_op_ = log_op; }
575 
577  LogicalOperator getLogicalOperator() const { return log_op_; }
578 
580  Size countEdges() const { return edges_.size(); }
582 
586  EdgeIterator begin() { return edges_.begin(); }
588 
590  EdgeIterator end() { return edges_.end(); }
591 
593  EdgeConstIterator begin() const { return edges_.begin(); }
594 
596  EdgeConstIterator end() const { return edges_.end(); }
598 
599  protected:
600 
602  bool internal_;
603 
605  bool is_not_;
606 
609 
611  //bool in_brackets_;
612 
615 
617  std::vector<SPEdge*> edges_;
618 
621 
624 
627 
630  };
631 
632 
636  SmartsParser();
638 
640  SmartsParser(const SmartsParser& parser);
641 
643  virtual ~SmartsParser();
645 
651  void parse(const String& s)
652  throw(Exception::ParseError);
653 
657  SPAtom* createAtom(const String& symbol, bool in_bracket = false);
659 
661  void setRoot(SPNode* root) { root_ = root; }
662 
664  SPNode* getRoot() const { return root_; }
665 
667  void dumpTree();
668 
670  void clear();
671 
673  void addRingConnection(SPNode* spnode, Size index);
674 
676  std::map<Size, std::vector<SPNode*> > getRingConnections() const;
677 
679  void setSSSR(const std::vector<std::vector<Atom*> >& sssr);
680 
682  void setNeedsSSSR(bool needs_sssr) { needs_SSSR_ = needs_sssr; }
683 
685  bool getNeedsSSSR() const { return needs_SSSR_; }
686 
688  void setRecursive(bool recursive) { recursive_ = recursive; }
689 
691  bool isRecursive() const { return recursive_; }
692 
694  void setComponentGrouping(bool component_grouping) { component_grouping_ = component_grouping; }
695 
697  bool hasComponentGrouping() const { return component_grouping_; }
698 
700  struct State
701  {
704  const char* buffer;
705  };
706 
708  static State state;
709 
711  const std::set<SPNode*>& getNodes() const { return nodes_; }
712 
714  const std::set<SPEdge*>& getEdges() const { return edges_; }
715 
717  void addEdge(SPEdge* edge) { edges_.insert(edge); }
718 
720  void addNode(SPNode* node) { nodes_.insert(node); }
721 
723  bool hasRecursiveEdge(SPEdge* edge) const { return rec_edges_.find(edge) != rec_edges_.end(); }
724 
726  void addRecursiveEdge(SPEdge* edge) { rec_edges_.insert(edge); }
727 
729  void setNextComponentNumberToSubTree(SPNode* spnode);
731 
732  protected:
733 
736 
739 
742 
744  static vector<std::set<const Atom*> >* sssr_;
745 
747  void dumpTreeRecursive_(SPNode* node, Size depth);
748 
750  void dumpTreeRecursive_(SPEdge* edge, Size depth);
751 
753  std::map<Size, std::vector<SPNode*> > ring_connections_;
754 
757 
759  std::set<SPEdge*> edges_;
760 
762  std::set<SPNode*> nodes_;
763 
765  std::set<SPEdge*> rec_edges_;
766 
769 
772  };
773 
774 } // namespace BALL
775 
776 #endif // BALL_STRUCTURE_SMARTS_PARSER_H
777 
bool recursive_
recursive flag
Definition: smartsParser.h:738
SmartsParser * current_parser
Definition: smartsParser.h:703
static vector< std::set< const Atom * > > * sssr_
the sssr
Definition: smartsParser.h:744
SPBondOrder
the bond orders supported by SMARTS-patterns
Definition: smartsParser.h:110
static State state
static member for the parser itself
Definition: smartsParser.h:708
BALL_EXTERN_VARIABLE const double E
Euler's number - base of the natural logarithm.
Definition: constants.h:38
SPNode * second_
second SPNode
Definition: smartsParser.h:469
ZEIsomerType ze_type_
Z/E isomer type.
Definition: smartsParser.h:170
bool getNot() const
returns the negation flag
Definition: smartsParser.h:561
const std::set< SPEdge * > & getEdges() const
returns the edges stored in the tree
Definition: smartsParser.h:714
void setFirstSPNode(SPNode *first)
set the first SPNode of this edge
Definition: smartsParser.h:418
PropertyValue getValue() const
returns the value of the property
Definition: smartsParser.h:255
void setFirstEdge(SPEdge *first)
sets the first edge (for tree use)
Definition: smartsParser.h:552
void setSPAtom(SPAtom *sp_atom)
set the associated SPAtom
Definition: smartsParser.h:546
void setSecondEdge(SPEdge *second)
sets the second edge (for tree use)
Definition: smartsParser.h:558
bool recursive_
recursive flag
Definition: smartsParser.h:608
bool needs_SSSR_
sssr needed flag
Definition: smartsParser.h:735
LogicalOperator getLogicalOperator() const
returns the logical operator of the SPNode
Definition: smartsParser.h:577
bool isNot() const
return true if a general negation is set
Definition: smartsParser.h:158
Atom * atom_
the atom which this sp_atom belongs to
Definition: smartsParser.h:371
void setComponentGrouping(bool component_grouping)
sets the component level flag
Definition: smartsParser.h:694
bool hasRecursiveEdge(SPEdge *edge) const
returns true if the tree has the given recursive edge
Definition: smartsParser.h:723
bool isRecursive() const
returns true if the tree represents a recursive SMARTS pattern
Definition: smartsParser.h:691
void setLogicalOperator(LogicalOperator log_op)
sets the logical operator associated with the SPNode
Definition: smartsParser.h:574
SPBondOrder getBondOrder() const
returns the bond order
Definition: smartsParser.h:155
SPNode * first_
first SPNode
Definition: smartsParser.h:466
void addSPEdge(SPEdge *sp_edge)
flag whether the pattern is in brackets
Definition: smartsParser.h:571
std::set< SPNode * > nodes_
the nodes
Definition: smartsParser.h:762
EdgeConstIterator begin() const
non-mutable access to begin of edges list
Definition: smartsParser.h:593
SPAtom * sp_atom_
SPAtom associated with this SPNode.
Definition: smartsParser.h:626
SPNode * root_
the root node of the tree
Definition: smartsParser.h:768
std::vector< SPEdge * >::iterator EdgeIterator
non-constant edge iterator
Definition: smartsParser.h:494
std::set< PropertyType > not_properties_
the properties which are negated
Definition: smartsParser.h:377
BALL_SIZE_TYPE Property
ChiralClass
chiral class definitions CW = clock wise, CCW = counter clock wise
Definition: smartsParser.h:48
LogicalOperator getLogicalOperator() const
returns the asociated logical operator (for the child edges)
Definition: smartsParser.h:454
SPEdge * getSecondEdge() const
returns the second edge (for tree use)
Definition: smartsParser.h:555
SPEdge * first_edge_
first SPEdge
Definition: smartsParser.h:475
std::map< PropertyType, PropertyValue > properties_
the properties of this SPAtom
Definition: smartsParser.h:374
Smarts Parser Atom class.
Definition: smartsParser.h:188
SPAtom * getSPAtom() const
returns the associated SPAtom
Definition: smartsParser.h:543
void setNeedsSSSR(bool needs_sssr)
sets the sssr needed flag
Definition: smartsParser.h:682
LogicalOperator log_op_
in brackets flag
Definition: smartsParser.h:614
Representation of a node in the smarts parser graph.
Definition: smartsParser.h:486
void setInternal(bool internal)
set this edge to a internal edge
Definition: smartsParser.h:409
SPBond * bond_
associated bond
Definition: smartsParser.h:472
bool isNot() const
returns true if negation is enabled
Definition: smartsParser.h:433
SPEdge * getFirstSPEdge() const
returns the first SPEdge (first tree child)
Definition: smartsParser.h:442
void setComponentNumber(int no)
set the component no of the component level grouping
Definition: smartsParser.h:537
EdgeConstIterator end() const
non-mutable access to end of edges list
Definition: smartsParser.h:596
void setNot(bool is_not)
set the general negation to the bool given
Definition: smartsParser.h:161
std::set< SPEdge * > rec_edges_
the recursive edges
Definition: smartsParser.h:765
void setZEType(ZEIsomerType type)
sets the Z/E isomer type
Definition: smartsParser.h:149
Size countEdges() const
counts the number of edges
Definition: smartsParser.h:580
SPNode * getSecondSPNode() const
returns the second SPNode of this edge
Definition: smartsParser.h:427
void setSecondSPEdge(SPEdge *second)
set the second SPEdge (second tree child)
Definition: smartsParser.h:445
void addEdge(SPEdge *edge)
adds an edge to the tree
Definition: smartsParser.h:717
std::vector< SPEdge * >::const_iterator EdgeConstIterator
constant edge iterator
Definition: smartsParser.h:497
bool getNeedsSSSR() const
returns true if the SMARTS pattern contains ring related parts
Definition: smartsParser.h:685
Property struct of smarts parser atom.
Definition: smartsParser.h:222
bool internal_
internal flag
Definition: smartsParser.h:460
bool hasComponentGrouping() const
returns true if the component level grouping was enabled
Definition: smartsParser.h:697
Bond representation of the smarts parser.
Definition: smartsParser.h:105
const std::set< SPNode * > & getNodes() const
returns the eodes stored in the tree
Definition: smartsParser.h:711
bool component_grouping_
component level grouping flag
Definition: smartsParser.h:741
SPEdge * second_edge_
second edge
Definition: smartsParser.h:623
SPEdge * getSecondSPEdge() const
returns the second SPEdge (second tree child)
Definition: smartsParser.h:448
void setNot(bool is_not)
sets the negation flag
Definition: smartsParser.h:564
void setSPBond(SPBond *sp_bond)
sets the corresponding SPBond of this edge
Definition: smartsParser.h:412
SPBondOrder bond_order_
the bond order
Definition: smartsParser.h:173
void addRecursiveEdge(SPEdge *edge)
adds a recursive edge to the tree
Definition: smartsParser.h:726
SPNode * getRoot() const
returns the root SPNode of the tree
Definition: smartsParser.h:664
std::vector< SPEdge * > edges_
edges list
Definition: smartsParser.h:617
LogicalOperator log_op_
logical operator associated with the SPEdges
Definition: smartsParser.h:481
SPNode * getFirstSPNode() const
returns the first SPNode of this edge
Definition: smartsParser.h:421
void setLogicalOperator(LogicalOperator log_op)
sets the associated logical operator (for the child edges)
Definition: smartsParser.h:451
std::set< SPEdge * > edges_
the edges
Definition: smartsParser.h:759
SPEdge * first_edge_
first edge
Definition: smartsParser.h:620
bool internal_
internal flag
Definition: smartsParser.h:602
Parser state (used by the parser itself)
Definition: smartsParser.h:700
bool isRecursive() const
returns true if the SPNode is a recursive node (from recursive SMARTS)
Definition: smartsParser.h:531
std::map< Size, std::vector< SPNode * > > ring_connections_
the ring connection sorted by index of the SMARTS pattern
Definition: smartsParser.h:753
Edge representation of the smarts parser graph.
Definition: smartsParser.h:385
PropertyType
enum of all properties possible for a smarts parser atom
Definition: smartsParser.h:193
Size getComponentNumber() const
returns the component number
Definition: smartsParser.h:540
static SmartsParser * current_parser_
current instance
Definition: smartsParser.h:756
char Atom[5]
Definition: PDBdefs.h:257
possible types of the properties
Definition: smartsParser.h:213
int component_no_
component level
Definition: smartsParser.h:629
void setNot(bool is_not)
set the negation flag
Definition: smartsParser.h:436
void setFirstSPEdge(SPEdge *first)
set the first SPEdge (first tree child)
Definition: smartsParser.h:439
void setInternal(bool internal)
sets the internal flag
Definition: smartsParser.h:528
void addNode(SPNode *node)
adds a node to the tree
Definition: smartsParser.h:720
SPEdge * second_edge_
second SPEdge
Definition: smartsParser.h:478
void setRecursive(bool recursive)
sets the recursive flag
Definition: smartsParser.h:688
SPNode * getPartnerSPNode(SPNode *node)
returns the partner; either the first or the second SPNode
Definition: smartsParser.h:430
bool is_not_
negotiation flag
Definition: smartsParser.h:605
bool is_not_
negation flag
Definition: smartsParser.h:463
void setRoot(SPNode *root)
sets the root SPNode of the tree
Definition: smartsParser.h:661
#define BALL_EXPORT
Definition: COMMON/global.h:50
void setSecondSPNode(SPNode *second)
sets the second SPNode of this edge
Definition: smartsParser.h:424
EdgeIterator end()
mutable access to end of edges list
Definition: smartsParser.h:590
SPEdge * getFirstEdge() const
returns the first edge (for tree use)
Definition: smartsParser.h:549
SPBond * getSPBond() const
returns the corresponding SPBond of this edge
Definition: smartsParser.h:415
bool not_
general negation flag
Definition: smartsParser.h:176
int component_no_
the actual component number
Definition: smartsParser.h:771