Search in sources :

Example 1 with AtomConfigurator

use of ambit2.core.processors.structure.AtomConfigurator in project ambit-mirror by ideaconsult.

the class StructureQueryResource method getSMILES.

protected String getSMILES(Form form, boolean aromatic) throws ResourceException {
    String query_smiles;
    String search_arg = form.getFirstValue(QueryResource.search_param);
    String searchb64_arg = form.getFirstValue(QueryResource.b64search_param);
    QueryType query_type = getQueryType(form, search_arg);
    switch(query_type) {
        case mol:
            {
                query_smiles = searchb64_arg;
                if (query_smiles != null) {
                    query_smiles = new String(Base64.decode(query_smiles));
                } else
                    query_smiles = search_arg;
                try {
                    IAtomContainer ac = MoleculeTools.readMolfile(query_smiles);
                    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(ac);
                    if (hadder == null) {
                        hadder = CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance());
                    }
                    hadder.addImplicitHydrogens(ac);
                    return SmilesGenerator.generic().create(ac);
                } catch (Exception x) {
                    throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage(), x);
                }
            }
        case smiles:
            {
                query_smiles = searchb64_arg;
                if (query_smiles != null) {
                    query_smiles = new String(Base64.decode(query_smiles));
                } else
                    query_smiles = search_arg;
                return query_smiles == null ? null : query_smiles.trim();
            }
        case url:
            try {
                if (search_arg == null)
                    return null;
                query_smiles = search_arg.trim();
                if (query_smiles == null)
                    throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Empty query");
                IAtomContainer mol = getFromURI(query_smiles.trim());
                AtomConfigurator c = new AtomConfigurator();
                mol = c.process(mol);
                ambit2.core.helper.CDKHueckelAromaticityDetector.detectAromaticity(mol);
                SmilesGenerator g = SmilesGenerator.generic();
                if (aromatic)
                    g = g.aromatic();
                return g.create(mol);
            } catch (Exception x) {
                throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage(), x);
            }
        default:
            return null;
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ResourceException(org.restlet.resource.ResourceException) AtomConfigurator(ambit2.core.processors.structure.AtomConfigurator) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) ResourceException(org.restlet.resource.ResourceException) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) SmilesGenerator(org.openscience.cdk.smiles.SmilesGenerator)

Example 2 with AtomConfigurator

use of ambit2.core.processors.structure.AtomConfigurator in project ambit-mirror by ideaconsult.

the class AtomConfiguratorProcessorTest method test.

/**
 * Atom configurator sets number of properties,which are otherwise uninitialized
 * @throws Exception
 */
@Test
public void test() throws Exception {
    AtomConfigurator p = new AtomConfigurator();
    IAtomContainer mol = MoleculeFactory.makeBenzene();
    int uninitialized = 0;
    for (int i = 0; i < mol.getAtomCount(); i++) {
        if (mol.getAtom(i).getAtomicNumber() == null || mol.getAtom(i).getHybridization() == null)
            uninitialized++;
    }
    if (uninitialized > 0) {
        mol = p.process(mol);
        for (int i = 0; i < mol.getAtomCount(); i++) {
            Assert.assertEquals(6, mol.getAtom(i).getAtomicNumber().intValue());
            Assert.assertEquals(Hybridization.SP2, mol.getAtom(i).getHybridization());
            Assert.assertNotNull(mol.getAtom(i).getValency());
        }
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomConfigurator(ambit2.core.processors.structure.AtomConfigurator) Test(org.junit.Test)

Example 3 with AtomConfigurator

use of ambit2.core.processors.structure.AtomConfigurator in project ambit-mirror by ideaconsult.

the class QuerySMARTS method prepareScreening.

public void prepareScreening() throws AmbitException {
    try {
        if (((screening.getValue() == null) && isFp1024_screening()) || ((screening.getFieldname() == null)) && isSk1024_screening()) {
            // if ((screening.getValue()==null) || (screening.getFieldname()==null)) {
            screening.setPageSize(0);
            screening.setPage(0);
            SmartsPatternAmbit matcher = new SmartsPatternAmbit(builder);
            matcher.setUseCDKIsomorphism(false);
            value.setQuery(matcher);
            IQueryAtomContainer container = matcher.getQuery();
            IAtomContainer atomContainer = smartsToChemObject.process(container);
            try {
                AtomConfigurator cfg = new AtomConfigurator();
                cfg.process(atomContainer);
            } catch (Exception x) {
                logger.log(Level.FINE, x.getMessage(), x);
            }
            try {
                CDKHueckelAromaticityDetector.detectAromaticity(atomContainer);
            } catch (Exception x) {
                logger.log(Level.FINE, x.getMessage(), x);
            }
            if ((atomContainer == null) || (atomContainer.getAtomCount() == 0)) {
                screening.setValue(null);
                screening.setFieldname(null);
            } else {
                try {
                    screening.setValue(fp1024_screening ? fpGenerator.process(atomContainer) : null);
                } catch (Exception x) {
                    screening.setValue(null);
                }
                try {
                    screening.setFieldname(sk1024_screening ? skGenerator.process(atomContainer) : null);
                } catch (Exception x) {
                    screening.setFieldname(null);
                }
            }
        }
    } catch (AmbitException x) {
        throw x;
    // screening.setValue(null);
    // screening.setFieldname(null);
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) SmartsPatternAmbit(ambit2.smarts.query.SmartsPatternAmbit) AtomConfigurator(ambit2.core.processors.structure.AtomConfigurator) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 4 with AtomConfigurator

use of ambit2.core.processors.structure.AtomConfigurator 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 5 with AtomConfigurator

use of ambit2.core.processors.structure.AtomConfigurator in project ambit-mirror by ideaconsult.

the class PKASmartsDescriptorTest method testAcid.

// 
@Test
public void testAcid() throws Exception {
    SmilesParser parser = new SmilesParser(SilentChemObjectBuilder.getInstance());
    IAtomContainer a = parser.parseSmiles("O[N+](=O)[O-]");
    AtomConfigurator cfg = new AtomConfigurator();
    cfg.process(a);
    HydrogenAdderProcessor ha = new HydrogenAdderProcessor();
    ha.setAddEexplicitHydrogens(true);
    a = ha.process(a);
    CDKHueckelAromaticityDetector.detectAromaticity(a);
    // otherwise getValency() of H atoms returns null (since cdk 1.3.6)
    cfg.process(a);
    for (int i = 0; i < a.getAtomCount(); i++) {
        /*
			System.out.print(a.getAtom(i).getSymbol());
			System.out.print('\t');
			System.out.print(a.getAtom(i).getFlag(CDKConstants.ISAROMATIC));
			System.out.print('\t');
			System.out.print(String.format("valency %d",a.getAtom(i).getValency()));
			System.out.print('\t');
			System.out.println(a.getAtom(i).getAtomTypeName());
			*/
        Assert.assertNotNull(a.getAtom(i).getValency());
    }
    for (int i = 0; i < a.getAtomCount(); i++) {
        Assert.assertNotNull(a.getAtom(i).getValency());
    }
    for (int i = 0; i < a.getBondCount(); i++) {
        Assert.assertNotNull(a.getBond(i).getOrder());
    }
    DescriptorValue value = pka.calculate(a);
    Assert.assertNotNull(value.getValue());
    Assert.assertNotNull(((VerboseDescriptorResult) value.getValue()).getExplanation());
}
Also used : SmilesParser(org.openscience.cdk.smiles.SmilesParser) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) HydrogenAdderProcessor(ambit2.core.processors.structure.HydrogenAdderProcessor) AtomConfigurator(ambit2.core.processors.structure.AtomConfigurator) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) Test(org.junit.Test)

Aggregations

AtomConfigurator (ambit2.core.processors.structure.AtomConfigurator)25 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)22 Test (org.junit.Test)13 HydrogenAdderProcessor (ambit2.core.processors.structure.HydrogenAdderProcessor)11 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)8 MoleculeReader (ambit2.core.processors.structure.MoleculeReader)6 SmilesParser (org.openscience.cdk.smiles.SmilesParser)6 IStructureRecord (ambit2.base.interfaces.IStructureRecord)5 RawIteratingSDFReader (ambit2.core.io.RawIteratingSDFReader)4 FunctionalGroup (ambit2.descriptors.FunctionalGroup)3 VerboseDescriptorResult (ambit2.descriptors.VerboseDescriptorResult)3 InputStreamReader (java.io.InputStreamReader)3 UniversalIsomorphismTester (org.openscience.cdk.isomorphism.UniversalIsomorphismTester)3 SmilesParserWrapper (ambit2.core.smiles.SmilesParserWrapper)2 PKANode (ambit2.descriptors.PKANode)2 SMARTSPropertiesReader (ambit2.smarts.processors.SMARTSPropertiesReader)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 ArrayList (java.util.ArrayList)2 BitSet (java.util.BitSet)2