Search in sources :

Example 1 with ArrayResult

use of ambit2.core.data.ArrayResult in project ambit-mirror by ideaconsult.

the class AbstractKekulizationVerifier method calculate.

public DescriptorValue calculate(IAtomContainer mol) {
    long now = System.currentTimeMillis();
    Object[] results = new Object[names.length];
    for (int i = 0; i < results.length; i++) results[i] = 0;
    try {
        for (IBond bond : mol.bonds()) {
            if (bond.getFlag(CDKConstants.ISAROMATIC))
                results[names_index.NumAromaticBondOriginal.ordinal()] = (Integer) results[names_index.NumAromaticBondOriginal.ordinal()] + 1;
            if (bond.getOrder().equals(IBond.Order.SINGLE))
                results[names_index.NumSingleBondOriginal.ordinal()] = (Integer) results[names_index.NumSingleBondOriginal.ordinal()] + 1;
            if (bond.getOrder().equals(IBond.Order.DOUBLE))
                results[names_index.NumDoubleBondOriginal.ordinal()] = (Integer) results[names_index.NumDoubleBondOriginal.ordinal()] + 1;
        }
        now = System.currentTimeMillis();
        // now clear the double bonds
        for (IBond bond : mol.bonds()) if (bond.getFlag(CDKConstants.ISAROMATIC))
            bond.setOrder(Order.SINGLE);
        IAtomContainer kekuleMol = transform2Kekule(mol);
        results[names_index.time_ms.ordinal()] = System.currentTimeMillis() - now;
        for (IBond bond : kekuleMol.bonds()) {
            if (bond.getFlag(CDKConstants.ISAROMATIC))
                results[names_index.NumAromaticBondKekule.ordinal()] = (Integer) results[names_index.NumAromaticBondKekule.ordinal()] + 1;
            if (bond.getOrder().equals(IBond.Order.SINGLE))
                results[names_index.NumSingleBondKekule.ordinal()] = (Integer) results[names_index.NumSingleBondKekule.ordinal()] + 1;
            if (bond.getOrder().equals(IBond.Order.DOUBLE))
                results[names_index.NumDoubleBondKekule.ordinal()] = (Integer) results[names_index.NumDoubleBondKekule.ordinal()] + 1;
        }
        results[names_index.status.ordinal()] = "OK";
        return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new ArrayResult(results), getDescriptorNames());
    } catch (Exception x) {
        for (IBond bond : mol.bonds()) {
            if (bond.getFlag(CDKConstants.ISAROMATIC))
                results[names_index.NumAromaticBondKekule.ordinal()] = -1;
            if (bond.getOrder().equals(IBond.Order.SINGLE))
                results[names_index.NumSingleBondKekule.ordinal()] = -1;
            if (bond.getOrder().equals(IBond.Order.DOUBLE))
                results[names_index.NumDoubleBondKekule.ordinal()] = -1;
        }
        results[names_index.time_ms.ordinal()] = System.currentTimeMillis() - now;
        results[names_index.status.ordinal()] = x.getMessage();
        return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new ArrayResult(results), getDescriptorNames());
    } finally {
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ArrayResult(ambit2.core.data.ArrayResult) StringArrayResult(ambit2.core.data.StringArrayResult) IBond(org.openscience.cdk.interfaces.IBond) CDKException(org.openscience.cdk.exception.CDKException) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue)

Example 2 with ArrayResult

use of ambit2.core.data.ArrayResult 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 3 with ArrayResult

use of ambit2.core.data.ArrayResult in project ambit-mirror by ideaconsult.

the class DescriptorSOMEShell method calculate.

public DescriptorValue calculate(IAtomContainer arg0) {
    ArrayResult r = null;
    try {
        if ((arg0 == null) || (arg0.getAtomCount() == 0))
            throw new CDKException("Empty molecule!");
        if (!StructureTypeProcessor.has3DCoordinates(arg0))
            throw new CDKException("No 3D coordinates!");
        logger.info(toString());
        IAtomContainer newmol = some_shell.runShell(arg0);
        Object value = newmol.getProperty(SOMEShell.SOME_RESULT);
        final int[] count = new int[SOMERawReader.someindex.values().length];
        for (int i = 0; i < count.length; i++) count[i] = 0;
        if (value == null)
            value = "@SOME results: NONE";
        else {
            SOMEResultsParser parser = new SOMEResultsParser() {

                @Override
                protected void process(int atomNum, String atomSymbol, someindex index, double value, boolean star) {
                    if (star)
                        count[index.ordinal()]++;
                }
            };
            parser.parseRecord(value.toString());
        }
        r = new ArrayResult(new Object[] { value.toString(), count[someindex.aliphaticHydroxylation.ordinal()], count[someindex.aromaticHydroxylation.ordinal()], count[someindex.NDealkylation.ordinal()], count[someindex.NOxidation.ordinal()], count[someindex.ODealkylation.ordinal()], count[someindex.SOxidation.ordinal()] });
        return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), r, getDescriptorNames());
    } catch (Exception x) {
        r = new ArrayResult(new Object[] { x.getMessage(), 0, 0, 0, 0, 0, 0 });
        return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), r, getDescriptorNames());
    }
}
Also used : SOMERawReader.someindex(ambit2.some.SOMERawReader.someindex) ArrayResult(ambit2.core.data.ArrayResult) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ShellException(ambit2.base.external.ShellException) CDKException(org.openscience.cdk.exception.CDKException) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue)

Aggregations

ArrayResult (ambit2.core.data.ArrayResult)3 CDKException (org.openscience.cdk.exception.CDKException)2 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)2 DescriptorValue (org.openscience.cdk.qsar.DescriptorValue)2 ShellException (ambit2.base.external.ShellException)1 AbstractDescriptorResultType (ambit2.core.data.AbstractDescriptorResultType)1 StringArrayResult (ambit2.core.data.StringArrayResult)1 VerboseDescriptorResult (ambit2.descriptors.VerboseDescriptorResult)1 SOMERawReader.someindex (ambit2.some.SOMERawReader.someindex)1 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)1 IBond (org.openscience.cdk.interfaces.IBond)1 BooleanResult (org.openscience.cdk.qsar.result.BooleanResult)1 DoubleArrayResult (org.openscience.cdk.qsar.result.DoubleArrayResult)1 DoubleResult (org.openscience.cdk.qsar.result.DoubleResult)1 IDescriptorResult (org.openscience.cdk.qsar.result.IDescriptorResult)1 IntegerArrayResult (org.openscience.cdk.qsar.result.IntegerArrayResult)1 IntegerResult (org.openscience.cdk.qsar.result.IntegerResult)1