tetranonplanar.h Source File

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

tetranonplanar.h
Go to the documentation of this file.

    00001 /**********************************************************************
    00002   tetranonplanar.h - OBTetraNonPlanarStereo
    00003
    00004   Copyright (C) 2009 by Tim Vandermeersch
    00005
    00006   This file is part of the Open Babel project.
    00007   For more information, see <http://openbabel.org/>
    00008
    00009   This program is free software; you can redistribute it and/or modify
    00010   it under the terms of the GNU General Public License as published by
    00011   the Free Software Foundation; either version 2 of the License, or
    00012   (at your option) any later version.
    00013
    00014   This program is distributed in the hope that it will be useful,
    00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
    00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00017   GNU General Public License for more details.
    00018
    00019   You should have received a copy of the GNU General Public License
    00020   along with this program; if not, write to the Free Software
    00021   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    00022   02110-1301, USA.
    00023  **********************************************************************/
    00024 #ifndef OB_TETRANONPLANAR_H
    00025 #define OB_TETRANONPLANAR_H
    00026
    00027 #include <openbabel/stereo/stereo.h>
    00028 #include <openbabel/oberror.h>
    00029
    00030 namespace OpenBabel {
    00031
    00034
    00091   class OBAPI OBTetraNonPlanarStereo : public OBStereoBase
    00092   {
    00093     public:
    00098       OBTetraNonPlanarStereo(OBMol *mol);
    00102       virtual ~OBTetraNonPlanarStereo();
    00103
    00144       template <typename ConfigType>
    00145       static ConfigType ToConfig(const ConfigType &cfg, unsigned long from_or_towards,
    00146           OBStereo::Winding winding = OBStereo::Clockwise,
    00147           OBStereo::View view = OBStereo::ViewFrom)
    00148       {
    00149         if (cfg.from == OBStereo::NoRef) {
    00150           obErrorLog.ThrowError(__FUNCTION__,
    00151               "OBTetraNonPlanarStereo::ToConfig : Invalid from in ConfigType struct.", obError);
    00152           return ConfigType();
    00153         }
    00154         if (cfg.refs.size() != 3) {
    00155           obErrorLog.ThrowError(__FUNCTION__,
    00156               "OBTetraNonPlanarStereo::ToConfig : Invalid refs size.", obError);
    00157           return ConfigType();
    00158         }
    00159
    00160         // copy the internal refs
    00161         ConfigType result = cfg;
    00162         result.from = from_or_towards;
    00163         result.winding = winding;
    00164         result.view = view;
    00165
    00166         // keep track of the permuations by using the oddness
    00167         bool odd = false;
    00168
    00169         // find id
    00170         if (cfg.from != from_or_towards) {
    00171           // move id to front and remove it = 1 permutation
    00172           for (int i = 0; i < 3; ++i) {
    00173             if (cfg.refs.at(i) == from_or_towards) {
    00174               result.refs[i] = cfg.from;
    00175               break;
    00176             }
    00177           }
    00178           // 1 permutation perfromed --> odd = true
    00179           odd = true;
    00180         }
    00181
    00182         // clockwise <-> anti-clockwise : odd = true
    00183         if (winding == cfg.winding)
    00184           odd = !odd;
    00185         // ViewFrom <-> ViewTowards : odd = true
    00186         if (view == cfg.view)
    00187           odd = !odd;
    00188
    00189         // make sure we actually found id
    00190         if (result.refs.size() == 3) {
    00191           if (odd)
    00192             OBStereo::Permutate(result.refs, 1, 2);
    00193           return result;
    00194         }
    00195
    00196         obErrorLog.ThrowError(__FUNCTION__,
    00197             "OBTetraNonPlanarStereo::ToConfig : Parameter id not found in internal refs.", obError);
    00198         return result;
    00199       }
    00203       template <typename ConfigType>
    00204       static void ChangeWinding(ConfigType &cfg)
    00205       {
    00206         cfg.winding = (cfg.winding == OBStereo::Clockwise) ? OBStereo::AntiClockwise : OBStereo::Clockwise;
    00207         OBStereo::Permutate(cfg.refs, 1, 2);
    00208       }
    00212       template <typename ConfigType>
    00213       static void ChangeView(ConfigType &cfg)
    00214       {
    00215         cfg.view = (cfg.view == OBStereo::ViewFrom) ? OBStereo::ViewTowards : OBStereo::ViewFrom;
    00216         OBStereo::Permutate(cfg.refs, 1, 2);
    00217       }
    00221       template <typename ConfigType>
    00222       static void Invert(ConfigType &cfg)
    00223       {
    00224         OBStereo::Permutate(cfg.refs, 1, 2);
    00225       }
    00226  };
    00227
    00229
    00230 }
    00231
    00232 #endif
    00233

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines