File: RDKitSVPanel.cc

package info (click to toggle)
rdkit 202503.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 220,160 kB
  • sloc: cpp: 399,240; python: 77,453; ansic: 25,517; java: 8,173; javascript: 4,005; sql: 2,389; yacc: 1,565; lex: 1,263; cs: 1,081; makefile: 580; xml: 229; fortran: 183; sh: 105
file content (101 lines) | stat: -rw-r--r-- 2,666 bytes parent folder | download | duplicates (3)
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
//
// file RDKitSVPanel.cc
// David Cosgrove
// AstraZeneca
// 20th June 2014
//

#include "RDKitSVPanel.H"
#include "MolDisplay2DWidget.H"

#include <QLabel>
#include <QLayout>
#include <QSlider>

using namespace std;

namespace RDKitSV {

// ****************************************************************************
RDKitSVPanel::RDKitSVPanel(bool left_slider, QWidget *parent, Qt::WindowFlags f)
    : QWidget(parent, f) {
  build_widget(left_slider);
}

// ****************************************************************************
void RDKitSVPanel::set_molecules(const vector<RDKit::ROMOL_SPTR> &new_mols,
                                 const vector<vector<int>> &highlight_atoms) {
#ifdef NOTYET
  cout << "RDKitSVPanel::set_molecules : " << new_mols.size() << endl;
#endif

  mols_ = new_mols;
  highlight_atoms_ = highlight_atoms;
  if (highlight_atoms_.size() != mols_.size()) {
    highlight_atoms_.clear();
  }

  if (mols_.empty()) {
    mol_slider_->setDisabled(true);
  } else {
    mol_slider_->setEnabled(true);
    mol_slider_->setRange(0, mols_.size() - 1);
    mol_slider_->setValue(0);
  }

  slot_slider_changed();  // to force picture update
}

// ****************************************************************************
void RDKitSVPanel::set_label(const QString &new_label) {
  label_->setText(new_label);
  label_->setWordWrap(true);
  label_->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  if (new_label.isEmpty()) {
    label_->hide();
  } else {
    label_->show();
  }
}

// ****************************************************************************
void RDKitSVPanel::build_widget(bool left_slider) {
  QHBoxLayout *hbox = new QHBoxLayout;
  mol_draw_ = new RDKit::MolDisplay2DWidget;

  mol_slider_ = new QSlider;
  connect(mol_slider_, &QSlider::valueChanged, this,
          &RDKitSVPanel::slot_slider_changed);
  mol_slider_->setPageStep(1);

  if (left_slider) {
    hbox->addWidget(mol_slider_);
    hbox->addWidget(mol_draw_, 1);
  } else {
    hbox->addWidget(mol_draw_, 1);
    hbox->addWidget(mol_slider_);
  }

  label_ = new QLabel;
  QVBoxLayout *vbox = new QVBoxLayout;
  vbox->addLayout(hbox, 1);
  vbox->addWidget(label_);
  setLayout(vbox);

  label_->hide();
}

// ****************************************************************************
void RDKitSVPanel::slot_slider_changed() {
  if (mols_.empty()) {
    mol_draw_->set_display_mol(RDKit::ROMOL_SPTR());
  } else {
    int mol_num = mol_slider_->value();
    mol_draw_->set_display_mol(mols_[mol_num]);
    if (!highlight_atoms_.empty()) {
      mol_draw_->set_selected_atoms(highlight_atoms_[mol_num]);
    }
  }
}

}  // namespace RDKitSV