use of ambit2.core.processors.structure.MoleculeReader in project ambit-mirror by ideaconsult.
the class CompoundJSONReporter method getSDFContent.
protected String getSDFContent(IStructureRecord item) throws AmbitException {
// most common case
if (MOL_TYPE.SDF.toString().equals(item.getFormat()))
return item.getContent();
// otherwise
if (reader == null)
reader = new MoleculeReader();
try {
StringWriter w = new StringWriter();
SDFWriter sdfwriter = new SDFWriter(w);
IAtomContainer ac = reader.process(item);
MoleculeTools.clearProperties(ac);
sdfwriter.write(ac);
sdfwriter.close();
return w.toString();
} catch (Exception x) {
throw new AmbitException(x);
}
}
use of ambit2.core.processors.structure.MoleculeReader in project ambit-mirror by ideaconsult.
the class CallableFingerprintsModelCreator method createProcessors.
protected ProcessorsChain<IStructureRecord, IBatchStatistics, IProcessor> createProcessors() throws Exception {
ProcessorsChain<IStructureRecord, IBatchStatistics, IProcessor> p1 = new ProcessorsChain<IStructureRecord, IBatchStatistics, IProcessor>();
p1.add(new ProcessorStructureRetrieval());
p1.add(new MoleculeReader());
p1.add(new FingerprintGenerator(new Fingerprinter()));
p1.add(new DefaultAmbitProcessor<BitSet, BitSet>() {
/**
*/
private static final long serialVersionUID = -2978697147490545478L;
public BitSet process(BitSet target) throws AmbitException {
builder.getTrainingData().add(target);
return target;
}
});
p1.setAbortOnError(true);
return p1;
}
use of ambit2.core.processors.structure.MoleculeReader in project ambit-mirror by ideaconsult.
the class FingerPrintGeneratorTest method test.
@Test
public void test() throws Exception {
BigInteger[] expected = /*{
new BigInteger("1126174803623952"),
new BigInteger("1152961362175993860"),
new BigInteger("2305843011903291728"),
new BigInteger("25769820160"),
new BigInteger("1099511627776"),
new BigInteger("33554496"),
new BigInteger("8864814662912"),
new BigInteger("4803285265416200"),
new BigInteger("9223372050830336000"),
new BigInteger("2454675102173515776"),
new BigInteger("1152921504611041536"),
new BigInteger("155684661740175875"),
new BigInteger("6917529131798265856"),
new BigInteger("310748377023266816"),
new BigInteger("67110400"),
new BigInteger("2305843009213710336")};
*/
{ new BigInteger("576462128137896992"), new BigInteger("10376293541473171584"), new BigInteger("2305843009214747777"), new BigInteger("72127962782121984"), new BigInteger("52776558133248"), new BigInteger("0"), new BigInteger("338649581355264"), new BigInteger("4366794756"), new BigInteger("17730770043904"), new BigInteger("2314887591865356288"), new BigInteger("2305844109263241488"), new BigInteger("2400709834665132544"), new BigInteger("13835058125075449856"), new BigInteger("10741891072"), new BigInteger("9007208196998144"), new BigInteger("18014398511644672") };
MoleculeReader molreader = new MoleculeReader();
FingerprintGenerator gen = new FingerprintGenerator(new Fingerprinter());
InputStream in = FingerPrintGeneratorTest.class.getClassLoader().getResourceAsStream("ambit2/core/data/fp/fptest.mol");
RawIteratingSDFReader reader = new RawIteratingSDFReader(new InputStreamReader(in));
while (reader.hasNext()) {
IStructureRecord record = reader.nextRecord();
BitSet bs1 = gen.process(molreader.process(record));
BigInteger[] h16 = new BigInteger[16];
MoleculeTools.bitset2bigint16(bs1, 64, h16);
new Random(10000);
BitSet bs2 = gen.process(molreader.process(record));
Assert.assertEquals(bs1, bs2);
MoleculeTools.bitset2bigint16(bs2, 64, h16);
for (int i = 0; i < 16; i++) {
Assert.assertEquals(expected[i], h16[i]);
}
}
/*
IStructureRecord record = new StructureRecord();
record.setContent();
MoleculeReader reader = new MoleculeReader();
reader.process(target)
*/
}
use of ambit2.core.processors.structure.MoleculeReader in project ambit-mirror by ideaconsult.
the class RawIteratingWrapperTest method testCSVReader.
@Test
public void testCSVReader() throws Exception {
RawIteratingCSVReader reader = new RawIteratingCSVReader(new InputStreamReader(RawIteratingWrapperTest.class.getClassLoader().getResourceAsStream("ambit2/core/data/io/test.txt")), CSVFormat.TDF);
MoleculeReader molreader = new MoleculeReader();
try {
int count = 0;
while (reader.hasNext()) {
IStructureRecord record = reader.nextRecord();
if (record.getSmiles() != null && record.getInchi() != null) {
Assert.assertNotNull(record.getContent());
Assert.assertNotNull(record.getSmiles());
Assert.assertNotNull(record.getInchi());
Assert.assertNotNull(record.getInchiKey());
}
Object o = reader.next();
Assert.assertNotNull(o);
Assert.assertTrue(o instanceof IStructureRecord);
IAtomContainer mol = molreader.process((IStructureRecord) o);
if (record.getSmiles() != null && !"".equals(record.getSmiles()))
Assert.assertTrue(String.format("Atoms %d", mol.getAtomCount()), mol.getAtomCount() > 0);
count++;
}
Assert.assertEquals(11, count);
} finally {
reader.close();
}
}
use of ambit2.core.processors.structure.MoleculeReader in project ambit-mirror by ideaconsult.
the class SDFReporter method getSDFContent.
protected String getSDFContent(IStructureRecord item) throws AmbitException {
// most common case
if (MOL_TYPE.SDF.toString().equals(item.getFormat())) {
if (isChangeLineSeparators())
return item.getContent().replaceAll(ux, wlinesep);
else
return item.getContent();
}
// otherwise
if (reader == null)
reader = new MoleculeReader();
try {
StringWriter w = new StringWriter();
SDFWriter sdfwriter = new SDFWriter(w);
IAtomContainer ac = reader.process(item);
// ac.getProperties().clear();
MoleculeTools.clearProperties(ac);
sdfwriter.write(ac);
sdfwriter.close();
if (isChangeLineSeparators())
return w.toString().replaceAll(ux, wlinesep);
else
return w.toString();
} catch (Exception x) {
throw new AmbitException(x);
}
}
Aggregations