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();
}
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\""));
}
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());
}
Aggregations