|
| 1 | +#!/usr/bin/env python |
| 2 | +# coding: utf-8 |
| 3 | +""" test script, creating articifial data and testing the TDs calculation for reactions |
| 4 | + only tests the combination and final outcome, not the individual functions |
| 5 | + 2024-02-22; DocMinus |
| 6 | +""" |
| 7 | + |
| 8 | +import pandas as pd |
| 9 | +import pytest |
| 10 | + |
| 11 | +from td_tools.rxntools import clean_smiles_multi, transform_descriptors |
| 12 | + |
| 13 | + |
| 14 | +def test_clean_smiles_multi_and_transform_descriptors(): |
| 15 | + dataset_size = 4 # number of compounds |
| 16 | + # we define some faulty/missing compounds, then the output table should have 3 rows less than the input table |
| 17 | + reactant1 = ["CCCN" for _ in range(dataset_size - 1)] |
| 18 | + reactant1.append("cc") # incorrect structure |
| 19 | + reactant1.append("CCO") |
| 20 | + reactant1.append("CCCl") |
| 21 | + reactant1.append("CCCl") |
| 22 | + total_dataset_size = len(reactant1) |
| 23 | + |
| 24 | + reactant2 = ["CCCCO" for _ in range(dataset_size)] |
| 25 | + reactant2.append("CC") |
| 26 | + reactant2.append("CCO") |
| 27 | + reactant2.append("CCBr") |
| 28 | + |
| 29 | + product = ["ClCC1=C(B)C(P)=CC(Br)=C1O" for _ in range(dataset_size)] |
| 30 | + product.append("cc") # incorrect structure |
| 31 | + product.append("") # missing structure |
| 32 | + product.append("CCI") |
| 33 | + |
| 34 | + """ a total of 3 rows faulty rows, from bottom of created table it would 2nd, 3rd and 4th last row.""" |
| 35 | + |
| 36 | + g0 = clean_smiles_multi(reactant1) |
| 37 | + g1 = clean_smiles_multi(reactant2) |
| 38 | + g2 = clean_smiles_multi(product) |
| 39 | + |
| 40 | + TD_numbers = transform_descriptors(g0, g1, g2) |
| 41 | + print(f"{TD_numbers.shape = }, {TD_numbers.shape[1] = }") |
| 42 | + |
| 43 | + final_table = pd.DataFrame({"Compound 1": g0, "Compound 2": g1, "Product": g2}) |
| 44 | + final_table = final_table[~((final_table.iloc[:, :3] == "").any(axis=1))] |
| 45 | + final_table = pd.concat([final_table, TD_numbers], axis=1, join="inner") |
| 46 | + |
| 47 | + # check if the final table is as expected (3 rows less than the input table) |
| 48 | + assert ( |
| 49 | + final_table.shape[0] == total_dataset_size - 3 |
| 50 | + ), "Number of rows in the final table is not as expected." |
| 51 | + |
| 52 | + # Check that the 2nd, 3rd, and 4th last rows have been removed |
| 53 | + removed_indices = [ |
| 54 | + total_dataset_size - 2, |
| 55 | + total_dataset_size - 3, |
| 56 | + total_dataset_size - 4, |
| 57 | + ] |
| 58 | + for index in removed_indices: |
| 59 | + assert ( |
| 60 | + index not in final_table.index |
| 61 | + ), f"Row {index} should have been removed but is still in the final table." |
0 commit comments