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