use of org.openscience.cdk.ChemModel in project cdk by cdk.
the class AbstractReaderFactoryTest method expectReader.
void expectReader(String filename, IResourceFormat expectedFormat, int expectedAtomCount, int expectedBondCount) 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);
assertAtomCount(expectedAtomCount, chemObject);
assertBondCount(expectedBondCount, chemObject);
read = true;
}
}
if (read) {
// ok, reseting worked
} else {
Assert.fail("Reading an IChemObject from the Reader did not work properly.");
}
}
use of org.openscience.cdk.ChemModel in project cdk by cdk.
the class MDLRXNReaderTest method testRDFModel.
/**
*/
@Test
public void testRDFModel() throws Exception {
String filename = "qsar-reaction-test.rdf";
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getResourceAsStream(filename);
MDLRXNReader reader = new MDLRXNReader(ins);
IChemModel chemModel = reader.read(new ChemModel());
reader.close();
Assert.assertNotNull(chemModel);
Assert.assertEquals(2, chemModel.getReactionSet().getReactionCount());
Assert.assertEquals(2, chemModel.getReactionSet().getReaction(0).getReactantCount());
Assert.assertEquals(3, chemModel.getReactionSet().getReaction(0).getReactants().getAtomContainer(0).getAtomCount());
Assert.assertEquals(2, chemModel.getReactionSet().getReaction(0).getReactants().getAtomContainer(1).getAtomCount());
Assert.assertEquals(2, chemModel.getReactionSet().getReaction(0).getProductCount());
Assert.assertEquals(2, chemModel.getReactionSet().getReaction(0).getProducts().getAtomContainer(0).getAtomCount());
Assert.assertEquals(2, chemModel.getReactionSet().getReaction(0).getProducts().getAtomContainer(1).getAtomCount());
Assert.assertEquals(1, chemModel.getReactionSet().getReaction(1).getReactantCount());
Assert.assertEquals(3, chemModel.getReactionSet().getReaction(1).getReactants().getAtomContainer(0).getAtomCount());
Assert.assertEquals(1, chemModel.getReactionSet().getReaction(1).getProductCount());
Assert.assertEquals(2, chemModel.getReactionSet().getReaction(1).getProducts().getAtomContainer(0).getAtomCount());
}
use of org.openscience.cdk.ChemModel in project cdk by cdk.
the class ChemFileManipulatorTest method setUp.
@Before
public void setUp() {
molecule1 = new AtomContainer();
atomInMol1 = new Atom("Cl");
molecule1.addAtom(atomInMol1);
molecule1.addAtom(new Atom("Cl"));
bondInMol1 = new Bond(atomInMol1, molecule1.getAtom(1));
molecule1.addBond(bondInMol1);
molecule2 = new AtomContainer();
atomInMol2 = new Atom("O");
atomInMol2.setImplicitHydrogenCount(2);
molecule2.addAtom(atomInMol2);
moleculeSet = new AtomContainerSet();
moleculeSet.addAtomContainer(molecule1);
moleculeSet.addAtomContainer(molecule2);
reaction = new Reaction();
reaction.addReactant(molecule1);
reaction.addProduct(molecule2);
reactionSet = new ReactionSet();
reactionSet.addReaction(reaction);
chemModel = new ChemModel();
chemModel.setMoleculeSet(moleculeSet);
chemModel.setReactionSet(reactionSet);
chemSequence1 = new ChemSequence();
chemSequence1.addChemModel(chemModel);
chemSequence2 = new ChemSequence();
chemFile = new ChemFile();
chemFile.addChemSequence(chemSequence1);
chemFile.addChemSequence(chemSequence2);
}
use of org.openscience.cdk.ChemModel in project cdk by cdk.
the class ChemModelManipulatorTest method testRemoveAtomAndConnectedElectronContainers_IChemModel_IAtom.
@Test
public void testRemoveAtomAndConnectedElectronContainers_IChemModel_IAtom() {
IAtomContainer mol1 = new AtomContainer();
IAtom atom1 = new Atom("Cl");
mol1.addAtom(atom1);
mol1.addAtom(new Atom("Cl"));
IBond bond1 = new Bond(mol1.getAtom(0), mol1.getAtom(1));
mol1.addBond(bond1);
IAtomContainer mol2 = new AtomContainer();
IAtom atom2 = new Atom("I");
mol2.addAtom(atom2);
mol2.addAtom(new Atom("I"));
IBond bond2 = new Bond(mol2.getAtom(0), mol2.getAtom(1));
mol2.addBond(bond2);
IAtomContainerSet molSet = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class);
molSet.addAtomContainer(mol1);
IReaction r = new Reaction();
r.addProduct(mol2);
IReactionSet rSet = new ReactionSet();
rSet.addReaction(r);
IChemModel model = new ChemModel();
model.setMoleculeSet(molSet);
model.setReactionSet(rSet);
IAtom otherAtom = new Atom("Cl");
Assert.assertEquals(2, ChemModelManipulator.getBondCount(model));
Assert.assertEquals(4, ChemModelManipulator.getAtomCount(model));
ChemModelManipulator.removeAtomAndConnectedElectronContainers(model, otherAtom);
Assert.assertEquals(2, ChemModelManipulator.getBondCount(model));
Assert.assertEquals(4, ChemModelManipulator.getAtomCount(model));
ChemModelManipulator.removeAtomAndConnectedElectronContainers(model, atom1);
Assert.assertEquals(1, ChemModelManipulator.getBondCount(model));
Assert.assertEquals(3, ChemModelManipulator.getAtomCount(model));
ChemModelManipulator.removeAtomAndConnectedElectronContainers(model, atom2);
Assert.assertEquals(0, ChemModelManipulator.getBondCount(model));
Assert.assertEquals(2, ChemModelManipulator.getAtomCount(model));
}
use of org.openscience.cdk.ChemModel in project cdk by cdk.
the class ChemModelManipulatorTest method testGetAllAtomContainers_IChemModel_WithReactions.
@Test
public void testGetAllAtomContainers_IChemModel_WithReactions() throws Exception {
String filename = "0024.stg02.rxn";
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getResourceAsStream(filename);
MDLRXNV2000Reader reader = new MDLRXNV2000Reader(ins, Mode.STRICT);
ChemModel chemFile = (ChemModel) reader.read((ChemObject) new ChemModel());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemModelManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(2, containersList.size());
}
Aggregations