File: molecule_automorphism_search.h

package info (click to toggle)
indigo 1.1.12-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 26,788 kB
  • ctags: 43,825
  • sloc: ansic: 309,179; cpp: 112,400; cs: 8,446; asm: 8,011; java: 6,652; sql: 6,647; xml: 3,397; python: 3,339; sh: 207; makefile: 158; php: 48
file content (130 lines) | stat: -rw-r--r-- 4,904 bytes parent folder | download | duplicates (2)
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
/****************************************************************************
 * Copyright (C) 2009-2013 GGA Software Services LLC
 * 
 * This file is part of Indigo toolkit.
 * 
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 3 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 * 
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 ***************************************************************************/

#ifndef __molecule_automorphism_search__
#define __molecule_automorphism_search__

#include "graph/automorphism_search.h"

namespace indigo {

class Molecule;
class MoleculeStereocenters;
class CancellationHandler;

class MoleculeAutomorphismSearch : public AutomorphismSearch
{
public:

   MoleculeAutomorphismSearch ();
   virtual ~MoleculeAutomorphismSearch () {}
   
   void process (Molecule &mol);

   // By default all stereocenters and cis-trans bonds are treated as valid.
   bool detect_invalid_stereocenters;
   bool detect_invalid_cistrans_bonds;
   bool find_canonical_ordering;

   // By default all the atoms with undefinded number of hydrogens throws an exception.
   // If allow_undefined is true then such atoms are simply uncomparable and some 
   // symmetries might be lost.
   bool allow_undefined;

   bool invalidCisTransBond (int idx);
   bool invalidStereocenter (int idx);

   // Bonds indices that will be checked for possible cis-trans property.
   // After calling "process" method all bonds, that cannot be cis-trans
   // will be removed from this array.
   Array<int> possible_cis_trans_to_check;

   DECL_ERROR;
   DECL_TIMEOUT_EXCEPTION;

protected:
   static int  _vertex_cmp  (Graph &graph, int v1, int v2, const void *context);
   static int  _edge_rank    (Graph &graph, int edge_idx, const void *context);
   static bool _check_automorphism (Graph &graph, const Array<int> &mapping, const void *context);

   static bool _isCisTransBondMappedRigid (Molecule &mol, int i, const int *mapping);
   static bool _isStereocenterMappedRigid (const MoleculeStereocenters &stereocenters, int i, const int *mapping);

   static int  _compare_mapped (Graph &graph, const Array<int> &mapping1, const Array<int> &mapping2, const void *context);

   static void _automorphismCallback (const int *automorphism, void *context);

   static int _compareRSites (Molecule &mol, int v1, int v2, const void *context);
   static int _compareStereo (Molecule &mol, int v1, int v2, const void *context);

   int _compareMappedStereocenters (Molecule &mol, const Array<int> &mapping1, 
      const Array<int> &mapping2, const Array<int> &inv_mapping1, const Array<int> &inv_mapping2) const;

   bool _checkStereocentersAutomorphism (Molecule &mol, const Array<int> &mapping) const;

   void _initialize                  (Molecule &mol);
   void _calculateHydrogensAndDegree (Molecule &mol);
   void _getFirstApproximation       (Molecule &mol);

   int _validCisTransBond (int idx, const Array<int> &orbits);
   int  _validStereocenter (int idx, Array<int> &orbits, int *parity = 0);
   int  _validStereocenterByAtom (int atom_idx, Array<int> &orbits, int *parity = 0);

   int _treat_undef_as;
   int _getStereo (int state) const;

   bool _findInvalidStereo (Molecule &mol);
   bool _findInvalidStereoCisTrans (Molecule &mol);
   void _markValidOrInvalidStereo (bool find_valid, Array<int> &approximation_orbits, bool *found);
   void _findCisTransStereoBondParirties (Molecule &mol);

   bool _hasStereo (Molecule &mol);

   void _markComplicatedStereocentersAsValid (Molecule &mol);

   bool _checkCisTransInvalid (Molecule &mol, int bond_idx);
   void _findAllPossibleCisTrans (Molecule &mol);
   void _findAllPossibleCisTransOneStep (Molecule &mol);

   struct EdgeInfo
   {
      int mapped_vertex;
      int edge;
   };

   static void _getSortedNei (Graph &g, int v, Array<EdgeInfo> &sorted_nei, Array<int>& inv_mapping);
   int _getMappedBondOrderAndParity (Molecule &m, int e, Array<int>& inv_mapping) const;

   TL_CP_DECL(Array<int>, _approximation_orbits);
   TL_CP_DECL(Array<int>, _approximation_orbits_saved);
   TL_CP_DECL(Array<int>, _hcount);
   TL_CP_DECL(Array<int>, _cistrans_stereo_bond_parity);
   TL_CP_DECL(Array<int>, _degree);
   TL_CP_DECL(Array<int>, _independent_component_index);

   enum { _NO_STEREO = -1, _INVALID, _VALID, _UNDEF };
   TL_CP_DECL(Array<int>, _stereocenter_state);
   TL_CP_DECL(Array<int>, _cistrans_bond_state);

   // Target stereocenters and cis-trans bond for checking permutation parity
   int _target_stereocenter, _target_bond;
   bool _target_stereocenter_parity_inv, _target_bond_parity_inv;
   int _fixed_atom;

   CancellationHandler *_cancellation_handler;
};

}

#endif