/src/openbabel/include/openbabel/alias.h
Line | Count | Source |
1 | | /********************************************************************** |
2 | | alias.h - OBGenericData class to hold alias information on atoms |
3 | | Copyright (C) Copyright (C) 2007 by Chris Morley |
4 | | |
5 | | This program is free software; you can redistribute it and/or modify |
6 | | it under the terms of the GNU General Public License as published by |
7 | | the Free Software Foundation version 2 of the License. |
8 | | |
9 | | This program is distributed in the hope that it will be useful, |
10 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | | GNU General Public License for more details. |
13 | | ***********************************************************************/ |
14 | | |
15 | | #ifndef OB_ALIAS_H |
16 | | #define OB_ALIAS_H |
17 | | |
18 | | #include <memory> |
19 | | #include <vector> |
20 | | #include <openbabel/generic.h> |
21 | | |
22 | | namespace OpenBabel |
23 | | { |
24 | | class OBSmartsPattern; |
25 | | class OBMol; |
26 | | |
27 | | // This macro is used in DLL builds. If it has not |
28 | | // been set in babelconfig.h, define it as nothing. |
29 | | #ifndef OBCOMMON |
30 | | #define OBCOMMON |
31 | | #endif |
32 | | |
33 | | const unsigned int AliasDataType = 0x7883; |
34 | | |
35 | | /** \class AliasData alias.h <openbabel/alias.h> |
36 | | \brief Indicate atoms as aliases for larger functional groups |
37 | | \since version 2.2 |
38 | | |
39 | | An object of this class can be attached to an OBAtom if it is considered |
40 | | to be a placeholder for an alias, such as Ph, COOH, etc. |
41 | | |
42 | | If the alias has not been interpreted chemically (expanded), the element type of the |
43 | | placeholder atom should be set to Xx so that the molecule is not interpreted |
44 | | incorrectly by formats which do not consider this class. |
45 | | |
46 | | If the alias has been interpreted chemically (which formats, etc. should |
47 | | normally do immediately), the alias may remain as extra |
48 | | information or as a hint for an alternative representation, for example to |
49 | | a chemical drawing program. The _expandedatoms vector would then contains |
50 | | the ids of the atoms to which the alias is an alternative. |
51 | | */ |
52 | | class OBCOMMON AliasData : public OBGenericData |
53 | | { |
54 | | protected: |
55 | | std::string _alias; |
56 | | std::string _right_form; |
57 | | std::vector<unsigned long> _expandedatoms; //atom ids (not idxs) |
58 | | std::string _color; |
59 | | public: |
60 | | |
61 | 0 | AliasData(): OBGenericData("Alias", AliasDataType){ } |
62 | | |
63 | 0 | virtual OBGenericData* Clone(OBBase* /*parent*/) const{return new AliasData(*this);} |
64 | | |
65 | | ///Add an alias |
66 | 0 | void SetAlias(const std::string& alias) {_alias = alias;} |
67 | 0 | void SetAlias(const char* alias) {_alias = alias;} |
68 | | |
69 | | /// /return value of alias or its version intended to be connected at its right hand end. |
70 | | std::string GetAlias(bool rightAligned = false) const; |
71 | | |
72 | | /// Return the color which has been assigned to this alias |
73 | 0 | std::string GetColor() const { return _color; } |
74 | | |
75 | | /// Assign a color to this alias |
76 | 0 | void SetColor(std::string color){ _color = color; } |
77 | | |
78 | 0 | bool IsExpanded()const { return !_expandedatoms.empty(); } |
79 | | |
80 | | ///Converts all the expanded aliases in a molecule to the alias form. |
81 | | ///Note that this deletes atoms and bonds. Use only as a preparation for display. |
82 | | static void RevertToAliasForm(OBMol& mol); |
83 | | |
84 | | ///Interprets the alias text and adds atoms as appropriate to mol. |
85 | | bool Expand(OBMol& mol, const unsigned int atomindex); |
86 | | |
87 | | ///Matches univalent fragments in the molecule and adds AliasData to provide an alternative representation. |
88 | | ///The molecule remains a respectable OBMol. Data in superatoms.txt decides what aliases are added. |
89 | | static bool AddAliases(OBMol* pmol); |
90 | | |
91 | | private: |
92 | | /// Interpret the alias as a formula |
93 | | bool FormulaParse(OBMol& mol, const unsigned atomindex); |
94 | | |
95 | | /// Add one of the atoms that can replace the alias |
96 | | void AddExpandedAtom(int id); |
97 | | |
98 | | /// Delete the atoms that replace the alias |
99 | | void DeleteExpandedAtoms(OBMol& mol); |
100 | | |
101 | | struct AliasItem |
102 | | { |
103 | | std::string right_form; |
104 | | std::string smiles; |
105 | | std::string color; |
106 | | }; |
107 | | typedef std::map<std::string, AliasItem> SuperAtomTable; //key=alias left-form |
108 | | |
109 | | static bool LoadFile(SuperAtomTable& table); |
110 | | static SuperAtomTable& table() |
111 | 0 | { |
112 | 0 | static SuperAtomTable t; |
113 | 0 | if(t.empty()) |
114 | 0 | LoadFile(t); |
115 | 0 | return t; |
116 | 0 | } |
117 | | bool FromNameLookup(OBMol& mol, const unsigned int atomindex); |
118 | | typedef std::vector< std::pair<std::string, std::shared_ptr<OBSmartsPattern> > > SmartsTable; |
119 | | static bool LoadFile(SmartsTable& smtable); |
120 | | }; |
121 | | } //namespace |
122 | | |
123 | | #endif // OB_ALIAS_H |
124 | | |
125 | | //! \file alias.h |
126 | | //! \brief OBGenericData class to for atom alias data (e.g., in 2D drawing programs for "COOH") |