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