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