Search in sources :

Example 1 with VerboseDescriptorResult

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;
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) SuppleAtomContainer(ambit2.core.groups.SuppleAtomContainer) SmartsToChemObject(ambit2.smarts.SmartsToChemObject) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) IntegerResult(org.openscience.cdk.qsar.result.IntegerResult)

Example 2 with VerboseDescriptorResult

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
}
Also used : IBatchStatistics(net.idea.modbcum.i.batch.IBatchStatistics) IProcessor(net.idea.modbcum.i.processors.IProcessor) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) QueryStructureByID(ambit2.db.search.structure.QueryStructureByID) IStructureRecord(ambit2.base.interfaces.IStructureRecord) FunctionalGroup(ambit2.descriptors.FunctionalGroup) MoleculeReader(ambit2.core.processors.structure.MoleculeReader) ProcessorsChain(net.idea.modbcum.i.processors.ProcessorsChain) ITable(org.dbunit.dataset.ITable) ProcessorStructureRetrieval(ambit2.db.processors.ProcessorStructureRetrieval) AtomConfigurator(ambit2.core.processors.structure.AtomConfigurator) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) VerboseDescriptorResult(ambit2.descriptors.VerboseDescriptorResult) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbUnitTest(ambit2.db.processors.test.DbUnitTest) Test(org.junit.Test)

Example 3 with VerboseDescriptorResult

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);
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) SMARTSException(ambit2.smarts.query.SMARTSException) IntegerResult(org.openscience.cdk.qsar.result.IntegerResult)

Example 4 with VerboseDescriptorResult

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);
    }
}
Also used : ArrayList(java.util.ArrayList) DoubleResult(org.openscience.cdk.qsar.result.DoubleResult) CDKException(org.openscience.cdk.exception.CDKException) IOException(java.io.IOException) SMARTSException(ambit2.smarts.query.SMARTSException) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue)

Example 5 with VerboseDescriptorResult

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);
    }
}
Also used : IDescriptorResult(org.openscience.cdk.qsar.result.IDescriptorResult) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IntegerArrayResult(org.openscience.cdk.qsar.result.IntegerArrayResult) ArrayList(java.util.ArrayList) List(java.util.List) VerboseDescriptorResult(ambit2.descriptors.VerboseDescriptorResult) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue)

Aggregations

VerboseDescriptorResult (ambit2.descriptors.VerboseDescriptorResult)7 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)7 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)5 Test (org.junit.Test)5 AtomConfigurator (ambit2.core.processors.structure.AtomConfigurator)4 FunctionalGroup (ambit2.descriptors.FunctionalGroup)4 HydrogenAdderProcessor (ambit2.core.processors.structure.HydrogenAdderProcessor)3 ArrayList (java.util.ArrayList)3 DescriptorValue (org.openscience.cdk.qsar.DescriptorValue)3 IntegerResult (org.openscience.cdk.qsar.result.IntegerResult)3 MoleculeReader (ambit2.core.processors.structure.MoleculeReader)2 SMARTSException (ambit2.smarts.query.SMARTSException)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 FileOutputStream (java.io.FileOutputStream)2 List (java.util.List)2 IBatchStatistics (net.idea.modbcum.i.batch.IBatchStatistics)2 DoubleResult (org.openscience.cdk.qsar.result.DoubleResult)2 IDescriptorResult (org.openscience.cdk.qsar.result.IDescriptorResult)2 IntegerArrayResult (org.openscience.cdk.qsar.result.IntegerArrayResult)2