use of ambit2.descriptors.VerboseDescriptorResult 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 ambit2.descriptors.VerboseDescriptorResult in project ambit-mirror by ideaconsult.
the class DbReaderTest method testProcess.
@Test
public void testProcess() throws Exception {
setUpDatabaseFromResource("ambit2/db/processors/test/descriptors-datasets.xml");
IDatabaseConnection c = getConnection();
ITable names = c.createQueryTable("EXPECTED_NAMES", "SELECT * FROM properties");
Assert.assertEquals(5, names.getRowCount());
ITable values = c.createQueryTable("EXPECTED_VALUES", "SELECT * FROM property_values");
Assert.assertEquals(2, values.getRowCount());
ProcessorsChain<IStructureRecord, IBatchStatistics, IProcessor> p = new ProcessorsChain<IStructureRecord, IBatchStatistics, IProcessor>();
p.add(new ProcessorStructureRetrieval());
p.add(new IProcessor<IStructureRecord, IStructureRecord>() {
public boolean isEnabled() {
return true;
}
public IStructureRecord process(IStructureRecord target) throws AmbitException {
// System.out.println(target.getContent());
return target;
}
public void setEnabled(boolean value) {
}
public long getID() {
return 0;
}
@Override
public void open() throws Exception {
}
@Override
public void close() throws Exception {
}
});
p.add(new MoleculeReader());
p.add(new AtomConfigurator());
p.add(new FunctionalGroup("Test", "P", "Test"));
p.add(new IProcessor<VerboseDescriptorResult, String>() {
/**
*/
private static final long serialVersionUID = -3923864774580483348L;
public String process(VerboseDescriptorResult target) throws AmbitException {
Assert.assertEquals("1", target.getResult().toString());
return target.toString();
}
public boolean isEnabled() {
return true;
}
public void setEnabled(boolean value) {
}
public long getID() {
return 0;
}
@Override
public void open() throws Exception {
}
@Override
public void close() throws Exception {
}
});
batch.setProcessorChain(p);
QueryStructureByID query = new QueryStructureByID(100215);
batch.setConnection(c.getConnection());
batch.open();
IBatchStatistics stats = batch.process(query);
Assert.assertEquals(1, stats.getRecords(IBatchStatistics.RECORDS_STATS.RECORDS_READ));
Assert.assertEquals(1, stats.getRecords(IBatchStatistics.RECORDS_STATS.RECORDS_PROCESSED));
// C20H20BrP
}
use of ambit2.descriptors.VerboseDescriptorResult 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 ambit2.descriptors.VerboseDescriptorResult in project ambit-mirror by ideaconsult.
the class PKASmartsDescriptor method calculate.
public DescriptorValue calculate(IAtomContainer arg0) {
try {
ArrayList<String> trace = new ArrayList<String>();
PKANode node = traverse(arg0, root, trace);
return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new VerboseDescriptorResult<String, DoubleResult>(new DoubleResult(node.getPka()), trace.toString()), title);
} catch (Exception x) {
return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), null, title, x);
}
}
use of ambit2.descriptors.VerboseDescriptorResult in project ambit-mirror by ideaconsult.
the class FunctionalGroupDescriptorTest method calculate.
protected void calculate(List<FunctionalGroup> groups, boolean verbose, IAtomContainer m, int hits) throws Exception {
d.setParameters(new Object[] { groups, verbose });
m = hadder.process(m);
DescriptorValue value = d.calculate(m);
IDescriptorResult v = value.getValue();
Assert.assertEquals(hits, value.getNames().length);
Assert.assertTrue(v instanceof VerboseDescriptorResult);
VerboseDescriptorResult verboseResult = (VerboseDescriptorResult) v;
IDescriptorResult r = verboseResult.getResult();
Assert.assertTrue(r instanceof IntegerArrayResult);
Assert.assertEquals(hits, ((IntegerArrayResult) r).length());
if (verbose) {
Assert.assertTrue(verboseResult.getExplanation() instanceof List);
Assert.assertTrue(((List) verboseResult.getExplanation()).get(0) instanceof IAtomContainer);
}
}
Aggregations