Open Babel  3.0
bindings.h
Go to the documentation of this file.
2 
3 namespace OpenBabel {
4 
6  {
7 #ifndef SWIG
9  {
11  config.center = other.center;
12  config.from = other.from_or_towards;
13  config.refs = other.refs;
14  config.winding = other.winding;
15  config.view = other.view;
16  config.specified = other.specified;
17  return config;
18  }
19 #endif
20 
21  bool operator==(const OBTetrahedralConfig &other) const
22  {
23  if (center != other.center)
24  return false;
25  if ((refs.size() != 3) || (other.refs.size() != 3))
26  return false;
27  // return true if either is unspecified (i.e. accidental)
28  if (!specified || !other.specified)
29  return true;
30 
31  // Convert both Config's refs to same from, winding and view while
32  // avoiding having an ImplicitRef in the 'from' position of either
33  OBTetrahedralStereo::Config thisConfig = Convert(*this), otherConfig = Convert(other);
34 
36  thisConfig = OBTetraNonPlanarStereo::ToConfig(thisConfig, refs[0], winding, view);
37  otherConfig = OBTetraNonPlanarStereo::ToConfig(otherConfig, thisConfig.from, winding, view);
38  }
39  else if (other.from_or_towards == OBStereo::ImplicitRef) {
40  otherConfig = OBTetraNonPlanarStereo::ToConfig(otherConfig, other.refs[0], winding, view);
41  thisConfig = OBTetraNonPlanarStereo::ToConfig(thisConfig, otherConfig.from, winding, view);
42  }
43  else {
44  otherConfig = OBTetraNonPlanarStereo::ToConfig(otherConfig, thisConfig.from, winding, view);
45  }
46 
47  if (!OBStereo::ContainsSameRefs(thisConfig.refs, otherConfig.refs)) {
49  // if both refs already contain ImplicitRef, return false
50  if (OBStereo::ContainsRef(otherConfig.refs, OBStereo::ImplicitRef))
51  return false;
52 
53  // example: *this = 23H
54  // otherConfig = 234 --> 23H
55 
56  // for each ref in otherConfig
57  for (unsigned int i = 0; i < otherConfig.refs.size(); ++i) {
58  bool found = false;
59  for (OBStereo::RefIter j = thisConfig.refs.begin(); j != thisConfig.refs.end(); ++j)
60  if (otherConfig.refs.at(i) == *j)
61  found = true;
62 
63  if (!found) {
64  // the ref from otherConfig is not found in this config
65  otherConfig.refs[i] = OBStereo::ImplicitRef;
66  break;
67  }
68  }
69  } else
70  if (OBStereo::ContainsRef(otherConfig.refs, OBStereo::ImplicitRef)) {
71  // if both refs already contain ImplicitRef, return false
73  return false;
74 
75  // example: *this = 234
76  // otherConfig = 23H --> 234
77 
78  // for each ref in *this
79  for (unsigned int i = 0; i < thisConfig.refs.size(); ++i) {
80  bool found = false;
81  // for each refs in otherConfig
82  for (OBStereo::RefIter j = otherConfig.refs.begin(); j != otherConfig.refs.end(); ++j)
83  if (thisConfig.refs.at(i) == *j)
84  found = true;
85 
86  if (!found) {
87  for (OBStereo::RefIter j = otherConfig.refs.begin(); j != otherConfig.refs.end(); ++j)
88  if (*j == OBStereo::ImplicitRef)
89  *j = thisConfig.refs.at(i);
90  break;
91  }
92  }
93  }
94  }
95 
96  int Ni1 = OBStereo::NumInversions(thisConfig.refs);
97  int Ni2 = OBStereo::NumInversions(otherConfig.refs);
98  return ((Ni1 + Ni2) % 2 == 0);
99  }
100 
101  bool operator!=(const OBTetrahedralConfig &other) const
102  {
103  return !(*this == other);
104  }
105 
106  unsigned long center;
107  unsigned long from_or_towards;
111  bool specified;
112  };
113 
115  {
116 #ifndef SWIG
118  {
120  config.begin = other.begin;
121  config.end = other.end;
122  config.refs = other.refs;
123  config.shape = other.shape;
124  config.specified = other.specified;
125  return config;
126  }
127 #endif
128 
129  bool operator==(const OBCisTransConfig &other) const
130  {
131  if ((begin != other.begin) && (begin != other.end))
132  return false;
133  if ((end != other.begin) && (end != other.end))
134  return false;
135  if ((refs.size() != 4) || (other.refs.size() != 4))
136  return false;
137 
139  if (!OBStereo::ContainsSameRefs(refs, other.refs)) {
140  // find a ref that occurs in both
141  for (OBStereo::ConstRefIter i = refs.begin(); i != refs.end(); ++i)
142  if (OBStereo::ContainsRef(other.refs, *i)) {
143  u1 = OBTetraPlanarStereo::ToConfig(Convert(*this), *i, OBStereo::ShapeU); // refs[0] = u1.refs[0]
144  u2 = OBTetraPlanarStereo::ToConfig(Convert(other), *i, OBStereo::ShapeU); // refs[0] = u2.refs[0]
145  }
146 
147  // check if they actualy share an id...
148  if (u1.refs.empty())
149  return false;
150  } else {
151  // normalize the other Config struct
152  u1 = OBTetraPlanarStereo::ToConfig(Convert(*this), refs.at(0), OBStereo::ShapeU); // refs[0] = u1.refs[0]
153  u2 = OBTetraPlanarStereo::ToConfig(Convert(other), refs.at(0), OBStereo::ShapeU); // refs[0] = u2.refs[0]
154  // both now start with the same ref
155  return (u1.refs[2] == u2.refs[2]);
156  }
157 
158  if ((u1.refs[2] == OBStereo::ImplicitRef) || (u2.refs[2] == OBStereo::ImplicitRef)) {
159  // 1 2 H 4
160  if ((u1.refs[3] == OBStereo::ImplicitRef) || (u2.refs[3] == OBStereo::ImplicitRef)) {
161  return (u1.refs[1] == u2.refs[1]); // 1 2 H H
162  } else {
163  return (u1.refs[3] == u2.refs[3]); // 1 H H 4
164  }
165  } else
166  return (u1.refs[2] == u2.refs[2]); // 1 2 3 4 & 1 H 3 4 & 1 2 3 H
167 
168  return false;
169  }
170 
171  bool operator!=(const OBCisTransConfig &other) const
172  {
173  return !(*this == other);
174  }
175 
176  unsigned long begin, end;
179  bool specified;
180  };
181 
183  {
184 #ifndef SWIG
186  {
188  config.center = other.center;
189  config.refs = other.refs;
190  config.shape = other.shape;
191  config.specified = other.specified;
192  return config;
193  }
194 #endif
195 
196  bool operator==(const OBSquarePlanarConfig &other) const
197  {
198  if (center != other.center)
199  return false;
200  if ((refs.size() != 4) || (other.refs.size() != 4))
201  return false;
202 
204  if (!OBStereo::ContainsSameRefs(refs, other.refs)) {
205  // find a ref that occurs in both
206  for (OBStereo::ConstRefIter i = refs.begin(); i != refs.end(); ++i)
207  if (OBStereo::ContainsRef(other.refs, *i)) {
208  u1 = OBTetraPlanarStereo::ToConfig(Convert(*this), *i, OBStereo::ShapeU); // refs[0] = u1.refs[0]
209  u2 = OBTetraPlanarStereo::ToConfig(Convert(other), *i, OBStereo::ShapeU); // refs[0] = u2.refs[0]
210  }
211 
212  // check if they actualy share an id...
213  if (u1.refs.empty())
214  return false;
215  } else {
216  // normalize the other Config struct
217  u1 = OBTetraPlanarStereo::ToConfig(Convert(*this), refs.at(0), OBStereo::ShapeU); // refs[0] = u1.refs[0]
218  u2 = OBTetraPlanarStereo::ToConfig(Convert(other), refs.at(0), OBStereo::ShapeU); // refs[0] = u2.refs[0]
219  // both now start with the same ref
220  return (u1.refs[2] == u2.refs[2]);
221  }
222 
223  if ((u1.refs[2] == OBStereo::ImplicitRef) || (u2.refs[2] == OBStereo::ImplicitRef)) {
224  // 1 2 H 4
225  if ((u1.refs[3] == OBStereo::ImplicitRef) || (u2.refs[3] == OBStereo::ImplicitRef)) {
226  return (u1.refs[1] == u2.refs[1]); // 1 2 H H
227  } else {
228  return (u1.refs[3] == u2.refs[3]); // 1 H H 4
229  }
230  } else
231  return (u1.refs[2] == u2.refs[2]); // 1 2 3 4 & 1 H 3 4 & 1 2 3 H
232 
233  return false;
234  }
235 
236  bool operator!=(const OBSquarePlanarConfig &other) const
237  {
238  return !(*this == other);
239  }
240 
241  unsigned long center;
244  bool specified;
245  };
246 
247 
248 }
static OBSquarePlanarStereo::Config Convert(const OBSquarePlanarConfig &other)
Definition: bindings.h:185
OBStereo::Refs refs
The 3 reference ids.
Definition: tetrahedral.h:176
bool specified
Definition: squareplanar.h:173
bool operator==(const OBTetrahedralConfig &other) const
Definition: bindings.h:21
Stereochemical configuration for square planar stereocenters.
Definition: squareplanar.h:71
OBStereo::Shape shape
The shape of the 4 reference ids.
Definition: squareplanar.h:172
unsigned long center
Definition: bindings.h:106
unsigned long from
Definition: tetrahedral.h:173
Refs::const_iterator ConstRefIter
Definition: stereo.h:164
Definition: bindings.h:182
Implicit Ref (i.e. hydrogen, N lone pair, ...).
Definition: stereo.h:151
Definition: bindings.h:114
OBStereo::Refs refs
Definition: bindings.h:242
static int NumInversions(const Refs &refs)
OBStereo::View view
Specify viewing from or towards the atom with from/towards id.
Definition: tetrahedral.h:178
static OBTetrahedralStereo::Config Convert(const OBTetrahedralConfig &other)
Definition: bindings.h:8
Definition: stereo.h:109
bool operator!=(const OBTetrahedralConfig &other) const
Definition: bindings.h:101
bool operator==(const OBSquarePlanarConfig &other) const
Definition: bindings.h:196
bool specified
Definition: bindings.h:244
static ConfigType ToConfig(const ConfigType &cfg, unsigned long start, OBStereo::Shape shape=OBStereo::ShapeU)
Definition: tetraplanar.h:90
OBStereo::Winding winding
Definition: bindings.h:109
static OBCisTransStereo::Config Convert(const OBCisTransConfig &other)
Definition: bindings.h:117
View
Definition: stereo.h:119
bool operator==(const OBCisTransConfig &other) const
Definition: bindings.h:129
bool specified
Definition: tetrahedral.h:179
static bool ContainsRef(const Refs &refs, unsigned long ref)
Process molecular stereochemistry information.
static bool ContainsSameRefs(const Refs &refs1, const Refs &refs2)
OBStereo::Refs refs
The 4 reference ids.
Definition: cistrans.h:200
Definition: bindings.h:5
Shape
Definition: stereo.h:108
unsigned long from_or_towards
Definition: bindings.h:107
unsigned long end
Definition: cistrans.h:199
Stereochemical configuration for tetrahedral stereocenters.
Definition: tetrahedral.h:84
OBStereo::Refs refs
Definition: bindings.h:108
bool operator!=(const OBSquarePlanarConfig &other) const
Definition: bindings.h:236
OBStereo::Shape shape
The shape of the 4 reference ids.
Definition: cistrans.h:201
unsigned long end
Definition: bindings.h:176
OBStereo::Refs refs
Definition: bindings.h:177
Winding
Definition: stereo.h:130
unsigned long center
Definition: squareplanar.h:170
OBStereo::Refs refs
The 4 reference ids.
Definition: squareplanar.h:171
bool specified
Definition: cistrans.h:202
bool specified
Definition: bindings.h:179
Stereochemical configuration for double-bond cis/trans stereochemistry.
Definition: cistrans.h:99
OBStereo::Shape shape
Definition: bindings.h:243
std::vector< Ref > Refs
Definition: stereo.h:156
OBStereo::View view
Definition: bindings.h:110
unsigned long center
Definition: tetrahedral.h:164
unsigned long center
Definition: bindings.h:241
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
OBStereo::Shape shape
Definition: bindings.h:178
OBStereo::Winding winding
Definition: tetrahedral.h:177
bool specified
Definition: bindings.h:111
unsigned long begin
Definition: cistrans.h:199
Refs::iterator RefIter
Definition: stereo.h:160
bool operator!=(const OBCisTransConfig &other) const
Definition: bindings.h:171
unsigned long begin
Definition: bindings.h:176
Global namespace for all Open Babel code.
Definition: alias.h:22