Search in sources :

Example 1 with WeightDescriptor

use of org.openscience.cdk.qsar.descriptors.molecular.WeightDescriptor 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 2 with WeightDescriptor

use of org.openscience.cdk.qsar.descriptors.molecular.WeightDescriptor in project cdk by cdk.

the class QSARCMLRoundTripTest method testQSARCustomization.

@Test
public void testQSARCustomization() throws Exception {
    StringWriter writer = new StringWriter();
    IAtomContainer molecule = TestMoleculeFactory.makeBenzene();
    IMolecularDescriptor descriptor = new WeightDescriptor();
    CMLWriter cmlWriter = new CMLWriter(writer);
    // not needed QSARCustomizer is on by default
    // convertor.registerCustomizer(new QSARCustomizer());
    DescriptorValue value = descriptor.calculate(molecule);
    molecule.setProperty(value.getSpecification(), value);
    cmlWriter.write(molecule);
    String cmlContent = writer.toString();
    logger.debug("****************************** testQSARCustomization()");
    logger.debug(cmlContent);
    logger.debug("******************************");
    Assert.assertTrue(cmlContent.contains("<property") && cmlContent.contains("xmlns:qsar"));
    Assert.assertTrue(cmlContent.contains("#weight\""));
}
Also used : WeightDescriptor(org.openscience.cdk.qsar.descriptors.molecular.WeightDescriptor) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) StringWriter(java.io.StringWriter) IMolecularDescriptor(org.openscience.cdk.qsar.IMolecularDescriptor) CMLWriter(org.openscience.cdk.io.CMLWriter) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) Test(org.junit.Test)

Example 3 with WeightDescriptor

use of org.openscience.cdk.qsar.descriptors.molecular.WeightDescriptor in project cdk by cdk.

the class QSARCMLRoundTripTest method testDescriptorValue_QSAR.

@Test
public void testDescriptorValue_QSAR() throws Exception {
    IAtomContainer molecule = TestMoleculeFactory.makeBenzene();
    IMolecularDescriptor descriptor = new WeightDescriptor();
    DescriptorValue originalValue;
    originalValue = descriptor.calculate(molecule);
    molecule.setProperty(originalValue.getSpecification(), originalValue);
    IAtomContainer roundTrippedMol = roundTripMolecule(convertor, molecule);
    Assert.assertEquals(1, roundTrippedMol.getProperties().size());
    Object object = roundTrippedMol.getProperties().keySet().toArray()[0];
    Assert.assertTrue(object instanceof DescriptorSpecification);
    DescriptorSpecification spec = (DescriptorSpecification) object;
    Assert.assertEquals(descriptor.getSpecification().getSpecificationReference(), spec.getSpecificationReference());
    Assert.assertEquals(descriptor.getSpecification().getImplementationIdentifier(), spec.getImplementationIdentifier());
    Assert.assertEquals(descriptor.getSpecification().getImplementationTitle(), spec.getImplementationTitle());
    Assert.assertEquals(descriptor.getSpecification().getImplementationVendor(), spec.getImplementationVendor());
    Object value = roundTrippedMol.getProperty(spec);
    Assert.assertNotNull(value);
    Assert.assertTrue(value instanceof DescriptorValue);
    DescriptorValue descriptorResult = (DescriptorValue) value;
    Assert.assertEquals(originalValue.getClass().getName(), descriptorResult.getClass().getName());
    Assert.assertEquals(originalValue.getValue().toString(), descriptorResult.getValue().toString());
}
Also used : WeightDescriptor(org.openscience.cdk.qsar.descriptors.molecular.WeightDescriptor) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IMolecularDescriptor(org.openscience.cdk.qsar.IMolecularDescriptor) DescriptorSpecification(org.openscience.cdk.qsar.DescriptorSpecification) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 DescriptorValue (org.openscience.cdk.qsar.DescriptorValue)3 WeightDescriptor (org.openscience.cdk.qsar.descriptors.molecular.WeightDescriptor)3 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)2 IMolecularDescriptor (org.openscience.cdk.qsar.IMolecularDescriptor)2 StructureRecord (ambit2.base.data.StructureRecord)1 IStructureRecord (ambit2.base.interfaces.IStructureRecord)1 StringWriter (java.io.StringWriter)1 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)1 ITable (org.dbunit.dataset.ITable)1 CMLWriter (org.openscience.cdk.io.CMLWriter)1 DescriptorSpecification (org.openscience.cdk.qsar.DescriptorSpecification)1