standardPredicates.h

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // $Id: standardPredicates.h,v 1.52.16.2 2007/03/29 10:34:59 bertsch Exp $
00005 //
00006 
00007 #ifndef BALL_KERNEL_STANDARDPREDICATES_H
00008 #define BALL_KERNEL_STANDARDPREDICATES_H
00009 
00010 #ifndef BALL_DATATYPE_STRINGHASHMAP_H
00011 # include <BALL/DATATYPE/stringHashMap.h>
00012 #endif
00013 
00014 #ifndef BALL_DATATYPE_HASHSET_H
00015 # include <BALL/DATATYPE/hashSet.h>
00016 #endif
00017 
00018 #ifndef BALL_KERNEL_BOND_H
00019 # include <BALL/KERNEL/bond.h>
00020 #endif
00021 
00022 #ifndef BALL_KERNEL_EXPRESSION_H
00023 # include <BALL/KERNEL/expression.h>
00024 #endif
00025 
00026 #ifndef BALL_STRUCTURE_SMARTSMATCHER_H
00027 # include <BALL/STRUCTURE/smartsMatcher.h>
00028 #endif
00029 
00030 #ifndef BALL_QSAR_AROMATICITYPROCESSOR_H
00031 # include <BALL/QSAR/aromaticityProcessor.h>
00032 #endif
00033 
00034 #ifndef BALL_QSAR_RINGPERCEPTIONPROCESSOR_H
00035 # include <BALL/QSAR/ringPerceptionProcessor.h>
00036 #endif
00037 
00038 namespace BALL 
00039 {
00040   class Atom;
00041 
00049 
00054   class BALL_EXPORT TruePredicate
00055     : public ExpressionPredicate
00056   {
00057     public:
00058       BALL_CREATE(TruePredicate)
00059 
00060       
00064       virtual bool operator () (const Atom& atom) const;
00065   };
00066 
00071   class BALL_EXPORT FalsePredicate
00072     : public ExpressionPredicate
00073   {
00074     public:
00075     BALL_CREATE(FalsePredicate)
00076 
00077     
00081     virtual bool operator () (const Atom& atom) const;
00082   };
00083 
00088   class BALL_EXPORT SelectedPredicate
00089     : public ExpressionPredicate
00090   {
00091     public:
00092       BALL_CREATE(SelectedPredicate)
00093 
00094       
00098       virtual bool operator () (const Atom& atom) const;
00099   };
00100 
00105   class BALL_EXPORT AtomNamePredicate
00106     : public  ExpressionPredicate
00107   {
00108     public:
00109       BALL_CREATE(AtomNamePredicate)
00110 
00111       
00115       virtual bool operator () (const Atom& atom) const;
00116   };
00117 
00121   class BALL_EXPORT AtomTypePredicate
00122     : public  ExpressionPredicate
00123   {
00124     public:
00125       BALL_CREATE(AtomTypePredicate)
00126 
00127       
00131       virtual bool operator () (const Atom& atom) const;
00132   };
00133 
00137   class BALL_EXPORT ElementPredicate
00138     : public  ExpressionPredicate
00139   {
00140     public:
00141       BALL_CREATE(ElementPredicate)
00142 
00143       
00147       virtual bool operator () (const Atom& atom) const;
00148   };
00149 
00154   class BALL_EXPORT ResiduePredicate
00155     : public  ExpressionPredicate
00156   {
00157     public:
00158       BALL_CREATE(ResiduePredicate)
00159 
00160       
00164       virtual bool operator () (const Atom& atom) const;
00165   };
00166 
00171   class BALL_EXPORT ResidueIDPredicate
00172     : public  ExpressionPredicate
00173   {
00174     public:
00175       BALL_CREATE(ResidueIDPredicate)
00176 
00177       
00181       virtual bool operator () (const Atom& atom) const;
00182   };
00183 
00188   class BALL_EXPORT ProteinPredicate
00189     : public  ExpressionPredicate
00190   {
00191     public:
00192       BALL_CREATE(ProteinPredicate)
00193 
00194       
00198       virtual bool operator () (const Atom& atom) const;
00199   };
00200 
00205   class BALL_EXPORT ChainPredicate
00206     : public  ExpressionPredicate
00207   {
00208     public:
00209       BALL_CREATE(ChainPredicate)
00210 
00211       
00215       virtual bool operator () (const Atom& atom) const;
00216   };
00217 
00222   class BALL_EXPORT SecondaryStructurePredicate
00223     : public  ExpressionPredicate
00224   {
00225     public:
00226       BALL_CREATE(SecondaryStructurePredicate)
00227 
00228       
00232       virtual bool operator () (const Atom& atom) const;
00233   };
00234 
00243   class BALL_EXPORT SolventPredicate
00244     : public  ExpressionPredicate
00245   {
00246     public:
00247     BALL_CREATE(SolventPredicate)
00248 
00249     
00253     virtual bool operator () (const Atom& atom) const;
00254   };
00255 
00259   class BALL_EXPORT MoleculePredicate
00260     : public  ExpressionPredicate
00261   {
00262     public:
00263       BALL_CREATE(MoleculePredicate)
00264 
00265       
00269       virtual bool operator () (const Atom& atom) const;
00270   };
00271 
00276   class BALL_EXPORT BackBonePredicate
00277     : public  ExpressionPredicate
00278   {
00279     public:
00280       BALL_CREATE(BackBonePredicate)
00281 
00282       
00286       virtual bool operator () (const Atom& atom) const;
00287   };
00288 
00291   class BALL_EXPORT NucleicAcidPredicate
00292     : public  ExpressionPredicate
00293   {
00294     public:
00295       BALL_CREATE(NucleicAcidPredicate)
00296 
00297       
00301       virtual bool operator () (const Atom& atom) const;
00302   };
00303 
00307   class BALL_EXPORT NucleotidePredicate
00308     : public  ExpressionPredicate
00309   {
00310     public:
00311       BALL_CREATE(NucleotidePredicate)
00312 
00313       
00317       virtual bool operator () (const Atom& atom) const;
00318   };
00319 
00322   class BALL_EXPORT InRingPredicate
00323     : public  ExpressionPredicate
00324   {
00325     public:
00326 
00327       BALL_CREATE(InRingPredicate)
00328 
00329       
00330       InRingPredicate();
00331 
00333       InRingPredicate(Size n);
00334 
00336       ~InRingPredicate();
00337 
00342       virtual bool operator () (const Atom& atom) const;
00343 
00344   };
00345 
00353   class BALL_EXPORT NumberOfBondsPredicate
00354     : public  ExpressionPredicate
00355   {
00356     public:
00357 
00359       NumberOfBondsPredicate();
00360 
00361       BALL_CREATE(NumberOfBondsPredicate)
00362 
00363       
00367       virtual bool operator () (const Atom& atom) const;
00368 
00369     protected:
00370       bool testPredicate_(const Atom& atom, Bond::Order order) const;
00371   };
00372 
00373 
00378   class BALL_EXPORT SingleBondsPredicate
00379     : public NumberOfBondsPredicate
00380   {
00381     public:
00382       BALL_CREATE(SingleBondsPredicate)
00383 
00384       
00388       virtual bool operator () (const Atom& atom) const;
00389   };
00390 
00391 
00396   class BALL_EXPORT DoubleBondsPredicate
00397     : public NumberOfBondsPredicate
00398   {
00399     public:
00400       BALL_CREATE(DoubleBondsPredicate)
00401 
00402       
00406       virtual bool operator () (const Atom& atom) const;
00407 
00408   };
00409 
00410 
00415   class BALL_EXPORT TripleBondsPredicate
00416     : public DoubleBondsPredicate
00417   {
00418     public:
00419       BALL_CREATE(TripleBondsPredicate)
00420 
00421       
00425       virtual bool operator () (const Atom& atom) const;
00426   };
00427 
00428 
00439   class BALL_EXPORT AromaticBondsPredicate
00440     : public ExpressionPredicate
00441   {
00442     public:
00443       BALL_CREATE(AromaticBondsPredicate)
00444 
00445       
00449       virtual bool operator () (const Atom& atom) const;
00450 
00451     protected:
00452       bool testPredicate_(const Atom& atom) const;
00453   };
00454 
00455 
00480   class BALL_EXPORT ConnectedToPredicate
00481     : public  ExpressionPredicate
00482   {
00483 
00484     public:
00485 
00486       class BALL_EXPORT CTPNode
00487       {
00488         public:
00489 
00490           enum BondType
00491           {
00492             BONDTYPE__UNINITIALISED = 0,
00493             BONDTYPE__ANY           = 1,
00494             BONDTYPE__SINGLE        = 2,
00495             BONDTYPE__DOUBLE        = 3,
00496             BONDTYPE__TRIPLE        = 4,
00497             BONDTYPE__QUADRUPLE     = 5,
00498             BONDTYPE__AROMATIC      = 6
00499           };
00500 
00501           typedef std::list<CTPNode*>::iterator Iterator;
00502           typedef std::list<CTPNode*>::const_iterator ConstIterator;
00503 
00504           /*
00505            */
00506           CTPNode();
00507 
00508           /*
00509            */
00510           CTPNode(const CTPNode& node);
00511 
00512           /*
00513            */
00514           virtual ~CTPNode();
00515 
00516           /*
00517           */
00518           virtual void destroy();
00519 
00520           /*
00521            */
00522           void setParent(CTPNode* parent);
00523 
00524           /*
00525            */
00526           CTPNode* getParent() const;
00527 
00528           /*
00529            */
00530           void addChild(CTPNode* child);
00531 
00532           /*
00533            */
00534           void removeChild(CTPNode* child);
00535 
00536           /*
00537            */
00538           ::std::list<CTPNode*>& getChildren();
00539 
00540           Iterator begin();
00541 
00542           ConstIterator begin() const;
00543 
00544           Iterator end();
00545 
00546           ConstIterator end() const;
00547 
00548           /*
00549            */
00550           Size getNumberOfChildren() const;
00551 
00552           /*
00553            */
00554           void setBondType(Size type);
00555 
00556           /*
00557            */
00558           void setBondType(char type);
00559 
00560           /*
00561            */
00562           Size getBondType() const;
00563 
00564           /*
00565            */
00566           char getBondTypeChar() const;
00567 
00568           /*
00569            */
00570           String getSymbol() const;
00571 
00572           /*
00573            */
00574           void setSymbol(const String& symbol);
00575 
00576           /*
00577            */
00578           void setFinished();
00579 
00580           /*
00581            */
00582           void unsetFinished();
00583 
00584           /*
00585            */
00586           bool isFinished() const;
00587 
00588           /*
00589            */
00590           void setLinked();
00591 
00592           /*
00593            */
00594           void unsetLinked();
00595 
00596           /*
00597            */
00598           bool isLinked() const;
00599 
00600           /*
00601            */
00602           void linkWith(CTPNode* partner);
00603 
00604           /*
00605            */
00606           const HashSet<CTPNode*>& getLinkSet() const;
00607 
00608 
00609         private: 
00610 
00611           /*
00612            */
00613           String element_symbol_;
00614 
00615           /* Bond type means the bond connecting *to* this node.
00616            */
00617           Size bond_type_;
00618 
00619           /*
00620            */
00621           std::list<CTPNode*> children_;
00622 
00623           /*
00624            */
00625           CTPNode* parent_;
00626 
00627           /*
00628            */
00629           bool finished_;
00630 
00631           /*
00632            */
00633           bool linked_;
00634 
00635           /*
00636            */
00637           HashSet<CTPNode*> link_set_;
00638 
00639           /*
00640           */
00641           struct greater_
00642             : public binary_function<const CTPNode*, const CTPNode*, bool>
00643           {
00644 
00645             bool operator () (const CTPNode* a, const CTPNode* b) const
00646             {
00647               if ((a != 0) && (b != 0))
00648               {
00649                 if (a->getSymbol() == "*")
00650                 {
00651                   return true;
00652                 }
00653                 else
00654                 {
00655                   return false;
00656                 }
00657               }
00658               else
00659               {
00660                 Log.error() << "greater_: got NULL pointers" << std::endl;
00661                 return false;
00662               }
00663             }
00664 
00665           };
00666 
00667       };
00668 
00669     public:
00670       BALL_CREATE(ConnectedToPredicate)
00671 
00672       ConnectedToPredicate();
00673 
00674       ConnectedToPredicate(const ConnectedToPredicate& predicate);
00675 
00676       virtual ~ConnectedToPredicate();
00677 
00678       virtual void clear();
00679 
00684       virtual bool operator () (const Atom& atom) const;
00685     
00686       void dump() const;
00687 
00688       void dump(const CTPNode* current) const;
00689 
00690       virtual void setArgument(const String& argument);
00691 
00692     private:
00693       /*_ The syntax tree
00694       */
00695       CTPNode* tree_;
00696 
00697       /*_ Needed for realising parsing of loops (or links).
00698       */
00699       HashMap<char, std::pair<CTPNode*, CTPNode*> > link_map_;
00700 
00701       /*_ Needed for realising parsing of loops (or links).
00702       */
00703       char link_mark_;
00704 
00705       /*_ Keep it consistent
00706       */
00707       CTPNode* createNewNode_(CTPNode* node);
00708     
00709       /*_
00710       */
00711       CTPNode* parse_();
00712 
00713       // Clean up nodes created if parse_ exits with a parse error.
00714       void cleanUpNodes_(std::vector<CTPNode*>& all_nodes);
00715 
00716       /*_
00717       */
00718       CTPNode* parse_(const String& input);
00719 
00720       bool bondOrderMatch_(const Bond& bond, const CTPNode& node) const;
00721 
00722       bool find_(const Atom& atom, const CTPNode* current,
00723           HashSet<const Bond*>& visited) const;
00724 
00725   };
00726 
00729   class BALL_EXPORT SpHybridizedPredicate
00730     : public  ExpressionPredicate
00731   {
00732     public:
00733       BALL_CREATE(SpHybridizedPredicate)
00734 
00735       
00739       virtual bool operator () (const Atom& atom) const;
00740   };
00741 
00744   class BALL_EXPORT Sp2HybridizedPredicate
00745     : public  ExpressionPredicate
00746   {
00747     public:
00748       BALL_CREATE(Sp2HybridizedPredicate)
00749 
00750       
00754       virtual bool operator () (const Atom& atom) const;
00755   };
00756 
00757 
00760   class BALL_EXPORT Sp3HybridizedPredicate
00761     : public  ExpressionPredicate
00762   {
00763     public:
00764       BALL_CREATE(Sp3HybridizedPredicate)
00765 
00766       
00770       virtual bool operator () (const Atom& atom) const;
00771   };
00772 
00775   class BALL_EXPORT ChargePredicate
00776     : public  ExpressionPredicate
00777   {
00778     public:
00779     BALL_CREATE(ChargePredicate)
00780 
00781     
00790     virtual bool operator () (const Atom& atom) const;
00791   };
00792 
00797   class BALL_EXPORT AxialPredicate
00798     : public  ExpressionPredicate
00799   {
00800     public:
00801     BALL_CREATE(AxialPredicate)
00802 
00803     
00812     virtual bool operator () (const Atom& atom) const;
00813   };
00814 
00818   class BALL_EXPORT Conformation4C1Predicate
00819     : public  ExpressionPredicate
00820   {
00821     public:
00822     BALL_CREATE(Conformation4C1Predicate)
00823 
00824     
00828     virtual bool operator () (const Atom& atom) const;
00829   };
00830 
00833   class BALL_EXPORT RingFinder
00834   {
00835     public:
00836 
00837       // BALL_CREATE(RingFinder)
00838 
00840       RingFinder();
00841 
00846       RingFinder(Size n);
00847 
00849       virtual ~RingFinder();
00850 
00853       bool operator () (const Atom& atom);
00854 
00857       bool dfs(const Atom& atom, const Size limit);
00858 
00863       void setRingSize(Size n);
00864 
00867       const HashSet<const Bond*>& getVisitedBonds() const;
00868 
00871       const std::vector<const Atom*>& getRingAtoms() const;
00872 
00873     private:
00874 
00877       const Atom* first_atom_;
00878       
00881       Size n_;
00882 
00885       bool exact_;
00886 
00887       /*_
00888       */
00889       HashSet<const Bond*> visited_bonds_;
00890 
00891       /*_
00892       */
00893       std::vector<const Atom*> ring_atoms_;
00894 
00895   };
00896 
00899   class BALL_EXPORT SMARTSPredicate
00900     : public ExpressionPredicate
00901   {
00902     public:
00903 
00905     SMARTSPredicate();
00906 
00908     SMARTSPredicate(const SMARTSPredicate& pred);
00909 
00911     virtual ~SMARTSPredicate();
00912   
00913     BALL_CREATE(SMARTSPredicate)
00914 
00915     
00919     virtual bool operator () (const Atom& atom) const;
00920 
00921     mutable SmartsMatcher matcher_;
00922     mutable Molecule* last_molecule_;
00923     mutable AromaticityProcessor arom_proc_;
00924     mutable RingPerceptionProcessor ring_proc_;
00925     // when was the aromaticity lastly calculated for a given molecule:
00926     static HashMap<Molecule*, TimeStamp> call_time_map_;
00927     static Molecule dummy_molecule_;
00928     mutable HashSet<Atom*> matches_;
00929   };
00930 
00931 
00933 } // namespace BALL
00934 
00935 #endif // BALL_KERNEL_STANDARDPREDICATES_H