Chemical Data Processing Library C++ API - Version 1.4.0
Biomol/UtilityFunctions.hpp
Go to the documentation of this file.
1 /*
2  * UtilityFunctions.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_BIOMOL_UTILITYFUNCTIONS_HPP
30 #define CDPL_BIOMOL_UTILITYFUNCTIONS_HPP
31 
32 #include <algorithm>
33 #include <functional>
34 
39 #include "CDPL/Chem/Atom.hpp"
40 
41 
42 namespace CDPL
43 {
44 
45  namespace Biomol
46  {
47 
67  template <typename Iter>
68  Iter findResidueAtom(Iter it, Iter end, const char* res_code = 0, const char* chain_id = 0, long res_seq_no = IGNORE_SEQUENCE_NO,
69  char ins_code = 0, std::size_t model_no = 0, const char* atom_name = 0, long serial_no = IGNORE_SERIAL_NO)
70  {
71  return std::find_if(it, end,
72  std::bind(static_cast<bool (*)(const Chem::Atom&, const char*, const char*, long, char, std::size_t, const char*, long)>(&matchesResidueInfo), std::placeholders::_1, res_code, chain_id, res_seq_no,
73  ins_code, model_no, atom_name, serial_no));
74  }
75 
96  template <typename Iter>
97  Iter findResidue(Iter it, Iter end, const char* res_code = 0, const char* chain_id = 0, long res_seq_no = IGNORE_SEQUENCE_NO,
98  char ins_code = 0, std::size_t model_no = 0, const char* atom_name = 0, long serial_no = IGNORE_SERIAL_NO)
99  {
100  for (; it != end; ++it) {
101  const Chem::MolecularGraph& res = *it;
102 
103  if (!matchesResidueInfo(res, res_code, chain_id, res_seq_no, ins_code, model_no))
104  continue;
105 
106  if (atom_name == 0 && serial_no == IGNORE_SERIAL_NO)
107  return it;
108 
109  if (std::find_if(res.getAtomsBegin(), res.getAtomsEnd(),
110  std::bind(static_cast<bool (*)(const Chem::Atom&, const char*, const char*, long, char, std::size_t, const char*, long)>(&matchesResidueInfo), std::placeholders::_1, res_code, chain_id, res_seq_no,
111  ins_code, model_no, atom_name, serial_no)) != res.getAtomsEnd())
112  return it;
113  }
114 
115  return end;
116  }
117  } // namespace Biomol
118 } // namespace CDPL
119 
120 #endif // CDPL_BIOMOL_UTILITYFUNCTIONS_HPP
Definition of class CDPL::Chem::Atom.
Declaration of functions that operate on Chem::Atom instances.
Declaration of functions that operate on Chem::MolecularGraph instances.
Definition of class CDPL::Chem::MolecularGraph.
Definition of flags for serial and residue sequence number processing.
ConstAtomIterator getAtomsBegin() const
Returns a constant iterator pointing to the beginning of the stored const Chem::Atom objects.
ConstAtomIterator getAtomsEnd() const
Returns a constant iterator pointing to the end of the stored const Chem::Atom objects.
Abstract base class representing a chemical atom and its bonded neighborhood.
Definition: Atom.hpp:57
Abstract base class for representations of a chemical structure as a graph of bonded atoms.
Definition: MolecularGraph.hpp:57
const long IGNORE_SEQUENCE_NO
Sentinel value indicating that the residue sequence number should be ignored when matching residues.
Definition: ProcessingFlags.hpp:44
Iter findResidueAtom(Iter it, Iter end, const char *res_code=0, const char *chain_id=0, long res_seq_no=IGNORE_SEQUENCE_NO, char ins_code=0, std::size_t model_no=0, const char *atom_name=0, long serial_no=IGNORE_SERIAL_NO)
Searches the iterator range [it, end) for the first atom whose PDB-style residue identity attributes ...
Definition: Biomol/UtilityFunctions.hpp:68
Iter findResidue(Iter it, Iter end, const char *res_code=0, const char *chain_id=0, long res_seq_no=IGNORE_SEQUENCE_NO, char ins_code=0, std::size_t model_no=0, const char *atom_name=0, long serial_no=IGNORE_SERIAL_NO)
Searches the iterator range [it, end) for the first residue (molecular graph) whose PDB-style identit...
Definition: Biomol/UtilityFunctions.hpp:97
CDPL_BIOMOL_API bool matchesResidueInfo(const Chem::Atom &atom, const char *res_code=0, const char *chain_id=0, long res_seq_no=IGNORE_SEQUENCE_NO, char ins_code=0, std::size_t model_no=0, const char *atom_name=0, long serial_no=IGNORE_SERIAL_NO)
Tells whether the residue-identity attributes of atom match the given filter values.
const long IGNORE_SERIAL_NO
Sentinel value indicating that the atom serial number should be ignored when matching atoms.
Definition: ProcessingFlags.hpp:49
The namespace of the Chemical Data Processing Library.