-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
68 makescaffoldgeneric set all carbons to wild card symbols to allow …
…a substrcutre search (#69)
- Loading branch information
1 parent
fa9363b
commit 4f69b9f
Showing
2 changed files
with
209 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
"""Test the mol2scaffold module.""" | ||
|
||
from typing import Any | ||
from unittest import TestCase | ||
|
||
from molpipeline import Pipeline | ||
from molpipeline.any2mol import AutoToMol | ||
from molpipeline.mol2any import MolToSmiles | ||
from molpipeline.mol2mol.scaffolds import MakeScaffoldGeneric, MurckoScaffold | ||
|
||
|
||
class TestMurckoScaffold(TestCase): | ||
"""Test the MurckoScaffold class.""" | ||
|
||
def test_murcko_scaffold_generation_pipeline(self) -> None: | ||
"""Test the scaffold generation.""" | ||
scaffold_pipeline = Pipeline( | ||
steps=[ | ||
("smiles_to_mol", AutoToMol()), | ||
("murcko_scaffold", MurckoScaffold()), | ||
("scaffold_to_smiles", MolToSmiles()), | ||
] | ||
) | ||
smiles_list = ["Cc1ccc(=O)[nH]c1", "O=CC1CCC(c2ccccc2)CC1", "CCC"] | ||
expected_scaffold_list = ["O=c1cccc[nH]1", "c1ccc(C2CCCCC2)cc1", ""] | ||
|
||
scaffold_list = scaffold_pipeline.transform(smiles_list) | ||
self.assertListEqual(expected_scaffold_list, scaffold_list) | ||
|
||
|
||
class TestMakeScaffoldGeneric(TestCase): | ||
"""Test the MakeScaffoldGeneric class.""" | ||
|
||
def setUp(self) -> None: | ||
"""Set up the pipeline and common variables.""" | ||
self.generic_scaffold_pipeline = Pipeline( | ||
steps=[ | ||
("smiles_to_mol", AutoToMol()), | ||
("murcko_scaffold", MurckoScaffold()), | ||
("make_scaffold_generic", MakeScaffoldGeneric()), | ||
("scaffold_to_smiles", MolToSmiles()), | ||
] | ||
) | ||
self.smiles_list = ["Cc1ccc(=O)[nH]c1", "O=CC1CCC(c2ccccc2)CC1", "CCC"] | ||
|
||
def check_generic_scaffold( | ||
self, params: dict[str, Any], expected_scaffold_list: list[str] | ||
) -> None: | ||
"""Helper function to set parameters and check the results. | ||
Parameters | ||
---------- | ||
params: dict[str, Any] | ||
Parameters to set for the pipeline. | ||
expected_scaffold_list: list[str] | ||
Expected output of the pipeline. | ||
""" | ||
self.generic_scaffold_pipeline.set_params(**params) | ||
generic_scaffold_list = self.generic_scaffold_pipeline.transform( | ||
self.smiles_list | ||
) | ||
self.assertListEqual(expected_scaffold_list, generic_scaffold_list) | ||
|
||
def test_generic_scaffold_generation_pipeline(self) -> None: | ||
"""Test the generic scaffold generation.""" | ||
self.check_generic_scaffold( | ||
params={}, expected_scaffold_list=["CC1CCCCC1", "C1CCC(C2CCCCC2)CC1", ""] | ||
) | ||
|
||
# Test the generic scaffold generation with generic atoms | ||
self.check_generic_scaffold( | ||
params={"make_scaffold_generic__generic_atoms": True}, | ||
expected_scaffold_list=["**1*****1", "*1***(*2*****2)**1", ""], | ||
) | ||
|
||
# Test the generic scaffold generation with generic bonds | ||
self.check_generic_scaffold( | ||
params={ | ||
"make_scaffold_generic__generic_atoms": False, | ||
"make_scaffold_generic__generic_bonds": True, | ||
}, | ||
expected_scaffold_list=[ | ||
"C~C1~C~C~C~C~C~1", | ||
"C1~C~C~C(~C2~C~C~C~C~C~2)~C~C~1", | ||
"", | ||
], | ||
) | ||
|
||
# Test the generic scaffold generation with generic atoms and bonds | ||
self.check_generic_scaffold( | ||
params={ | ||
"make_scaffold_generic__generic_atoms": True, | ||
"make_scaffold_generic__generic_bonds": True, | ||
}, | ||
expected_scaffold_list=[ | ||
"*~*1~*~*~*~*~*~1", | ||
"*1~*~*~*(~*2~*~*~*~*~*~2)~*~*~1", | ||
"", | ||
], | ||
) |