// Based on an implementation from a correspondance with Bernd Rohde. void EvenSamplePairsStrategy::initializeStrategy(const ChemicalReaction &, const BBS &bbs) { size_t npos = bbs.size(); used_count.resize(npos); std::fill(used_count.begin(), used_count.end(), 0); var_used.resize(npos); for (size_t i = 0; i < npos; ++i) { var_used[i].resize(m_permutationSizes[i]); std::fill(var_used[i].begin(), var_used[i].end(), 0); } boost::uint64_t nmonomers = 0; for (size_t i = 0; i < bbs.size(); ++i) nmonomers += m_permutationSizes[i]; pair_used.resize(nmonomers); for (size_t i = 0; i < nmonomers; ++i) { pair_used[i].resize(nmonomers); std::fill(pair_used[i].begin(), pair_used[i].end(), 0); } pair_counts.resize(npos); for (size_t i = 0; i < npos; i++) { pair_counts[i].resize(npos); std::fill(pair_counts[i].begin(), pair_counts[i].end(), 0); } /* Initialize random number generator */ /* Find modulus */ for (M = 1; M < rdcast<size_t>(m_numPermutations); M = 2 * M) ; /* Set factor */ a = 5; b = 7; // control of random number and heuristics seed = 0; m_numPermutationsProcessed = 0; nslack = 0; // increase this to break evenness criteria rejected_period = 0; rejected_unique = 0; rejected_slack_condition = 0; rejected_bb_sampling_condition = 0; selected.clear(); // clear the selected (unique) set }
BBS removeNonmatchingReagents(const ChemicalReaction &rxn, BBS bbs, const EnumerationParams ¶ms) { PRECONDITION(bbs.size() <= rxn.getNumReactantTemplates(), "Number of Reagents not compatible with reaction templates"); BBS result; result.resize(bbs.size()); for (size_t reactant_idx = 0; reactant_idx < bbs.size(); ++reactant_idx) { size_t removedCount = 0; const unsigned int maxMatches = (params.reagentMaxMatchCount == INT_MAX) ? 0 : rdcast<unsigned int>(params.reagentMaxMatchCount); ROMOL_SPTR reactantTemplate = rxn.getReactants()[reactant_idx]; for (size_t reagent_idx = 0; reagent_idx < bbs[reactant_idx].size(); ++reagent_idx) { ROMOL_SPTR mol = bbs[reactant_idx][reagent_idx]; size_t matches = countMatches(*mol.get(), *reactantTemplate.get(), maxMatches); bool removeReagent = false; if (!matches || matches > rdcast<size_t>(params.reagentMaxMatchCount)) { removeReagent = true; } if (!removeReagent && params.sanePartialProducts) { // see if we have any sane products in the results std::vector<MOL_SPTR_VECT> partialProducts = rxn.runReactant(mol, reactant_idx); for (size_t productTemplate_idx = 0; productTemplate_idx < partialProducts.size(); ++productTemplate_idx) { int saneProducts = 0; for (size_t product_idx = 0; product_idx < partialProducts[productTemplate_idx].size(); ++product_idx) { try { RWMol *m = dynamic_cast<RWMol *>( partialProducts[productTemplate_idx][product_idx].get()); MolOps::sanitizeMol(*m); saneProducts++; } catch (...) { } } if (!saneProducts) { // if any product template has no sane products, we bail removeReagent = true; break; } } } if (removeReagent) removedCount++; else result[reactant_idx].push_back(mol); } if (removedCount) { BOOST_LOG(rdInfoLog) << "Removed " << removedCount << " non matching reagents at template " << reactant_idx << std::endl; } } return result; }