Skip to content

toxicity #

Functions:

  • rule_of_five

    Function to calculate the Ro5 properties for a molecule. Needs the new R group to be joined to form a single

  • filter_mols

    Function to carry out a filter of a list of molecules dependent on the catalog supplied.

  • tox_props

    Function to get properties of a list of molecules and return a dataframe of results.

rule_of_five #

rule_of_five(mol)

Function to calculate the Ro5 properties for a molecule. Needs the new R group to be joined to form a single RDKit mol object as input. Returns a series containing the molecular weight, number of hydrogen bond donors and acceptors and the calculated LogP.

A flag of True is returned if the molecule complies and False if it doesn't.

Source code in fegrow/toxicity.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def rule_of_five(mol):
    """
    Function to calculate the Ro5 properties for a molecule. Needs the new R group to be joined to form a single
    RDKit mol object as input. Returns a series containing the molecular weight, number of hydrogen bond donors and
    acceptors and the calculated LogP.

    A flag of True is returned if the molecule complies and False if it doesn't.
    """

    # Ro5 descriptors
    MW = Descriptors.MolWt(mol)
    HBA = Lipinski.NOCount(mol)
    HBD = Lipinski.NHOHCount(mol)
    LogP = Descriptors.MolLogP(mol)

    # Ro5 conditions
    conditions = [MW <= 500, HBA <= 10, HBD <= 5, LogP <= 5]

    # passes Ro5 if no more than one out of four conditions is violated
    pass_ro5 = conditions.count(True) >= 3

    ro5 = {
        "MW": MW,
        "HBA": HBA,
        "HBD": HBD,
        "LogP": LogP,
        "Pass_Ro5": pass_ro5,
    }

    return ro5

filter_mols #

filter_mols(mol, catalog, filter_type)

Function to carry out a filter of a list of molecules dependent on the catalog supplied. Returns a flag of True if unwanted features are detected and False if none are found

Source code in fegrow/toxicity.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def filter_mols(mol, catalog, filter_type):
    """
    Function to carry out a filter of a list of molecules dependent on the catalog supplied.
    Returns a flag of True if unwanted features are detected and False if none are found
    """

    entry = catalog.GetFirstMatch(mol)  # Get the first matching PAINS
    if entry is not None:
        flag = True  # true if mol contains filter
    else:
        flag = False  # false if not

    result = {filter_type: flag}  # return dict of values

    return result

tox_props #

tox_props(data)

Function to get properties of a list of molecules and return a dataframe of results.

Source code in fegrow/toxicity.py
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
def tox_props(data):
    """
    Function to get properties of a list of molecules and return a dataframe of results.
    """

    # initialize pains filter
    params_pains = FilterCatalogParams()
    params_pains.AddCatalog(FilterCatalogParams.FilterCatalogs.PAINS)
    catalog_pains = FilterCatalog(params_pains)

    # initialize unwanted substructures filter
    params_unwanted = FilterCatalogParams()
    params_unwanted.AddCatalog(FilterCatalogParams.FilterCatalogs.BRENK)
    catalog_unwanted = FilterCatalog(params_unwanted)

    # initialise functional group filter
    params_nih = FilterCatalogParams()
    params_nih.AddCatalog(FilterCatalogParams.FilterCatalogs.NIH)
    catalog_nih = FilterCatalog(params_nih)

    # if a dataframe of mols is supplied
    if isinstance(data, pd.DataFrame):
        mols = list(data["ROMol"])
        ro5 = pd.DataFrame([rule_of_five(mol) for mol in mols])
        pains = pd.DataFrame(
            [filter_mols(mol, catalog_pains, "has_pains") for mol in mols]
        )
        unwanted_subs = pd.DataFrame(
            [filter_mols(mol, catalog_unwanted, "has_unwanted_subs") for mol in mols]
        )
        nih = pd.DataFrame(
            [filter_mols(mol, catalog_nih, "has_prob_fgs") for mol in mols]
        )
        sa_score = [calculateScore(mol) for mol in mols]

        data = pd.concat(
            [data, ro5, pains, unwanted_subs, nih], axis=1
        )  # put results together
        data["synthetic_accessibility"] = sa_score

        return data

    # if a single molecule is supplied
    else:
        mol = data
        ro5 = pd.DataFrame([rule_of_five(data)])
        pains = pd.DataFrame([filter_mols(mol, catalog_pains, "has_pains")])
        unwanted_subs = pd.DataFrame(
            [filter_mols(mol, catalog_unwanted, "has_unwanted_subs")]
        )
        nih = pd.DataFrame([filter_mols(mol, catalog_nih, "has_prob_fgs")])
        sa_score = [calculateScore(mol)]

        data = pd.concat([ro5, pains, unwanted_subs, nih], axis=1)
        data["synthetic_accessibility"] = sa_score

        return data