Chemical Data Processing Library C++ API - Version 1.4.0
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 
63  {
64 
65  public:
70 
80 
82 
84 
92  void calculate(const MolecularGraph& molgraph, Util::STArray& numbering);
93 
94  private:
95  typedef std::pair<std::size_t, std::size_t> STPair;
96 
97  typedef std::vector<STPair> STPairArray;
98  typedef std::vector<std::size_t> STArray;
99  typedef std::vector<long> LArray;
100  typedef std::vector<std::string> SArray;
101 
102  class NumberingState
103  {
104 
105  public:
106  NumberingState(STPairArray* sym_class_ids, SArray* symbols,
107  LArray* charges, STArray* isotopes, Math::SparseULMatrix* bond_mtx):
108  symClassIDs(sym_class_ids),
109  atomSymbols(symbols),
110  atomCharges(charges), atomIsotopes(isotopes), bondMatrix(bond_mtx) {}
111 
112  void calculate(const MolecularGraph&, Util::STArray&);
113 
114  private:
115  NumberingState() {}
116 
117  void init(const MolecularGraph&);
118 
119  void perceiveSymClasses();
120 
121  void distributeNumbers(Util::STArray&);
122  void distributeNumbers(std::size_t);
123 
124  void getNextAtomIndices(STArray&);
125 
126  void addListEntriesForAtom(std::size_t, std::size_t);
127 
128  void copy(NumberingState&);
129 
130  typedef STPairArray::const_iterator STPairArrayIterator;
131 
132  STPairArray* symClassIDs;
133  SArray* atomSymbols;
134  LArray* atomCharges;
135  STArray* atomIsotopes;
136  Math::SparseULMatrix* bondMatrix;
137  const MolecularGraph* molGraph;
138  STPairArray atomNumbering;
139  STArray indexLookupTable;
140  STArray fromList;
141  STArray ringClosures;
142  std::string nodeValues;
143  STArray lineValues;
144  LArray modifications;
145  STPairArrayIterator lastSymClass;
146  std::size_t centerAtomNumber;
147  std::size_t nextAtomNumber;
148  bool sortRCList;
149  };
150 
151  STPairArray symClassIDs;
152  SArray atomSymbols;
153  LArray atomCharges;
154  STArray atomIsotopes;
155  Math::SparseULMatrix bondMatrix;
156  NumberingState numbering;
157  };
158  } // namespace Chem
159 } // namespace CDPL
160 
161 #endif // CDPL_CHEM_MORGANNUMBERINGCALCULATOR_HPP
Definition of class CDPL::Util::Array.
Definition of the preprocessor macro CDPL_CHEM_API.
#define CDPL_CHEM_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
Definition of matrix data types.
Abstract base class for representations of a chemical structure as a graph of bonded atoms.
Definition: MolecularGraph.hpp:57
Computes a canonical atom numbering of a molecular graph using a modified Morgan algorithm.
Definition: MorganNumberingCalculator.hpp:63
MorganNumberingCalculator()
Constructs the MorganNumberingCalculator instance.
MorganNumberingCalculator(const MolecularGraph &molgraph, Util::STArray &numbering)
Constructs the MorganNumberingCalculator instance and performs a canonical numbering of the atoms in ...
MorganNumberingCalculator(const MorganNumberingCalculator &)=delete
void calculate(const MolecularGraph &molgraph, Util::STArray &numbering)
Performs a canonical numbering of the atoms in the molecular graph molgraph.
MorganNumberingCalculator & operator=(const MorganNumberingCalculator &)=delete
SparseMatrix< unsigned long > SparseULMatrix
Unbounded sparse matrix holding unsigned integers of type unsigned long.
Definition: Matrix.hpp:3235
Array< std::size_t > STArray
Array storing unsigned integers of type std::size_t.
Definition: Array.hpp:575
Array< long > LArray
Array storing integers of type long.
Definition: Array.hpp:580
Array< STPair > STPairArray
Array storing pairs of unsigned integers of type std::size_t.
Definition: Array.hpp:590
Array< std::string > SArray
Array storing std::string objects.
Definition: Array.hpp:600
std::pair< std::size_t, std::size_t > STPair
Pair of unsigned integers of type std::size_t.
Definition: Array.hpp:585
The namespace of the Chemical Data Processing Library.