Open Babel  3.0
stereo.h
Go to the documentation of this file.
1 /**********************************************************************
2  stereo.h - OBStereo & OBStereoBase
3 
4  Copyright (C) 2009-2010 by Tim Vandermeersch
5 
6  This file is part of the Open Babel project.
7  For more information, see <http://openbabel.org/>
8 
9  This program is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  02110-1301, USA.
23  **********************************************************************/
24 #ifndef OB_STEREO_H
25 #define OB_STEREO_H
26 
27 #include <openbabel/base.h> // OBGenericData
28 #include <openbabel/isomorphism.h> // Automorphisms
29 #include <vector>
30 #include <map>
31 #include <set>
32 #include <climits> // UINT_MAX
33 
34 namespace OpenBabel {
35 
38 
75  struct OBAPI OBStereo
76  {
80  enum Type {
81  CisTrans = (1<<0),
82  ExtendedCisTrans = (1<<1),
83  SquarePlanar = (1<<2),
84  Tetrahedral = (1<<3),
85  ExtendedTetrahedral = (1<<4),
86  TrigonalBipyramidal = (1<<5),
87  Octahedral = (1<<6)
88  };
89 
94  enum BondDirection { // Values taken from MDL format
95  NotStereo = 0,
96  UpBond = 1,
97  DownBond = 6,
98  UnknownDir = 4
99  };
100 
108  enum Shape {
109  ShapeU = 1,
110  ShapeZ = 2,
111  Shape4 = 3
112  };
113 
119  enum View
120  {
121  ViewFrom = 1,
122  ViewTowards = 2
123  };
124 
130  enum Winding {
131  Clockwise = 1,
132  AntiClockwise = 2,
133  UnknownWinding = 3
134  };
135 
137 
138 
145  typedef unsigned long Ref;
149  enum {
150  NoRef = UINT_MAX,
151  ImplicitRef = UINT_MAX - 1
152  };
156  typedef std::vector<Ref> Refs;
160  typedef Refs::iterator RefIter;
164  typedef Refs::const_iterator ConstRefIter;
166 
168 
169 
175  static Refs MakeRefs(Ref ref1, Ref ref2, Ref ref3, Ref ref4 = NoRef)
176  {
177  Refs refs(3);
178  refs[0] = ref1;
179  refs[1] = ref2;
180  refs[2] = ref3;
181  if (ref4 != NoRef)
182  refs.push_back(ref4);
183  return refs;
184  }
197  static bool ContainsSameRefs(const Refs &refs1, const Refs &refs2);
201  static bool ContainsRef(const Refs &refs, unsigned long ref);
203 
205 
206 
226  static int NumInversions(const Refs &refs);
236  static void Permutate(Refs &refs, unsigned int i, unsigned int j);
248  static Refs Permutated(const Refs &refs, unsigned int i, unsigned int j);
250 
251  };
252 
259  {
264  OBStereoUnit() : type(static_cast<OBStereo::Type>(0)), id(OBStereo::NoRef), para(false)
265  {
266  }
267 
271  OBStereoUnit(OBStereo::Type _type, unsigned long _id, bool _para = false) :
272  type(_type), id(_id), para(_para)
273  {
274  }
275 
277  unsigned long id;
278  bool para;
279  };
287  typedef std::vector<OBStereoUnit> OBStereoUnitSet;
294  typedef std::vector<OBStereoUnitSet> OBStereoUnitSetOfSets;
295 
296 
297  // fwd decl
298  class OBMol;
321  class OBAPI OBStereoBase : public OBGenericData
322  {
323  public:
331  OBGenericData("StereoData", OBGenericDataType::StereoData, perceived),
332  m_mol(mol), m_specified(true)
333  {
334  }
338  virtual ~OBStereoBase() { m_mol = 0; }
339 
341 
342 
346  OBMol* GetMolecule() const { return m_mol; }
350  virtual OBStereo::Type GetType() const = 0;
356  void SetSpecified(bool specified) { m_specified = specified; }
360  bool IsSpecified() const { return m_specified; }
362  private:
363  OBMol *m_mol;
364  bool m_specified;
365  };
366 
367  // fwd decl
368  class OBTetrahedralStereo;
369  class OBCisTransStereo;
370  class OBSquarePlanarStereo;
384  class OBAPI OBStereoFacade
385  {
386  public:
394  OBStereoFacade(OBMol *mol, bool perceive = true) :
395  m_mol(mol), m_init(false), m_perceive(perceive)
396  {
397  }
398 
401 
404  unsigned int NumTetrahedralStereo();
409  bool HasTetrahedralStereo(unsigned long atomId);
415  OBTetrahedralStereo* GetTetrahedralStereo(unsigned long atomId);
417 
420 
423  unsigned int NumCisTransStereo();
428  bool HasCisTransStereo(unsigned long bondId);
434  OBCisTransStereo* GetCisTransStereo(unsigned long bondId);
436 
439 
442  unsigned int NumSquarePlanarStereo();
447  bool HasSquarePlanarStereo(unsigned long atomId);
453  OBSquarePlanarStereo* GetSquarePlanarStereo(unsigned long atomId);
455 
456  template<int StereoType>
457  bool HasStereo(unsigned long id);
458  template<typename T>
459  T* GetStereo(unsigned long id);
460 
461 
462  private:
466  inline void EnsureInit() { if (!m_init) InitMaps(); }
472  void InitMaps();
473 
474  OBMol *m_mol;
475  bool m_init;
476  bool m_perceive;
477  std::map<unsigned long, OBTetrahedralStereo*> m_tetrahedralMap;
478  std::map<unsigned long, OBCisTransStereo*> m_cistransMap;
479  std::map<unsigned long, OBSquarePlanarStereo*> m_squarePlanarMap;
480  };
481 
482  // fwd decl
483  class OBBond;
486 
494  OBAPI void PerceiveStereo(OBMol *mol, bool force = false);
526  OBAPI void StereoFrom2D(OBMol *mol,
527  std::map<OBBond*, enum OBStereo::BondDirection> *updown = NULL, bool force = false);
544  OBAPI void StereoFrom3D(OBMol *mol, bool force = false);
560  OBAPI void StereoFrom0D(OBMol *mol);
562 
565 
603  OBAPI std::vector<OBTetrahedralStereo*> TetrahedralFrom3D(OBMol *mol,
604  const OBStereoUnitSet &stereoUnits, bool addToMol = true);
649  OBAPI std::vector<OBTetrahedralStereo*> TetrahedralFrom2D(OBMol *mol,
650  const OBStereoUnitSet &stereoUnits, bool addToMol = true);
670  OBAPI std::vector<OBTetrahedralStereo*> TetrahedralFrom0D(OBMol *mol,
671  const OBStereoUnitSet &stereoUnits, bool addToMol = true);
672 
709  OBAPI std::vector<OBCisTransStereo*> CisTransFrom3D(OBMol *mol,
710  const OBStereoUnitSet &stereoUnits, bool addToMol = true);
741  OBAPI std::vector<OBCisTransStereo*> CisTransFrom2D(OBMol *mol,
742  const OBStereoUnitSet &stereoUnits,
743  const std::map<OBBond*, enum OBStereo::BondDirection> *updown = NULL, bool addToMol = true);
770  OBAPI bool TetStereoToWedgeHash(OBMol &mol,
771  std::map<OBBond*, enum OBStereo::BondDirection> &updown,
772  std::map<OBBond*, OBStereo::Ref> &from);
784  OBAPI std::set<OBBond*> GetUnspecifiedCisTrans(OBMol& mol);
796  OBAPI void StereoRefToImplicit(OBMol& mol, OBStereo::Ref atomId);
810  OBAPI void ImplicitRefToStereo(OBMol& mol, OBStereo::Ref centerId, OBStereo::Ref newId);
830  OBAPI std::vector<OBCisTransStereo*> CisTransFrom0D(OBMol *mol,
831  const OBStereoUnitSet &stereoUnits,
832  bool addToMol = true);
834 
835 
838 
918  OBAPI OBStereoUnitSet FindStereogenicUnits(OBMol *mol,
919  const std::vector<unsigned int> &symClasses);
996  OBAPI OBStereoUnitSet FindStereogenicUnits(OBMol *mol,
997  const std::vector<unsigned int> &symClasses,
998  const Automorphisms &automorphisms);
1000 
1150 }
1152 
1153 #endif
1154 
bool IsSpecified() const
Definition: stereo.h:360
OBStereoBase(OBMol *mol)
Definition: stereo.h:330
Struct representing a single stereogenic unit.
Definition: stereo.h:258
Definition: residue.h:336
OBIsomorphismMapper class for finding isomorphisms.
std::set< OBBond * > GetUnspecifiedCisTrans(OBMol &mol)
Base class for generic data.
Definition: base.h:188
std::vector< OBCisTransStereo * > CisTransFrom3D(OBMol *mol, const OBStereoUnitSet &stereoUnits, bool addToMol=true)
Stereochemistry data (see OBStereoBase)
Definition: base.h:147
Base classes to build a graph.
OBStereoUnitSet FindStereogenicUnits(OBMol *mol, const std::vector< unsigned int > &symClasses)
Refs::const_iterator ConstRefIter
Definition: stereo.h:164
Class for handling and storing cis/trans stereochemistry.
Definition: cistrans.h:75
void ImplicitRefToStereo(OBMol &mol, OBStereo::Ref centerId, OBStereo::Ref newId)
void StereoFrom3D(OBMol *mol, bool force=false)
Perceived by Open Babel library methods.
Definition: base.h:180
void StereoFrom0D(OBMol *mol)
Bond class.
Definition: bond.h:58
OBIsomorphismMapper::Mappings Automorphisms
A group of automorphic permutations.
Definition: isomorphism.h:206
void SetSpecified(bool specified)
Definition: stereo.h:356
Placeholder for enums & Ref/Refs related functions.
Definition: stereo.h:75
std::vector< OBTetrahedralStereo * > TetrahedralFrom3D(OBMol *mol, const OBStereoUnitSet &stereoUnits, bool addToMol=true)
Molecule Class.
Definition: mol.h:118
OBStereoFacade(OBMol *mol, bool perceive=true)
Definition: stereo.h:394
void StereoRefToImplicit(OBMol &mol, OBStereo::Ref atomId)
View
Definition: stereo.h:119
std::vector< OBTetrahedralStereo * > TetrahedralFrom0D(OBMol *mol, const OBStereoUnitSet &stereoUnits, bool addToMol=true)
static Refs MakeRefs(Ref ref1, Ref ref2, Ref ref3, Ref ref4=NoRef)
Definition: stereo.h:175
BondDirection
Definition: stereo.h:94
Shape
Definition: stereo.h:108
void StereoFrom2D(OBMol *mol, std::map< OBBond *, enum OBStereo::BondDirection > *updown=NULL, bool force=false)
OBMol * GetMolecule() const
Definition: stereo.h:346
virtual ~OBStereoBase()
Definition: stereo.h:338
unsigned long id
Definition: stereo.h:277
Base class for all stereochemistry classes.
Definition: stereo.h:321
bool para
the atom/bond (depends on type) unique id
Definition: stereo.h:278
Winding
Definition: stereo.h:130
void PerceiveStereo(OBMol *mol, bool force=false)
std::vector< OBStereoUnit > OBStereoUnitSet
A single set of OBStereoUnit objects.
Definition: stereo.h:287
Facade to simplify retrieval of OBStereoBase derived objects.
Definition: stereo.h:384
bool TetStereoToWedgeHash(OBMol &mol, std::map< OBBond *, enum OBStereo::BondDirection > &updown, std::map< OBBond *, OBStereo::Ref > &from)
std::vector< Ref > Refs
Definition: stereo.h:156
std::vector< OBTetrahedralStereo * > TetrahedralFrom2D(OBMol *mol, const OBStereoUnitSet &stereoUnits, bool addToMol=true)
Class for handling and storing square planar stereochemistry.
Definition: squareplanar.h:48
std::vector< OBStereoUnitSet > OBStereoUnitSetOfSets
A set of sets of OBStereoUnit objects.
Definition: stereo.h:294
std::vector< OBCisTransStereo * > CisTransFrom2D(OBMol *mol, const OBStereoUnitSet &stereoUnits, const std::map< OBBond *, enum OBStereo::BondDirection > *updown=NULL, bool addToMol=true)
Class for handling and storing tetrahedral atom stereochemistry.
Definition: tetrahedral.h:58
OBStereoUnit()
Definition: stereo.h:264
unsigned long Ref
Definition: stereo.h:145
std::vector< OBCisTransStereo * > CisTransFrom0D(OBMol *mol, const OBStereoUnitSet &stereoUnits, bool addToMol=true)
Type
Definition: stereo.h:80
OBStereo::Type type
the type for this stereogenic unit
Definition: stereo.h:276
Refs::iterator RefIter
Definition: stereo.h:160
OBStereoUnit(OBStereo::Type _type, unsigned long _id, bool _para=false)
Definition: stereo.h:271
Global namespace for all Open Babel code.
Definition: alias.h:22