Esempio n. 1
0
def test__backbone_isomorphic():
    """ test graph.backbone_isomorphic
    """
    assert graph.backbone_isomorphic(CH2FH2H_CGR_IMP, CH2FH2H_CGR_EXP)

    cgr = C8H13O_CGR
    natms = len(graph.atoms(cgr))
    for _ in range(10):
        pmt_dct = dict(enumerate(numpy.random.permutation(natms)))
        cgr_pmt = graph.relabel(cgr, pmt_dct)
        assert graph.backbone_isomorphic(cgr, cgr_pmt)
Esempio n. 2
0
def test__trans__hydrogen_abstraction():
    """ test graph.trans.hydrogen_abstraction
    """
    cgr1 = ({
        0: ('C', 3, None),
        1: ('C', 3, None),
        2: ('C', 1, None),
        3: ('C', 2, None),
        4: ('C', 1, None),
        5: ('C', 2, None),
        6: ('C', 2, None),
        7: ('O', 1, None)
    }, {
        frozenset({4, 6}): (1, None),
        frozenset({0, 2}): (1, None),
        frozenset({2, 4}): (1, None),
        frozenset({5, 6}): (1, None),
        frozenset({3, 5}): (1, None),
        frozenset({1, 3}): (1, None)
    })
    cgr2 = ({
        0: ('C', 2, None),
        1: ('C', 3, None),
        2: ('C', 1, None),
        3: ('C', 2, None),
        4: ('C', 1, None),
        5: ('C', 2, None),
        6: ('C', 2, None),
        7: ('O', 2, None)
    }, {
        frozenset({4, 6}): (1, None),
        frozenset({0, 2}): (1, None),
        frozenset({2, 4}): (1, None),
        frozenset({5, 6}): (1, None),
        frozenset({3, 5}): (1, None),
        frozenset({1, 3}): (1, None)
    })

    cgr1 = graph.explicit(cgr1)
    cgr2 = graph.explicit(cgr2)

    tra = graph.trans.hydrogen_abstraction(cgr1, cgr2)
    assert graph.backbone_isomorphic(graph.trans.apply(tra, cgr1), cgr2)

    tra = graph.trans.hydrogen_abstraction(cgr2, cgr1)
    assert graph.backbone_isomorphic(graph.trans.apply(tra, cgr2), cgr1)
Esempio n. 3
0
def test__trans__is_stereo_compatible():
    """ test graph.trans.is_stereo_compatible
    """
    cgr1 = ({
        0: ('C', 1, None),
        1: ('C', 1, None),
        2: ('C', 1, None),
        3: ('C', 1, None),
        4: ('F', 0, None),
        5: ('F', 0, None),
        6: ('O', 1, None)
    }, {
        frozenset({0, 1}): (1, None),
        frozenset({0, 2}): (1, None),
        frozenset({2, 4}): (1, None),
        frozenset({3, 5}): (1, None),
        frozenset({1, 3}): (1, None)
    })
    cgr2 = ({
        0: ('C', 1, None),
        1: ('C', 1, None),
        2: ('C', 1, None),
        3: ('C', 1, None),
        4: ('F', 0, None),
        5: ('F', 0, None),
        6: ('O', 1, None)
    }, {
        frozenset({0, 1}): (1, None),
        frozenset({0, 2}): (1, None),
        frozenset({3, 6}): (1, None),
        frozenset({2, 4}): (1, None),
        frozenset({3, 5}): (1, None),
        frozenset({1, 3}): (1, None)
    })

    cgr1 = graph.explicit(cgr1)
    cgr2 = graph.explicit(cgr2)

    ich1 = graph.inchi(cgr1)
    ich2 = graph.inchi(cgr2)
    smi1 = automol.inchi.smiles(ich1)
    smi2 = automol.inchi.smiles(ich2)
    print(smi1)
    print(smi2)

    cgr1s = graph.connected_components(cgr1)
    cgr2s = graph.connected_components(cgr2)
    tras, _, _ = graph.reac.addition(cgr1s, cgr2s)
    for tra in tras:
        assert graph.backbone_isomorphic(graph.trans.apply(tra, cgr1), cgr2)

        sgr1 = graph.stereomers(cgr1)[0]
        print(sgr1)
        for sgr2 in graph.stereomers(cgr2):
            print(sgr2)
            print(graph.trans.is_stereo_compatible(tra, sgr1, sgr2))
Esempio n. 4
0
def test__reac__beta_scission():
    """ test graph.reac.beta_scission
    """
    rct_cgr = ({
        0: ('C', 1, None),
        1: ('C', 1, None),
        2: ('C', 1, None),
        3: ('C', 1, None),
        4: ('F', 0, None),
        5: ('F', 0, None),
        6: ('O', 1, None)
    }, {
        frozenset({0, 1}): (1, None),
        frozenset({0, 2}): (1, None),
        frozenset({3, 6}): (1, None),
        frozenset({2, 4}): (1, None),
        frozenset({3, 5}): (1, None),
        frozenset({1, 3}): (1, None)
    })
    prd_cgr = ({
        0: ('C', 1, None),
        1: ('C', 1, None),
        2: ('C', 1, None),
        3: ('C', 1, None),
        4: ('F', 0, None),
        5: ('F', 0, None),
        6: ('O', 1, None)
    }, {
        frozenset({0, 1}): (1, None),
        frozenset({0, 2}): (1, None),
        frozenset({2, 4}): (1, None),
        frozenset({3, 5}): (1, None),
        frozenset({1, 3}): (1, None)
    })

    rct_cgr = graph.explicit(rct_cgr)
    prd_cgr = graph.explicit(prd_cgr)

    rct_cgrs = graph.connected_components(rct_cgr)
    prd_cgrs = graph.connected_components(prd_cgr)

    tras, rct_idxs, prd_idxs = graph.reac.beta_scission(rct_cgrs, prd_cgrs)
    assert tras
    assert rct_idxs
    assert prd_idxs

    print("beta scission")
    for tra in tras:
        print(tra)
        assert graph.backbone_isomorphic(graph.trans.apply(tra, rct_cgr),
                                         prd_cgr)
Esempio n. 5
0
def test__trans__addition():
    """ test graph.trans.addition
    """
    cgr1 = ({
        0: ('C', 1, None),
        1: ('C', 1, None),
        2: ('C', 1, None),
        3: ('C', 1, None),
        4: ('F', 0, None),
        5: ('F', 0, None),
        6: ('O', 1, None)
    }, {
        frozenset({0, 1}): (1, None),
        frozenset({0, 2}): (1, None),
        frozenset({2, 4}): (1, None),
        frozenset({3, 5}): (1, None),
        frozenset({1, 3}): (1, None)
    })
    cgr2 = ({
        0: ('C', 1, None),
        1: ('C', 1, None),
        2: ('C', 1, None),
        3: ('C', 1, None),
        4: ('F', 0, None),
        5: ('F', 0, None),
        6: ('O', 1, None)
    }, {
        frozenset({0, 1}): (1, None),
        frozenset({0, 2}): (1, None),
        frozenset({3, 6}): (1, None),
        frozenset({2, 4}): (1, None),
        frozenset({3, 5}): (1, None),
        frozenset({1, 3}): (1, None)
    })

    cgr1 = graph.explicit(cgr1)
    cgr2 = graph.explicit(cgr2)

    tra = graph.trans.addition(cgr1, cgr2)
    assert graph.backbone_isomorphic(graph.trans.apply(tra, cgr1), cgr2)
Esempio n. 6
0
def test__reac__substitution():
    """ test graph.reac.substitution
    """
    # CH3OOH + CH3 => CH3OCH3 + OH
    rct_cgr = ({
        0: ('C', 3, None),
        1: ('O', 1, None),
        2: ('O', 0, None),
        3: ('C', 3, None)
    }, {
        frozenset({0, 2}): (1, None),
        frozenset({1, 2}): (1, None)
    })
    prd_cgr = ({
        0: ('C', 3, None),
        1: ('C', 3, None),
        2: ('O', 0, None),
        3: ('O', 1, None)
    }, {
        frozenset({0, 2}): (1, None),
        frozenset({1, 2}): (1, None)
    })

    rct_cgr = graph.explicit(rct_cgr)
    prd_cgr = graph.explicit(prd_cgr)

    rct_cgrs = graph.connected_components(rct_cgr)
    prd_cgrs = graph.connected_components(prd_cgr)

    tras, rct_idxs, prd_idxs = graph.reac.substitution(rct_cgrs, prd_cgrs)
    assert tras
    assert rct_idxs
    assert prd_idxs

    print("substitution")
    for tra in tras:
        print(tra)
        assert graph.backbone_isomorphic(graph.trans.apply(tra, rct_cgr),
                                         prd_cgr)
Esempio n. 7
0
def test__reac__hydrogen_migration():
    """ test graph.reac.hydrogen_migration
    """
    # first test a radical site migration
    rct_cgr = ({
        0: ('C', 1, None),
        1: ('C', 1, None),
        2: ('C', 1, None),
        3: ('C', 1, None),
        4: ('C', 1, None),
        5: ('O', 0, None)
    }, {
        frozenset({3, 4}): (1, None),
        frozenset({2, 3}): (1, None),
        frozenset({1, 2}): (1, None),
        frozenset({4, 5}): (1, None),
        frozenset({0, 1}): (1, None)
    })

    prd_cgr = ({
        0: ('C', 2, None),
        1: ('C', 1, None),
        2: ('C', 1, None),
        3: ('C', 1, None),
        4: ('C', 0, None),
        5: ('O', 0, None)
    }, {
        frozenset({3, 4}): (1, None),
        frozenset({2, 3}): (1, None),
        frozenset({1, 2}): (1, None),
        frozenset({4, 5}): (1, None),
        frozenset({0, 1}): (1, None)
    })

    rct_cgr = graph.explicit(rct_cgr)
    prd_cgr = graph.explicit(prd_cgr)

    rct_cgrs = graph.connected_components(rct_cgr)
    prd_cgrs = graph.connected_components(prd_cgr)

    tras, rct_idxs, prd_idxs = graph.reac.hydrogen_migration(
        rct_cgrs, prd_cgrs)
    assert tras
    assert rct_idxs
    assert prd_idxs

    print("hydrogen migration")
    rct_cgr = graph.union_from_sequence(rct_cgrs)
    prd_cgr = graph.union_from_sequence(prd_cgrs)
    for tra in tras:
        print(tra)
        assert graph.backbone_isomorphic(graph.trans.apply(tra, rct_cgr),
                                         prd_cgr)

    tras, rct_idxs, prd_idxs = graph.reac.hydrogen_migration(
        prd_cgrs, rct_cgrs)
    assert tras
    assert rct_idxs
    assert prd_idxs

    # then test a tautomerization
    rct_cgr = ({
        0: ('C', 2, None),
        1: ('C', 1, None),
        2: ('O', 1, None)
    }, {
        frozenset({0, 1}): (1, None),
        frozenset({1, 2}): (1, None)
    })

    prd_cgr = ({
        0: ('C', 3, None),
        1: ('C', 1, None),
        2: ('O', 0, None)
    }, {
        frozenset({0, 1}): (1, None),
        frozenset({1, 2}): (1, None)
    })

    rct_cgr = graph.explicit(rct_cgr)
    prd_cgr = graph.explicit(prd_cgr)

    rct_cgrs = graph.connected_components(rct_cgr)
    prd_cgrs = graph.connected_components(prd_cgr)

    tras, rct_idxs, prd_idxs = graph.reac.hydrogen_migration(
        rct_cgrs, prd_cgrs)
    assert tras
    assert rct_idxs
    assert prd_idxs

    for tra in tras:
        print(tra)
        assert graph.backbone_isomorphic(graph.trans.apply(tra, rct_cgr),
                                         prd_cgr)

    tras, rct_idxs, prd_idxs = graph.reac.hydrogen_migration(
        prd_cgrs, rct_cgrs)
    assert tras
    assert rct_idxs
    assert prd_idxs
Esempio n. 8
0
def test__reac__insertion():
    """ test graph.reac.insertion
    """
    # CH2CH2 + HOO => CH3CH3OO
    rct_cgr = ({
        0: ('C', 2, None),
        1: ('C', 2, None),
        2: ('O', 1, None),
        3: ('O', 0, None)
    }, {
        frozenset({0, 1}): (1, None),
        frozenset({2, 3}): (1, None)
    })
    prd_cgr = ({
        0: ('C', 3, None),
        1: ('C', 2, None),
        2: ('O', 0, None),
        3: ('O', 0, None)
    }, {
        frozenset({0, 1}): (1, None),
        frozenset({1, 3}): (1, None),
        frozenset({2, 3}): (1, None)
    })

    rct_cgr = graph.explicit(rct_cgr)
    prd_cgr = graph.explicit(prd_cgr)

    rct_cgrs = graph.connected_components(rct_cgr)
    prd_cgrs = graph.connected_components(prd_cgr)

    tras, rct_idxs, prd_idxs = graph.reac.insertion(rct_cgrs, prd_cgrs)
    assert tras
    assert rct_idxs
    assert prd_idxs

    print("insertion")
    for tra in tras:
        print(tra)
        assert graph.backbone_isomorphic(graph.trans.apply(tra, rct_cgr),
                                         prd_cgr)

    # CH3CH3 + :C=O => CH3C(=O)CH3 (CO insertion)
    rct_cgr = ({
        0: ('C', 3, None),
        1: ('C', 3, None),
        2: ('C', 0, None),
        3: ('O', 0, None)
    }, {
        frozenset({0, 1}): (1, None),
        frozenset({2, 3}): (1, None)
    })
    prd_cgr = ({
        0: ('C', 3, None),
        1: ('C', 3, None),
        2: ('C', 0, None),
        3: ('O', 0, None)
    }, {
        frozenset({0, 2}): (1, None),
        frozenset({2, 3}): (1, None),
        frozenset({1, 2}): (1, None)
    })

    rct_cgr = graph.explicit(rct_cgr)
    prd_cgr = graph.explicit(prd_cgr)

    rct_cgrs = graph.connected_components(rct_cgr)
    prd_cgrs = graph.connected_components(prd_cgr)

    tras, rct_idxs, prd_idxs = graph.reac.insertion(rct_cgrs, prd_cgrs)
    assert tras
    assert rct_idxs
    assert prd_idxs

    for tra in tras:
        print(tra)
        assert graph.backbone_isomorphic(graph.trans.apply(tra, rct_cgr),
                                         prd_cgr)

    # CH3CH3 + O=C=O => CH3C(=O)OCH3 (CO2 insertion)
    rct_cgr = ({
        0: ('C', 3, None),
        1: ('C', 3, None),
        2: ('C', 0, None),
        3: ('O', 0, None),
        4: ('O', 0, None)
    }, {
        frozenset({0, 1}): (1, None),
        frozenset({2, 3}): (1, None),
        frozenset({2, 4}): (1, None)
    })
    prd_cgr = ({
        0: ('C', 3, None),
        1: ('C', 3, None),
        2: ('C', 0, None),
        3: ('O', 0, None),
        4: ('O', 0, None)
    }, {
        frozenset({0, 2}): (1, None),
        frozenset({1, 4}): (1, None),
        frozenset({2, 3}): (1, None),
        frozenset({2, 4}): (1, None)
    })

    rct_cgr = graph.explicit(rct_cgr)
    prd_cgr = graph.explicit(prd_cgr)

    rct_cgrs = graph.connected_components(rct_cgr)
    prd_cgrs = graph.connected_components(prd_cgr)

    tras, rct_idxs, prd_idxs = graph.reac.insertion(rct_cgrs, prd_cgrs)
    assert tras
    assert rct_idxs
    assert prd_idxs

    for tra in tras:
        print(tra)
        assert graph.backbone_isomorphic(graph.trans.apply(tra, rct_cgr),
                                         prd_cgr)
Esempio n. 9
0
def test__reac__hydrogen_abstraction():
    """ test graph.reac.hydrogen_abstraction
    """
    rct_cgr = ({
        0: ('C', 3, None),
        1: ('C', 3, None),
        2: ('C', 1, None),
        3: ('C', 2, None),
        4: ('C', 1, None),
        5: ('C', 2, None),
        6: ('C', 2, None),
        7: ('O', 1, None)
    }, {
        frozenset({4, 6}): (1, None),
        frozenset({0, 2}): (1, None),
        frozenset({2, 4}): (1, None),
        frozenset({5, 6}): (1, None),
        frozenset({3, 5}): (1, None),
        frozenset({1, 3}): (1, None)
    })
    prd_cgr = ({
        0: ('C', 2, None),
        1: ('C', 3, None),
        2: ('C', 1, None),
        3: ('C', 2, None),
        4: ('C', 1, None),
        5: ('C', 2, None),
        6: ('C', 2, None),
        7: ('O', 2, None)
    }, {
        frozenset({4, 6}): (1, None),
        frozenset({0, 2}): (1, None),
        frozenset({2, 4}): (1, None),
        frozenset({5, 6}): (1, None),
        frozenset({3, 5}): (1, None),
        frozenset({1, 3}): (1, None)
    })

    rct_cgr = graph.explicit(rct_cgr)
    prd_cgr = graph.explicit(prd_cgr)

    rct_cgrs = graph.connected_components(rct_cgr)
    prd_cgrs = graph.connected_components(prd_cgr)

    tras, rct_idxs, prd_idxs = graph.reac.hydrogen_abstraction(
        rct_cgrs, prd_cgrs)
    assert tras
    assert rct_idxs
    assert prd_idxs

    print("hydrogen abstraction")
    rct_cgr = graph.union_from_sequence(rct_cgrs)
    print(rct_cgr)
    for tra in tras:
        print(tra)
        assert graph.backbone_isomorphic(graph.trans.apply(tra, rct_cgr),
                                         prd_cgr)

    tras, prd_idxs, rct_idxs = graph.reac.hydrogen_abstraction(
        prd_cgrs, rct_cgrs)
    assert tras
    assert rct_idxs
    assert prd_idxs

    for tra in tras:
        print(tra)
        assert graph.backbone_isomorphic(graph.trans.apply(tra, prd_cgr),
                                         rct_cgr)