Open Babel  3.0
tetraplanar.h
Go to the documentation of this file.
1 /**********************************************************************
2  tetraplanar.h - OBTetraPlanarStereo
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_TETRAPLANAR_H
25 #define OB_TETRAPLANAR_H
26 
27 #include "stereo.h"
28 #include <algorithm> // std::rotate
29 
30 namespace OpenBabel {
31 
83  class OBAPI OBTetraPlanarStereo : public OBStereoBase
84  {
85  public:
87  virtual ~OBTetraPlanarStereo();
88 
89  template <typename ConfigType>
90  static ConfigType ToConfig(const ConfigType &cfg, unsigned long start,
92  {
93  ConfigType result = cfg;
94  result.shape = shape;
95 
96  // convert from U/Z/4 to U shape
97  switch (cfg.shape) {
98  case OBStereo::ShapeU:
99  break;
100  case OBStereo::ShapeZ:
101  OBStereo::Permutate(result.refs, 2, 3); // convert to U shape
102  break;
103  case OBStereo::Shape4:
104  OBStereo::Permutate(result.refs, 1, 2); // convert to U shape
105  break;
106  }
107 
108 
109  // since refs are U shaped we can rotate the refs lexicographically
110  for (int i = 0; i < 4; ++i) {
111  std::rotate(result.refs.begin(), result.refs.begin() + 1, result.refs.end());
112  // start at refs[0]?
113  if (result.refs.at(0) == start)
114  break;
115  }
116 
117  // convert from U to desired U/Z/4
118  // (don't change refs[0]!)
119  switch (shape) {
120  case OBStereo::ShapeU:
121  break;
122  case OBStereo::ShapeZ:
123  OBStereo::Permutate(result.refs, 2, 3); // convert to Z shape
124  break;
125  case OBStereo::Shape4:
126  OBStereo::Permutate(result.refs, 1, 2); // convert to 4 shape
127  break;
128  }
129 
130  return result;
131  }
132 
133  };
134 
135 }
136 
137 #endif
138 
Definition: stereo.h:110
Definition: stereo.h:109
Molecule Class.
Definition: mol.h:118
static ConfigType ToConfig(const ConfigType &cfg, unsigned long start, OBStereo::Shape shape=OBStereo::ShapeU)
Definition: tetraplanar.h:90
static void Permutate(Refs &refs, unsigned int i, unsigned int j)
Base class for handling and storing planar stereochemistry with 4 reference atoms.
Definition: tetraplanar.h:83
Process molecular stereochemistry information.
Shape
Definition: stereo.h:108
Base class for all stereochemistry classes.
Definition: stereo.h:321
Definition: stereo.h:111
Global namespace for all Open Babel code.
Definition: alias.h:22