Open Babel: stereo.h Source File

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

# stereo.h

Go to the documentation of this file.

    00001 /**********************************************************************
    00002   stereo.h - OBStereo & OBStereoBase
    00003
    00004   Copyright (C) 2009-2010 by Tim Vandermeersch
    00005
    00006   This file is part of the Open Babel project.
    00007   For more information, see <http://openbabel.org/>
    00008
    00009   This program is free software; you can redistribute it and/or modify
    00010   it under the terms of the GNU General Public License as published by
    00011   the Free Software Foundation; either version 2 of the License, or
    00012   (at your option) any later version.
    00013
    00014   This program is distributed in the hope that it will be useful,
    00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
    00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00017   GNU General Public License for more details.
    00018
    00019   You should have received a copy of the GNU General Public License
    00020   along with this program; if not, write to the Free Software
    00021   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    00022   02110-1301, USA.
    00023  **********************************************************************/
    00024 #ifndef OB_STEREO_H
    00025 #define OB_STEREO_H
    00026
    00027 #include <openbabel/base.h> // OBGenericData
    00028 #include <openbabel/isomorphism.h> // Automorphisms
    00029 #include <vector>
    00030 #include <map>
    00031 #include <set>
    00032 #include <climits> // UINT_MAX
    00033
    00034 namespace OpenBabel {
    00035
    00038
    00075   struct OBAPI OBStereo
    00076   {
    00080     enum Type {
    00081       CisTrans            = (1<<0),
    00082       ExtendedCisTrans    = (1<<1),
    00083       SquarePlanar        = (1<<2),
    00084       Tetrahedral         = (1<<3),
    00085       ExtendedTetrahedral = (1<<4),
    00086       TrigonalBipyramidal = (1<<5),
    00087       Octahedral          = (1<<6)
    00088     };
    00089
    00094     enum BondDirection { // Values taken from MDL format
    00095       NotStereo =   0,
    00096       UpBond =      1,
    00097       DownBond =    6,
    00098       UnknownDir =  4
    00099     };
    00100
    00108     enum Shape {
    00109       ShapeU = 1,
    00110       ShapeZ = 2,
    00111       Shape4 = 3
    00112     };
    00113
    00119     enum View
    00120     {
    00121       ViewFrom = 1,
    00122       ViewTowards = 2
    00123     };
    00124
    00130     enum Winding {
    00131       Clockwise = 1,
    00132       AntiClockwise = 2
    00133     };
    00134
    00136
    00137
    00144     typedef unsigned long Ref;
    00148     enum {
    00149       NoRef = UINT_MAX,
    00150       ImplicitRef = UINT_MAX - 1
    00151     };
    00155     typedef std::vector<Ref> Refs;
    00159     typedef Refs::iterator RefIter;
    00163     typedef Refs::const_iterator ConstRefIter;
    00165
    00167
    00168
    00174     static Refs MakeRefs(Ref ref1, Ref ref2, Ref ref3, Ref ref4 = NoRef)
    00175     {
    00176       Refs refs(3);
    00177       refs[0] = ref1;
    00178       refs[1] = ref2;
    00179       refs[2] = ref3;
    00180       if (ref4 != NoRef)
    00181         refs.push_back(ref4);
    00182       return refs;
    00183     }
    00196     static bool ContainsSameRefs(const Refs &refs1, const Refs &refs2);
    00200     static bool ContainsRef(const Refs &refs, unsigned long ref);
    00202
    00204
    00205
    00225     static int NumInversions(const Refs &refs);
    00235     static void Permutate(Refs &refs, int i, int j);
    00247     static Refs Permutated(const Refs &refs, int i, int j);
    00249
    00250   };
    00251
    00257   struct OBStereoUnit
    00258   {
    00263     OBStereoUnit() : type(static_cast<OBStereo::Type>(0)), id(OBStereo::NoRef), para(false)
    00264     {
    00265     }
    00266
    00270     OBStereoUnit(OBStereo::Type _type, unsigned long _id, bool _para = false) :
    00271         type(_type), id(_id), para(_para)
    00272     {
    00273     }
    00274
    00275     OBStereo::Type type;
    00276     unsigned long id;
    00277     bool para;
    00278   };
    00286   typedef std::vector<OBStereoUnit> OBStereoUnitSet;
    00293   typedef std::vector<OBStereoUnitSet> OBStereoUnitSetOfSets;
    00294
    00295
    00296   // fwd decl
    00297   class OBMol;
    00320   class OBAPI OBStereoBase : public OBGenericData
    00321   {
    00322     public:
    00329       OBStereoBase(OBMol *mol) :
    00330         OBGenericData("StereoData", OBGenericDataType::StereoData, perceived),
    00331         m_mol(mol), m_specified(true)
    00332       {
    00333       }
    00337       virtual ~OBStereoBase() { m_mol = 0; }
    00338
    00340
    00341
    00345       OBMol* GetMolecule() const { return m_mol; }
    00349       virtual OBStereo::Type GetType() const = 0;
    00355       void SetSpecified(bool specified) { m_specified = specified; }
    00359       bool IsSpecified() const { return m_specified; }
    00361     private:
    00362       OBMol *m_mol;
    00363       bool m_specified;
    00364   };
    00365
    00366   // fwd decl
    00367   class OBTetrahedralStereo;
    00368   class OBCisTransStereo;
    00369   class OBSquarePlanarStereo;
    00383   class OBAPI OBStereoFacade
    00384   {
    00385     public:
    00393       OBStereoFacade(OBMol *mol, bool perceive = true) :
    00394           m_mol(mol), m_init(false), m_perceive(perceive)
    00395       {
    00396       }
    00397
    00400
    00403       unsigned int NumTetrahedralStereo();
    00408       bool HasTetrahedralStereo(unsigned long atomId);
    00414       OBTetrahedralStereo* GetTetrahedralStereo(unsigned long atomId);
    00416
    00419
    00422       unsigned int NumCisTransStereo();
    00427       bool HasCisTransStereo(unsigned long bondId);
    00433       OBCisTransStereo* GetCisTransStereo(unsigned long bondId);
    00435
    00438
    00441       unsigned int NumSquarePlanarStereo();
    00446       bool HasSquarePlanarStereo(unsigned long atomId);
    00452       OBSquarePlanarStereo* GetSquarePlanarStereo(unsigned long atomId);
    00454
    00455       template<int StereoType>
    00456       bool HasStereo(unsigned long id);
    00457       template<typename T>
    00458       T* GetStereo(unsigned long id);
    00459
    00460
    00461     private:
    00465       inline void EnsureInit() { if (!m_init) InitMaps(); }
    00471       void InitMaps();
    00472
    00473       OBMol *m_mol;
    00474       bool m_init;
    00475       bool m_perceive;
    00476       std::map<unsigned long, OBTetrahedralStereo*> m_tetrahedralMap;
    00477       std::map<unsigned long, OBCisTransStereo*> m_cistransMap;
    00478       std::map<unsigned long, OBSquarePlanarStereo*> m_squarePlanarMap;
    00479   };
    00480
    00481   // fwd decl
    00482   class OBBond;
    00485
    00493   OBAPI void PerceiveStereo(OBMol *mol, bool force = false);
    00525   OBAPI void StereoFrom2D(OBMol *mol,
    00526     std::map<OBBond*, enum OBStereo::BondDirection> *updown = NULL, bool force = false);
    00543   OBAPI void StereoFrom3D(OBMol *mol, bool force = false);
    00559   OBAPI void StereoFrom0D(OBMol *mol);
    00561
    00564
    00602   OBAPI std::vector<OBTetrahedralStereo*> TetrahedralFrom3D(OBMol *mol,
    00603       const OBStereoUnitSet &stereoUnits, bool addToMol = true);
    00648   OBAPI std::vector<OBTetrahedralStereo*> TetrahedralFrom2D(OBMol *mol,
    00649       const OBStereoUnitSet &stereoUnits, bool addToMol = true);
    00669   OBAPI std::vector<OBTetrahedralStereo*> TetrahedralFrom0D(OBMol *mol,
    00670       const OBStereoUnitSet &stereoUnits, bool addToMol = true);
    00671
    00708   OBAPI std::vector<OBCisTransStereo*> CisTransFrom3D(OBMol *mol,
    00709       const OBStereoUnitSet &stereoUnits, bool addToMol = true);
    00740   OBAPI std::vector<OBCisTransStereo*> CisTransFrom2D(OBMol *mol,
    00741       const OBStereoUnitSet &stereoUnits,
    00742       const std::map<OBBond*, enum OBStereo::BondDirection> *updown = NULL, bool addToMol = true);
    00769   OBAPI bool TetStereoToWedgeHash(OBMol &mol,
    00770       std::map<OBBond*, enum OBStereo::BondDirection> &updown,
    00771       std::map<OBBond*, OBStereo::Ref> &from);
    00783   OBAPI std::set<OBBond*> GetUnspecifiedCisTrans(OBMol& mol);
    00795   OBAPI void StereoRefToImplicit(OBMol& mol, OBStereo::Ref atomId);
    00815   OBAPI std::vector<OBCisTransStereo*> CisTransFrom0D(OBMol *mol,
    00816       const OBStereoUnitSet &stereoUnits,
    00817       bool addToMol = true);
    00819
    00820
    00823
    00903   OBAPI OBStereoUnitSet FindStereogenicUnits(OBMol *mol,
    00904       const std::vector<unsigned int> &symClasses);
    00981   OBAPI OBStereoUnitSet FindStereogenicUnits(OBMol *mol,
    00982       const std::vector<unsigned int> &symClasses,
    00983       const Automorphisms &automorphisms);
    00985
    01135
    01136 }
    01137
    01138 #endif
    01139

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

This file is part of the documentation for Open Babel, version 2.3.

Documentation copyright © 1998-2007, the Open Babel Developers.
Open Babel is hosted by:
Generated on Mon Oct 25 2010 11:55:12 by 1.7.2.