use of org.openscience.cdk.Reaction in project cdk by cdk.
the class ExtraReaderFactoryTest method expectReader.
void expectReader(String filename, IResourceFormat expectedFormat) throws Exception {
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
Assert.assertNotNull("Cannot find file: " + filename, ins);
if (expectedFormat instanceof IChemFormatMatcher) {
factory.registerFormat((IChemFormatMatcher) expectedFormat);
}
ISimpleChemObjectReader reader = factory.createReader(ins);
Assert.assertNotNull(reader);
Assert.assertEquals(((IChemFormat) expectedFormat).getReaderClassName(), reader.getClass().getName());
// now try reading something from it
IChemObject[] objects = { new ChemFile(), new ChemModel(), new AtomContainer(), new Reaction() };
boolean read = false;
for (int i = 0; (i < objects.length && !read); i++) {
if (reader.accepts(objects[i].getClass())) {
IChemObject chemObject = reader.read(objects[i]);
Assert.assertNotNull("Reader accepted a " + objects[i].getClass().getName() + " but failed to read it", chemObject);
read = true;
}
}
Assert.assertTrue("Reading an IChemObject from the Reader did not work properly.", read);
}
use of org.openscience.cdk.Reaction in project cdk by cdk.
the class MDLRXNV3000ReaderTest method testReadReactions1.
/**
* @cdk.bug 1849925
*/
@Test
public void testReadReactions1() throws Exception {
String filename1 = "reaction_v3.rxn";
logger.info("Testing: " + filename1);
InputStream ins1 = this.getClass().getResourceAsStream(filename1);
MDLRXNV3000Reader reader1 = new MDLRXNV3000Reader(ins1, Mode.STRICT);
IReaction reaction1 = new Reaction();
reaction1 = reader1.read(reaction1);
reader1.close();
Assert.assertNotNull(reaction1);
Assert.assertEquals(1, reaction1.getReactantCount());
Assert.assertEquals(1, reaction1.getProductCount());
IAtomContainer reactant = reaction1.getReactants().getAtomContainer(0);
Assert.assertNotNull(reactant);
Assert.assertEquals(32, reactant.getAtomCount());
Assert.assertEquals(29, reactant.getBondCount());
IAtomContainer product = reaction1.getProducts().getAtomContainer(0);
Assert.assertNotNull(product);
Assert.assertEquals(32, product.getAtomCount());
Assert.assertEquals(29, product.getBondCount());
}
use of org.openscience.cdk.Reaction in project cdk by cdk.
the class MDLRXNReaderTest method testReadReactions2.
@Test
public void testReadReactions2() throws Exception {
String filename2 = "reaction-2.rxn";
logger.info("Testing: " + filename2);
InputStream ins2 = this.getClass().getResourceAsStream(filename2);
MDLRXNReader reader2 = new MDLRXNReader(ins2);
IReaction reaction2 = new Reaction();
reaction2 = reader2.read(reaction2);
reader2.close();
Assert.assertNotNull(reaction2);
Assert.assertEquals(2, reaction2.getReactantCount());
Assert.assertEquals(2, reaction2.getProductCount());
}
use of org.openscience.cdk.Reaction in project cdk by cdk.
the class MDLRXNReaderTest method testReadReactions1.
@Test
public void testReadReactions1() throws Exception {
String filename1 = "reaction-1.rxn";
logger.info("Testing: " + filename1);
InputStream ins1 = this.getClass().getResourceAsStream(filename1);
MDLRXNReader reader1 = new MDLRXNReader(ins1);
IReaction reaction1 = new Reaction();
reaction1 = reader1.read(reaction1);
reader1.close();
Assert.assertNotNull(reaction1);
Assert.assertEquals(2, reaction1.getReactantCount());
Assert.assertEquals(1, reaction1.getProductCount());
IAtomContainerSet educts = reaction1.getReactants();
// Check Atom symbols of first educt
String[] atomSymbolsOfEduct1 = { "C", "C", "O", "Cl" };
for (int i = 0; i < educts.getAtomContainer(0).getAtomCount(); i++) {
Assert.assertEquals(atomSymbolsOfEduct1[i], educts.getAtomContainer(0).getAtom(i).getSymbol());
}
// Check Atom symbols of second educt
for (int i = 0; i < educts.getAtomContainer(1).getAtomCount(); i++) {
Assert.assertEquals("C", educts.getAtomContainer(1).getAtom(i).getSymbol());
}
// Check Atom symbols of first product
IAtomContainerSet products = reaction1.getProducts();
String[] atomSymbolsOfProduct1 = { "C", "C", "C", "C", "C", "C", "C", "O", "C" };
for (int i = 0; i < products.getAtomContainer(0).getAtomCount(); i++) {
Assert.assertEquals(atomSymbolsOfProduct1[i], products.getAtomContainer(0).getAtom(i).getSymbol());
}
}
use of org.openscience.cdk.Reaction in project cdk by cdk.
the class MDLRXNV2000ReaderTest method testAgentParts.
@Test
public void testAgentParts() throws Exception {
try (InputStream in = this.getClass().getResourceAsStream("ethylesterification.mol");
MDLRXNV2000Reader rdr = new MDLRXNV2000Reader(in)) {
IReaction reaction = rdr.read(new Reaction());
assertThat(reaction.getAgents().getAtomContainerCount(), is(1));
}
}
Aggregations