Beispiel #1
0
    def from_reaction_template(cls, template_smarts):
        template = ReactionTemplate(template_smarts)
        _rdkit_config = rdkit_config(reaction_center=template.ReactingAtomsMN,
                                     reactant_or_product='reactant',
                                     IsSanitized=False,
                                     set_morgan_identifier=False)
        reaction = Graph.from_rdkit(template.reactants[0],
                                    _rdkit_config).to_networkx()
        for reactant in template.reactants[1:]:
            g = Graph.from_rdkit(reactant, _rdkit_config).to_networkx()
            reaction = nx.disjoint_union(reaction, g)

        _rdkit_config = rdkit_config(reaction_center=template.ReactingAtomsMN,
                                     reactant_or_product='product',
                                     IsSanitized=False,
                                     set_morgan_identifier=False)
        for product in template.products:
            g = Graph.from_rdkit(product, _rdkit_config).to_networkx()
            reaction = nx.disjoint_union(reaction, g)

        g = _from_networkx(cls, reaction)
        if g.nodes.to_pandas()['ReactingCenter'].max() <= 0:
            raise RuntimeError(f'No reacting atoms are found in reactants: '
                               f'{template_smarts}')
        if g.nodes.to_pandas()['ReactingCenter'].min() >= 0:
            raise RuntimeError(f'No reacting atoms are found in products: '
                               f'{template_smarts}')
        return g
Beispiel #2
0
from graphdot.kernel.marginalized.starting_probability import Uniform
from graphdot.microkernel import (Additive, Convolution as kConv, Constant as
                                  kC, KroneckerDelta as kDelta,
                                  SquareExponential as kSE)
from graphdot.model.gaussian_process import LowRankApproximateGPR

smiles = [
    'CC', 'CCC', 'CCCC', 'CCCCC', 'CCCCCC', 'CCCCCCC', 'CCCCCCCC', 'CCCCCCCCC',
    'CCCCCCCCCC', 'CCCCCCCCCCC', 'CCCCCCCCCCCC'
]
energy = [
    -719.05, -1014.16, -1309.27, -1604.29, -1899.33, -2194.35, -2489.38,
    -2784.41, -3079.44, -3374.47, -3669.50
]

graphs = list(map(lambda smi: Graph.from_rdkit(MolFromSmiles(smi)), smiles))
train_X = graphs[::2]
train_y = energy[::2]
test_X = graphs[1::2]
test_y = energy[1::2]
core = train_X[::2]

kernel = MarginalizedGraphKernel(
    node_kernel=Additive(
        aromatic=kC(0.5, (0.1, 1.0)) * kDelta(0.5, (0.1, 0.9)),
        atomic_number=kC(0.5, (0.1, 1.0)) * kDelta(0.8, (0.1, 0.9)),
        charge=kC(0.5, (0.1, 1.0)) * kSE(1.0),
        chiral=kC(0.5, (0.1, 1.0)) * kDelta(0.5, (0.1, 0.9)),
        hcount=kC(0.5, (0.1, 1.0)) * kSE(1.0),
        hybridization=kC(0.5, (0.1, 1.0)) * kDelta(0.5, (0.1, 0.9)),
        ring_list=kC(0.5, (0.01, 1.0)) * kConv(kDelta(0.5,