Skip to content

test_general #

Functions:

test_growing_keep_larger_component #

test_growing_keep_larger_component(RGroups)

When a growing vector is an internal atom that divides the molecule, the largest component becomes the scaffold.

Source code in fegrow/testing/test_general.py
15
16
17
18
19
20
21
22
23
24
25
26
27
def test_growing_keep_larger_component(RGroups):
    """
    When a growing vector is an internal atom that divides the molecule,
    the largest component becomes the scaffold.
    """
    scaffold = Chem.MolFromSmiles("O=c1c(-c2cccc(Cl)c2)cccn1-c1cccnc1")

    # use C on the chlorinated benzene
    attachment_index = 3
    ethanol_rgroup = RGroups[RGroups.Name == "*CCO"].Mol.values[0]
    rmol = fegrow.build_molecule(scaffold, ethanol_rgroup, attachment_index)

    assert Chem.MolToSmiles(Chem.RemoveHs(rmol)) == "O=c1c(CCO)cccn1-c1cccnc1"

test_growing_keep_larger_component_implicit_index #

test_growing_keep_larger_component_implicit_index(RGroups)

When a growing vector is an internal atom that divides the molecule, the largest component becomes the scaffold.

Source code in fegrow/testing/test_general.py
30
31
32
33
34
35
36
37
38
39
40
41
42
def test_growing_keep_larger_component_implicit_index(RGroups):
    """
    When a growing vector is an internal atom that divides the molecule,
    the largest component becomes the scaffold.
    """
    scaffold = Chem.MolFromSmiles("O=c1c(-c2cccc(Cl)c2)cccn1-c1cccnc1")
    # use C on the chlorinated benzene
    scaffold.GetAtomWithIdx(3).SetAtomicNum(0)

    methanol = Chem.MolFromSmiles("*CO")
    rmol = fegrow.build_molecule(scaffold, methanol)

    assert Chem.MolToSmiles(Chem.RemoveHs(rmol)) == "O=c1c(CO)cccn1-c1cccnc1"

test_growing_keep_cue_component #

test_growing_keep_cue_component(RGroups)

When a growing vector is an atom that divides the molecule, the user can specify which side to keep.

Keep the smaller chlorinated benzene ring for growing ethanol

Source code in fegrow/testing/test_general.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def test_growing_keep_cue_component(RGroups):
    """
    When a growing vector is an atom that divides the molecule,
    the user can specify which side to keep.

    Keep the smaller chlorinated benzene ring for growing ethanol
    """
    scaffold = Chem.MolFromSmiles("O=c1c(-c2cccc(Cl)c2)cccn1-c1cccnc1")
    Chem.AllChem.Compute2DCoords(scaffold)

    # use C on the chlorinated benzene
    attachment_index = 2
    keep_smaller_ring = 3
    ethanol_rgroup = RGroups[RGroups.Name == "*CCO"].Mol.values[0]
    rmol = fegrow.build_molecule(
        scaffold, ethanol_rgroup, attachment_index, keep=keep_smaller_ring
    )

    assert Chem.MolToSmiles(Chem.RemoveHs(rmol)) == "OCCc1cccc(Cl)c1"

test_replace_methyl #

test_replace_methyl(RGroups, sars_core_scaffold)
Source code in fegrow/testing/test_general.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def test_replace_methyl(RGroups, sars_core_scaffold):
    """ """
    params = Chem.SmilesParserParams()
    params.removeHs = False  # keep the hydrogens
    mol = Chem.MolFromSmiles(
        "[H]c1nc(N([H])C(=O)C([H])([H])[H])c([H])c([H])c1[H]", params=params
    )
    Chem.AllChem.Compute2DCoords(mol)

    scaffold = fegrow.RMol(mol)

    # replace the methyl group
    attachment_index = 8
    ethanol_rgroup = RGroups[RGroups.Name == "*CCO"].Mol.values[0]
    rmol = fegrow.build_molecule(scaffold, ethanol_rgroup, attachment_index)

    assert (
        Chem.MolToSmiles(rmol)
        == "[H]OC([H])([H])C([H])([H])C(=O)N([H])c1nc([H])c([H])c([H])c1[H]"
    )

test_replace_methyl_keep_h #

test_replace_methyl_keep_h(RGroups)
Source code in fegrow/testing/test_general.py
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
def test_replace_methyl_keep_h(RGroups):
    """ """
    params = Chem.SmilesParserParams()
    params.removeHs = False  # keep the hydrogens
    mol = Chem.MolFromSmiles(
        "[H]c1nc(N([H])C(=O)C([H])([H])[H])c([H])c([H])c1[H]", params=params
    )
    Chem.AllChem.Compute2DCoords(mol)

    scaffold = fegrow.RMol(mol)

    # replace the methyl group
    attachment_index = 8
    keep_only_h = 10
    ethanol_rgroup = RGroups[RGroups.Name == "*CCO"].Mol.values[0]
    rmol = fegrow.build_molecule(
        scaffold, ethanol_rgroup, attachment_index, keep=keep_only_h
    )

    assert Chem.MolToSmiles(Chem.RemoveHs(rmol)) == "CCO"

test_add_smiles_linker #

test_add_smiles_linker(sars_scaffold_chunk_sdf)

:return:

Source code in fegrow/testing/test_general.py
169
170
171
172
173
174
175
176
177
def test_add_smiles_linker(sars_scaffold_chunk_sdf):
    """
    :return:
    """
    # Check if conformers are generated correctly.
    attachment_index = 7

    linker_rccr = Chem.AddHs(Chem.MolFromSmiles("*CC*"))
    fegrow.build_molecule(sars_scaffold_chunk_sdf, linker_rccr, attachment_index)

test_add_linker_rgroup_first #

test_add_linker_rgroup_first()

:return:

Source code in fegrow/testing/test_general.py
180
181
182
183
184
185
186
187
188
189
def test_add_linker_rgroup_first():
    """
    :return:
    """
    # we can also link the linker and the R-group first
    # before merging them into the main structure
    linker_rccr = Chem.MolFromSmiles("*CC*")
    methyl = Chem.MolFromSmiles("CO*")
    prep = fegrow.build_molecule(linker_rccr, methyl)
    assert Chem.MolToSmiles(prep) == "*CCOC"

test_linker_c_first #

test_linker_c_first()

Mark the C as the first connecting point in the linker

:return:

Source code in fegrow/testing/test_general.py
192
193
194
195
196
197
198
199
200
201
202
def test_linker_c_first():
    """
    Mark the C as the first connecting point in the linker

    :return:
    """
    linker_rccr = Chem.MolFromSmiles("[*:0]CO[*:1]")

    carbon = Chem.MolFromSmiles("C*")
    cco = fegrow.build_molecule(linker_rccr, carbon)
    assert Chem.MolToSmiles(cco) == "CCO[*:1]"

test_linker_o_first #

test_linker_o_first()

Mark the O as the first connecting point in the linker

:return:

Source code in fegrow/testing/test_general.py
205
206
207
208
209
210
211
212
213
214
215
def test_linker_o_first():
    """
    Mark the O as the first connecting point in the linker

    :return:
    """
    linker_rccr = Chem.MolFromSmiles("[*:1]CO[*:0]")

    carbon = Chem.MolFromSmiles("C*")
    cco = fegrow.build_molecule(linker_rccr, carbon)
    assert Chem.MolToSmiles(cco) == "COC[*:1]"

test_add_a_linker_check_star #

test_add_a_linker_check_star(RLinkers, sars_scaffold_sdf)
  1. load the core
  2. load the linker
  3. add the linker to the core
  4. check if there is a danling R/ atom linker = R1 C R2, 1 C 2, Core-C-1,

:return:

Source code in fegrow/testing/test_general.py
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def test_add_a_linker_check_star(RLinkers, sars_scaffold_sdf):
    """
    1. load the core
    2. load the linker
    3. add the linker to the core
    4. check if there is a danling R/* atom
    linker = R1 C R2, *1 C *2, Core-C-*1,

    :return:
    """
    # Check if conformers are generated correctly.
    attachment_index = 40
    # Select a linker
    linker = RLinkers[RLinkers.Name == "R1NC(R2)=O"].Mol.values[0]
    template_with_linker = fegrow.build_molecule(
        sars_scaffold_sdf, linker, attachment_index
    )

    for atom in template_with_linker.GetAtoms():
        if atom.GetAtomicNum() == 0:
            assert len(atom.GetBonds()) == 1