Open Babel  3.0
tetranonplanar.h
Go to the documentation of this file.
1 /**********************************************************************
2  tetranonplanar.h - OBTetraNonPlanarStereo
3 
4  Copyright (C) 2009 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_TETRANONPLANAR_H
25 #define OB_TETRANONPLANAR_H
26 
28 #include <openbabel/oberror.h>
29 
30 namespace OpenBabel {
31 
34 
91  class OBAPI OBTetraNonPlanarStereo : public OBStereoBase
92  {
93  public:
102  virtual ~OBTetraNonPlanarStereo();
103 
144  template <typename ConfigType>
145  static ConfigType ToConfig(const ConfigType &cfg, unsigned long from_or_towards,
148  {
149  if (cfg.from == OBStereo::NoRef) {
150  obErrorLog.ThrowError(__FUNCTION__,
151  "OBTetraNonPlanarStereo::ToConfig : Invalid from in ConfigType struct.", obError);
152  return ConfigType();
153  }
154  if (cfg.refs.size() != 3) {
155  obErrorLog.ThrowError(__FUNCTION__,
156  "OBTetraNonPlanarStereo::ToConfig : Invalid refs size.", obError);
157  return ConfigType();
158  }
159 
160  // copy the internal refs
161  ConfigType result = cfg;
162  result.from = from_or_towards;
163  result.winding = winding;
164  result.view = view;
165 
166  // keep track of the permuations by using the oddness
167  bool odd = false;
168 
169  // find id
170  if (cfg.from != from_or_towards) {
171  // move id to front and remove it = 1 permutation
172  for (int i = 0; i < 3; ++i) {
173  if (cfg.refs.at(i) == from_or_towards) {
174  result.refs[i] = cfg.from;
175  break;
176  }
177  }
178  // 1 permutation perfromed --> odd = true
179  odd = true;
180  }
181 
182  // clockwise <-> anti-clockwise : odd = true
183  if (winding == cfg.winding)
184  odd = !odd;
185  // ViewFrom <-> ViewTowards : odd = true
186  if (view == cfg.view)
187  odd = !odd;
188 
189  // make sure we actually found id
190  if (result.refs.size() == 3) {
191  if (odd)
192  OBStereo::Permutate(result.refs, 1, 2);
193  return result;
194  }
195 
196  obErrorLog.ThrowError(__FUNCTION__,
197  "OBTetraNonPlanarStereo::ToConfig : Parameter id not found in internal refs.", obError);
198  return result;
199  }
203  template <typename ConfigType>
204  static void ChangeWinding(ConfigType &cfg)
205  {
206  cfg.winding = (cfg.winding == OBStereo::Clockwise) ? OBStereo::AntiClockwise : OBStereo::Clockwise;
207  OBStereo::Permutate(cfg.refs, 1, 2);
208  }
212  template <typename ConfigType>
213  static void ChangeView(ConfigType &cfg)
214  {
215  cfg.view = (cfg.view == OBStereo::ViewFrom) ? OBStereo::ViewTowards : OBStereo::ViewFrom;
216  OBStereo::Permutate(cfg.refs, 1, 2);
217  }
221  template <typename ConfigType>
222  static void Invert(ConfigType &cfg)
223  {
224  OBStereo::Permutate(cfg.refs, 1, 2);
225  }
226  };
227 
229 
230 }
231 
232 #endif
233 
for critical errors (e.g., cannot read a file)
Definition: oberror.h:40
OBMessageHandler obErrorLog
Global OBMessageHandler error handler.
Definition: oberror.h:187
static void ChangeView(ConfigType &cfg)
Definition: tetranonplanar.h:213
Clockwise winding.
Definition: stereo.h:131
static void Invert(ConfigType &cfg)
Definition: tetranonplanar.h:222
static void ChangeWinding(ConfigType &cfg)
Definition: tetranonplanar.h:204
Molecule Class.
Definition: mol.h:118
No Ref set (invalid Ref)
Definition: stereo.h:150
static void Permutate(Refs &refs, unsigned int i, unsigned int j)
View
Definition: stereo.h:119
Process molecular stereochemistry information.
AntiClockwise winding (or CounterClockwise)
Definition: stereo.h:132
Base class for all stereochemistry classes.
Definition: stereo.h:321
view from the atom (id parameter) towards the center atom
Definition: stereo.h:121
Winding
Definition: stereo.h:130
Base class for handling and storing non-planar stereochemistry with 4 reference atom ids...
Definition: tetranonplanar.h:91
view from center atom towards the atom (id paramater)
Definition: stereo.h:122
void ThrowError(OBError err, errorQualifier qqualifier=always)
Throw an error with an already-formatted OBError object.
Definition: oberror.cpp:163
Handle error messages, warnings, notices, etc.
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
Global namespace for all Open Babel code.
Definition: alias.h:22