Search in sources :

Example 1 with FunctionalGroup

use of ambit2.descriptors.FunctionalGroup 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 2 with FunctionalGroup

use of ambit2.descriptors.FunctionalGroup in project ambit-mirror by ideaconsult.

the class QuerySmartsTest method testMatchNoAccelerator.

@Test
public void testMatchNoAccelerator() throws Exception {
    Preferences.setProperty(Preferences.FASTSMARTS, "false");
    QuerySMARTS q = new QuerySMARTS();
    q.setValue(new FunctionalGroup("aromatic aldehyde example", "c1ccccc1[$(C(C)C(=O)),$(CC(C)C(=O))]", ""));
    // "c1ccccc1C(C)C(=O)",""));
    RawIteratingSDFReader reader = new RawIteratingSDFReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("ambit2/db/processors/test/smartssearch.sdf")));
    int count = 0;
    while (reader.hasNext()) {
        IStructureRecord record = reader.nextRecord();
        Assert.assertEquals(1.0, q.calculateMetric(record));
        count++;
    }
    Assert.assertEquals(2, count);
}
Also used : QuerySMARTS(ambit2.db.search.structure.QuerySMARTS) IStructureRecord(ambit2.base.interfaces.IStructureRecord) FunctionalGroup(ambit2.descriptors.FunctionalGroup) RawIteratingSDFReader(ambit2.core.io.RawIteratingSDFReader) InputStreamReader(java.io.InputStreamReader) Test(org.junit.Test)

Example 3 with FunctionalGroup

use of ambit2.descriptors.FunctionalGroup in project ambit-mirror by ideaconsult.

the class FuncGroupsDescriptorFactoryTest method testSaveFragments.

@Test
public void testSaveFragments() throws Exception {
    FuncGroupsDescriptorFactory factory = new FuncGroupsDescriptorFactory();
    Collection<FunctionalGroup> list = factory.process(null);
    File temp = File.createTempFile("test_save_funcgroups", ".xml");
    OutputStream writer = new FileOutputStream(temp);
    FuncGroupsDescriptorFactory.saveFragments(writer, list);
    writer.flush();
    writer.close();
    Collection<FunctionalGroup> newlist = factory.process(temp.getAbsolutePath());
    Assert.assertEquals(list.size(), newlist.size());
    for (FunctionalGroup group : newlist) {
        Assert.assertNotSame("", group.getSmarts());
        Assert.assertNotSame("", group.getName());
        Assert.assertNotSame("", group.getFamily());
    }
    temp.delete();
}
Also used : FunctionalGroup(ambit2.descriptors.FunctionalGroup) FuncGroupsDescriptorFactory(ambit2.descriptors.FuncGroupsDescriptorFactory) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Test(org.junit.Test)

Example 4 with FunctionalGroup

use of ambit2.descriptors.FunctionalGroup in project ambit-mirror by ideaconsult.

the class FunctionalGroupDescriptorTest method testMultiple.

@Test
public void testMultiple() throws Exception {
    groups = new ArrayList<FunctionalGroup>();
    groups.add(new FunctionalGroup("C4", "CCCC", "test4"));
    groups.add(new FunctionalGroup("C5", "CCCCC", "test5"));
    calculate(groups, false, MoleculeFactory.makeAlkane(4), 2);
}
Also used : FunctionalGroup(ambit2.descriptors.FunctionalGroup) Test(org.junit.Test)

Example 5 with FunctionalGroup

use of ambit2.descriptors.FunctionalGroup in project ambit-mirror by ideaconsult.

the class FunctionalGroupDescriptorTest method testSingle.

@Test
public void testSingle() throws Exception {
    groups = new ArrayList<FunctionalGroup>();
    groups.add(new FunctionalGroup("C4", "CCCC", "test4"));
    calculate(groups, false, MoleculeFactory.makeAlkane(4), 1);
}
Also used : FunctionalGroup(ambit2.descriptors.FunctionalGroup) Test(org.junit.Test)

Aggregations

FunctionalGroup (ambit2.descriptors.FunctionalGroup)15 Test (org.junit.Test)11 VerboseDescriptorResult (ambit2.descriptors.VerboseDescriptorResult)5 IStructureRecord (ambit2.base.interfaces.IStructureRecord)4 QuerySMARTS (ambit2.db.search.structure.QuerySMARTS)4 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)4 AtomConfigurator (ambit2.core.processors.structure.AtomConfigurator)3 FuncGroupsDescriptorFactory (ambit2.descriptors.FuncGroupsDescriptorFactory)3 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)3 RawIteratingSDFReader (ambit2.core.io.RawIteratingSDFReader)2 HydrogenAdderProcessor (ambit2.core.processors.structure.HydrogenAdderProcessor)2 MoleculeReader (ambit2.core.processors.structure.MoleculeReader)2 QueryStructureByID (ambit2.db.search.structure.QueryStructureByID)2 FunctionalGroupDescriptor (ambit2.descriptors.FunctionalGroupDescriptor)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 SmilesParser (org.openscience.cdk.smiles.SmilesParser)2 ISourceDataset (ambit2.base.data.ISourceDataset)1 SourceDataset (ambit2.base.data.SourceDataset)1 StructureRecord (ambit2.base.data.StructureRecord)1