use of ambit2.core.io.InteractiveIteratingMDLReader in project ambit-mirror by ideaconsult.
the class DataSet method getReader.
public static IIteratingChemObjectReader<IAtomContainer> getReader(InputStream in, String extension) throws CDKException, AmbitIOException {
FileInputState instate = new FileInputState();
IIteratingChemObjectReader<IAtomContainer> reader;
if (extension.endsWith(FileInputState._FILE_TYPE.SDF_INDEX.getExtension())) {
reader = new InteractiveIteratingMDLReader(in, SilentChemObjectBuilder.getInstance());
((InteractiveIteratingMDLReader) reader).setSkip(true);
} else
reader = instate.getReader(in, extension);
reader.setReaderMode(Mode.RELAXED);
reader.setErrorHandler(new IChemObjectReaderErrorHandler() {
@Override
public void handleError(String message, int row, int colStart, int colEnd, Exception exception) {
exception.printStackTrace();
}
@Override
public void handleError(String message, int row, int colStart, int colEnd) {
System.out.println(message);
}
@Override
public void handleError(String message, Exception exception) {
exception.printStackTrace();
}
@Override
public void handleError(String message) {
System.out.println(message);
}
});
return reader;
}
use of ambit2.core.io.InteractiveIteratingMDLReader in project ambit-mirror by ideaconsult.
the class SLNCli method getReader.
public IIteratingChemObjectReader<IAtomContainer> getReader(InputStream in, String extension) throws CDKException, AmbitIOException {
FileInputState instate = new FileInputState();
IIteratingChemObjectReader<IAtomContainer> reader;
if (extension.endsWith(FileInputState._FILE_TYPE.SDF_INDEX.getExtension())) {
reader = new InteractiveIteratingMDLReader(in, SilentChemObjectBuilder.getInstance());
((InteractiveIteratingMDLReader) reader).setSkip(true);
} else
reader = instate.getReader(in, extension);
reader.setReaderMode(Mode.RELAXED);
reader.setErrorHandler(new IChemObjectReaderErrorHandler() {
@Override
public void handleError(String message, int row, int colStart, int colEnd, Exception exception) {
exception.printStackTrace();
}
@Override
public void handleError(String message, int row, int colStart, int colEnd) {
System.out.println(message);
}
@Override
public void handleError(String message, Exception exception) {
exception.printStackTrace();
}
@Override
public void handleError(String message) {
System.out.println(message);
}
});
return reader;
}
use of ambit2.core.io.InteractiveIteratingMDLReader in project ambit-mirror by ideaconsult.
the class ListenerTest method testListenerSDF.
@Test
public void testListenerSDF() throws Exception {
IIteratingChemObjectReader reader = new InteractiveIteratingMDLReader(getClass().getClassLoader().getResourceAsStream("test_properties.sdf"), DefaultChemObjectBuilder.getInstance(), true);
String[] labels = { "ID", "SMILES", "WEIGHT", "FORMULA", "NAME", "Drug" };
readFile(reader, labels);
reader.close();
}
use of ambit2.core.io.InteractiveIteratingMDLReader in project ambit-mirror by ideaconsult.
the class ParserTest method testStereo.
public void testStereo(SmilesGenerator g) throws Exception {
SmilesParser p = new SmilesParser(SilentChemObjectBuilder.getInstance());
InChIGeneratorFactory factory = InChIGeneratorFactory.getInstance();
IIteratingChemObjectReader<IAtomContainer> reader = null;
int error = 0;
try {
InputStream in = ParserTest.class.getClassLoader().getResourceAsStream("ambit2/dbcli/test/stereo.sdf");
Assert.assertNotNull(in);
reader = new InteractiveIteratingMDLReader(in, SilentChemObjectBuilder.getInstance());
Assert.assertNotNull(reader);
StructureStandardizer standardizer = new StructureStandardizer();
standardizer.setGenerateSMILES(true);
standardizer.setGenerateSMILES_Canonical(false);
standardizer.setNeutralise(true);
standardizer.setSplitFragments(true);
standardizer.setGenerateTautomers(false);
standardizer.setImplicitHydrogens(true);
standardizer.setClearIsotopes(true);
while (reader.hasNext()) {
IAtomContainer m1 = reader.next();
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(m1);
try {
String smi = g.create(m1);
IAtomContainer m2 = p.parseSmiles(smi);
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(m2);
String newsmiles = g.create(m2);
Assert.assertEquals(smi, newsmiles);
InChIGenerator gen1 = factory.getInChIGenerator(m1);
InChIGenerator gen2 = factory.getInChIGenerator(m2);
Assert.assertEquals(gen1.getInchi(), gen2.getInchi());
Assert.assertEquals(gen1.getInchiKey(), gen2.getInchiKey());
Assert.assertEquals(g.create(m1), g.create(m2));
System.out.println(smi);
printstereo(m1);
System.out.println(newsmiles);
printstereo(m2);
IAtomContainer m1_transformed = standardizer.process(m1);
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(m1_transformed);
IAtomContainer m2_transformed = standardizer.process(m2);
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(m2_transformed);
System.out.println(g.create(m1_transformed));
printstereo(m1_transformed);
System.out.println(g.create(m2_transformed));
printstereo(m2_transformed);
gen1 = factory.getInChIGenerator(m1_transformed);
gen2 = factory.getInChIGenerator(m2_transformed);
Assert.assertEquals(gen1.getInchi(), gen2.getInchi());
Assert.assertEquals(gen1.getInchiKey(), gen2.getInchiKey());
} catch (Exception x) {
error++;
System.out.println(x.getMessage());
}
}
} finally {
if (reader != null)
reader.close();
}
Assert.assertEquals(0, error);
}
use of ambit2.core.io.InteractiveIteratingMDLReader in project ambit-mirror by ideaconsult.
the class StandardisationTest method test_xv5_sh.
@Test
public void test_xv5_sh() throws Exception {
try (InputStream in = getClass().getClassLoader().getResourceAsStream("ambit2/dbcli/test/xv5.sdf")) {
// IteratingSDFReader reader = new IteratingSDFReader(in,
// SilentChemObjectBuilder.getInstance());
InteractiveIteratingMDLReader reader = new InteractiveIteratingMDLReader(in, SilentChemObjectBuilder.getInstance());
StructureStandardizer z = new StructureStandardizer();
z.setImplicitHydrogens(true);
z.setNeutralise(false);
z.setGenerateTautomers(false);
z.setGenerateSMILES(true);
z.setGenerateSMILES_Canonical(false);
z.setGenerateSMILES_Aromatic(false);
z.setSplitFragments(false);
z.setClearIsotopes(true);
z.setGenerateInChI(true);
CDKHydrogenAdder h = CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance());
while (reader.hasNext()) {
IAtomContainer mol = reader.next();
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
h.addImplicitHydrogens(mol);
System.out.println(SmilesGenerator.generic().create(mol));
mol = z.process(mol);
// mol = AtomContainerManipulator.suppressHydrogens(mol);
// System.out.println(SmilesGenerator.generic().create(mol));
System.out.println(mol.getProperties().get(Property.getSMILESInstance()));
}
}
}
Aggregations