Search in sources :

Example 1 with IntegerResult

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

the class QuerySMARTS method calculateMetric.

@Override
public double calculateMetric(IStructureRecord object) {
    try {
        if (getValue() != null) {
            getValue().setVerboseMatch(false);
            IAtomContainer mol = reader.process(object);
            // empty or markush
            if ((mol == null) || (mol.getAtomCount() == 0) || (mol instanceof SuppleAtomContainer))
                return 0;
            if (hAdder == null)
                hAdder = CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance());
            boolean detectAromaticity = true;
            if ("true".equals(Preferences.getProperty(Preferences.FASTSMARTS)) && isUsePrecalculatedAtomProperties()) {
                Object smartsdata = object.getRecordProperty(smartsProperty);
                if (smartsdata != null) {
                    mol.setProperty(smartsProperty, smartsdata);
                    detectAromaticity = false;
                } else {
                    mol.removeProperty(smartsProperty);
                }
            } else {
                mol.removeProperty(smartsProperty);
            }
            mol = configurator.process(mol);
            switch(object.getType()) {
                case D1:
                    {
                        hAdder.addImplicitHydrogens(mol);
                        break;
                    }
                case D2noH:
                    {
                        hAdder.addImplicitHydrogens(mol);
                        break;
                    }
                case D3noH:
                    {
                        hAdder.addImplicitHydrogens(mol);
                        break;
                    }
            }
            if (detectAromaticity) {
                CDKHueckelAromaticityDetector.detectAromaticity(mol);
            }
            int aromatic = 0;
            VerboseDescriptorResult<String, IntegerResult> result = getValue().process(mol);
            return result.getResult().intValue();
        } else
            return 0;
    } catch (Exception x) {
        return -1;
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) SuppleAtomContainer(ambit2.core.groups.SuppleAtomContainer) SmartsToChemObject(ambit2.smarts.SmartsToChemObject) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) IntegerResult(org.openscience.cdk.qsar.result.IntegerResult)

Example 2 with IntegerResult

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

the class FunctionalGroup method process.

public VerboseDescriptorResult process(IAtomContainer target) throws AmbitException {
    if (query == null)
        query = SmartsPatternFactory.createSmartsPattern(SmartsPatternFactory.SmartsParser.smarts_nk, getSmarts(), false);
    int hits = 0;
    IAtomContainer match = null;
    if (isVerboseMatch())
        try {
            match = query.getMatchingStructure(target);
            hits = (match.getAtomCount() > 0) ? 1 : 0;
            return new VerboseDescriptorResult<IAtomContainer, IntegerResult>(new IntegerResult(hits), match);
        } catch (UnsupportedOperationException x) {
            hits = query.match(target);
            return new VerboseDescriptorResult<String, IntegerResult>(new IntegerResult(hits), null);
        } catch (SMARTSException x) {
            match = null;
            hits = 0;
            return new VerboseDescriptorResult<String, IntegerResult>(new IntegerResult(hits), x.getMessage());
        }
    else {
        hits = query.match(target);
        return new VerboseDescriptorResult<String, IntegerResult>(new IntegerResult(hits), null);
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) SMARTSException(ambit2.smarts.query.SMARTSException) IntegerResult(org.openscience.cdk.qsar.result.IntegerResult)

Example 3 with IntegerResult

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

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

the class MolecularDescriptorTest method assertEqualOutput.

/**
 * Checks that the results of the first and the second descriptor results
 * are identical.
 *
 * @param v1           first {@link org.openscience.cdk.qsar.result.IDescriptorResult}
 * @param v2           second {@link org.openscience.cdk.qsar.result.IDescriptorResult}
 * @param errorMessage error message to report when the results are not the same
 */
private void assertEqualOutput(IDescriptorResult v1, IDescriptorResult v2, String errorMessage) {
    if (v1 instanceof IntegerResult) {
        Assert.assertEquals(errorMessage, ((IntegerResult) v1).intValue(), ((IntegerResult) v2).intValue());
    } else if (v1 instanceof DoubleResult) {
        Assert.assertEquals(errorMessage, ((DoubleResult) v1).doubleValue(), ((DoubleResult) v2).doubleValue(), 0.00001);
    } else if (v1 instanceof BooleanResult) {
        Assert.assertEquals(errorMessage, ((BooleanResult) v1).booleanValue(), ((BooleanResult) v2).booleanValue());
    } else if (v1 instanceof DoubleArrayResult) {
        DoubleArrayResult da1 = (DoubleArrayResult) v1;
        DoubleArrayResult da2 = (DoubleArrayResult) v2;
        for (int i = 0; i < da1.length(); i++) {
            Assert.assertEquals(errorMessage, da1.get(i), da2.get(i), 0.00001);
        }
    } else if (v1 instanceof IntegerArrayResult) {
        IntegerArrayResult da1 = (IntegerArrayResult) v1;
        IntegerArrayResult da2 = (IntegerArrayResult) v2;
        for (int i = 0; i < da1.length(); i++) {
            Assert.assertEquals(errorMessage, da1.get(i), da2.get(i));
        }
    }
}
Also used : BooleanResult(org.openscience.cdk.qsar.result.BooleanResult) IntegerArrayResult(org.openscience.cdk.qsar.result.IntegerArrayResult) DoubleArrayResult(org.openscience.cdk.qsar.result.DoubleArrayResult) DoubleResult(org.openscience.cdk.qsar.result.DoubleResult) IntegerResult(org.openscience.cdk.qsar.result.IntegerResult)

Example 5 with IntegerResult

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

the class BasicGroupCountDescriptorTest method testAmine.

@Test
public void testAmine() throws Exception {
    SmilesParser sp = new SmilesParser(SilentChemObjectBuilder.getInstance());
    IAtomContainer mol = sp.parseSmiles("NC");
    IntegerResult result = (IntegerResult) descriptor.calculate(mol).getValue();
    Assert.assertEquals(1, result.intValue());
}
Also used : SmilesParser(org.openscience.cdk.smiles.SmilesParser) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IntegerResult(org.openscience.cdk.qsar.result.IntegerResult) Test(org.junit.Test)

Aggregations

IntegerResult (org.openscience.cdk.qsar.result.IntegerResult)39 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)24 DescriptorValue (org.openscience.cdk.qsar.DescriptorValue)22 IAtom (org.openscience.cdk.interfaces.IAtom)16 Test (org.junit.Test)12 CDKException (org.openscience.cdk.exception.CDKException)10 SmilesParser (org.openscience.cdk.smiles.SmilesParser)8 IBond (org.openscience.cdk.interfaces.IBond)7 DoubleResult (org.openscience.cdk.qsar.result.DoubleResult)5 IntegerArrayResult (org.openscience.cdk.qsar.result.IntegerArrayResult)4 List (java.util.List)3 BooleanResult (org.openscience.cdk.qsar.result.BooleanResult)3 DoubleArrayResult (org.openscience.cdk.qsar.result.DoubleArrayResult)3 IDescriptorResult (org.openscience.cdk.qsar.result.IDescriptorResult)3 Point2d (javax.vecmath.Point2d)2 SmartsPattern (org.openscience.cdk.smarts.SmartsPattern)2 AbstractDescriptorResultType (ambit2.core.data.AbstractDescriptorResultType)1 ArrayResult (ambit2.core.data.ArrayResult)1 SuppleAtomContainer (ambit2.core.groups.SuppleAtomContainer)1 VerboseDescriptorResult (ambit2.descriptors.VerboseDescriptorResult)1