Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mol2morgan_fingerprint: fix bug of mismatched indices after folding #93

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions molpipeline/mol2any/mol2morgan_fingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ def _explain_rdmol(self, mol_obj: RDKitMol) -> dict[int, list[tuple[int, int]]]:
fp_generator = self._get_fp_generator()
additional_output = AllChem.AdditionalOutput()
additional_output.AllocateBitInfoMap()
_ = fp_generator.GetSparseFingerprint(
mol_obj, additionalOutput=additional_output
)
# using the dense fingerprint here, to get indices after folding
_ = fp_generator.GetFingerprint(mol_obj, additionalOutput=additional_output)
bit_info = additional_output.GetBitInfoMap()
return bit_info
12 changes: 2 additions & 10 deletions tests/test_elements/test_mol2any/test_mol2morgan_fingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,8 @@ def test_setter_getter_error_handling(self) -> None:
self.assertRaises(ValueError, mol_fp.set_params, **params)

def test_bit2atom_mapping(self) -> None:
"""Test that the mapping from bits to atom weights works as intended.

Notes
-----
lower n_bit values, e.g. 2048, will lead to a bit clash during folding,
for the test smiles "NCCOCCCC(=O)O".
We want no folding clashes in this test to check the correct length
of the bit-to-atom mapping.
"""
n_bits = 2100
"""Test that the mapping from bits to atom weights works as intended."""
n_bits = 2048
sparse_morgan = MolToMorganFP(radius=2, n_bits=n_bits, return_as="sparse")
dense_morgan = MolToMorganFP(radius=2, n_bits=n_bits, return_as="dense")
explicit_bit_vect_morgan = MolToMorganFP(
Expand Down
Loading