File: RingInfo.cpp

package info (click to toggle)
rdkit 201403-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 62,288 kB
  • ctags: 15,156
  • sloc: cpp: 125,376; python: 55,674; java: 4,831; ansic: 4,178; xml: 2,499; sql: 1,775; yacc: 1,551; lex: 1,051; makefile: 353; fortran: 183; sh: 148; cs: 93
file content (118 lines) | stat: -rw-r--r-- 3,780 bytes parent folder | download
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
// $Id$
//
//  Copyright (C) 2004-2008 Greg Landrum and Rational Discovery LLC
//
//   @@ All Rights Reserved @@
//  This file is part of the RDKit.
//  The contents are covered by the terms of the BSD license
//  which is included in the file license.txt, found at the root
//  of the RDKit source tree.
//
#include "RingInfo.h"
#include <RDGeneral/Invariant.h>
#include <algorithm>

namespace RDKit{
  bool RingInfo::isAtomInRingOfSize(unsigned int idx,unsigned int size) const {
    PRECONDITION(df_init,"RingInfo not initialized");

    if( idx < d_atomMembers.size() ){
      return std::find(d_atomMembers[idx].begin(),d_atomMembers[idx].end(),
                       static_cast<int>(size))!=d_atomMembers[idx].end();
    } else {
      return false;
    }
  }
  unsigned int RingInfo::minAtomRingSize(unsigned int idx) const {
    PRECONDITION(df_init,"RingInfo not initialized");

    if( idx < d_atomMembers.size() && d_atomMembers[idx].size() ){
      return *std::min_element(d_atomMembers[idx].begin(),d_atomMembers[idx].end());
    } else {
      return 0;
    }
  }
  unsigned int RingInfo::numAtomRings(unsigned int idx) const {
    PRECONDITION(df_init,"RingInfo not initialized");

    if( idx < d_atomMembers.size() ){
      return d_atomMembers[idx].size();
    } else {
      return 0;
    }
  }
  bool RingInfo::isBondInRingOfSize(unsigned int idx,unsigned int size) const {
    PRECONDITION(df_init,"RingInfo not initialized");

    if( idx < d_bondMembers.size() ){
      return std::find(d_bondMembers[idx].begin(),
                       d_bondMembers[idx].end(),
                       static_cast<int>(size))!=d_bondMembers[idx].end();
    } else {
      return false;
    }

  }
  unsigned int RingInfo::minBondRingSize(unsigned int idx) const {
    PRECONDITION(df_init,"RingInfo not initialized");

    if( idx < d_bondMembers.size() && d_bondMembers[idx].size() ){
      return *std::min_element(d_bondMembers[idx].begin(),d_bondMembers[idx].end());
    } else {
      return 0;
    }

  }
  unsigned int RingInfo::numBondRings(unsigned int idx) const {
    PRECONDITION(df_init,"RingInfo not initialized");

    if( idx < d_bondMembers.size() ){
      return d_bondMembers[idx].size();
    } else {
      return 0;
    }
  }

  unsigned int RingInfo::numRings() const {
    PRECONDITION(df_init,"RingInfo not initialized");
    PRECONDITION(d_atomRings.size()==d_bondRings.size(),"length mismatch");
    return d_atomRings.size();
  }

  unsigned int RingInfo::addRing(const INT_VECT &atomIndices,const INT_VECT &bondIndices){
    PRECONDITION(df_init,"RingInfo not initialized");
    PRECONDITION(atomIndices.size()==bondIndices.size(),"length mismatch");
    int sz = atomIndices.size();
    for(INT_VECT::const_iterator i=atomIndices.begin();
	i<atomIndices.end(); i++){
      if( *i>=static_cast<int>(d_atomMembers.size()) ) d_atomMembers.resize((*i)+1);
      d_atomMembers[*i].push_back(sz);
    }
    for(INT_VECT::const_iterator i=bondIndices.begin();
	i<bondIndices.end(); i++){
      if( *i>=static_cast<int>(d_bondMembers.size()) ) d_bondMembers.resize((*i)+1);
      d_bondMembers[*i].push_back(sz);
    }
    d_atomRings.push_back(atomIndices);
    d_bondRings.push_back(bondIndices);
    POSTCONDITION(d_atomRings.size()==d_bondRings.size(),"length mismatch");
    return d_atomRings.size();
  }

  void RingInfo::initialize() {
    PRECONDITION(!df_init,"already initialized");
    df_init=true;
  };
  void RingInfo::reset(){
    if(!df_init) return;
    df_init=false;
    d_atomMembers.clear();
    d_bondMembers.clear();
    d_atomRings.clear();
    d_bondRings.clear();
  }
  void RingInfo::preallocate(unsigned int numAtoms,unsigned int numBonds){
    d_atomMembers.resize(numAtoms);
    d_bondMembers.resize(numBonds);
  }
}