/src/openbabel/src/ops/gen2D.cpp
Line | Count | Source |
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: |
33 | 2 | OpGen2D(const char* ID) : OBOp(ID, false){}; |
34 | 0 | const char* Description() override { return |
35 | 0 | "Generate 2D coordinates\n" |
36 | 0 | "Trepalin, S. V.; Yarkov, A. V.; Pletnev, I. V.; Gakh, A.A." |
37 | 0 | "A Java Chemical Structure Editor Supporting the" |
38 | 0 | "Modular Chemical Descriptor Language (MCDL)." |
39 | 0 | "Molecules, 2006, 11, 219-231"; } |
40 | | |
41 | 0 | bool WorksWith(OBBase* pOb) const override { return dynamic_cast<OBMol*>(pOb) != nullptr; } |
42 | | bool Do(OBBase* pOb, const char* OptionText=nullptr, OpMap* pOptions=nullptr, |
43 | | OBConversion* pConv=nullptr) override; |
44 | | }; |
45 | | |
46 | | ///////////////////////////////////////////////////////////////// |
47 | | OpGen2D theOpGen2D("gen2D"); //Global instance |
48 | | |
49 | | ///////////////////////////////////////////////////////////////// |
50 | | bool OpGen2D::Do(OBBase* pOb, const char* OptionText, OpMap* pOptions, OBConversion* pConv) |
51 | 15.2k | { |
52 | 15.2k | OBMol* pmol = dynamic_cast<OBMol*>(pOb); |
53 | 15.2k | if(!pmol) |
54 | 0 | return false; |
55 | | |
56 | | // If we are coming from a 0D structure, then we need to perceive the cis/trans |
57 | | // bonds *now*, before adding the coordinates, to mark unspecified cis/trans |
58 | | // as such. Otherwise, when writing a MOL file it will be missing the '3', or |
59 | | // similarly when depicting it would be presented as specified. |
60 | | // Really, all we need to do is handle the cis/trans bond cases. |
61 | | // However, the current API requires us to also reperceive the tet stereo, |
62 | | // and to remove any stereo that is not real. |
63 | | |
64 | 15.2k | if (pmol->GetDimension() == 0) { |
65 | 0 | pmol->UnsetFlag(OB_CHIRALITY_MOL); |
66 | 0 | StereoFrom0D(pmol); |
67 | 0 | } |
68 | | |
69 | 15.2k | generateDiagram(pmol); |
70 | 15.2k | pmol->SetDimension(2); |
71 | | |
72 | 15.2k | return true; |
73 | 15.2k | } |
74 | | }//namespace |