mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
* Fixes #982 also changes bond-wedging algorithm to favor lighter non-ring bonds * prefer wedging bonds to lower-degree atoms * Fixes #983 * small fixes - Fix a problem where a chiral atom is selected to draw a wedge to instead of a ring atom - Fix a problem where two calls to PrepareMolForDrawing() led to two wedged bonds from an atom. * Fixes #985 This isn't the most satisfying solution (the wedged bonds are sometimes a bit too large), but it gives reasonable results on the test cases I've tried.
64 lines
1.9 KiB
C++
64 lines
1.9 KiB
C++
//
|
|
// Copyright (C) 2016 Greg Landrum
|
|
//
|
|
// @@ 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 <GraphMol/MolDraw2D/MolDraw2DUtils.h>
|
|
#include <GraphMol/RWMol.h>
|
|
#include <GraphMol/MolOps.h>
|
|
#include <GraphMol/Depictor/RDDepictor.h>
|
|
#include <GraphMol/FileParsers/MolFileStereochem.h>
|
|
|
|
namespace RDKit {
|
|
namespace MolDraw2DUtils {
|
|
|
|
namespace {
|
|
bool isAtomCandForChiralH(const RWMol &mol, const Atom *atom) {
|
|
// conditions for needing a chiral H:
|
|
// - stereochem specified
|
|
// - in at least two rings
|
|
if ((!mol.getRingInfo()->isInitialized() ||
|
|
mol.getRingInfo()->numAtomRings(atom->getIdx()) > 1) &&
|
|
(atom->getChiralTag() == Atom::CHI_TETRAHEDRAL_CCW ||
|
|
atom->getChiralTag() == Atom::CHI_TETRAHEDRAL_CW)) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
} // end of anonymous namespace
|
|
|
|
void prepareMolForDrawing(RWMol &mol, bool kekulize, bool addChiralHs,
|
|
bool wedgeBonds, bool forceCoords) {
|
|
if (kekulize) {
|
|
MolOps::Kekulize(mol, false); // kekulize, but keep the aromatic flags!
|
|
}
|
|
if (addChiralHs) {
|
|
std::vector<unsigned int> chiralAts;
|
|
for (RWMol::AtomIterator atIt = mol.beginAtoms(); atIt != mol.endAtoms();
|
|
++atIt) {
|
|
if (isAtomCandForChiralH(mol, *atIt)) {
|
|
chiralAts.push_back((*atIt)->getIdx());
|
|
}
|
|
}
|
|
if (chiralAts.size()) {
|
|
bool addCoords = false;
|
|
if (!forceCoords && mol.getNumConformers()) addCoords = true;
|
|
MolOps::addHs(mol, false, addCoords, &chiralAts);
|
|
}
|
|
}
|
|
if (forceCoords || !mol.getNumConformers()) {
|
|
// compute 2D coordinates in a standard orientation:
|
|
const bool canonOrient = true;
|
|
RDDepict::compute2DCoords(mol, NULL, canonOrient);
|
|
}
|
|
if (wedgeBonds) {
|
|
WedgeMolBonds(mol, &mol.getConformer());
|
|
}
|
|
}
|
|
}
|
|
}
|