File: RingFinder.cpp

package info (click to toggle)
pymol 2.5.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 42,288 kB
  • sloc: cpp: 476,472; python: 76,538; ansic: 29,510; javascript: 6,792; sh: 47; makefile: 24
file content (44 lines) | stat: -rw-r--r-- 1,084 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
#include "RingFinder.h"
#include "ObjectMolecule.h"

void AbstractRingFinder::recursion(int atm, int depth)
{
  m_indices[depth] = atm;

  for (auto const& neighbor : AtomNeighbors(m_obj, atm)) {
    // check bond order
    if (m_obj->Bond[neighbor.bond].order < 1)
      continue;

    const auto atm_neighbor = neighbor.atm;

    // check atom filter
    if (atomIsExcluded(m_obj->AtomInfo[atm_neighbor]))
      continue;

    // check if closing a ring of size >= 3
    if (depth > 1 && atm_neighbor == m_indices[0]) {
      // found ring, add it to the selection
      onRingFound(m_obj, m_indices.data(), depth + 1);
    } else if (depth < m_indices.size() - 1) {
      // check for undesired ring with start != 0
      int i = depth;
      while ((--i) >= 0)
        if (atm_neighbor == m_indices[i])
          break; // stop recursion
      if (i == -1) {
        recursion(atm_neighbor, depth + 1);
      }
    }
  }
}

void AbstractRingFinder::apply(ObjectMolecule* obj, int atm)
{
  if (m_obj != obj) {
    m_obj = obj;
    prepareObject(m_obj);
  }

  recursion(atm, 0);
}