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 {
}
}
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;
}
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());
}
}
Aggregations