Search in sources :

Example 1 with DoubleResult

use of org.openscience.cdk.qsar.result.DoubleResult in project ambit-mirror by ideaconsult.

the class DbDescriptorValuesWriterTest method testWriteDescriptorValue.

/**
 * Test method for
 * {@link ambit2.db.processors.DbDescriptorWriter#write(org.openscience.cdk.qsar.DescriptorValue)}
 * .
 */
@Test
public void testWriteDescriptorValue() 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());
    ITable templates = c.createQueryTable("EXPECTED_TEMPLATES", "SELECT * FROM template");
    Assert.assertEquals(5, templates.getRowCount());
    ITable dictionary = c.createQueryTable("EXPECTED_ONTOLOGY", "SELECT * FROM dictionary");
    Assert.assertEquals(3, dictionary.getRowCount());
    writer.setConnection(c.getConnection());
    writer.open();
    XLogPDescriptor xlogp = new XLogPDescriptor();
    writer.setStructure(new StructureRecord(7, 100211, "", ""));
    writer.write(xlogp.calculate(MoleculeFactory.makeAlkane(10)));
    names = c.createQueryTable("EXPECTED_NAMES", "SELECT * FROM properties");
    Assert.assertEquals(6, names.getRowCount());
    values = c.createQueryTable("EXPECTED_VALUES", "SELECT * FROM property_values");
    Assert.assertEquals(3, values.getRowCount());
    DescriptorValue v = new DescriptorValue(new DescriptorSpecification("XLogPReference", "XLogPTitle", "XLogPIdentifier", "XLogPVendor"), new String[] {}, new Object[] {}, new DoubleResult(5.01), new String[] { "XLogP" });
    writer.setStructure(new StructureRecord(10, 100214, "", ""));
    writer.write(v);
    // one more time
    writer.write(v);
    c.close();
    c = getConnection();
    names = c.createQueryTable("EXPECTED_NAMES", "SELECT * FROM properties");
    Assert.assertEquals(7, names.getRowCount());
    values = c.createQueryTable("EXPECTED_VALUES", "SELECT value_num FROM property_values WHERE idstructure=100214");
    Assert.assertEquals(1, values.getRowCount());
    Assert.assertEquals(5.01, (Double) DataType.DOUBLE.typeCast(values.getValue(0, "value_num")), 1E-4);
    c.close();
}
Also used : StructureRecord(ambit2.base.data.StructureRecord) IStructureRecord(ambit2.base.interfaces.IStructureRecord) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DoubleResult(org.openscience.cdk.qsar.result.DoubleResult) DescriptorSpecification(org.openscience.cdk.qsar.DescriptorSpecification) XLogPDescriptor(org.openscience.cdk.qsar.descriptors.molecular.XLogPDescriptor) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) Test(org.junit.Test)

Example 2 with DoubleResult

use of org.openscience.cdk.qsar.result.DoubleResult in project ambit-mirror by ideaconsult.

the class DbDescriptorWriterTest method testWriteAllDescriptors.

@Test
public void testWriteAllDescriptors() throws Exception {
    setUpDatabaseFromResource("ambit2/db/processors/test/descriptors-datasets.xml");
    DbDescriptorWriter writer = new DbDescriptorWriter();
    IDatabaseConnection c = getConnection();
    ITable names = c.createQueryTable("EXPECTED_NAMES", "SELECT * FROM properties");
    Assert.assertEquals(5, names.getRowCount());
    writer.setConnection(c.getConnection());
    writer.open();
    XLogPDescriptor xlogp = new XLogPDescriptor();
    writer.write(xlogp.calculate(MoleculeFactory.makeAlkane(10)));
    DescriptorValue v = new DescriptorValue(new DescriptorSpecification("XLogPReference", "XLogPTitle", "XLogPIdentifier", "XLogPVendor"), new String[] {}, new Object[] {}, new DoubleResult(5), new String[] { "XLogP" });
    writer.write(xlogp.calculate(MoleculeFactory.makeAlkane(10)));
    writer.write(v);
    c.close();
    c = getConnection();
    names = c.createQueryTable("EXPECTED_NAMES", "SELECT * FROM properties");
    Assert.assertEquals(7, names.getRowCount());
    ITable values = c.createQueryTable("EXPECTED_VALUES", "SELECT * FROM property_values");
    Assert.assertEquals(2, values.getRowCount());
    c.close();
}
Also used : DbDescriptorWriter(ambit2.db.processors.DbDescriptorWriter) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DoubleResult(org.openscience.cdk.qsar.result.DoubleResult) DescriptorSpecification(org.openscience.cdk.qsar.DescriptorSpecification) XLogPDescriptor(org.openscience.cdk.qsar.descriptors.molecular.XLogPDescriptor) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) Test(org.junit.Test)

Example 3 with DoubleResult

use of org.openscience.cdk.qsar.result.DoubleResult in project ambit-mirror by ideaconsult.

the class RetrieveDescriptorTest method testGetObject.

@Test
public void testGetObject() throws Exception {
    setUpDatabaseFromResource(getTestDatabase());
    IDatabaseConnection c = getConnection();
    ITable names = c.createQueryTable("EXPECTED_DATASETS", "SELECT id,idproperty,idstructure,value_num as value,status,user_name FROM property_values where value_num is not null");
    Assert.assertEquals(4, names.getRowCount());
    QueryExecutor<RetrieveDescriptor> qe = new QueryExecutor<RetrieveDescriptor>();
    qe.setConnection(c.getConnection());
    ResultSet rs = qe.process((RetrieveDescriptor) query);
    int count = 0;
    while (rs.next()) {
        DescriptorValue value = query.getObject(rs);
        double d = ((DoubleResult) value.getValue()).doubleValue();
        String[] descrnames = value.getNames();
        for (String name : descrnames) {
            String sql = "SELECT value_num,name FROM properties join property_values using(idproperty) where name='" + name + "' and value_num=" + d;
            names = c.createQueryTable("EXPECTED_DATASETS", sql);
            Assert.assertEquals(1, names.getRowCount());
        }
        count++;
    }
    Assert.assertEquals(2, count);
    rs.close();
    qe.close();
    c.close();
}
Also used : RetrieveDescriptor(ambit2.db.readers.RetrieveDescriptor) QueryExecutor(ambit2.db.search.QueryExecutor) ResultSet(java.sql.ResultSet) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DoubleResult(org.openscience.cdk.qsar.result.DoubleResult) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) Test(org.junit.Test)

Example 4 with DoubleResult

use of org.openscience.cdk.qsar.result.DoubleResult in project ambit-mirror by ideaconsult.

the class MolecularWeight method calculate.

/**
 * Calculate the weight of specified element type in the supplied
 * {@link IAtomContainer}.
 *
 * @param container
 *            The AtomContainer for which this descriptor is to be
 *            calculated. If 'H' is specified as the element symbol make
 *            sure that the AtomContainer has hydrogens.
 * @return The total weight of atoms of the specified element type
 */
public DescriptorValue calculate(IAtomContainer container) {
    double weight = 0;
    if (elementName.equals("*")) {
        try {
            for (int i = 0; i < container.getAtomCount(); i++) {
                // logger.debug("WEIGHT: "+container.getAtomAt(i).getSymbol()
                // +" " +IsotopeFactory.getInstance().getMajorIsotope(
                // container.getAtomAt(i).getSymbol() ).getExactMass());
                weight += IsotopeFactory.getInstance(container.getBuilder()).getMajorIsotope(container.getAtom(i).getSymbol()).getExactMass();
                /*
					 * //Integer hcount =
					 * container.getAtom(i).getHydrogenCount();
					 * https://sourceforge
					 * .net/tracker/?func=detail&aid=3020065&group_id
					 * =20024&atid=120024
					 */
                Integer hcount = container.getAtom(i).getImplicitHydrogenCount();
                if (hcount == CDKConstants.UNSET)
                    hcount = 0;
                weight += (hcount * 1.00782504);
            }
        } catch (Exception e) {
            return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new DoubleResult(weight), getDescriptorNames(), e);
        }
    } else if (elementName.equals("H")) {
        try {
            IsotopeFactory factory = ambit2.descriptors.IsotopeFactory.getInstance(container.getBuilder());
            IIsotope h = factory.getMajorIsotope("H");
            for (int i = 0; i < container.getAtomCount(); i++) {
                if (container.getAtom(i).getSymbol().equals(elementName)) {
                    weight += factory.getMajorIsotope(container.getAtom(i).getSymbol()).getExactMass();
                } else {
                    /*
						 * https://sourceforge.net/tracker/?func=detail&aid=3020065
						 * &group_id=20024&atid=120024 weight +=
						 * (container.getAtom(i).getHydrogenCount() *
						 * h.getExactMass());
						 */
                    weight += (container.getAtom(i).getImplicitHydrogenCount() * h.getExactMass());
                }
            }
        } catch (Exception e) {
            return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new DoubleResult(weight), getDescriptorNames(), e);
        }
    } else {
        try {
            for (int i = 0; i < container.getAtomCount(); i++) {
                if (container.getAtom(i).getSymbol().equals(elementName)) {
                    weight += IsotopeFactory.getInstance(container.getBuilder()).getMajorIsotope(container.getAtom(i).getSymbol()).getExactMass();
                }
            }
        } catch (Exception e) {
            return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new DoubleResult(weight), getDescriptorNames(), e);
        }
    }
    return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new DoubleResult(weight), getDescriptorNames());
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) DoubleResult(org.openscience.cdk.qsar.result.DoubleResult) CDKException(org.openscience.cdk.exception.CDKException) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue)

Example 5 with DoubleResult

use of org.openscience.cdk.qsar.result.DoubleResult 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)

Aggregations

DoubleResult (org.openscience.cdk.qsar.result.DoubleResult)222 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)172 Test (org.junit.Test)162 SmilesParser (org.openscience.cdk.smiles.SmilesParser)91 DescriptorValue (org.openscience.cdk.qsar.DescriptorValue)64 IAtom (org.openscience.cdk.interfaces.IAtom)62 SlowTest (org.openscience.cdk.test.SlowTest)53 Category (org.junit.experimental.categories.Category)52 IAtomicDescriptor (org.openscience.cdk.qsar.IAtomicDescriptor)48 CDKException (org.openscience.cdk.exception.CDKException)41 LonePairElectronChecker (org.openscience.cdk.tools.LonePairElectronChecker)29 IAtomType (org.openscience.cdk.interfaces.IAtomType)13 IDescriptorResult (org.openscience.cdk.qsar.result.IDescriptorResult)12 DoubleArrayResult (org.openscience.cdk.qsar.result.DoubleArrayResult)11 IBond (org.openscience.cdk.interfaces.IBond)8 Atom (org.openscience.cdk.Atom)7 Order (org.openscience.cdk.interfaces.IBond.Order)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)5 JPlogPDescriptor (org.openscience.cdk.qsar.descriptors.molecular.JPlogPDescriptor)5