Search in sources :

Example 1 with IntegerArrayResult

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

the class AtomEnvironmentGeneratorTest method testAtomTypeMatrixDescriptor.

public void testAtomTypeMatrixDescriptor() throws Exception {
    FileWriter w = new FileWriter(new File("F:/nina/Ideaconsult/Proposals/2014-columndb/ae.txt"));
    AtomEnvironmentMatrixDescriptor gen = new AtomEnvironmentMatrixDescriptor();
    InputStream in = AtomEnvironmentGeneratorTest.class.getClassLoader().getResourceAsStream("ambit2/descriptors/3d/test.sdf");
    IIteratingChemObjectReader<IAtomContainer> reader = new IteratingSDFReader(new InputStreamReader(in), SilentChemObjectBuilder.getInstance());
    while (reader.hasNext()) {
        IAtomContainer mol = reader.next();
        AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
        // atom list - bug?
        try {
            if (hAdder == null)
                hAdder = CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance());
            hAdder.addImplicitHydrogens(mol);
        } catch (Exception x) {
        }
        CDKHueckelAromaticityDetector.detectAromaticity(mol);
        DescriptorValue value = gen.calculate(mol);
        System.out.println("Value");
        for (int i = 0; i < value.getNames().length; i++) {
            if (((IntegerArrayResult) value.getValue()).get(i) > 0) {
                System.out.println(value.getNames()[i] + " = " + ((IntegerArrayResult) value.getValue()).get(i));
            }
            String[] split = value.getNames()[i].split("_");
            w.append(String.format("%d\t%s\t%s\t%s\n", (i + 1), split[0].replace("L", ""), split[1], split.length < 3 ? "" : split[2]));
        }
        System.out.println("End Value");
        w.flush();
    }
    w.close();
    reader.close();
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) FileWriter(java.io.FileWriter) AtomEnvironmentMatrixDescriptor(ambit2.descriptors.AtomEnvironmentMatrixDescriptor) IntegerArrayResult(org.openscience.cdk.qsar.result.IntegerArrayResult) IteratingSDFReader(org.openscience.cdk.io.iterator.IteratingSDFReader) RawIteratingSDFReader(ambit2.core.io.RawIteratingSDFReader) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) File(java.io.File)

Example 2 with IntegerArrayResult

use of org.openscience.cdk.qsar.result.IntegerArrayResult 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 IntegerArrayResult

use of org.openscience.cdk.qsar.result.IntegerArrayResult 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 IntegerArrayResult

use of org.openscience.cdk.qsar.result.IntegerArrayResult 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 IntegerArrayResult

use of org.openscience.cdk.qsar.result.IntegerArrayResult 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

IntegerArrayResult (org.openscience.cdk.qsar.result.IntegerArrayResult)24 DescriptorValue (org.openscience.cdk.qsar.DescriptorValue)13 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)12 Test (org.junit.Test)10 IDescriptorResult (org.openscience.cdk.qsar.result.IDescriptorResult)6 SmilesParser (org.openscience.cdk.smiles.SmilesParser)6 CDKException (org.openscience.cdk.exception.CDKException)5 DoubleArrayResult (org.openscience.cdk.qsar.result.DoubleArrayResult)4 IntegerResult (org.openscience.cdk.qsar.result.IntegerResult)4 List (java.util.List)3 IBioPolymer (org.openscience.cdk.interfaces.IBioPolymer)3 BooleanResult (org.openscience.cdk.qsar.result.BooleanResult)3 DoubleResult (org.openscience.cdk.qsar.result.DoubleResult)3 VerboseDescriptorResult (ambit2.descriptors.VerboseDescriptorResult)2 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 IAtom (org.openscience.cdk.interfaces.IAtom)2 AbstractDescriptorResultType (ambit2.core.data.AbstractDescriptorResultType)1 ArrayResult (ambit2.core.data.ArrayResult)1 RawIteratingSDFReader (ambit2.core.io.RawIteratingSDFReader)1