def test_cdk(self):
     from cinfony import cdk
     mol = cdk.readstring("smi", "CCC")
     desc = mol.calcdesc(cdk.descs[1:3])
     for d in desc:
         if desc[d] != desc[d]:
             desc[d] = '?'
     expectedDesc = {'ip': 0.0, 'weight': 44.062600320000001}
     self.assertEqual(desc,expectedDesc)
 def hide_test_cdk(self):
     from cinfony import cdk
     mol = cdk.readstring("smi", "CCC")
     desc = mol.calcdesc(cdk.descs[1:3])
     for d in desc:
         if desc[d] != desc[d]:
             desc[d] = '?'
     expectedDesc = {'ip': 0.0, 'weight': 44.062600320000001}
     self.assertEqual(desc,expectedDesc)
def getCdkDescResult(data,descList):
    """ Calculates the descriptors for the descList using cdk
        It expects an attribute containing smiles with a name defined in AZOrangeConfig.SMILESNAMES
        It returns a dataset with the same smiles input variable, and as many variables as the descriptors 
       returned by the toolkit
    """
    if "cdk" not in toolkitsEnabled:
        return None
    smilesName = getSMILESAttr(data)
    if not smilesName: return None

    myDescList = [desc.replace(cdkTag,"") for desc in descList if cdkTag in desc]
    if not myDescList: return None
    #Compute the results
    results = {}
    for ex in data:
        smile = str(ex[smilesName].value)
        mol = cdk.readstring("smi", smile)
        results[smile] = mol.calcdesc(myDescList)
    # Get all the different descriptor names returned by cdk
    varNames = []
    for res in results:
        for desc in results[res]:
            if desc not in varNames:
                varNames.append(desc)
    # Generate the dataset assuring the same order of examples
    resData = orange.ExampleTable(orange.Domain([data.domain[smilesName]] + [orange.FloatVariable(cdkTag+name) for name in varNames],0))
    for ex in data:
        newEx = orange.Example(resData.domain)
        smile = str(ex[smilesName].value)
        newEx[smilesName] =smile
        for desc in results[smile]:
            newEx[cdkTag+desc] = results[smile][desc]
        resData.append(newEx)

    return resData
def getCdkDescResult(data,descList):
    """ Calculates the descriptors for the descList using cdk
        It expects an attribute containing smiles with a name defined in AZOrangeConfig.SMILESNAMES
        It returns a dataset with the same smiles input variable, and as many variables as the descriptors 
       returned by the toolkit
    """
    if "cdk" not in toolkitsEnabled:
        return None
    smilesName = getSMILESAttr(data)
    if not smilesName: return None

    myDescList = [desc.replace(toolkitsDef["cdk"]["tag"],"") for desc in descList if toolkitsDef["cdk"]["tag"] in desc]
    if not myDescList: return None
    #Compute the results
    results = {}
    for ex in data:
        smile = str(ex[smilesName].value)
        mol = cdk.readstring("smi", smile)
        results[smile] = mol.calcdesc(myDescList)
    # Get all the different descriptor names returned by cdk
    varNames = []
    for res in results:
        for desc in results[res]:
            if desc not in varNames:
                varNames.append(desc)
    # Generate the dataset assuring the same order of examples
    resData = orange.ExampleTable(orange.Domain([data.domain[smilesName]] + [orange.FloatVariable(toolkitsDef["cdk"]["tag"]+name) for name in varNames],0))
    for ex in data:
        newEx = orange.Example(resData.domain)
        smile = str(ex[smilesName].value)
        newEx[smilesName] =smile
        for desc in results[smile]:
            newEx[toolkitsDef["cdk"]["tag"]+desc] = results[smile][desc]
        resData.append(newEx)

    return resData