コード例 #1
0
def test_ecfp_3(data):
    fps = ECFP(n_jobs=1, input_type='any')
    try:
        fps.transform(data['mols'] + data['smis'])
    except BaseException as e:
        print(e)
        assert False, 'should not got error'
    else:
        assert True
コード例 #2
0
ファイル: test_fingerprint.py プロジェクト: yanhejin/XenonPy
def test_ecfp_4(data):
    fps = ECFP(n_jobs=1, input_type='any')
    with pytest.raises(ValueError):
        fps.transform(data['err_smis'])

    fps = ECFP(n_jobs=1, input_type='any', on_errors='nan')
    ret = fps.transform(data['err_smis'])
    assert pd.DataFrame(data=ret).shape == (4, 2048)
    assert np.isnan(ret[1][10])
    assert np.isnan(ret[2][20])
コード例 #3
0
def test_iqspr_1(data):
    np.random.seed(0)
    ecfp = ECFP(n_jobs=1, input_type='smiles')
    bre = BayesianRidgeEstimator(descriptor=ecfp)
    ngram = NGram()
    iqspr = IQSPR(estimator=bre, modifier=ngram)
    X, y = data['pg']
    bre.fit(X, y)
    ngram.fit(data['pg'][0][0:20], train_order=10)
    beta = np.linspace(0.05, 1, 10)
    for s, ll, p, f in iqspr(data['pg'][0][:5], beta, yield_lpf=True, bandgap=(0.1, 0.2), density=(0.9, 1.2)):
        assert np.abs(np.sum(p) - 1.0) < 1e-5
        assert np.sum(f) == 5, print(f)
コード例 #4
0
ファイル: test_iqspr.py プロジェクト: yoshida-lab/XenonPy
def data():
    # ignore numpy warning
    import warnings
    print('ignore NumPy RuntimeWarning\n')
    warnings.filterwarnings("ignore", message="numpy.dtype size changed")
    warnings.filterwarnings("ignore", message="numpy.ndarray size changed")

    pwd = Path(__file__).parent
    pg_data = pd.read_csv(str(pwd / 'polymer_test_data.csv'))

    X = pg_data['smiles']
    y = pg_data.drop(['smiles', 'Unnamed: 0'], axis=1)
    ecfp = ECFP(n_jobs=1, input_type='smiles', target_col=0)
    rdkitfp = RDKitFP(n_jobs=1, input_type='smiles', target_col=0)
    bre = GaussianLogLikelihood(descriptor=ecfp)
    bre2 = GaussianLogLikelihood(descriptor=rdkitfp)
    bre.fit(X, y[['bandgap', 'glass_transition_temperature']])
    bre2.fit(X, y[['density', 'refractive_index']])
    bre.update_targets(bandgap=(1, 2), glass_transition_temperature=(200, 300))
    bre2.update_targets(refractive_index=(2, 3), density=(0.9, 1.2))

    class MyLogLikelihood(BaseLogLikelihoodSet):
        def __init__(self):
            super().__init__()

            self.loglike = bre
            self.loglike = bre2

    like_mdl = MyLogLikelihood()
    ngram = NGram()
    ngram.fit(X[0:20], train_order=5)
    iqspr = IQSPR(estimator=bre, modifier=ngram)
    # prepare test data
    yield dict(ecfp=ecfp,
               rdkitfp=rdkitfp,
               bre=bre,
               bre2=bre2,
               like_mdl=like_mdl,
               ngram=ngram,
               iqspr=iqspr,
               pg=(X, y))

    print('test over')
コード例 #5
0
def test_fps_4(data):
    fps = Fingerprints(n_jobs=1, input_type='any')
    try:
        fps.transform(data['err_smis'])
    except ValueError:
        assert True
    else:
        assert False, 'should not got error'

    fps = ECFP(n_jobs=1, input_type='any', on_errors='nan')
    try:
        ret = fps.transform(data['err_smis'])
        assert pd.DataFrame(data=ret).shape == (4, 2048)
        assert np.isnan(ret[1][10])
        assert np.isnan(ret[2][20])
    except:
        assert False
    else:
        assert True
コード例 #6
0
def data():
    # ignore numpy warning
    import warnings
    print('ignore NumPy RuntimeWarning\n')
    warnings.filterwarnings("ignore", message="numpy.dtype size changed")
    warnings.filterwarnings("ignore", message="numpy.ndarray size changed")

    pwd = Path(__file__).parent
    pg_data = pd.read_csv(str(pwd / 'polymer_test_data.csv'))

    X = pg_data['smiles']
    y = pg_data.drop(['smiles', 'Unnamed: 0'], axis=1)
    ecfp = ECFP(n_jobs=1, input_type='smiles')
    bre = BayesianRidgeEstimator(descriptor=ecfp)
    ngram = NGram()
    iqspr = IQSPR(estimator=bre, modifier=ngram)
    # prepare test data
    yield dict(ecfp=ecfp, bre=bre, ngram=ngram, iqspr=iqspr, pg=(X, y))

    print('test over')
コード例 #7
0
def test_ecfp_2(data):
    fps = ECFP(n_jobs=1, input_type='smiles')
    try:
        fps.transform(data['mols'])
    except TypeError:
        assert True
    else:
        assert False, 'should not got error'

    try:
        fps.transform(data['smis'])
    except:
        assert False, 'should not got error'
    else:
        assert True
コード例 #8
0
def test_ecfp_1(data):
    fps = ECFP(n_jobs=1)

    try:
        fps.transform(data['mols'])
    except:
        assert False, 'should not got error'
    else:
        assert True

    try:
        fps.transform(data['smis'])
    except TypeError:
        assert True
    else:
        assert False, 'should not got error'
コード例 #9
0
ファイル: test_fingerprint.py プロジェクト: yanhejin/XenonPy
def test_ecfp_3(data):
    fps = ECFP(n_jobs=1, input_type='any')
    fps.transform(data['mols'] + data['smis'])
コード例 #10
0
ファイル: test_fingerprint.py プロジェクト: yanhejin/XenonPy
def test_ecfp_2(data):
    fps = ECFP(n_jobs=1, input_type='smiles')
    with pytest.raises(TypeError):
        fps.transform(data['mols'])

    fps.transform(data['smis'])
コード例 #11
0
ファイル: test_fingerprint.py プロジェクト: yanhejin/XenonPy
def test_ecfp_1(data):
    fps = ECFP(n_jobs=1)
    fps.transform(data['mols'])

    with pytest.raises(TypeError):
        fps.transform(data['smis'])
コード例 #12
0
    def __init__(self, n_jobs=-1):
        super().__init__()
        self.n_jobs = n_jobs

        self.rdkit_fp = ECFP(n_jobs, on_errors='nan', input_type='smiles')
        self.rdkit_fp = MACCS(n_jobs, on_errors='nan', input_type='smiles')