Search in sources :

Example 1 with BooleanResult

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

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

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

the class PiContactDetectionDescriptor method calculate.

/**
 * The method returns if two atoms have pi-contact.
 *
 * @param  atomContainer                AtomContainer
 * @return                   true if the atoms have pi-contact
 */
@Override
public DescriptorValue calculate(IAtom first, IAtom second, IAtomContainer atomContainer) {
    IAtomContainer ac;
    try {
        ac = atomContainer.clone();
    } catch (CloneNotSupportedException e) {
        return getDummyDescriptorValue(e);
    }
    IAtom clonedFirst = ac.getAtom(atomContainer.indexOf(first));
    IAtom clonedSecond = ac.getAtom(atomContainer.indexOf(second));
    IAtomContainer mol = ac.getBuilder().newInstance(IAtomContainer.class, ac);
    if (checkAromaticity) {
        try {
            AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
            Aromaticity.cdkLegacy().apply(mol);
        } catch (CDKException e) {
            return getDummyDescriptorValue(e);
        }
    }
    boolean piContact = false;
    int counter = 0;
    if (acold != ac) {
        acold = ac;
        acSet = ConjugatedPiSystemsDetector.detect(mol);
    }
    java.util.Iterator<IAtomContainer> detected = acSet.atomContainers().iterator();
    List<IAtom> neighboorsFirst = mol.getConnectedAtomsList(clonedFirst);
    List<IAtom> neighboorsSecond = mol.getConnectedAtomsList(clonedSecond);
    while (detected.hasNext()) {
        IAtomContainer detectedAC = detected.next();
        if (detectedAC.contains(clonedFirst) && detectedAC.contains(clonedSecond)) {
            counter += 1;
            break;
        }
        if (isANeighboorsInAnAtomContainer(neighboorsFirst, detectedAC) && isANeighboorsInAnAtomContainer(neighboorsSecond, detectedAC)) {
            counter += 1;
            break;
        }
    }
    if (counter > 0) {
        piContact = true;
    }
    return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new BooleanResult(piContact), getDescriptorNames());
}
Also used : BooleanResult(org.openscience.cdk.qsar.result.BooleanResult) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) IAtom(org.openscience.cdk.interfaces.IAtom) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue)

Example 4 with BooleanResult

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

the class QSARCustomizer method createScalar.

private Element createScalar(IDescriptorResult value) {
    Element scalar;
    if (value instanceof DoubleResult) {
        scalar = new CMLScalar();
        scalar.addAttribute(new Attribute("dataType", "xsd:double"));
        scalar.appendChild("" + ((DoubleResult) value).doubleValue());
    } else if (value instanceof IntegerResult) {
        scalar = new CMLScalar();
        scalar.addAttribute(new Attribute("dataType", "xsd:int"));
        scalar.appendChild("" + ((IntegerResult) value).intValue());
    } else if (value instanceof BooleanResult) {
        scalar = new CMLScalar();
        scalar.addAttribute(new Attribute("dataType", "xsd:boolean"));
        scalar.appendChild("" + ((BooleanResult) value).booleanValue());
    } else if (value instanceof IntegerArrayResult) {
        IntegerArrayResult result = (IntegerArrayResult) value;
        scalar = new CMLArray();
        scalar.addAttribute(new Attribute("dataType", "xsd:int"));
        scalar.addAttribute(new Attribute("size", "" + result.length()));
        StringBuilder buffer = new StringBuilder();
        for (int i = 0; i < result.length(); i++) {
            buffer.append(result.get(i) + " ");
        }
        scalar.appendChild(buffer.toString());
    } else if (value instanceof DoubleArrayResult) {
        DoubleArrayResult result = (DoubleArrayResult) value;
        scalar = new CMLArray();
        scalar.addAttribute(new Attribute("dataType", "xsd:double"));
        scalar.addAttribute(new Attribute("size", "" + result.length()));
        StringBuilder buffer = new StringBuilder();
        for (int i = 0; i < result.length(); i++) {
            buffer.append(result.get(i) + " ");
        }
        scalar.appendChild(buffer.toString());
    } else {
        // logger.error("Could not convert this object to a scalar element: ", value);
        scalar = new CMLScalar();
        scalar.appendChild(value.toString());
    }
    return scalar;
}
Also used : BooleanResult(org.openscience.cdk.qsar.result.BooleanResult) Attribute(nu.xom.Attribute) Element(nu.xom.Element) IntegerArrayResult(org.openscience.cdk.qsar.result.IntegerArrayResult) DoubleArrayResult(org.openscience.cdk.qsar.result.DoubleArrayResult) DoubleResult(org.openscience.cdk.qsar.result.DoubleResult) CMLScalar(org.xmlcml.cml.element.CMLScalar) IntegerResult(org.openscience.cdk.qsar.result.IntegerResult) CMLArray(org.xmlcml.cml.element.CMLArray)

Example 5 with BooleanResult

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

the class IsProtonInConjugatedPiSystemDescriptor method calculate.

/**
 *  The method is a proton descriptor that evaluates if a proton is joined to a conjugated system.
 *
 *@param  atom              The IAtom for which the DescriptorValue is requested
 *@param  atomContainer              AtomContainer
 *@return                   true if the proton is bonded to a conjugated system
 */
@Override
public DescriptorValue calculate(IAtom atom, IAtomContainer atomContainer) {
    IAtomContainer clonedAtomContainer;
    try {
        clonedAtomContainer = atomContainer.clone();
    } catch (CloneNotSupportedException e) {
        return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new BooleanResult(false), NAMES, e);
    }
    IAtom clonedAtom = clonedAtomContainer.getAtom(atomContainer.indexOf(atom));
    boolean isProtonInPiSystem = false;
    IAtomContainer mol = clonedAtom.getBuilder().newInstance(IAtomContainer.class, clonedAtomContainer);
    if (checkAromaticity) {
        try {
            AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
            Aromaticity.cdkLegacy().apply(mol);
        } catch (CDKException e) {
            return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new BooleanResult(false), NAMES, e);
        }
    }
    if (atom.getAtomicNumber() == IElement.H) {
        if (acold != clonedAtomContainer) {
            acold = clonedAtomContainer;
            acSet = ConjugatedPiSystemsDetector.detect(mol);
        }
        Iterator<IAtomContainer> detected = acSet.atomContainers().iterator();
        List<IAtom> neighboors = mol.getConnectedAtomsList(clonedAtom);
        for (IAtom neighboor : neighboors) {
            while (detected.hasNext()) {
                IAtomContainer detectedAC = detected.next();
                if ((detectedAC != null) && (detectedAC.contains(neighboor))) {
                    isProtonInPiSystem = true;
                    break;
                }
            }
        }
    }
    return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new BooleanResult(isProtonInPiSystem), NAMES);
}
Also used : BooleanResult(org.openscience.cdk.qsar.result.BooleanResult) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) IAtom(org.openscience.cdk.interfaces.IAtom) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue)

Aggregations

BooleanResult (org.openscience.cdk.qsar.result.BooleanResult)6 DescriptorValue (org.openscience.cdk.qsar.DescriptorValue)3 DoubleArrayResult (org.openscience.cdk.qsar.result.DoubleArrayResult)3 DoubleResult (org.openscience.cdk.qsar.result.DoubleResult)3 IntegerArrayResult (org.openscience.cdk.qsar.result.IntegerArrayResult)3 IntegerResult (org.openscience.cdk.qsar.result.IntegerResult)3 CDKException (org.openscience.cdk.exception.CDKException)2 IAtom (org.openscience.cdk.interfaces.IAtom)2 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)2 AbstractDescriptorResultType (ambit2.core.data.AbstractDescriptorResultType)1 ArrayResult (ambit2.core.data.ArrayResult)1 VerboseDescriptorResult (ambit2.descriptors.VerboseDescriptorResult)1 Attribute (nu.xom.Attribute)1 Element (nu.xom.Element)1 IDescriptorResult (org.openscience.cdk.qsar.result.IDescriptorResult)1 CMLArray (org.xmlcml.cml.element.CMLArray)1 CMLScalar (org.xmlcml.cml.element.CMLScalar)1