Chemical Data Processing Library C++ API - Version 1.1.1
MorganNumberingCalculator.hpp
Go to the documentation of this file.
1 /*
2  * MorganNumberingCalculator.hpp
3  *
4  * Morgan Algorithm for canonical numbering
5  * (H. L. Morgan, J. Chem. Doc. 1965, 5, 107)
6  *
7  * This file is part of the Chemical Data Processing Toolkit
8  *
9  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * along with this library; see the file COPYING. If not, write to
23  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24  * Boston, MA 02111-1307, USA.
25  */
26 
32 #ifndef CDPL_CHEM_MORGANNUMBERINGCALCULATOR_HPP
33 #define CDPL_CHEM_MORGANNUMBERINGCALCULATOR_HPP
34 
35 #include <vector>
36 #include <string>
37 #include <utility>
38 #include <cstddef>
39 
40 #include "CDPL/Chem/APIPrefix.hpp"
41 #include "CDPL/Math/Matrix.hpp"
42 #include "CDPL/Util/Array.hpp"
43 
44 
45 namespace CDPL
46 {
47 
48  namespace Chem
49  {
50 
51  class MolecularGraph;
52 
58  {
59 
60  public:
65 
75 
83  void calculate(const MolecularGraph& molgraph, Util::STArray& numbering);
84 
85  private:
87 
89 
90  typedef std::pair<std::size_t, std::size_t> STPair;
91 
92  typedef std::vector<STPair> STPairArray;
93  typedef std::vector<std::size_t> STArray;
94  typedef std::vector<long> LArray;
95  typedef std::vector<std::string> SArray;
96 
97  class NumberingState
98  {
99 
100  public:
101  NumberingState(STPairArray* sym_class_ids, SArray* symbols,
102  LArray* charges, STArray* isotopes, Math::SparseULMatrix* bond_mtx):
103  symClassIDs(sym_class_ids),
104  atomSymbols(symbols),
105  atomCharges(charges), atomIsotopes(isotopes), bondMatrix(bond_mtx) {}
106 
107  void calculate(const MolecularGraph&, Util::STArray&);
108 
109  private:
110  NumberingState() {}
111 
112  void init(const MolecularGraph&);
113 
114  void perceiveSymClasses();
115 
116  void distributeNumbers(Util::STArray&);
117  void distributeNumbers(std::size_t);
118 
119  void getNextAtomIndices(STArray&);
120 
121  void addListEntriesForAtom(std::size_t, std::size_t);
122 
123  void copy(NumberingState&);
124 
125  typedef STPairArray::const_iterator STPairArrayIterator;
126 
127  STPairArray* symClassIDs;
128  SArray* atomSymbols;
129  LArray* atomCharges;
130  STArray* atomIsotopes;
131  Math::SparseULMatrix* bondMatrix;
132  const MolecularGraph* molGraph;
133  STPairArray atomNumbering;
134  STArray indexLookupTable;
135  STArray fromList;
136  STArray ringClosures;
137  std::string nodeValues;
138  STArray lineValues;
139  LArray modifications;
140  STPairArrayIterator lastSymClass;
141  std::size_t centerAtomNumber;
142  std::size_t nextAtomNumber;
143  bool sortRCList;
144  };
145 
146  STPairArray symClassIDs;
147  SArray atomSymbols;
148  LArray atomCharges;
149  STArray atomIsotopes;
150  Math::SparseULMatrix bondMatrix;
151  NumberingState numbering;
152  };
153  } // namespace Chem
154 } // namespace CDPL
155 
156 #endif // CDPL_CHEM_MORGANNUMBERINGCALCULATOR_HPP
CDPL::Util::LArray
Array< long > LArray
An array of unsigned integers of type long.
Definition: Array.hpp:572
CDPL::Util::SArray
Array< std::string > SArray
An array of std::string objects.
Definition: Array.hpp:592
APIPrefix.hpp
Definition of the preprocessor macro CDPL_CHEM_API.
CDPL_CHEM_API
#define CDPL_CHEM_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
CDPL::Chem::MorganNumberingCalculator
MorganNumberingCalculator.
Definition: MorganNumberingCalculator.hpp:58
CDPL::Chem::MolecularGraph
MolecularGraph.
Definition: MolecularGraph.hpp:52
CDPL::Chem::MorganNumberingCalculator::MorganNumberingCalculator
MorganNumberingCalculator()
Constructs the MorganNumberingCalculator instance.
Array.hpp
Definition of the class CDPL::Util::Array.
CDPL::Chem::MorganNumberingCalculator::calculate
void calculate(const MolecularGraph &molgraph, Util::STArray &numbering)
Performs a canonical numbering of the atoms in the molecular graph molgraph.
CDPL::Util::STPairArray
Array< STPair > STPairArray
An array of pairs of unsigned integers of type std::size_t.
Definition: Array.hpp:582
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Util::STArray
Array< std::size_t > STArray
An array of unsigned integers of type std::size_t.
Definition: Array.hpp:567
Matrix.hpp
Definition of matrix data types.
CDPL::Chem::MorganNumberingCalculator::MorganNumberingCalculator
MorganNumberingCalculator(const MolecularGraph &molgraph, Util::STArray &numbering)
Constructs the MorganNumberingCalculator instance and performs a canonical numbering of the atoms in ...
CDPL::Util::STPair
std::pair< std::size_t, std::size_t > STPair
A pair of unsigned integers of type std::size_t.
Definition: Array.hpp:577
CDPL::Math::SparseULMatrix
SparseMatrix< unsigned long > SparseULMatrix
An unbounded sparse matrix holding unsigned integers of type unsigned long.
Definition: Matrix.hpp:1904