Open Babel  3.0
alias.h
Go to the documentation of this file.
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 <vector>
19 #include <openbabel/generic.h>
20 #include <openbabel/shared_ptr.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 
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  AliasData(): OBGenericData("Alias", AliasDataType){ }
62 
63  virtual OBGenericData* Clone(OBBase* /*parent*/) const{return new AliasData(*this);}
64 
66  void SetAlias(const std::string& alias) {_alias = alias;}
67  void SetAlias(const char* alias) {_alias = alias;}
68 
70  std::string GetAlias(bool rightAligned = false) const;
71 
73  std::string GetColor() const { return _color; }
74 
76  void SetColor(std::string color){ _color = color; }
77 
78  bool IsExpanded()const { return !_expandedatoms.empty(); }
79 
82  static void RevertToAliasForm(OBMol& mol);
83 
85  bool Expand(OBMol& mol, const unsigned int atomindex);
86 
87  #ifdef HAVE_SHARED_POINTER
88  static bool AddAliases(OBMol* pmol);
91  #endif
92 
93 private:
95  bool FormulaParse(OBMol& mol, const unsigned atomindex);
96 
98  void AddExpandedAtom(int id);
99 
101  void DeleteExpandedAtoms(OBMol& mol);
102 
103  struct AliasItem
104  {
105  std::string right_form;
106  std::string smiles;
107  std::string color;
108  };
109  typedef std::map<std::string, AliasItem> SuperAtomTable; //key=alias left-form
110 
111  static bool LoadFile(SuperAtomTable& table);
112  static SuperAtomTable& table()
113  {
114  static SuperAtomTable t;
115  if(t.empty())
116  LoadFile(t);
117  return t;
118  }
119  bool FromNameLookup(OBMol& mol, const unsigned int atomindex);
120 #ifdef HAVE_SHARED_POINTER
121  typedef std::vector< std::pair<std::string, obsharedptr<OBSmartsPattern> > > SmartsTable;
122  static bool LoadFile(SmartsTable& smtable);
123 #endif
124 };
125 } //namespace
126 
127 #endif // OB_ALIAS_H
128 
std::vector< unsigned long > _expandedatoms
Definition: alias.h:57
Base class for generic data.
Definition: base.h:188
const unsigned int AliasDataType
Definition: alias.h:33
bool IsExpanded() const
Definition: alias.h:78
std::string _right_form
Definition: alias.h:56
std::string _alias
Definition: alias.h:55
Molecule Class.
Definition: mol.h:118
std::string GetColor() const
Return the color which has been assigned to this alias.
Definition: alias.h:73
void SetAlias(const std::string &alias)
Add an alias.
Definition: alias.h:66
AliasData()
Definition: alias.h:61
SMARTS (SMiles ARbitrary Target Specification) substructure searching.
Definition: parsmart.h:154
void SetAlias(const char *alias)
Definition: alias.h:67
void SetColor(std::string color)
Assign a color to this alias.
Definition: alias.h:76
virtual OBGenericData * Clone(OBBase *) const
Definition: alias.h:63
Shared pointer.
std::string _color
Definition: alias.h:58
Handle generic data classes. Custom data for atoms, bonds, etc.
Base Class.
Definition: base.h:239
Indicate atoms as aliases for larger functional groups.
Definition: alias.h:52
Global namespace for all Open Babel code.
Definition: alias.h:22