Loading...
Searching...
No Matches
stereo.h
Go to the documentation of this file.
/**********************************************************************
stereo.h - OBStereo & OBStereoBase
Copyright (C) 2009-2010 by Tim Vandermeersch
This file is part of the Open Babel project.
For more information, see <http://openbabel.org/>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
**********************************************************************/
#ifndef OB_STEREO_H
#define OB_STEREO_H
#include <openbabel/base.h> // OBGenericData
#include <openbabel/isomorphism.h> // Automorphisms
#include <vector>
#include <map>
#include <set>
#include <climits> // UINT_MAX
namespace OpenBabel {
struct OBAPI OBStereo
{
enum Type {
CisTrans = (1<<0),
ExtendedCisTrans = (1<<1),
SquarePlanar = (1<<2),
Tetrahedral = (1<<3),
ExtendedTetrahedral = (1<<4),
TrigonalBipyramidal = (1<<5),
Octahedral = (1<<6)
};
enum BondDirection { // Values taken from MDL format
NotStereo = 0,
UpBond = 1,
DownBond = 6,
UnknownDir = 4
};
enum Shape {
ShapeU = 1,
ShapeZ = 2,
Shape4 = 3
};
enum View
{
ViewFrom = 1,
ViewTowards = 2
};
enum Winding {
Clockwise = 1,
AntiClockwise = 2,
UnknownWinding = 3
};
typedef unsigned long Ref;
enum {
NoRef = UINT_MAX,
ImplicitRef = UINT_MAX - 1
};
typedef std::vector<Ref> Refs;
typedef Refs::iterator RefIter;
typedef Refs::const_iterator ConstRefIter;
static Refs MakeRefs(Ref ref1, Ref ref2, Ref ref3, Ref ref4 = NoRef)
{
Refs refs(3);
refs[0] = ref1;
refs[1] = ref2;
refs[2] = ref3;
if (ref4 != NoRef)
refs.push_back(ref4);
return refs;
}
static bool ContainsSameRefs(const Refs &refs1, const Refs &refs2);
static bool ContainsRef(const Refs &refs, unsigned long ref);
static int NumInversions(const Refs &refs);
static void Permutate(Refs &refs, unsigned int i, unsigned int j);
static Refs Permutated(const Refs &refs, unsigned int i, unsigned int j);
};
struct OBStereoUnit
{
OBStereoUnit() : type(static_cast<OBStereo::Type>(0)), id(OBStereo::NoRef), para(false)
{
}
OBStereoUnit(OBStereo::Type _type, unsigned long _id, bool _para = false) :
type(_type), id(_id), para(_para)
{
}
OBStereo::Type type;
unsigned long id;
bool para;
};
typedef std::vector<OBStereoUnit> OBStereoUnitSet;
typedef std::vector<OBStereoUnitSet> OBStereoUnitSetOfSets;
// fwd decl
class OBMol;
class OBAPI OBStereoBase : public OBGenericData
{
public:
OBStereoBase(OBMol *mol) :
OBGenericData("StereoData", OBGenericDataType::StereoData, perceived),
m_mol(mol), m_specified(true)
{
}
virtual ~OBStereoBase() { m_mol = nullptr; }
OBMol* GetMolecule() const { return m_mol; }
virtual OBStereo::Type GetType() const = 0;
void SetSpecified(bool specified) { m_specified = specified; }
bool IsSpecified() const { return m_specified; }
private:
OBMol *m_mol;
bool m_specified;
};
// fwd decl
class OBTetrahedralStereo;
class OBCisTransStereo;
class OBSquarePlanarStereo;
class OBAPI OBStereoFacade
{
public:
OBStereoFacade(OBMol *mol, bool perceive = true) :
m_mol(mol), m_init(false), m_perceive(perceive)
{
}
unsigned int NumTetrahedralStereo();
std::vector<OBTetrahedralStereo*> GetAllTetrahedralStereo();
bool HasTetrahedralStereo(unsigned long atomId);
OBTetrahedralStereo* GetTetrahedralStereo(unsigned long atomId);
unsigned int NumCisTransStereo();
std::vector<OBCisTransStereo*> GetAllCisTransStereo();
bool HasCisTransStereo(unsigned long bondId);
OBCisTransStereo* GetCisTransStereo(unsigned long bondId);
unsigned int NumSquarePlanarStereo();
std::vector<OBSquarePlanarStereo*> GetAllSquarePlanarStereo();
bool HasSquarePlanarStereo(unsigned long atomId);
OBSquarePlanarStereo* GetSquarePlanarStereo(unsigned long atomId);
template<int StereoType>
bool HasStereo(unsigned long id);
template<typename T>
T* GetStereo(unsigned long id);
private:
inline void EnsureInit() { if (!m_init) InitMaps(); }
void InitMaps();
OBMol *m_mol;
bool m_init;
bool m_perceive;
std::map<unsigned long, OBTetrahedralStereo*> m_tetrahedralMap;
std::map<unsigned long, OBCisTransStereo*> m_cistransMap;
std::map<unsigned long, OBSquarePlanarStereo*> m_squarePlanarMap;
};
// fwd decl
class OBBond;
OBAPI void PerceiveStereo(OBMol *mol, bool force = false);
OBAPI void StereoFrom2D(OBMol *mol,
std::map<OBBond*, enum OBStereo::BondDirection> *updown = nullptr, bool force = false);
OBAPI void StereoFrom3D(OBMol *mol, bool force = false);
OBAPI void StereoFrom0D(OBMol *mol);
OBAPI std::vector<OBTetrahedralStereo*> TetrahedralFrom3D(OBMol *mol,
const OBStereoUnitSet &stereoUnits, bool addToMol = true);
OBAPI std::vector<OBTetrahedralStereo*> TetrahedralFrom2D(OBMol *mol,
const OBStereoUnitSet &stereoUnits, bool addToMol = true);
OBAPI std::vector<OBTetrahedralStereo*> TetrahedralFrom0D(OBMol *mol,
const OBStereoUnitSet &stereoUnits, bool addToMol = true);
OBAPI std::vector<OBCisTransStereo*> CisTransFrom3D(OBMol *mol,
const OBStereoUnitSet &stereoUnits, bool addToMol = true);
OBAPI std::vector<OBCisTransStereo*> CisTransFrom2D(OBMol *mol,
const OBStereoUnitSet &stereoUnits,
const std::map<OBBond*, enum OBStereo::BondDirection> *updown = nullptr, bool addToMol = true);
OBAPI bool TetStereoToWedgeHash(OBMol &mol,
std::map<OBBond*, enum OBStereo::BondDirection> &updown,
std::map<OBBond*, OBStereo::Ref> &from);
OBAPI std::set<OBBond*> GetUnspecifiedCisTrans(OBMol& mol);
OBAPI void StereoRefToImplicit(OBMol& mol, OBStereo::Ref atomId);
OBAPI void ImplicitRefToStereo(OBMol& mol, OBStereo::Ref centerId, OBStereo::Ref newId);
OBAPI std::vector<OBCisTransStereo*> CisTransFrom0D(OBMol *mol,
const OBStereoUnitSet &stereoUnits,
bool addToMol = true);
OBAPI OBStereoUnitSet FindStereogenicUnits(OBMol *mol,
const std::vector<unsigned int> &symClasses);
OBAPI OBStereoUnitSet FindStereogenicUnits(OBMol *mol,
const std::vector<unsigned int> &symClasses,
const Automorphisms &automorphisms);
}
#endif
base.h
Base classes to build a graph.
OpenBabel::OBCisTransStereo
Class for handling and storing cis/trans stereochemistry.
Definition cistrans.h:76
OpenBabel::OBGenericData::OBGenericData
OBGenericData(const std::string attr="undefined", const unsigned int type=OBGenericDataType::UndefinedData, const DataOrigin source=any)
Definition generic.cpp:166
OpenBabel::OBMol
Molecule Class.
Definition mol.h:121
OpenBabel::OBSquarePlanarStereo
Class for handling and storing square planar stereochemistry.
Definition squareplanar.h:49
OpenBabel::OBStereoBase::OBStereoBase
OBStereoBase(OBMol *mol)
Definition stereo.h:330
OpenBabel::OBStereoBase::GetType
virtual OBStereo::Type GetType() const =0
OpenBabel::OBStereoBase::IsSpecified
bool IsSpecified() const
Definition stereo.h:360
OpenBabel::OBStereoBase::GetMolecule
OBMol * GetMolecule() const
Definition stereo.h:346
OpenBabel::OBStereoBase::SetSpecified
void SetSpecified(bool specified)
Definition stereo.h:356
OpenBabel::OBStereoBase::~OBStereoBase
virtual ~OBStereoBase()
Definition stereo.h:338
OpenBabel::OBStereoFacade::HasSquarePlanarStereo
bool HasSquarePlanarStereo(unsigned long atomId)
OpenBabel::OBStereoFacade::GetSquarePlanarStereo
OBSquarePlanarStereo * GetSquarePlanarStereo(unsigned long atomId)
OpenBabel::OBStereoFacade::HasStereo
bool HasStereo(unsigned long id)
OpenBabel::OBStereoFacade::NumCisTransStereo
unsigned int NumCisTransStereo()
OpenBabel::OBStereoFacade::HasCisTransStereo
bool HasCisTransStereo(unsigned long bondId)
OpenBabel::OBStereoFacade::NumSquarePlanarStereo
unsigned int NumSquarePlanarStereo()
OpenBabel::OBStereoFacade::HasTetrahedralStereo
bool HasTetrahedralStereo(unsigned long atomId)
OpenBabel::OBStereoFacade::GetAllCisTransStereo
std::vector< OBCisTransStereo * > GetAllCisTransStereo()
OpenBabel::OBStereoFacade::NumTetrahedralStereo
unsigned int NumTetrahedralStereo()
OpenBabel::OBStereoFacade::GetCisTransStereo
OBCisTransStereo * GetCisTransStereo(unsigned long bondId)
OpenBabel::OBStereoFacade::GetAllSquarePlanarStereo
std::vector< OBSquarePlanarStereo * > GetAllSquarePlanarStereo()
OpenBabel::OBStereoFacade::GetAllTetrahedralStereo
std::vector< OBTetrahedralStereo * > GetAllTetrahedralStereo()
OpenBabel::OBStereoFacade::GetStereo
T * GetStereo(unsigned long id)
OpenBabel::OBStereoFacade::GetTetrahedralStereo
OBTetrahedralStereo * GetTetrahedralStereo(unsigned long atomId)
OpenBabel::OBStereoFacade::OBStereoFacade
OBStereoFacade(OBMol *mol, bool perceive=true)
Definition stereo.h:394
OpenBabel::OBTetrahedralStereo
Class for handling and storing tetrahedral atom stereochemistry.
Definition tetrahedral.h:59
OpenBabel::TetrahedralFrom0D
std::vector< OBTetrahedralStereo * > TetrahedralFrom0D(OBMol *mol, const OBStereoUnitSet &stereoUnits, bool addToMol=true)
OpenBabel::OBStereoUnitSet
std::vector< OBStereoUnit > OBStereoUnitSet
A single set of OBStereoUnit objects.
Definition stereo.h:287
OpenBabel::PerceiveStereo
void PerceiveStereo(OBMol *mol, bool force=false)
OpenBabel::TetrahedralFrom2D
std::vector< OBTetrahedralStereo * > TetrahedralFrom2D(OBMol *mol, const OBStereoUnitSet &stereoUnits, bool addToMol=true)
OpenBabel::ImplicitRefToStereo
void ImplicitRefToStereo(OBMol &mol, OBStereo::Ref centerId, OBStereo::Ref newId)
OpenBabel::StereoFrom2D
void StereoFrom2D(OBMol *mol, std::map< OBBond *, enum OBStereo::BondDirection > *updown=nullptr, bool force=false)
OpenBabel::TetrahedralFrom3D
std::vector< OBTetrahedralStereo * > TetrahedralFrom3D(OBMol *mol, const OBStereoUnitSet &stereoUnits, bool addToMol=true)
OpenBabel::CisTransFrom2D
std::vector< OBCisTransStereo * > CisTransFrom2D(OBMol *mol, const OBStereoUnitSet &stereoUnits, const std::map< OBBond *, enum OBStereo::BondDirection > *updown=nullptr, bool addToMol=true)
OpenBabel::OBStereoUnitSetOfSets
std::vector< OBStereoUnitSet > OBStereoUnitSetOfSets
A set of sets of OBStereoUnit objects.
Definition stereo.h:294
OpenBabel::GetUnspecifiedCisTrans
std::set< OBBond * > GetUnspecifiedCisTrans(OBMol &mol)
OpenBabel::CisTransFrom0D
std::vector< OBCisTransStereo * > CisTransFrom0D(OBMol *mol, const OBStereoUnitSet &stereoUnits, bool addToMol=true)
OpenBabel::CisTransFrom3D
std::vector< OBCisTransStereo * > CisTransFrom3D(OBMol *mol, const OBStereoUnitSet &stereoUnits, bool addToMol=true)
OpenBabel::StereoFrom3D
void StereoFrom3D(OBMol *mol, bool force=false)
OpenBabel::StereoFrom0D
void StereoFrom0D(OBMol *mol)
OpenBabel::TetStereoToWedgeHash
bool TetStereoToWedgeHash(OBMol &mol, std::map< OBBond *, enum OBStereo::BondDirection > &updown, std::map< OBBond *, OBStereo::Ref > &from)
OpenBabel::StereoRefToImplicit
void StereoRefToImplicit(OBMol &mol, OBStereo::Ref atomId)
OpenBabel::FindStereogenicUnits
OBStereoUnitSet FindStereogenicUnits(OBMol *mol, const std::vector< unsigned int > &symClasses)
OpenBabel::Automorphisms
OBIsomorphismMapper::Mappings Automorphisms
A group of automorphic permutations.
Definition isomorphism.h:206
isomorphism.h
OBIsomorphismMapper class for finding isomorphisms.
OpenBabel::OBGenericDataType
Classification of data stored via OBGenericData class and subclasses.
Definition base.h:63
OpenBabel
Global namespace for all Open Babel code.
Definition alias.h:23
OpenBabel::perceived
@ perceived
Perceived by Open Babel library methods.
Definition base.h:180
OpenBabel::OBStereoUnit::OBStereoUnit
OBStereoUnit(OBStereo::Type _type, unsigned long _id, bool _para=false)
Definition stereo.h:271
OpenBabel::OBStereoUnit::para
bool para
the atom/bond (depends on type) unique id
Definition stereo.h:278
OpenBabel::OBStereoUnit::OBStereoUnit
OBStereoUnit()
Definition stereo.h:264
OpenBabel::OBStereoUnit::type
OBStereo::Type type
the type for this stereogenic unit
Definition stereo.h:276
OpenBabel::OBStereoUnit::id
unsigned long id
Definition stereo.h:277
OpenBabel::OBStereo
Placeholder for enums & Ref/Refs related functions.
Definition stereo.h:76
OpenBabel::OBStereo::ImplicitRef
@ ImplicitRef
Implicit Ref (i.e. hydrogen, N lone pair, ...).
Definition stereo.h:151
OpenBabel::OBStereo::NoRef
@ NoRef
No Ref set (invalid Ref).
Definition stereo.h:150
OpenBabel::OBStereo::NumInversions
static int NumInversions(const Refs &refs)
OpenBabel::OBStereo::RefIter
Refs::iterator RefIter
Definition stereo.h:160
OpenBabel::OBStereo::Type
Type
Definition stereo.h:80
OpenBabel::OBStereo::ExtendedCisTrans
@ ExtendedCisTrans
allene, biphenyl, ...
Definition stereo.h:82
OpenBabel::OBStereo::Tetrahedral
@ Tetrahedral
tetrahedral
Definition stereo.h:84
OpenBabel::OBStereo::Octahedral
@ Octahedral
Octahedral stereochemistry.
Definition stereo.h:87
OpenBabel::OBStereo::SquarePlanar
@ SquarePlanar
Square-planar stereochemistry.
Definition stereo.h:83
OpenBabel::OBStereo::TrigonalBipyramidal
@ TrigonalBipyramidal
Trigonal-bipyramidal stereochemistry.
Definition stereo.h:86
OpenBabel::OBStereo::ExtendedTetrahedral
@ ExtendedTetrahedral
extended tetrahedral
Definition stereo.h:85
OpenBabel::OBStereo::CisTrans
@ CisTrans
cis/trans double bond
Definition stereo.h:81
OpenBabel::OBStereo::Shape
Shape
Definition stereo.h:108
OpenBabel::OBStereo::ShapeU
@ ShapeU
Definition stereo.h:109
OpenBabel::OBStereo::ShapeZ
@ ShapeZ
Definition stereo.h:110
OpenBabel::OBStereo::Shape4
@ Shape4
Definition stereo.h:111
OpenBabel::OBStereo::MakeRefs
static Refs MakeRefs(Ref ref1, Ref ref2, Ref ref3, Ref ref4=NoRef)
Definition stereo.h:175
OpenBabel::OBStereo::ConstRefIter
Refs::const_iterator ConstRefIter
Definition stereo.h:164
OpenBabel::OBStereo::Permutate
static void Permutate(Refs &refs, unsigned int i, unsigned int j)
OpenBabel::OBStereo::ContainsRef
static bool ContainsRef(const Refs &refs, unsigned long ref)
OpenBabel::OBStereo::BondDirection
BondDirection
Definition stereo.h:94
OpenBabel::OBStereo::UnknownDir
@ UnknownDir
Definition stereo.h:98
OpenBabel::OBStereo::DownBond
@ DownBond
Definition stereo.h:97
OpenBabel::OBStereo::NotStereo
@ NotStereo
Definition stereo.h:95
OpenBabel::OBStereo::UpBond
@ UpBond
Definition stereo.h:96
OpenBabel::OBStereo::Refs
std::vector< Ref > Refs
Definition stereo.h:156
OpenBabel::OBStereo::Permutated
static Refs Permutated(const Refs &refs, unsigned int i, unsigned int j)
OpenBabel::OBStereo::ContainsSameRefs
static bool ContainsSameRefs(const Refs &refs1, const Refs &refs2)
OpenBabel::OBStereo::Winding
Winding
Definition stereo.h:130
OpenBabel::OBStereo::AntiClockwise
@ AntiClockwise
AntiClockwise winding (or CounterClockwise).
Definition stereo.h:132
OpenBabel::OBStereo::UnknownWinding
@ UnknownWinding
The configuration is specified as unknown (squiggly line in depiction).
Definition stereo.h:133
OpenBabel::OBStereo::Clockwise
@ Clockwise
Clockwise winding.
Definition stereo.h:131
OpenBabel::OBStereo::View
View
Definition stereo.h:120
OpenBabel::OBStereo::ViewTowards
@ ViewTowards
view from center atom towards the atom (id parameter)
Definition stereo.h:122
OpenBabel::OBStereo::ViewFrom
@ ViewFrom
view from the atom (id parameter) towards the center atom
Definition stereo.h:121
OpenBabel::OBStereo::Ref
unsigned long Ref
Definition stereo.h:145