Loading...
Searching...
No Matches
query.h
Go to the documentation of this file.
/**********************************************************************
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/bond.h> // TODO: Move OBBond code out of this header
#include <openbabel/bitvec.h>
#include <openbabel/tokenst.h>
namespace OpenBabel {
class OBQueryBond;
class OBMol;
class OBAPI OBQueryAtom
{
public:
friend class OBQuery;
friend class OBQueryBond;
OBQueryAtom(int atomicNum = 6, bool isInRing = false, bool isAromatic = false) :
m_atomicNum(atomicNum), m_isInRing(isInRing), m_isAromatic(isAromatic) {}
virtual ~OBQueryAtom() {}
unsigned int GetIndex() const
{
return m_index;
}
const std::vector<OBQueryBond*>& GetBonds() const
{
return m_bonds;
}
const std::vector<OBQueryAtom*>& GetNbrs() const
{
return m_nbrs;
}
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 OBAPI OBQueryBond
{
public:
friend class OBQuery;
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() {}
unsigned int GetIndex() const
{
return m_index;
}
OBQueryAtom* GetBeginAtom() const { return m_begin; }
OBQueryAtom* GetEndAtom() const { return m_end; }
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 OBAPI OBQuery
{
public:
~OBQuery();
unsigned int NumAtoms() const
{
return m_atoms.size();
}
unsigned int NumBonds() const
{
return m_bonds.size();
}
const std::vector<OBQueryAtom*>& GetAtoms() const
{
return m_atoms;
}
const std::vector<OBQueryBond*>& GetBonds() const
{
return m_bonds;
}
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 nullptr;
}
void AddAtom(OBQueryAtom *atom)
{
atom->m_index = m_atoms.size();
m_atoms.push_back(atom);
}
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;
};
OBAPI OBQuery* CompileMoleculeQuery(OBMol *mol, const OBBitVec &mask = OBBitVec());
OBAPI OBQuery* CompileSmilesQuery(const std::string &smiles, const OBBitVec &mask = OBBitVec());
}
#endif
bitvec.h
Fast and efficient bitstring class.
bond.h
Handle bonds.
OpenBabel::OBAtom
Atom class.
Definition atom.h:72
OpenBabel::OBAtom::GetAtomicNum
unsigned int GetAtomicNum() const
Definition atom.h:176
OpenBabel::OBAtom::IsInRing
bool IsInRing() const
Definition atom.cpp:786
OpenBabel::OBAtom::IsAromatic
bool IsAromatic() const
Definition atom.cpp:774
OpenBabel::OBBitVec
A speed-optimized vector of bits.
Definition bitvec.h:58
OpenBabel::OBBond
Bond class.
Definition bond.h:59
OpenBabel::OBBond::GetBondOrder
unsigned int GetBondOrder() const
Definition bond.h:157
OpenBabel::OBBond::IsAromatic
bool IsAromatic() const
Definition bond.cpp:466
OpenBabel::OBMol
Molecule Class.
Definition mol.h:121
OpenBabel::OBQueryAtom
Atom in an OBQuery.
Definition query.h:55
OpenBabel::OBQueryAtom::m_isInRing
bool m_isInRing
Definition query.h:115
OpenBabel::OBQueryAtom::OBQueryBond
friend class OBQueryBond
Definition query.h:58
OpenBabel::OBQueryAtom::m_isAromatic
bool m_isAromatic
Definition query.h:115
OpenBabel::OBQueryAtom::m_index
unsigned int m_index
Definition query.h:113
OpenBabel::OBQueryAtom::OBQuery
friend class OBQuery
Definition query.h:57
OpenBabel::OBQueryAtom::OBQueryAtom
OBQueryAtom(int atomicNum=6, bool isInRing=false, bool isAromatic=false)
Definition query.h:65
OpenBabel::OBQueryAtom::GetBonds
const std::vector< OBQueryBond * > & GetBonds() const
Definition query.h:82
OpenBabel::OBQueryAtom::m_atomicNum
unsigned int m_atomicNum
Definition query.h:114
OpenBabel::OBQueryAtom::~OBQueryAtom
virtual ~OBQueryAtom()
Definition query.h:68
OpenBabel::OBQueryAtom::GetIndex
unsigned int GetIndex() const
Definition query.h:74
OpenBabel::OBQueryAtom::m_nbrs
std::vector< OBQueryAtom * > m_nbrs
Definition query.h:117
OpenBabel::OBQueryAtom::Matches
virtual bool Matches(const OBAtom *atom) const
Definition query.h:101
OpenBabel::OBQueryAtom::GetNbrs
const std::vector< OBQueryAtom * > & GetNbrs() const
Definition query.h:90
OpenBabel::OBQueryAtom::m_bonds
std::vector< OBQueryBond * > m_bonds
Definition query.h:116
OpenBabel::OBQueryBond
Bond in an OBQuery.
Definition query.h:137
OpenBabel::OBQueryBond::GetBeginAtom
OBQueryAtom * GetBeginAtom() const
Definition query.h:164
OpenBabel::OBQueryBond::m_begin
OBQueryAtom * m_begin
Definition query.h:185
OpenBabel::OBQueryBond::m_index
unsigned int m_index
Definition query.h:184
OpenBabel::OBQueryBond::OBQuery
friend class OBQuery
Definition query.h:139
OpenBabel::OBQueryBond::m_order
unsigned int m_order
Definition query.h:186
OpenBabel::OBQueryBond::OBQueryBond
OBQueryBond(OBQueryAtom *begin, OBQueryAtom *end, int order=1, bool aromatic=false)
Definition query.h:143
OpenBabel::OBQueryBond::~OBQueryBond
virtual ~OBQueryBond()
Definition query.h:152
OpenBabel::OBQueryBond::m_end
OBQueryAtom * m_end
Definition query.h:185
OpenBabel::OBQueryBond::GetIndex
unsigned int GetIndex() const
Definition query.h:157
OpenBabel::OBQueryBond::Matches
virtual bool Matches(const OBBond *bond) const
Definition query.h:177
OpenBabel::OBQueryBond::m_aromatic
bool m_aromatic
Definition query.h:187
OpenBabel::OBQueryBond::GetEndAtom
OBQueryAtom * GetEndAtom() const
Definition query.h:168
OpenBabel::OBQuery
A substructure query.
Definition query.h:198
OpenBabel::OBQuery::NumAtoms
unsigned int NumAtoms() const
Definition query.h:204
OpenBabel::OBQuery::AddAtom
void AddAtom(OBQueryAtom *atom)
Definition query.h:243
OpenBabel::OBQuery::GetBonds
const std::vector< OBQueryBond * > & GetBonds() const
Definition query.h:225
OpenBabel::OBQuery::NumBonds
unsigned int NumBonds() const
Definition query.h:211
OpenBabel::OBQuery::GetAtoms
const std::vector< OBQueryAtom * > & GetAtoms() const
Definition query.h:218
OpenBabel::OBQuery::AddBond
void AddBond(OBQueryBond *bond)
Definition query.h:251
OpenBabel::OBQuery::m_atoms
std::vector< OBQueryAtom * > m_atoms
Definition query.h:257
OpenBabel::OBQuery::GetBond
OBQueryBond * GetBond(OBQueryAtom *begin, OBQueryAtom *end) const
Definition query.h:233
OpenBabel::OBQuery::m_bonds
std::vector< OBQueryBond * > m_bonds
Definition query.h:258
OpenBabel::CompileSmilesQuery
OBQuery * CompileSmilesQuery(const std::string &smiles, const OBBitVec &mask=OBBitVec())
Definition query.cpp:75
OpenBabel::CompileMoleculeQuery
OBQuery * CompileMoleculeQuery(OBMol *mol, const OBBitVec &mask=OBBitVec())
Definition query.cpp:43
OpenBabel
Global namespace for all Open Babel code.
Definition alias.h:23
tokenst.h
Tokenize strings, open data files.