Exemple #1
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;
}
Exemple #2
0
// Figure out the CIP ranks for the atoms of a molecule
void assignAtomCIPRanks(const ROMol &mol, UINT_VECT &ranks) {
  PRECONDITION((!ranks.size() || ranks.size() >= mol.getNumAtoms()),
               "bad ranks size");
  if (!ranks.size()) ranks.resize(mol.getNumAtoms());
  unsigned int numAtoms = mol.getNumAtoms();
#ifndef USE_NEW_STEREOCHEMISTRY
  // get the initial invariants:
  DOUBLE_VECT invars(numAtoms, 0);
  buildCIPInvariants(mol, invars);
  iterateCIPRanks(mol, invars, ranks, false);
#else
  Canon::chiralRankMolAtoms(mol, ranks);
#endif

  // copy the ranks onto the atoms:
  for (unsigned int i = 0; i < numAtoms; ++i) {
    mol[i]->setProp(common_properties::_CIPRank, ranks[i], 1);
  }
}