Loading...
Searching...
No Matches
bindings.h
Go to the documentation of this file.
#include <openbabel/stereo/stereo.h>
namespace OpenBabel {
struct OBTetrahedralConfig
{
#ifndef SWIG
static OBTetrahedralStereo::Config Convert(const OBTetrahedralConfig &other)
{
OBTetrahedralStereo::Config config;
config.center = other.center;
config.from = other.from_or_towards;
config.refs = other.refs;
config.winding = other.winding;
config.view = other.view;
config.specified = other.specified;
return config;
}
#endif
bool operator==(const OBTetrahedralConfig &other) const
{
if (center != other.center)
return false;
if ((refs.size() != 3) || (other.refs.size() != 3))
return false;
// return true if either is unspecified (i.e. accidental)
if (!specified || !other.specified)
return true;
// Convert both Config's refs to same from, winding and view while
// avoiding having an ImplicitRef in the 'from' position of either
OBTetrahedralStereo::Config thisConfig = Convert(*this), otherConfig = Convert(other);
if (from_or_towards == OBStereo::ImplicitRef) {
thisConfig = OBTetraNonPlanarStereo::ToConfig(thisConfig, refs[0], winding, view);
otherConfig = OBTetraNonPlanarStereo::ToConfig(otherConfig, thisConfig.from, winding, view);
}
else if (other.from_or_towards == OBStereo::ImplicitRef) {
otherConfig = OBTetraNonPlanarStereo::ToConfig(otherConfig, other.refs[0], winding, view);
thisConfig = OBTetraNonPlanarStereo::ToConfig(thisConfig, otherConfig.from, winding, view);
}
else {
otherConfig = OBTetraNonPlanarStereo::ToConfig(otherConfig, thisConfig.from, winding, view);
}
if (!OBStereo::ContainsSameRefs(thisConfig.refs, otherConfig.refs)) {
if (OBStereo::ContainsRef(thisConfig.refs, OBStereo::ImplicitRef)) {
// if both refs already contain ImplicitRef, return false
if (OBStereo::ContainsRef(otherConfig.refs, OBStereo::ImplicitRef))
return false;
// example: *this = 23H
// otherConfig = 234 --> 23H
// for each ref in otherConfig
for (unsigned int i = 0; i < otherConfig.refs.size(); ++i) {
bool found = false;
for (OBStereo::RefIter j = thisConfig.refs.begin(); j != thisConfig.refs.end(); ++j)
if (otherConfig.refs.at(i) == *j)
found = true;
if (!found) {
// the ref from otherConfig is not found in this config
otherConfig.refs[i] = OBStereo::ImplicitRef;
break;
}
}
} else
if (OBStereo::ContainsRef(otherConfig.refs, OBStereo::ImplicitRef)) {
// if both refs already contain ImplicitRef, return false
if (OBStereo::ContainsRef(thisConfig.refs, OBStereo::ImplicitRef))
return false;
// example: *this = 234
// otherConfig = 23H --> 234
// for each ref in *this
for (unsigned int i = 0; i < thisConfig.refs.size(); ++i) {
bool found = false;
// for each refs in otherConfig
for (OBStereo::RefIter j = otherConfig.refs.begin(); j != otherConfig.refs.end(); ++j)
if (thisConfig.refs.at(i) == *j)
found = true;
if (!found) {
for (OBStereo::RefIter j = otherConfig.refs.begin(); j != otherConfig.refs.end(); ++j)
if (*j == OBStereo::ImplicitRef)
*j = thisConfig.refs.at(i);
break;
}
}
}
}
int Ni1 = OBStereo::NumInversions(thisConfig.refs);
int Ni2 = OBStereo::NumInversions(otherConfig.refs);
return ((Ni1 + Ni2) % 2 == 0);
}
bool operator!=(const OBTetrahedralConfig &other) const
{
return !(*this == other);
}
unsigned long center;
unsigned long from_or_towards;
OBStereo::Refs refs;
OBStereo::Winding winding;
OBStereo::View view;
bool specified;
};
struct OBCisTransConfig
{
#ifndef SWIG
static OBCisTransStereo::Config Convert(const OBCisTransConfig &other)
{
OBCisTransStereo::Config config;
config.begin = other.begin;
config.end = other.end;
config.refs = other.refs;
config.shape = other.shape;
config.specified = other.specified;
return config;
}
#endif
bool operator==(const OBCisTransConfig &other) const
{
if ((begin != other.begin) && (begin != other.end))
return false;
if ((end != other.begin) && (end != other.end))
return false;
if ((refs.size() != 4) || (other.refs.size() != 4))
return false;
OBCisTransStereo::Config u1, u2;
if (!OBStereo::ContainsSameRefs(refs, other.refs)) {
// find a ref that occurs in both
for (OBStereo::ConstRefIter i = refs.begin(); i != refs.end(); ++i)
if (OBStereo::ContainsRef(other.refs, *i)) {
u1 = OBTetraPlanarStereo::ToConfig(Convert(*this), *i, OBStereo::ShapeU); // refs[0] = u1.refs[0]
u2 = OBTetraPlanarStereo::ToConfig(Convert(other), *i, OBStereo::ShapeU); // refs[0] = u2.refs[0]
}
// check if they actualy share an id...
if (u1.refs.empty())
return false;
} else {
// normalize the other Config struct
u1 = OBTetraPlanarStereo::ToConfig(Convert(*this), refs.at(0), OBStereo::ShapeU); // refs[0] = u1.refs[0]
u2 = OBTetraPlanarStereo::ToConfig(Convert(other), refs.at(0), OBStereo::ShapeU); // refs[0] = u2.refs[0]
// both now start with the same ref
return (u1.refs[2] == u2.refs[2]);
}
if ((u1.refs[2] == OBStereo::ImplicitRef) || (u2.refs[2] == OBStereo::ImplicitRef)) {
// 1 2 H 4
if ((u1.refs[3] == OBStereo::ImplicitRef) || (u2.refs[3] == OBStereo::ImplicitRef)) {
return (u1.refs[1] == u2.refs[1]); // 1 2 H H
} else {
return (u1.refs[3] == u2.refs[3]); // 1 H H 4
}
} else
return (u1.refs[2] == u2.refs[2]); // 1 2 3 4 & 1 H 3 4 & 1 2 3 H
return false;
}
bool operator!=(const OBCisTransConfig &other) const
{
return !(*this == other);
}
unsigned long begin, end;
OBStereo::Refs refs;
OBStereo::Shape shape;
bool specified;
};
struct OBSquarePlanarConfig
{
#ifndef SWIG
static OBSquarePlanarStereo::Config Convert(const OBSquarePlanarConfig &other)
{
OBSquarePlanarStereo::Config config;
config.center = other.center;
config.refs = other.refs;
config.shape = other.shape;
config.specified = other.specified;
return config;
}
#endif
bool operator==(const OBSquarePlanarConfig &other) const
{
if (center != other.center)
return false;
if ((refs.size() != 4) || (other.refs.size() != 4))
return false;
OBSquarePlanarStereo::Config u1, u2;
if (!OBStereo::ContainsSameRefs(refs, other.refs)) {
// find a ref that occurs in both
for (OBStereo::ConstRefIter i = refs.begin(); i != refs.end(); ++i)
if (OBStereo::ContainsRef(other.refs, *i)) {
u1 = OBTetraPlanarStereo::ToConfig(Convert(*this), *i, OBStereo::ShapeU); // refs[0] = u1.refs[0]
u2 = OBTetraPlanarStereo::ToConfig(Convert(other), *i, OBStereo::ShapeU); // refs[0] = u2.refs[0]
}
// check if they actualy share an id...
if (u1.refs.empty())
return false;
} else {
// normalize the other Config struct
u1 = OBTetraPlanarStereo::ToConfig(Convert(*this), refs.at(0), OBStereo::ShapeU); // refs[0] = u1.refs[0]
u2 = OBTetraPlanarStereo::ToConfig(Convert(other), refs.at(0), OBStereo::ShapeU); // refs[0] = u2.refs[0]
// both now start with the same ref
return (u1.refs[2] == u2.refs[2]);
}
if ((u1.refs[2] == OBStereo::ImplicitRef) || (u2.refs[2] == OBStereo::ImplicitRef)) {
// 1 2 H 4
if ((u1.refs[3] == OBStereo::ImplicitRef) || (u2.refs[3] == OBStereo::ImplicitRef)) {
return (u1.refs[1] == u2.refs[1]); // 1 2 H H
} else {
return (u1.refs[3] == u2.refs[3]); // 1 H H 4
}
} else
return (u1.refs[2] == u2.refs[2]); // 1 2 3 4 & 1 H 3 4 & 1 2 3 H
return false;
}
bool operator!=(const OBSquarePlanarConfig &other) const
{
return !(*this == other);
}
unsigned long center;
OBStereo::Refs refs;
OBStereo::Shape shape;
bool specified;
};
}
OpenBabel::OBTetraNonPlanarStereo::ToConfig
static ConfigType ToConfig(const ConfigType &cfg, unsigned long from_or_towards, OBStereo::Winding winding=OBStereo::Clockwise, OBStereo::View view=OBStereo::ViewFrom)
Definition tetranonplanar.h:145
OpenBabel::OBTetraPlanarStereo::ToConfig
static ConfigType ToConfig(const ConfigType &cfg, unsigned long start, OBStereo::Shape shape=OBStereo::ShapeU)
Definition tetraplanar.h:90
OpenBabel
Global namespace for all Open Babel code.
Definition alias.h:23
stereo.h
Process molecular stereochemistry information.
OpenBabel::OBCisTransConfig
Definition bindings.h:115
OpenBabel::OBCisTransConfig::refs
OBStereo::Refs refs
Definition bindings.h:177
OpenBabel::OBCisTransConfig::begin
unsigned long begin
Definition bindings.h:176
OpenBabel::OBCisTransConfig::operator==
bool operator==(const OBCisTransConfig &other) const
Definition bindings.h:129
OpenBabel::OBCisTransConfig::shape
OBStereo::Shape shape
Definition bindings.h:178
OpenBabel::OBCisTransConfig::end
unsigned long end
Definition bindings.h:176
OpenBabel::OBCisTransConfig::operator!=
bool operator!=(const OBCisTransConfig &other) const
Definition bindings.h:171
OpenBabel::OBCisTransConfig::specified
bool specified
Definition bindings.h:179
OpenBabel::OBCisTransConfig::Convert
static OBCisTransStereo::Config Convert(const OBCisTransConfig &other)
Definition bindings.h:117
OpenBabel::OBCisTransStereo::Config
Stereochemical configuration for double-bond cis/trans stereochemistry.
Definition cistrans.h:100
OpenBabel::OBCisTransStereo::Config::refs
OBStereo::Refs refs
The 4 reference ids.
Definition cistrans.h:200
OpenBabel::OBCisTransStereo::Config::begin
unsigned long begin
Definition cistrans.h:199
OpenBabel::OBCisTransStereo::Config::shape
OBStereo::Shape shape
The shape of the 4 reference ids.
Definition cistrans.h:201
OpenBabel::OBCisTransStereo::Config::end
unsigned long end
Definition cistrans.h:199
OpenBabel::OBCisTransStereo::Config::specified
bool specified
Definition cistrans.h:202
OpenBabel::OBSquarePlanarConfig
Definition bindings.h:183
OpenBabel::OBSquarePlanarConfig::operator!=
bool operator!=(const OBSquarePlanarConfig &other) const
Definition bindings.h:236
OpenBabel::OBSquarePlanarConfig::refs
OBStereo::Refs refs
Definition bindings.h:242
OpenBabel::OBSquarePlanarConfig::operator==
bool operator==(const OBSquarePlanarConfig &other) const
Definition bindings.h:196
OpenBabel::OBSquarePlanarConfig::shape
OBStereo::Shape shape
Definition bindings.h:243
OpenBabel::OBSquarePlanarConfig::center
unsigned long center
Definition bindings.h:241
OpenBabel::OBSquarePlanarConfig::specified
bool specified
Definition bindings.h:244
OpenBabel::OBSquarePlanarConfig::Convert
static OBSquarePlanarStereo::Config Convert(const OBSquarePlanarConfig &other)
Definition bindings.h:185
OpenBabel::OBSquarePlanarStereo::Config
Stereochemical configuration for square planar stereocenters.
Definition squareplanar.h:72
OpenBabel::OBSquarePlanarStereo::Config::refs
OBStereo::Refs refs
The 4 reference ids.
Definition squareplanar.h:171
OpenBabel::OBSquarePlanarStereo::Config::shape
OBStereo::Shape shape
The shape of the 4 reference ids.
Definition squareplanar.h:172
OpenBabel::OBSquarePlanarStereo::Config::center
unsigned long center
Definition squareplanar.h:170
OpenBabel::OBSquarePlanarStereo::Config::specified
bool specified
Definition squareplanar.h:173
OpenBabel::OBStereo::ImplicitRef
@ ImplicitRef
Implicit Ref (i.e. hydrogen, N lone pair, ...).
Definition stereo.h:151
OpenBabel::OBStereo::NumInversions
static int NumInversions(const Refs &refs)
OpenBabel::OBStereo::RefIter
Refs::iterator RefIter
Definition stereo.h:160
OpenBabel::OBStereo::Shape
Shape
Definition stereo.h:108
OpenBabel::OBStereo::ShapeU
@ ShapeU
Definition stereo.h:109
OpenBabel::OBStereo::ConstRefIter
Refs::const_iterator ConstRefIter
Definition stereo.h:164
OpenBabel::OBStereo::ContainsRef
static bool ContainsRef(const Refs &refs, unsigned long ref)
OpenBabel::OBStereo::Refs
std::vector< Ref > Refs
Definition stereo.h:156
OpenBabel::OBStereo::ContainsSameRefs
static bool ContainsSameRefs(const Refs &refs1, const Refs &refs2)
OpenBabel::OBStereo::Winding
Winding
Definition stereo.h:130
OpenBabel::OBStereo::View
View
Definition stereo.h:120
OpenBabel::OBTetrahedralConfig
Definition bindings.h:6
OpenBabel::OBTetrahedralConfig::Convert
static OBTetrahedralStereo::Config Convert(const OBTetrahedralConfig &other)
Definition bindings.h:8
OpenBabel::OBTetrahedralConfig::operator==
bool operator==(const OBTetrahedralConfig &other) const
Definition bindings.h:21
OpenBabel::OBTetrahedralConfig::view
OBStereo::View view
Definition bindings.h:110
OpenBabel::OBTetrahedralConfig::refs
OBStereo::Refs refs
Definition bindings.h:108
OpenBabel::OBTetrahedralConfig::winding
OBStereo::Winding winding
Definition bindings.h:109
OpenBabel::OBTetrahedralConfig::center
unsigned long center
Definition bindings.h:106
OpenBabel::OBTetrahedralConfig::specified
bool specified
Definition bindings.h:111
OpenBabel::OBTetrahedralConfig::operator!=
bool operator!=(const OBTetrahedralConfig &other) const
Definition bindings.h:101
OpenBabel::OBTetrahedralConfig::from_or_towards
unsigned long from_or_towards
Definition bindings.h:107
OpenBabel::OBTetrahedralStereo::Config
Stereochemical configuration for tetrahedral stereocenters.
Definition tetrahedral.h:85
OpenBabel::OBTetrahedralStereo::Config::from
unsigned long from
Definition tetrahedral.h:173
OpenBabel::OBTetrahedralStereo::Config::view
OBStereo::View view
Specify viewing from or towards the atom with from/towards id.
Definition tetrahedral.h:178
OpenBabel::OBTetrahedralStereo::Config::refs
OBStereo::Refs refs
The 3 reference ids.
Definition tetrahedral.h:176
OpenBabel::OBTetrahedralStereo::Config::winding
OBStereo::Winding winding
Definition tetrahedral.h:177
OpenBabel::OBTetrahedralStereo::Config::center
unsigned long center
Definition tetrahedral.h:164
OpenBabel::OBTetrahedralStereo::Config::specified
bool specified
Definition tetrahedral.h:179