Allow inclusion of molecule names in ScaffoldNetwork (#7956)

* Add molecules names into ScaffoldNetwork

- added parameter to ScaffoldNetwork Params to include molecule names in the
  ScaffoldNetwork nodes corresponding to input molecules

* Document _Name assumption

- fixed a binary and instead of a boolean and

* Forgot has prop check before access

* Misunderstood semantics of CHECK vs. REQUIRE
This commit is contained in:
PatrickPenner
2024-10-30 05:11:30 +00:00
committed by greg landrum
parent 2dc0c7c6aa
commit e35079c949
4 changed files with 25 additions and 0 deletions

View File

@@ -201,6 +201,9 @@ size_t addEntryIfMissing(T &vect, const V &e,
void addMolToNetwork(const ROMol &mol, ScaffoldNetwork &network,
const ScaffoldNetworkParams &params) {
auto ismi = MolToSmiles(mol);
if (params.includeNames && mol.hasProp("_Name")) {
ismi += ' ' + mol.getProp<std::string>("_Name");
}
boost::shared_ptr<ROMol> fmol(flattenMol(mol, params));
if (params.pruneBeforeFragmenting) {
boost::shared_ptr<ROMol> pmol(pruneMol(*fmol, params));

View File

@@ -44,6 +44,8 @@ struct RDKIT_SCAFFOLDNETWORK_EXPORT ScaffoldNetworkParams {
true; ///< remove attachment points from scaffolds and include the result
bool includeScaffoldsWithAttachments =
true; ///< Include the version of the scaffold with attachment points
bool includeNames =
false; ///< Include molecules names of the input molecules
bool keepOnlyFirstFragment =
true; ///< keep only the first fragment from the bond breaking rule
bool pruneBeforeFragmenting =

View File

@@ -102,6 +102,11 @@ BOOST_PYTHON_MODULE(rdScaffoldNetwork) {
&ScaffoldNetwork::ScaffoldNetworkParams::
includeScaffoldsWithAttachments,
"Include the version of the scaffold with attachment points")
.def_readwrite(
"includeNames",
&ScaffoldNetwork::ScaffoldNetworkParams::
includeNames,
"Include molecules names of the input molecules")
.def_readwrite(
"keepOnlyFirstFragment",
&ScaffoldNetwork::ScaffoldNetworkParams::keepOnlyFirstFragment,

View File

@@ -270,6 +270,21 @@ TEST_CASE("addMolToNetwork", "[unittest][scaffolds]") {
CHECK(std::find(net.nodes.begin(), net.nodes.end(),
"*1**1**1:*:*:*:*:*:1") != net.nodes.end());
}
SECTION("includes names") {
auto m = "CC(=O)Oc1ccccc1C(=O)O aspirin"_smiles;
REQUIRE(m);
// check that the name was parsed into "_Name"
CHECK(m->getProp<std::string>("_Name") == "aspirin");
ScaffoldNetwork::ScaffoldNetworkParams ps;
ScaffoldNetwork::ScaffoldNetwork net;
ScaffoldNetwork::detail::addMolToNetwork(*m, net, ps);
CHECK(net.nodes.at(0) == "CC(=O)Oc1ccccc1C(=O)O");
ps.includeNames = true;
ScaffoldNetwork::ScaffoldNetwork otherNet;
ScaffoldNetwork::detail::addMolToNetwork(*m, otherNet, ps);
CHECK(otherNet.nodes.at(0) == "CC(=O)Oc1ccccc1C(=O)O aspirin");
}
}
TEST_CASE("Network defaults", "[scaffolds]") {
auto smis = {"c1ccccc1CC1NC(=O)CCC1", "c1cccnc1CC1NC(=O)CCC1"};