/usr/include/openbabel-2.0/openbabel/query.h is in libopenbabel-dev 2.3.2+dfsg-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | /**********************************************************************
query.h - OBQuery, OBQueryAtom & OBQueryBond classes.
Copyright (C) 2010 by Tim Vandermeersch
This file is part of the Open Babel project.
For more information, see <http://openbabel.org/>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
**********************************************************************/
#ifndef OB_QUERY_H
#define OB_QUERY_H
#include <openbabel/mol.h>
#include <openbabel/tokenst.h>
namespace OpenBabel {
class OBQueryBond;
///@addtogroup substructure Substructure Searching
///@{
/**
* @class OBQueryAtom query.h <openbabel/query.h>
* @brief Atom in an OBQuery
*
* The OBQueryAtom class defines an interface for query atoms. The class provides
* some general methods and properties to access the topology information. The Matches
* method can be reimplemented in subclasses to get custom matching behavior.
*
* The default Matches implementation only checks the atomic number.
*
* See @ref substructure for more information.
*
* @sa OBQuery OBQueryBond OBIsomorphismMapper
* @since version 2.3
*/
class OBAPI OBQueryAtom
{
public:
friend class OBQuery;
friend class OBQueryBond;
/**
* Constructor.
* @param atomicNum The atomic number for this query atom.
* @param isInRing Specify wether the query atom is in a ring. Default is false.
* @param isAromatic Specify wether the query atom is aromatic. Default is false.
*/
OBQueryAtom(int atomicNum = 6, bool isInRing = false, bool isAromatic = false) :
m_atomicNum(atomicNum), m_isInRing(isInRing), m_isAromatic(isAromatic) {}
virtual ~OBQueryAtom() {}
/**
* Get the index for this query atom. Atoms are indexed starting from 0.
* This method is used by OBIsomorphismMapper implementations.
*/
unsigned int GetIndex() const
{
return m_index;
}
/**
* Get the query bonds for this atom.
* This method is used by OBIsomorphismMapper implementations.
*/
const std::vector<OBQueryBond*>& GetBonds() const
{
return m_bonds;
}
/**
* Get the neighbor query atoms.
* This method is used by OBIsomorphismMapper implementations.
*/
const std::vector<OBQueryAtom*>& GetNbrs() const
{
return m_nbrs;
}
/**
* This is the match method to verify if an OBQueryAtom and OBAtom class match.
* The default implementation only checks if the atomic numbers match. Reimplement
* this method in a subclass for more advances matching.
* This method is used by OBIsomorphismMapper implementations.
* @param atom The OBAtom object to compare this OBQueryAtom with.
*/
virtual bool Matches(const OBAtom *atom) const
{
if (atom->GetAtomicNum() != m_atomicNum)
return false;
if (atom->IsAromatic() != m_isAromatic)
return false;
if (m_isInRing)
if (!atom->IsInRing())
return false;
return true;
}
protected:
unsigned int m_index;
unsigned int m_atomicNum;
bool m_isInRing, m_isAromatic;
std::vector<OBQueryBond*> m_bonds;
std::vector<OBQueryAtom*> m_nbrs;
};
/**
* @class OBQueryBond query.h <openbabel/query.h>
* @brief Bond in an OBQuery
*
* The OBQueryBond class defines an interface for query bonds. The class provides
* some general methods and properties to access the topology information. The Matches
* method can be reimplemented in subclasses to get custom matching behavior.
*
* The default Matches implementation only checks if the bonds are both aromatic,
* otherwise the bond orders are compared.
*
* See @ref substructure for more information.
*
* @sa OBQuery OBQueryAtom OBIsomorphismMapper
* @since version 2.3
*/
class OBAPI OBQueryBond
{
public:
friend class OBQuery;
/**
* Constructor.
*/
OBQueryBond(OBQueryAtom *begin, OBQueryAtom *end, int order = 1, bool aromatic = false) :
m_begin(begin), m_end(end), m_order(order), m_aromatic(aromatic)
{
m_begin->m_bonds.push_back(this);
m_end->m_bonds.push_back(this);
m_begin->m_nbrs.push_back(m_end);
m_end->m_nbrs.push_back(m_begin);
}
virtual ~OBQueryBond() {}
/**
* Get the index for this query bonds. Query bonds are indexed starting from 0.
*/
unsigned int GetIndex() const
{
return m_index;
}
/**
* Get the begin atom.
*/
OBQueryAtom* GetBeginAtom() const { return m_begin; }
/**
* Get the end atom.
*/
OBQueryAtom* GetEndAtom() const { return m_end; }
/**
* This is the match method to verify if an OBQueryBond and OBBond class match.
* The default implementation checks if both bonds are aromatic and compares the
* bond orders otherwise. Reimplement this method in a subclass for more
* advances matching.
* This method is used by OBIsomorphismMapper implementations.
* @param bond The OBBond object to compare this OBQueryBond with.
*/
virtual bool Matches(const OBBond *bond) const
{
if (m_aromatic)
return bond->IsAromatic();
return bond->GetBondOrder() == m_order;
}
protected:
unsigned int m_index;
OBQueryAtom *m_begin, *m_end;
unsigned int m_order;
bool m_aromatic;
};
/**
* @class OBQuery query.h <openbabel/query.h>
* @brief A substructure query
*
* See @ref substructure for more information.
* @since version 2.3
*/
class OBAPI OBQuery
{
public:
~OBQuery()
{
std::for_each(m_atoms.begin(),m_atoms.end(), DeleteObject());
std::for_each(m_bonds.begin(),m_bonds.end(), DeleteObject());
}
/**
* @return The number of atoms in the query.
*/
unsigned int NumAtoms() const
{
return m_atoms.size();
}
/**
* @return The number of bonds in the query.
*/
unsigned int NumBonds() const
{
return m_bonds.size();
}
/**
* @return std::vector with pointers to the query atoms.
*/
const std::vector<OBQueryAtom*>& GetAtoms() const
{
return m_atoms;
}
/**
* @return std::vector with pointers to the query bonds.
*/
const std::vector<OBQueryBond*>& GetBonds() const
{
return m_bonds;
}
/**
* @return The query bond between @p begin and @p end. If there is no
* bond between @p begin and @p end, this function returns 0.
*/
OBQueryBond* GetBond(OBQueryAtom *begin, OBQueryAtom *end) const
{
for (unsigned int i = 0; i < begin->GetBonds().size(); ++i)
if (begin->GetNbrs()[i] == end)
return begin->GetBonds()[i];
return 0;
}
/**
* Add a query atom to the query. This function steals the pointer.
*/
void AddAtom(OBQueryAtom *atom)
{
atom->m_index = m_atoms.size();
m_atoms.push_back(atom);
}
/**
* Add a query atom to the query. This function steals the pointer.
*/
void AddBond(OBQueryBond *bond)
{
bond->m_index = m_bonds.size();
m_bonds.push_back(bond);
}
protected:
std::vector<OBQueryAtom*> m_atoms;
std::vector<OBQueryBond*> m_bonds;
};
/**
* Create an OBQuery object from an OBMol object.
* @param mol The query molecule.
* @param mask The mask specifying the atoms to use. Indexed from 1 (i.e. OBAtom::GetIdx()).
* @return A pointer to an OBQuery object for the smiles string. This pointer should be deleted.
* @since version 2.3
*/
OBAPI OBQuery* CompileMoleculeQuery(OBMol *mol, const OBBitVec &mask = OBBitVec());
/**
* Create an OBQuery object from a smiles string.
* @param smiles The query smiles string.
* @param mask The mask specifying the atoms to use. Indexed from 1 (i.e. OBAtom::GetIdx()).
* @return A pointer to an OBQuery object for the smiles string. This pointer should be deleted.
* @since version 2.3
*/
OBAPI OBQuery* CompileSmilesQuery(const std::string &smiles, const OBBitVec &mask = OBBitVec());
///@}
}
#endif
/// @file query.h
/// @brief OBQuery, OBQueryAtom & OBQueryBond classes.
|