def test_rdfp_3(data): fps = RDKitFP(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
def test_rdfp_4(data): fps = RDKitFP(n_jobs=1, input_type='any') with pytest.raises(ValueError): fps.transform(data['err_smis']) fps = RDKitFP(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])
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')
def test_rdfp_2(data): fps = RDKitFP(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
def test_rdfp_4(data): fps = RDKitFP(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
def test_rdfp_3(data): fps = RDKitFP(n_jobs=1, input_type='any') fps.transform(data['mols'] + data['smis'])
def test_rdfp_2(data): fps = RDKitFP(n_jobs=1, input_type='smiles') with pytest.raises(TypeError): fps.transform(data['mols']) fps.transform(data['smis'])
def test_rdfp_1(data): fps = RDKitFP(n_jobs=1) fps.transform(data['mols']) with pytest.raises(TypeError): fps.transform(data['smis'])