Search in sources :

Example 1 with DescriptorValue

use of org.openscience.cdk.qsar.DescriptorValue in project MetFragRelaunched by ipb-halle.

the class LinearRetentionTimeModel method calculateXLogpValues.

/**
 * @param inchis
 * @return
 */
public Double[] calculateXLogpValues(java.util.ArrayList<String> inchis) {
    Double[] values = new Double[inchis.size()];
    if (this.xlogp == null)
        return values;
    try {
        for (int i = 0; i < inchis.size(); i++) {
            DescriptorValue value = null;
            boolean calculated = false;
            int trials = 0;
            while (!calculated) {
                try {
                    trials++;
                    value = this.xlogp.calculate(MoleculeFunctions.getAtomContainerFromInChI(inchis.get(i)));
                } catch (Exception e) {
                    if (trials == 10) {
                        break;
                    }
                    continue;
                }
                calculated = true;
            }
            if (value != null) {
                IDescriptorResult result = value.getValue();
                values[i] = Double.parseDouble(result.toString());
            } else
                values[i] = null;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return values;
}
Also used : IDescriptorResult(org.openscience.cdk.qsar.result.IDescriptorResult) CDKException(org.openscience.cdk.exception.CDKException) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue)

Example 2 with DescriptorValue

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

the class DbDescriptorValuesWriterTest method testWriteMultipleValues.

/**
 * Multiple values with the same name for a given structure are not allowed.
 *
 * @throws Exception
 */
@Test
public void testWriteMultipleValues() 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 join properties using(idproperty)");
    Assert.assertEquals(2, values.getRowCount());
    writer.setConnection(c.getConnection());
    writer.open();
    WeightDescriptor xlogp = new WeightDescriptor();
    writer.setStructure(new StructureRecord(7, 100211, "", ""));
    DescriptorValue value = xlogp.calculate(MoleculeFactory.makeBenzene());
    Assert.assertEquals(72.0, ((DoubleResult) value.getValue()).doubleValue(), 1E-4);
    writer.write(value);
    names = c.createQueryTable("EXPECTED_NAMES", "SELECT * FROM properties");
    Assert.assertEquals(6, names.getRowCount());
    values = c.createQueryTable("EXPECTED_VALUES", "SELECT * FROM property_values join properties using(idproperty) WHERE abs(value_num-72)<1E-4");
    Assert.assertEquals(1, values.getRowCount());
    values = c.createQueryTable("EXPECTED_VALUES", "SELECT * FROM property_values join properties using(idproperty) WHERE abs(value_num-144)<1E-4");
    Assert.assertEquals(0, values.getRowCount());
    value = xlogp.calculate(MoleculeFactory.makeAlkane(12));
    Assert.assertEquals(144.0, ((DoubleResult) value.getValue()).doubleValue(), 1E-4);
    writer.write(value);
    values = c.createQueryTable("EXPECTED_VALUES", "SELECT * FROM property_values join properties using(idproperty) WHERE abs(value_num-144)<1E-4");
    Assert.assertEquals(1, values.getRowCount());
    values = c.createQueryTable("EXPECTED_VALUES", "SELECT * FROM property_values join properties using(idproperty) WHERE abs(value_num-72)<1E-4");
    Assert.assertEquals(0, values.getRowCount());
    c.close();
}
Also used : WeightDescriptor(org.openscience.cdk.qsar.descriptors.molecular.WeightDescriptor) StructureRecord(ambit2.base.data.StructureRecord) IStructureRecord(ambit2.base.interfaces.IStructureRecord) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) Test(org.junit.Test)

Example 3 with DescriptorValue

use of org.openscience.cdk.qsar.DescriptorValue 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 4 with DescriptorValue

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

the class DbDescriptorValuesWriterTest method testWriteDescriptorValueFromProfile.

/**
 * Test method for
 * {@link ambit2.db.processors.DbDescriptorWriter#write(org.openscience.cdk.qsar.DescriptorValue)}
 * .
 */
@Test
public void testWriteDescriptorValueFromProfile() 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 template_def = c.createQueryTable("EXPECTED_TEMPLATES", "SELECT * FROM template_def");
    Assert.assertEquals(3, template_def.getRowCount());
    ITable dictionary = c.createQueryTable("EXPECTED_ONTOLOGY", "SELECT * FROM dictionary");
    Assert.assertEquals(3, dictionary.getRowCount());
    writer.setConnection(c.getConnection());
    writer.open();
    writer.setStructure(new StructureRecord(7, 100211, "", ""));
    // 3D molecule
    IAtomContainer mol = getTestMolecule();
    HydrogenAdderProcessor h = new HydrogenAdderProcessor();
    h.setAddEexplicitHydrogens(false);
    mol = h.process(mol);
    DescriptorsFactory factory = new DescriptorsFactory();
    PropertyCalculationProcessor calc = new PropertyCalculationProcessor();
    Profile profile = factory.process(null);
    Iterator<Property> i = profile.getProperties(true);
    int count = 0;
    int countValues = 0;
    while (i.hasNext()) {
        try {
            Property p = i.next();
            // if (p.getClazz().getName().indexOf("ambit")>=0) {
            if (p.isEnabled()) {
                count++;
                calc.setProperty(i.next());
                DescriptorValue value = calc.process(mol);
                countValues += value.getNames().length;
                writer.write(value);
            }
        } catch (Exception x) {
            throw new Exception(x);
        }
    }
    names = c.createQueryTable("EXPECTED_NAMES", "SELECT * FROM properties");
    Assert.assertEquals(5 + countValues, names.getRowCount());
    values = c.createQueryTable("EXPECTED_VALUES", "SELECT * FROM property_values WHERE status ='OK' ");
    Assert.assertEquals(countValues, values.getRowCount());
    template_def = c.createQueryTable("EXPECTED_TEMPLATES", "SELECT type FROM catalog_references where type=\"Algorithm\"");
    Assert.assertEquals(4, template_def.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();
		 */
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) Profile(ambit2.base.data.Profile) PropertyCalculationProcessor(ambit2.descriptors.processors.PropertyCalculationProcessor) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) HydrogenAdderProcessor(ambit2.core.processors.structure.HydrogenAdderProcessor) StructureRecord(ambit2.base.data.StructureRecord) IStructureRecord(ambit2.base.interfaces.IStructureRecord) ITable(org.dbunit.dataset.ITable) DescriptorsFactory(ambit2.descriptors.processors.DescriptorsFactory) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Property(ambit2.base.data.Property) Test(org.junit.Test)

Example 5 with DescriptorValue

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

Aggregations

DescriptorValue (org.openscience.cdk.qsar.DescriptorValue)235 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)141 Test (org.junit.Test)89 CDKException (org.openscience.cdk.exception.CDKException)89 DoubleArrayResult (org.openscience.cdk.qsar.result.DoubleArrayResult)67 DoubleResult (org.openscience.cdk.qsar.result.DoubleResult)64 IAtom (org.openscience.cdk.interfaces.IAtom)59 IDescriptorResult (org.openscience.cdk.qsar.result.IDescriptorResult)28 SmilesParser (org.openscience.cdk.smiles.SmilesParser)27 IBond (org.openscience.cdk.interfaces.IBond)22 IntegerResult (org.openscience.cdk.qsar.result.IntegerResult)22 IAtomType (org.openscience.cdk.interfaces.IAtomType)20 ArrayList (java.util.ArrayList)18 InputStream (java.io.InputStream)14 IMolecularDescriptor (org.openscience.cdk.qsar.IMolecularDescriptor)14 CDKHydrogenAdder (org.openscience.cdk.tools.CDKHydrogenAdder)14 IntegerArrayResult (org.openscience.cdk.qsar.result.IntegerArrayResult)13 List (java.util.List)11 MDLV2000Reader (org.openscience.cdk.io.MDLV2000Reader)11 LonePairElectronChecker (org.openscience.cdk.tools.LonePairElectronChecker)11