00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef OB_STEREO_H
00025 #define OB_STEREO_H
00026
00027 #include <openbabel/base.h>
00028 #include <openbabel/isomorphism.h>
00029 #include <vector>
00030 #include <map>
00031 #include <set>
00032 #include <climits>
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 {
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 UnknownWinding = 3
00134 };
00135
00137
00138
00145 typedef unsigned long Ref;
00149 enum {
00150 NoRef = UINT_MAX,
00151 ImplicitRef = UINT_MAX - 1
00152 };
00156 typedef std::vector<Ref> Refs;
00160 typedef Refs::iterator RefIter;
00164 typedef Refs::const_iterator ConstRefIter;
00166
00168
00169
00175 static Refs MakeRefs(Ref ref1, Ref ref2, Ref ref3, Ref ref4 = NoRef)
00176 {
00177 Refs refs(3);
00178 refs[0] = ref1;
00179 refs[1] = ref2;
00180 refs[2] = ref3;
00181 if (ref4 != NoRef)
00182 refs.push_back(ref4);
00183 return refs;
00184 }
00197 static bool ContainsSameRefs(const Refs &refs1, const Refs &refs2);
00201 static bool ContainsRef(const Refs &refs, unsigned long ref);
00203
00205
00206
00226 static int NumInversions(const Refs &refs);
00236 static void Permutate(Refs &refs, int i, int j);
00248 static Refs Permutated(const Refs &refs, int i, int j);
00250
00251 };
00252
00258 struct OBStereoUnit
00259 {
00264 OBStereoUnit() : type(static_cast<OBStereo::Type>(0)), id(OBStereo::NoRef), para(false)
00265 {
00266 }
00267
00271 OBStereoUnit(OBStereo::Type _type, unsigned long _id, bool _para = false) :
00272 type(_type), id(_id), para(_para)
00273 {
00274 }
00275
00276 OBStereo::Type type;
00277 unsigned long id;
00278 bool para;
00279 };
00287 typedef std::vector<OBStereoUnit> OBStereoUnitSet;
00294 typedef std::vector<OBStereoUnitSet> OBStereoUnitSetOfSets;
00295
00296
00297
00298 class OBMol;
00321 class OBAPI OBStereoBase : public OBGenericData
00322 {
00323 public:
00330 OBStereoBase(OBMol *mol) :
00331 OBGenericData("StereoData", OBGenericDataType::StereoData, perceived),
00332 m_mol(mol), m_specified(true)
00333 {
00334 }
00338 virtual ~OBStereoBase() { m_mol = 0; }
00339
00341
00342
00346 OBMol* GetMolecule() const { return m_mol; }
00350 virtual OBStereo::Type GetType() const = 0;
00356 void SetSpecified(bool specified) { m_specified = specified; }
00360 bool IsSpecified() const { return m_specified; }
00362 private:
00363 OBMol *m_mol;
00364 bool m_specified;
00365 };
00366
00367
00368 class OBTetrahedralStereo;
00369 class OBCisTransStereo;
00370 class OBSquarePlanarStereo;
00384 class OBAPI OBStereoFacade
00385 {
00386 public:
00394 OBStereoFacade(OBMol *mol, bool perceive = true) :
00395 m_mol(mol), m_init(false), m_perceive(perceive)
00396 {
00397 }
00398
00401
00404 unsigned int NumTetrahedralStereo();
00409 bool HasTetrahedralStereo(unsigned long atomId);
00415 OBTetrahedralStereo* GetTetrahedralStereo(unsigned long atomId);
00417
00420
00423 unsigned int NumCisTransStereo();
00428 bool HasCisTransStereo(unsigned long bondId);
00434 OBCisTransStereo* GetCisTransStereo(unsigned long bondId);
00436
00439
00442 unsigned int NumSquarePlanarStereo();
00447 bool HasSquarePlanarStereo(unsigned long atomId);
00453 OBSquarePlanarStereo* GetSquarePlanarStereo(unsigned long atomId);
00455
00456 template<int StereoType>
00457 bool HasStereo(unsigned long id);
00458 template<typename T>
00459 T* GetStereo(unsigned long id);
00460
00461
00462 private:
00466 inline void EnsureInit() { if (!m_init) InitMaps(); }
00472 void InitMaps();
00473
00474 OBMol *m_mol;
00475 bool m_init;
00476 bool m_perceive;
00477 std::map<unsigned long, OBTetrahedralStereo*> m_tetrahedralMap;
00478 std::map<unsigned long, OBCisTransStereo*> m_cistransMap;
00479 std::map<unsigned long, OBSquarePlanarStereo*> m_squarePlanarMap;
00480 };
00481
00482
00483 class OBBond;
00486
00494 OBAPI void PerceiveStereo(OBMol *mol, bool force = false);
00526 OBAPI void StereoFrom2D(OBMol *mol,
00527 std::map<OBBond*, enum OBStereo::BondDirection> *updown = NULL, bool force = false);
00544 OBAPI void StereoFrom3D(OBMol *mol, bool force = false);
00560 OBAPI void StereoFrom0D(OBMol *mol);
00562
00565
00603 OBAPI std::vector<OBTetrahedralStereo*> TetrahedralFrom3D(OBMol *mol,
00604 const OBStereoUnitSet &stereoUnits, bool addToMol = true);
00649 OBAPI std::vector<OBTetrahedralStereo*> TetrahedralFrom2D(OBMol *mol,
00650 const OBStereoUnitSet &stereoUnits, bool addToMol = true);
00670 OBAPI std::vector<OBTetrahedralStereo*> TetrahedralFrom0D(OBMol *mol,
00671 const OBStereoUnitSet &stereoUnits, bool addToMol = true);
00672
00709 OBAPI std::vector<OBCisTransStereo*> CisTransFrom3D(OBMol *mol,
00710 const OBStereoUnitSet &stereoUnits, bool addToMol = true);
00741 OBAPI std::vector<OBCisTransStereo*> CisTransFrom2D(OBMol *mol,
00742 const OBStereoUnitSet &stereoUnits,
00743 const std::map<OBBond*, enum OBStereo::BondDirection> *updown = NULL, bool addToMol = true);
00770 OBAPI bool TetStereoToWedgeHash(OBMol &mol,
00771 std::map<OBBond*, enum OBStereo::BondDirection> &updown,
00772 std::map<OBBond*, OBStereo::Ref> &from);
00784 OBAPI std::set<OBBond*> GetUnspecifiedCisTrans(OBMol& mol);
00796 OBAPI void StereoRefToImplicit(OBMol& mol, OBStereo::Ref atomId);
00816 OBAPI std::vector<OBCisTransStereo*> CisTransFrom0D(OBMol *mol,
00817 const OBStereoUnitSet &stereoUnits,
00818 bool addToMol = true);
00820
00821
00824
00904 OBAPI OBStereoUnitSet FindStereogenicUnits(OBMol *mol,
00905 const std::vector<unsigned int> &symClasses);
00982 OBAPI OBStereoUnitSet FindStereogenicUnits(OBMol *mol,
00983 const std::vector<unsigned int> &symClasses,
00984 const Automorphisms &automorphisms);
00986
01136
01137 }
01138
01139 #endif
01140