def test_handle_charge():
    tsf = Transformation(
        "[#6:1]-[#7&+:2](-[#6:3])(-[#6])-[#6:4]-[#6:5](=[#8:6])-[#8&-:7]>>[#6:1]-[#7:2](-[#6:3])-[#6:4]-[#6:5](=[#8:6])-[#8:7]"
    )
    assert tsf.mass_delta < 0
    assert [simp.smarts
            for simp in tsf.simplify()] == ["[#7&+:1]-[#6]>>[#7:1]"]
def test_reverse():
    tsf = Transformation(
        "[#6:1]1:[#6:2]:[#6:4]:[#6:6](-[#8:7]-[#1:8]):[#6:5]:[#6:3]:1>>[#6:8]-[#8:7]-[#6:6]1:[#6:4]:[#6:2]:[#6:1]:[#6:3]:[#6:5]:1"
    )
    tsf.reverse()
    assert (
        tsf.smarts ==
        "[#6:8]-[#8:7]-[#6:6]1:[#6:4]:[#6:2]:[#6:1]:[#6:3]:[#6:5]:1>>[#6:1]1:[#6:2]:[#6:4]:[#6:6](-[#8:7]-[#1:8]):[#6:5]:[#6:3]:1"
    )
def test__reindex_mapping():
    tsf = Transformation(
        "[#6:11]-[#8:10]-[#6:9]1:[#6:7]:[#6:5]:[#6:4]:[#6:6]:[#6:8]:1>>[#6:4]1:[#6:5]:[#6:7]:[#6:9](-[#8:10]-[#1:11]):[#6:8]:[#6:6]:1"
    )
    tsf._reindex_mapping()
    assert (
        tsf.smarts ==
        "[#6:8]-[#8:7]-[#6:6]1:[#6:4]:[#6:2]:[#6:1]:[#6:3]:[#6:5]:1>>[#6:1]1:[#6:2]:[#6:4]:[#6:6](-[#8:7]-[#1:8]):[#6:5]:[#6:3]:1"
    )
def test_from_metwork_v0():
    tsf = Transformation.from_metwork_v0(
        "[#6:1](=,:[#8:2])(-[#6:3])-[#6:4]>>[#6:4]-[#6:1](-[#8:2]-[H])(-[H])-[#6:3]"
    )
    assert (tsf.smarts ==
            "[#6:1](=[#8:2])(-[#6:3])-[#6:4]>>[#6:3]-[#6:1](-[#8:2])-[#6:4]")
    tsf = Transformation.from_metwork_v0(
        "[#6:1](-[#7:2]-[H:3])-[#6:4]-[#6:5]>>[#7:2](-[#6:3]1-[#6](-[#6](-[#6](-[#6](-[#8]-1)-[#6](=,:[#8])-[#8])-[#8])-[#8])-[#8])-[#6:1]-[#6:4]-[#6:5]"
    )
    assert (
        tsf.smarts ==
        "[#6:3](-[#7:1]-[#1:2])-[#6:4]-[#6:5]>>[#7:1](-[#6:2]1(-[#6](-[#6](-[#6](-[#6](-[#8]-1)-[#6](=[#8])-[#8])-[#8])-[#8])-[#8])-[H])-[#6:3]-[#6:4]-[#6:5]"
    )
def test_run():
    tsf = Transformation.from_smiles("N1C=CC2=C1C=CC=C2",
                                     "OC1=CC2=C(NC=C2)C=C1")
    products = tsf.run("N1C=CC2=C1C=CC=C2")
    assert [p.smiles for p in products] == ["Oc1ccc2c(c1)C=CN2"]

    tsf = Transformation.from_smiles("N1C=CC2=C1C=CC=C2",
                                     "OC1=CC2=C(NC=C2)C=C1")
    products = tsf.run("N1C=CC2=C1C=CC=C2")
    assert [p.smiles for p in products] == ["Oc1ccc2c(c1)C=CN2"]

    tsf = Transformation.from_smiles("OC1=CC=CC=C1", "OC1=CC=CC=C1Br")
    products = tsf.run("CCC1=CC=CC=C1O")
    assert [p.smiles for p in products] == ["CCc1cccc(Br)c1O"]
    products = tsf.run("CCC1=CC=CC(CC)=C1O")
    assert not products
def test_preserve_explicit_H():
    tsf = Transformation.from_smiles("[H]C([H])([H])OC1=CC=CC=C1",
                                     "OC1=CC=CC=C1")
    assert (
        tsf.smarts ==
        "[#1]-[#6:3](-[#1])(-[#1])-[#8:1]-[#6:2]1:[#6:4]:[#6:6]:[#6:8]:[#6:7]:[#6:5]:1>>[#8:1](-[#6:2]1:[#6:4]:[#6:6]:[#6:8]:[#6:7]:[#6:5]:1)-[#1:3]"
    )
def test_simplify():
    tsf = Transformation.from_smiles(
        "OCC1OC(Oc2cc(O)c3c(occc3=O)c2O)C(O)C(O)C1O",
        "CC(=O)OCC1OC(Oc2cc(O)c3c(occc3=O)c2O)C(O)C(O)C1O",
    )
    assert (tsf.simplify()[0].smarts ==
            "[#8:1](-[#6:2])-[#1:3]>>[#6]-[#6:3](=[#8])-[#8:1]-[#6:2]")
def test_from_smarts():
    tsf = Transformation(SMARTS)
    assert tsf.smarts == SMARTS
    smarts = SmartsGenerator(
        "[#8]-[#6]1:[#6]:[#6]:[#6]:[#6]:[#6]:1",
        "[#8]-[#6]1:[#6]:[#6]:[#6]:[#6]:[#6]:1-[#35]",
    )
    assert smarts == SMARTS
Exemple #9
0
async def smiles_from_smarts(
    smarts: str = Body(
        ...,
        embed=True,
        example="[#8:1]-[#6:2]1:[#6:3]>>[#8:1]-[#6:2]1:[#6:3]",
    ),
):
    transformation = Transformation(smarts)
    smiles = [transformation.reactant.smiles, transformation.product.smiles]

    return smiles
Exemple #10
0
async def transformations_from_smiles(
    smiles: List[str] = Body(..., example=["CCO", "CCOC"]),
    reverse: bool = Body(False, example=["CCO", "CCOC"]),
    params: SimplifierParams = Body(BaseModel(), example=SimplifierParams()),
):
    result = []
    transformation = Transformation.from_smiles(*smiles)
    simplified = transformation.simplify(**params.dict())
    idx = 0
    for tsf in simplified:
        result.append(gen_tsf_data(idx, tsf))
        idx += 1
        if reverse:
            tsf.reverse()
            result.append(gen_tsf_data(idx, tsf))
            idx += 1
    return result
def test_simplify_keep_conjugated(conjugated, smarts):
    smiles = [r"CC\C=C\C1=CC(O)=CC=C1", r"CC\C=C\C1=CC(OC)=CC=C1"]
    tsf = Transformation.from_smiles(*smiles)
    simp = tsf.simplify(conjugated=conjugated)[0]
    assert simp.smarts == smarts
def test_simplify_keep_bond_diff(smarts_metwork, smarts_simplified):
    tsf = Transformation.from_metwork_v0(smarts_metwork)
    assert tsf.simplify()[0].smarts == smarts_simplified
def test_simplify_keep_aromatization(smiles_set, smarts_simplified):
    tsf = Transformation.from_smiles(*smiles_set)
    assert tsf.simplify()[0].smarts == smarts_simplified
def test_from_smiles():
    tsf = Transformation.from_smiles("OC1=CC=CC=C1", "OC1=CC=CC=C1Br")
    assert tsf.smarts == SMARTS
def test_simplify_keep_cycles(smarts_metwork, smarts_simplified):
    tsf = Transformation.from_metwork_v0(smarts_metwork)
    assert tsf.simplify(cycles=True)[0].smarts == smarts_simplified
def test_repr_svg():
    tsf = Transformation(SMARTS)
    assert tsf._repr_svg_() is None
def test_repr_png(shared_datadir):
    tsf = Transformation(SMARTS)
    assert (shared_datadir / "tsf.png").read_bytes() == tsf._repr_png_()
def test_rdkit():
    tsf = Transformation(SMARTS)
    assert AllChem.ReactionToSmarts(tsf.rdkit) == AllChem.ReactionToSmarts(
        AllChem.ReactionFromSmarts(SMARTS))
def test_simplify_to_many_transformations(smiles_set, smarts_simplified):
    tsf = Transformation.from_smiles(*smiles_set)
    assert set([simp.smarts
                for simp in tsf.simplify()]) == set(smarts_simplified)
def test_simplify_keep_hetero_atoms(hetero_atoms, smarts):
    smiles = [r"OCO", r"COCO"]
    tsf = Transformation.from_smiles(*smiles)
    simp = tsf.simplify(hetero_atoms=hetero_atoms)[0]
    assert simp.smarts == smarts