Search in sources :

Example 1 with StringArrayResult

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

the class InChI method calculate.

public DescriptorValue calculate(IAtomContainer mol) {
    try {
        InChIGenerator gen = processor.process(mol);
        INCHI_RET ret = gen.getReturnStatus();
        if (ret.equals(INCHI_RET.OKAY) || ret.equals(INCHI_RET.WARNING)) {
            StringArrayResult value = new StringArrayResult(new String[] { gen.getInchi(), null, gen.getInchiKey() });
            return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), value, getDescriptorNames());
        } else {
            return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), null, getDescriptorNames(), new Exception(String.format("[%s] %s", gen.getReturnStatus(), gen.getMessage())));
        }
    } catch (Exception x) {
        return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), null, getDescriptorNames(), x);
    }
}
Also used : StringArrayResult(ambit2.core.data.StringArrayResult) InChIGenerator(org.openscience.cdk.inchi.InChIGenerator) CDKException(org.openscience.cdk.exception.CDKException) INCHI_RET(net.sf.jniinchi.INCHI_RET) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue)

Example 2 with StringArrayResult

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

the class PropertyCalculationProcessorTest method testInChI.

@Test
public void testInChI() throws Exception {
    PropertyCalculationProcessor p = new PropertyCalculationProcessor();
    Property prop = Property.getInstance("Count", "Descriptors");
    prop.setLabel("Count");
    prop.setClazz(Class.forName("ambit2.descriptors.InChI"));
    p.setProperty(prop);
    DescriptorValue value = p.process(MoleculeFactory.makeAlkane(10));
    Assert.assertNotNull(value);
    Assert.assertTrue(value.getValue() instanceof StringArrayResult);
    StringArrayResult r = (StringArrayResult) value.getValue();
    Assert.assertEquals("InChI=1S/C10H22/c1-3-5-7-9-10-8-6-4-2/h3-10H2,1-2H3", r.get(0));
    // Assert.assertEquals("AuxInfo=1/0/N:1,10,2,9,3,8,4,7,5,6/E:(1,2)(3,4)(5,6)(7,8)(9,10)/rA:10CCCCCCCCCC/rB:s1;s2;s3;s4;s5;s6;s7;s8;s9;/rC:;;;;;;;;;;",
    // r.get(1));
    // we discarded AuxInfo
    Assert.assertNull(r.get(1));
    Assert.assertEquals("DIOQZVSQGTUSAI-UHFFFAOYSA-N", r.get(2));
}
Also used : StringArrayResult(ambit2.core.data.StringArrayResult) Property(ambit2.base.data.Property) PropertyCalculationProcessor(ambit2.descriptors.processors.PropertyCalculationProcessor) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) Test(org.junit.Test)

Example 3 with StringArrayResult

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

the class AtomTypeVerifierDescriptor method calculate.

public DescriptorValue calculate(IAtomContainer mol) {
    String pref = Preferences.getProperty(Preferences.STOP_AT_UNKNOWNATOMTYPES);
    Preferences.setProperty(Preferences.STOP_AT_UNKNOWNATOMTYPES, "true");
    try {
        typer.process(mol);
        StringArrayResult value = new StringArrayResult(new String[] { OK });
        return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), value, getDescriptorNames());
    } catch (Exception x) {
        StringArrayResult value = new StringArrayResult(new String[] { x.getMessage() });
        return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), value, getDescriptorNames());
    } finally {
        Preferences.setProperty(Preferences.STOP_AT_UNKNOWNATOMTYPES, pref == null ? "false" : pref);
    }
}
Also used : StringArrayResult(ambit2.core.data.StringArrayResult) CDKException(org.openscience.cdk.exception.CDKException) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue)

Aggregations

StringArrayResult (ambit2.core.data.StringArrayResult)3 DescriptorValue (org.openscience.cdk.qsar.DescriptorValue)3 CDKException (org.openscience.cdk.exception.CDKException)2 Property (ambit2.base.data.Property)1 PropertyCalculationProcessor (ambit2.descriptors.processors.PropertyCalculationProcessor)1 INCHI_RET (net.sf.jniinchi.INCHI_RET)1 Test (org.junit.Test)1 InChIGenerator (org.openscience.cdk.inchi.InChIGenerator)1