Skip to content

Commit

Permalink
feat: Add npscore and depict tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kohulan committed Apr 20, 2023
1 parent 6e8a2e2 commit 14be128
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 4 deletions.
6 changes: 2 additions & 4 deletions app/modules/depict.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ def getCDKDepiction(smiles: str, molSize=(512, 512), rotate=0, unicolor=False):
Args:
smiles (string): SMILES string given by the user.
Returns:
imag (PIL): CDK Structure Depiction as a pillow image.
image (png): CDK Structure Depiction as a PNG image.
image (SVG): CDK Structure Depiction as a SVG image.
"""
cdk_base = "org.openscience.cdk"
StandardGenerator = JClass(
Expand Down Expand Up @@ -70,8 +69,7 @@ def getRDKitDepiction(smiles, molSize=(512, 512), rotate=0, kekulize=True):
Args:
smiles (string): SMILES string given by the user.
Returns:
imag (PIL): CDK Structure Depiction as a pillow image.
image (png): CDK Structure Depiction as a PNG image.
image (SVG): RDKit Structure Depiction as a SVG image.
"""
if any(char.isspace() for char in smiles):
smiles = smiles.replace(" ", "+")
Expand Down
71 changes: 71 additions & 0 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,80 @@
import pytest
import selfies as sf
from app.modules.depict import getRDKitDepiction, getCDKDepiction
from app.modules.npscorer import getNPScore
from STOUT import translate_forward, translate_reverse
from DECIMER import predict_SMILES


@pytest.fixture
def test_smiles():
return "CN1C=NC2=C1C(=O)N(C(=O)N2C)C"


def test_npscore(test_smiles):
expected_result = "-1.09"
actual_result = getNPScore(test_smiles)
assert expected_result == actual_result


# RDKit Depiction tests
def test_getRDKitDepiction(test_smiles):
svg = getRDKitDepiction(test_smiles)
assert isinstance(svg, str)
assert "svg" in svg
assert "Error" not in svg


def test_getRDKitDepiction_kekulize(test_smiles):
svg = getRDKitDepiction(test_smiles, kekulize=False)
assert isinstance(svg, str)
assert "svg" in svg
assert "Error" not in svg


def test_getRDKitDepiction_rotate(test_smiles):
svg = getRDKitDepiction(test_smiles, rotate=90)
assert isinstance(svg, str)
assert "svg" in svg
assert "Error" not in svg


def test_getRDKitDepiction_size(test_smiles):
svg = getRDKitDepiction(test_smiles, molSize=(512, 512))
assert isinstance(svg, str)
assert "svg" in svg
assert "Error" not in svg


# CDK depiction tests
def test_getCDKDepiction(test_smiles):
svg = getCDKDepiction(test_smiles)
assert isinstance(svg, str)
assert "svg" in svg
assert "Error" not in svg


def test_getCDKDepiction_unicolor(test_smiles):
svg = getCDKDepiction(test_smiles, unicolor=True)
assert isinstance(svg, str)
assert "svg" in svg
assert "Error" not in svg


def test_getCDKDepiction_rotate(test_smiles):
svg = getCDKDepiction(test_smiles, rotate=90)
assert isinstance(svg, str)
assert "svg" in svg
assert "Error" not in svg


def test_getCDKDepiction_size(test_smiles):
svg = getCDKDepiction(test_smiles, molSize=(512, 512))
assert isinstance(svg, str)
assert "svg" in svg
assert "Error" not in svg


def test_smilestoiupac():
smiles = "CN1C=NC2=C1C(=O)N(C(=O)N2C)C"
expected_result = "1,3,7-trimethylpurine-2,6-dione"
Expand Down

0 comments on commit 14be128

Please sign in to comment.