Exemple #1
0
void VanDerWaals::process(const Core::Molecule &molecule,
                          Rendering::GroupNode &node)
{
  // Add a sphere node to contain all of the VdW spheres.
  GeometryNode *geometry = new GeometryNode;
  node.addChild(geometry);
  SphereGeometry *spheres = new SphereGeometry;
  spheres->identifier().molecule = &molecule;
  spheres->identifier().type = Rendering::AtomType;
  geometry->addDrawable(spheres);

  for (size_t i = 0; i < molecule.atomCount(); ++i) {
    Core::Atom atom = molecule.atom(i);
    unsigned char atomicNumber = atom.atomicNumber();
    const unsigned char *c = Elements::color(atomicNumber);
    Vector3ub color(c[0], c[1], c[2]);
    spheres->addSphere(atom.position3d().cast<float>(), color,
                       static_cast<float>(Elements::radiusVDW(atomicNumber)));
  }
}
void OpenBabel::onHydrogenOperationFinished(const QByteArray &mdl)
{
  m_progress->setLabelText(tr("Reading obabel output..."));

  // MDL --> molecule
  Core::Molecule mol;
  if (!Io::FileFormatManager::instance().readString(mol, mdl.constData(),
                                                    "mol")) {
    m_progress->reset();
    qWarning() << "Bad MDL: " << mdl;
    QMessageBox::critical(qobject_cast<QWidget*>(parent()),
                          tr("Error"),
                          tr("Error interpreting obabel MDL output."),
                          QMessageBox::Ok);
    return;
  }

  /// @todo cache a pointer to the current molecule in the above slot, and
  /// verify that we're still operating on the same molecule.

  // Update molecule
  m_molecule->clearAtoms();
  for (Index i = 0; i < mol.atomCount(); ++i) {
    Core::Atom atom = mol.atom(i);
    m_molecule->addAtom(atom.atomicNumber()).setPosition3d(atom.position3d());
  }
  for (Index i = 0; i < mol.bondCount(); ++i) {
    Core::Bond bond = mol.bond(i);
    m_molecule->addBond(m_molecule->atom(bond.atom1().index()),
                        m_molecule->atom(bond.atom2().index()),
                        bond.order());
  }

  m_molecule->emitChanged(Molecule::Atoms | Molecule::Bonds | Molecule::Added |
                          Molecule::Removed | Molecule::Modified);

  m_progress->reset();
}