Skip to content
Snippets Groups Projects
Commit 011dac85 authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

add functions to generate InChi and InChiKey

part of #80


Former-commit-id: e53db3ee8f88b741ef33e30884f3cf57aff072cb
parent df7a69e9
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@ from django.test import TestCase
from openbabel import vectorUnsignedInt
from .models import Compound, CompoundTanimoto, create_tanimoto
from .utils import FingerPrinter, mol2smi, smi2mol
from .utils import FingerPrinter, mol2smi, smi2mol, smi2inchi, smi2inchikey
class MolSmiTestCase(TestCase):
"""
......@@ -22,6 +22,22 @@ class MolSmiTestCase(TestCase):
def test_smi2mol2smi(self):
self.assertTrue(re.compile(self.mol_str).match(smi2mol(self.smiles_str)))
class SmiInchi(TestCase):
"""
Test INCHI and INCHIKEY generation functions
"""
def setUp(self):
self.smiles_str = "CC(C)C(=O)C1=C(C(=C(C(=C1)C(=O)C2=CC=C(C=C2)OC3=CC=CC=C3)O)O)O"
self.inchi_str = "InChI=1S/C23H20O6/c1-13(2)19(24)17-12-18(22(27)23(28)21(17)26)20(25)14-8-10-16(11-9-14)29-15-6-4-3-5-7-15/h3-13,26-28H,1-2H3"
self.inchikey_str = "CVVQMBDTMYUWTR-UHFFFAOYSA-N"
def test_smi2inchi(self):
self.assertEqual(smi2inchi(self.smiles_str), self.inchi_str)
def test_smi2inchikey(self):
self.assertEqual(smi2inchikey(self.smiles_str), self.inchikey_str)
class FingerPrinterTestCase(TestCase):
......
......@@ -16,6 +16,24 @@ def smi2mol(smi_string):
pybel._operations['gen2D'].Do(m.OBMol)
return m.write(format='mol')
smi2inchi_conv = ob.OBConversion()
smi2inchi_conv.SetInAndOutFormats("smi", "inchi")
def smi2inchi(smi_string):
mol = ob.OBMol()
smi2inchi_conv.ReadString(mol, smi_string)
return smi2inchi_conv.WriteString(mol).strip()
smi2inchikey_conv = ob.OBConversion()
smi2inchikey_conv.SetInAndOutFormats("smi", "inchi")
smi2inchikey_conv.SetOptions("K",smi2inchikey_conv.OUTOPTIONS)
def smi2inchikey(smi_string):
mol = ob.OBMol()
smi2inchikey_conv.ReadString(mol, smi_string)
return smi2inchikey_conv.WriteString(mol).strip()
class FingerPrinter(object):
def __init__(self, name="FP4"):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment