mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
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:
committed by
greg landrum
parent
2dc0c7c6aa
commit
e35079c949
@@ -201,6 +201,9 @@ size_t addEntryIfMissing(T &vect, const V &e,
|
||||
void addMolToNetwork(const ROMol &mol, ScaffoldNetwork &network,
|
||||
const ScaffoldNetworkParams ¶ms) {
|
||||
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));
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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"};
|
||||
|
||||
Reference in New Issue
Block a user