1 /**********************************************************************
2 gen2d.cpp - A OBOp for generation of 2D coordinates
3 
4 Copyright (C) 2007,2008 by Sergei V. Trepalin sergey_trepalin@chemical-block.com
5 Copyright (C) 2007,2008 by Andrei Gakh andrei.gakh@nnsa.doe.gov
6           (C) 2007 by Chris Morley
7 
8 This file is part of the Open Babel project.
9 For more information, see <http://openbabel.org/>
10 
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation version 2 of the License.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19 ***********************************************************************/
20 #include <openbabel/babelconfig.h>
21 #include <iostream>
22 #include<openbabel/op.h>
23 #include<openbabel/mol.h>
24 #include <openbabel/mcdlutil.h>
25 #include <openbabel/stereo/stereo.h>
26 
27 namespace OpenBabel
28 {
29 
30 class OpGen2D : public OBOp
31 {
32 public:
OpGen2D(const char * ID)33   OpGen2D(const char* ID) : OBOp(ID, false){};
Description()34   const char* Description(){ return
35     "Generate 2D coordinates\n"
36     "Trepalin, S. V.; Yarkov, A. V.; Pletnev, I. V.; Gakh, A.A."
37     "A Java Chemical Structure Editor Supporting the"
38     "Modular Chemical Descriptor Language (MCDL)."
39     "Molecules, 2006, 11, 219-231"; }
40 
WorksWith(OBBase * pOb) const41   virtual bool WorksWith(OBBase* pOb) const { return dynamic_cast<OBMol*>(pOb) != nullptr; }
42   virtual bool Do(OBBase* pOb, const char* OptionText=nullptr, OpMap* pOptions=nullptr, OBConversion* pConv=nullptr);
43 };
44 
45 /////////////////////////////////////////////////////////////////
46 OpGen2D theOpGen2D("gen2D"); //Global instance
47 
48 /////////////////////////////////////////////////////////////////
Do(OBBase * pOb,const char * OptionText,OpMap * pOptions,OBConversion * pConv)49 bool OpGen2D::Do(OBBase* pOb, const char* OptionText, OpMap* pOptions, OBConversion* pConv)
50 {
51   OBMol* pmol = dynamic_cast<OBMol*>(pOb);
52   if(!pmol)
53     return false;
54 
55   // If we are coming from a 0D structure, then we need to perceive the cis/trans
56   // bonds *now*, before adding the coordinates, to mark unspecified cis/trans
57   // as such. Otherwise, when writing a MOL file it will be missing the '3', or
58   // similarly when depicting it would be presented as specified.
59   // Really, all we need to do is handle the cis/trans bond cases.
60   // However, the current API requires us to also reperceive the tet stereo,
61   // and to remove any stereo that is not real.
62 
63   if (pmol->GetDimension() == 0) {
64     pmol->UnsetFlag(OB_CHIRALITY_MOL);
65     StereoFrom0D(pmol);
66   }
67 
68   generateDiagram(pmol);
69   pmol->SetDimension(2);
70 
71   return true;
72 }
73 }//namespace
74