Search in sources :

Example 1 with IDescriptorResult

use of org.openscience.cdk.qsar.result.IDescriptorResult in project MetFragRelaunched by ipb-halle.

the class LinearRetentionTimeModel method calculateXLogpValues.

/**
 * @param inchis
 * @return
 */
public Double[] calculateXLogpValues(java.util.ArrayList<String> inchis) {
    Double[] values = new Double[inchis.size()];
    if (this.xlogp == null)
        return values;
    try {
        for (int i = 0; i < inchis.size(); i++) {
            DescriptorValue value = null;
            boolean calculated = false;
            int trials = 0;
            while (!calculated) {
                try {
                    trials++;
                    value = this.xlogp.calculate(MoleculeFunctions.getAtomContainerFromInChI(inchis.get(i)));
                } catch (Exception e) {
                    if (trials == 10) {
                        break;
                    }
                    continue;
                }
                calculated = true;
            }
            if (value != null) {
                IDescriptorResult result = value.getValue();
                values[i] = Double.parseDouble(result.toString());
            } else
                values[i] = null;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return values;
}
Also used : IDescriptorResult(org.openscience.cdk.qsar.result.IDescriptorResult) CDKException(org.openscience.cdk.exception.CDKException) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue)

Example 2 with IDescriptorResult

use of org.openscience.cdk.qsar.result.IDescriptorResult in project ambit-mirror by ideaconsult.

the class FunctionalGroupDescriptorTest method calculate.

protected void calculate(List<FunctionalGroup> groups, boolean verbose, IAtomContainer m, int hits) throws Exception {
    d.setParameters(new Object[] { groups, verbose });
    m = hadder.process(m);
    DescriptorValue value = d.calculate(m);
    IDescriptorResult v = value.getValue();
    Assert.assertEquals(hits, value.getNames().length);
    Assert.assertTrue(v instanceof VerboseDescriptorResult);
    VerboseDescriptorResult verboseResult = (VerboseDescriptorResult) v;
    IDescriptorResult r = verboseResult.getResult();
    Assert.assertTrue(r instanceof IntegerArrayResult);
    Assert.assertEquals(hits, ((IntegerArrayResult) r).length());
    if (verbose) {
        Assert.assertTrue(verboseResult.getExplanation() instanceof List);
        Assert.assertTrue(((List) verboseResult.getExplanation()).get(0) instanceof IAtomContainer);
    }
}
Also used : IDescriptorResult(org.openscience.cdk.qsar.result.IDescriptorResult) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IntegerArrayResult(org.openscience.cdk.qsar.result.IntegerArrayResult) ArrayList(java.util.ArrayList) List(java.util.List) VerboseDescriptorResult(ambit2.descriptors.VerboseDescriptorResult) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue)

Example 3 with IDescriptorResult

use of org.openscience.cdk.qsar.result.IDescriptorResult in project ambit-mirror by ideaconsult.

the class DescriptorValue2Property method getValue.

public Object getValue(DescriptorValue descriptor, Property property, int propertyIndex) {
    if (descriptor.getException() != null) {
        Throwable x = descriptor.getException();
        while (x.getCause() != null) x = x.getCause();
        return x;
    }
    IDescriptorResult result = descriptor.getValue();
    Object value = Double.NaN;
    if (result instanceof VerboseDescriptorResult)
        result = ((VerboseDescriptorResult) result).getResult();
    if (result instanceof DoubleResult)
        value = ((DoubleResult) result).doubleValue();
    else if (result instanceof IntegerResult)
        value = ((IntegerResult) result).intValue();
    else if (result instanceof BooleanResult) {
        value = (((BooleanResult) result).booleanValue()) ? answer.YES.toString() : answer.NO.toString();
    } else if (result instanceof ArrayResult)
        value = ((ArrayResult) result).get(propertyIndex);
    else if (result instanceof IntegerArrayResult)
        value = ((IntegerArrayResult) result).get(propertyIndex);
    else if (result instanceof DoubleArrayResult)
        value = ((DoubleArrayResult) result).get(propertyIndex);
    else if (result instanceof AbstractDescriptorResultType)
        return ((AbstractDescriptorResultType) result).getValue();
    return value;
}
Also used : IDescriptorResult(org.openscience.cdk.qsar.result.IDescriptorResult) BooleanResult(org.openscience.cdk.qsar.result.BooleanResult) IntegerArrayResult(org.openscience.cdk.qsar.result.IntegerArrayResult) DoubleArrayResult(org.openscience.cdk.qsar.result.DoubleArrayResult) ArrayResult(ambit2.core.data.ArrayResult) IntegerArrayResult(org.openscience.cdk.qsar.result.IntegerArrayResult) DoubleArrayResult(org.openscience.cdk.qsar.result.DoubleArrayResult) DoubleResult(org.openscience.cdk.qsar.result.DoubleResult) AbstractDescriptorResultType(ambit2.core.data.AbstractDescriptorResultType) VerboseDescriptorResult(ambit2.descriptors.VerboseDescriptorResult) IntegerResult(org.openscience.cdk.qsar.result.IntegerResult)

Example 4 with IDescriptorResult

use of org.openscience.cdk.qsar.result.IDescriptorResult in project cdk by cdk.

the class AminoAcidCountDescriptorTest method testAACount.

@Test
public void testAACount() throws Exception {
    IBioPolymer protein = ProteinBuilderTool.createProtein("ARNDCFQEGHIPLKMSTYVW", SilentChemObjectBuilder.getInstance());
    IDescriptorResult result = descriptor.calculate(protein).getValue();
    Assert.assertTrue(result instanceof IntegerArrayResult);
    IntegerArrayResult iaResult = (IntegerArrayResult) result;
    for (int i = 0; i < iaResult.length(); i++) {
        // all AAs are found at least once
        Assert.assertTrue(iaResult.get(i) >= 1);
    }
    // glycine is in all of them, so 20 times
    Assert.assertEquals(20, iaResult.get(8));
}
Also used : IDescriptorResult(org.openscience.cdk.qsar.result.IDescriptorResult) IntegerArrayResult(org.openscience.cdk.qsar.result.IntegerArrayResult) IBioPolymer(org.openscience.cdk.interfaces.IBioPolymer) Test(org.junit.Test)

Example 5 with IDescriptorResult

use of org.openscience.cdk.qsar.result.IDescriptorResult in project cdk by cdk.

the class AminoAcidCountDescriptorTest method testTCount.

@Test
public void testTCount() throws Exception {
    IBioPolymer protein = ProteinBuilderTool.createProtein("TT", SilentChemObjectBuilder.getInstance());
    IDescriptorResult result = descriptor.calculate(protein).getValue();
    Assert.assertTrue(result instanceof IntegerArrayResult);
    IntegerArrayResult iaResult = (IntegerArrayResult) result;
    Assert.assertEquals(2, iaResult.get(8));
    Assert.assertEquals(2, iaResult.get(16));
}
Also used : IDescriptorResult(org.openscience.cdk.qsar.result.IDescriptorResult) IntegerArrayResult(org.openscience.cdk.qsar.result.IntegerArrayResult) IBioPolymer(org.openscience.cdk.interfaces.IBioPolymer) Test(org.junit.Test)

Aggregations

IDescriptorResult (org.openscience.cdk.qsar.result.IDescriptorResult)42 Test (org.junit.Test)29 DescriptorValue (org.openscience.cdk.qsar.DescriptorValue)28 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)24 IAtom (org.openscience.cdk.interfaces.IAtom)14 DoubleArrayResult (org.openscience.cdk.qsar.result.DoubleArrayResult)12 DoubleResult (org.openscience.cdk.qsar.result.DoubleResult)12 DescriptorTest (org.openscience.cdk.test.qsar.DescriptorTest)7 Atom (org.openscience.cdk.Atom)6 IChemObjectBuilder (org.openscience.cdk.interfaces.IChemObjectBuilder)6 IntegerArrayResult (org.openscience.cdk.qsar.result.IntegerArrayResult)6 InputStream (java.io.InputStream)5 AtomContainer (org.openscience.cdk.AtomContainer)5 ChemFile (org.openscience.cdk.ChemFile)5 ChemObject (org.openscience.cdk.ChemObject)5 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)5 IChemModel (org.openscience.cdk.interfaces.IChemModel)5 IChemSequence (org.openscience.cdk.interfaces.IChemSequence)5 MDLV2000Reader (org.openscience.cdk.io.MDLV2000Reader)5 CDKException (org.openscience.cdk.exception.CDKException)4