Esempio n. 1
0
// find the neighbors for an atoms that are not connected by single bond that is
// not refBond
// if checkDir is true only neighbor atoms with bonds marked with a direction
// will be returned
void findAtomNeighborsHelper(const ROMol &mol, const Atom *atom,
                             const Bond *refBond, UINT_VECT &neighbors,
                             bool checkDir = false) {
  PRECONDITION(atom, "bad atom");
  PRECONDITION(refBond, "bad bond");
  neighbors.clear();
  ROMol::OEDGE_ITER beg, end;
  boost::tie(beg, end) = mol.getAtomBonds(atom);
  while (beg != end) {
    const BOND_SPTR bond = mol[*beg];
    Bond::BondDir dir = bond->getBondDir();
    if (bond->getBondType() == Bond::SINGLE &&
        bond->getIdx() != refBond->getIdx()) {
      if (checkDir) {
        if ((dir != Bond::ENDDOWNRIGHT) && (dir != Bond::ENDUPRIGHT)) {
          ++beg;
          continue;
        }
      }
      Atom *nbrAtom = bond->getOtherAtom(atom);
      neighbors.push_back(nbrAtom->getIdx());
    }
    ++beg;
  }
}
Esempio n. 2
0
std::string MolToSmarts(ROMol &inmol, bool doIsomericSmiles) {
  RDUNUSED_PARAM(doIsomericSmiles);  // does this parameter even make sense?
  std::string res;
  unsigned int nAtoms = inmol.getNumAtoms();
  if (!nAtoms) return "";

  ROMol mol(inmol);
  UINT_VECT ranks;
  ranks.resize(nAtoms);
  // For smiles writing we would be canonicalizing but we will not do that here.
  // We will simple use the atom indices as the rank
  for (ROMol::AtomIterator atIt = mol.beginAtoms(); atIt != mol.endAtoms();
       atIt++) {
    ranks.push_back((*atIt)->getIdx());
  }

  std::vector<AtomColors> colors;
  colors.resize(nAtoms);
  std::vector<AtomColors>::iterator colorIt;
  for (colorIt = colors.begin(); colorIt != colors.end(); colorIt++)
    *colorIt = Canon::WHITE_NODE;

  colorIt = std::find(colors.begin(), colors.end(), Canon::WHITE_NODE);
  while (colorIt != colors.end()) {
    unsigned int nextAtomIdx = 0;
    unsigned int nextRank;
    std::string subSmi;
    nextRank = nAtoms + 1;
    for (unsigned int i = 0; i < nAtoms; i++) {
      if (colors[i] == Canon::WHITE_NODE && ranks[i] < nextRank) {
        nextRank = ranks[i];
        nextAtomIdx = i;
      }
    }

    subSmi = FragmentSmartsConstruct(mol, nextAtomIdx, colors, ranks);
    res += subSmi;

    colorIt = std::find(colors.begin(), colors.end(), Canon::WHITE_NODE);
    if (colorIt != colors.end()) {
      res += ".";
    }
  }
  return res;
}