Skip to content

Derived Class for Fragmenter

Once you have the fragmentation algorithms such as BRICS, you can get derived class from Fragmenter base class.

Example Use

from fragmentretro.fragmenter import BRICSFragmenter

smiles = "COc1ccc(-n2nccn2)c(C(=O)N2CCC[C@@]2(C)c2nc3c(C)c(Cl)ccc3[nH]2)c1"
fragmenter = BRICSFragmenter(smiles)

# Custom figure size
fragmenter.visualize(figsize=(20, 10), verbose=False, with_indices=True)

Source Code

fragmentretro.fragmenter

Module for fragmenting molecules using BRICS (add other algorithms later).

BRICSFragmenter

Bases: Fragmenter

Source code in src/fragmentretro/fragmenter.py
class BRICSFragmenter(Fragmenter):
    def __init__(self, smiles: str) -> None:
        """
        Initialize with SMILES string.

        Args:
            smiles: SMILES string of molecule to fragment
        """
        super().__init__(smiles)

    def _find_fragmentation_bonds(self, mol: Mol) -> list[BondType]:
        return list(FindBRICSBonds(mol))

    def _break_bonds(self, mol: Mol, bonds: list[BondType]) -> Mol:
        return BreakBRICSBonds(mol, bonds)

__init__(smiles)

Initialize with SMILES string.

Parameters:

Name Type Description Default
smiles str

SMILES string of molecule to fragment

required
Source code in src/fragmentretro/fragmenter.py
def __init__(self, smiles: str) -> None:
    """
    Initialize with SMILES string.

    Args:
        smiles: SMILES string of molecule to fragment
    """
    super().__init__(smiles)

rBRICSFragmenter

Bases: Fragmenter

Source code in src/fragmentretro/fragmenter.py
class rBRICSFragmenter(Fragmenter):
    def __init__(self, smiles: str) -> None:
        """
        Initialize with SMILES string.

        Args:
            smiles: SMILES string of molecule to fragment
        """
        super().__init__(smiles)

    def _find_fragmentation_bonds(self, mol: Mol) -> list[BondType]:
        return list(find_brics_bonds(mol))  # type: ignore[no-untyped-call]

    def _break_bonds(self, mol: Mol, bonds: list[BondType]) -> Mol:
        return break_r_brics_bonds(mol, bonds)  # type: ignore[no-untyped-call]

__init__(smiles)

Initialize with SMILES string.

Parameters:

Name Type Description Default
smiles str

SMILES string of molecule to fragment

required
Source code in src/fragmentretro/fragmenter.py
def __init__(self, smiles: str) -> None:
    """
    Initialize with SMILES string.

    Args:
        smiles: SMILES string of molecule to fragment
    """
    super().__init__(smiles)