Search in sources :

Example 11 with ChemModel

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.");
    }
}
Also used : IChemFormatMatcher(org.openscience.cdk.io.formats.IChemFormatMatcher) IChemObject(org.openscience.cdk.interfaces.IChemObject) ChemModel(org.openscience.cdk.ChemModel) IChemModel(org.openscience.cdk.interfaces.IChemModel) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) InputStream(java.io.InputStream) IChemFile(org.openscience.cdk.interfaces.IChemFile) ChemFile(org.openscience.cdk.ChemFile) Reaction(org.openscience.cdk.Reaction) IReaction(org.openscience.cdk.interfaces.IReaction)

Example 12 with ChemModel

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());
}
Also used : ChemModel(org.openscience.cdk.ChemModel) IChemModel(org.openscience.cdk.interfaces.IChemModel) InputStream(java.io.InputStream) IChemModel(org.openscience.cdk.interfaces.IChemModel) SimpleChemObjectReaderTest(org.openscience.cdk.test.io.SimpleChemObjectReaderTest) Test(org.junit.Test)

Example 13 with ChemModel

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);
}
Also used : ChemSequence(org.openscience.cdk.ChemSequence) IChemSequence(org.openscience.cdk.interfaces.IChemSequence) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) ReactionSet(org.openscience.cdk.ReactionSet) ChemModel(org.openscience.cdk.ChemModel) IChemModel(org.openscience.cdk.interfaces.IChemModel) ChemFile(org.openscience.cdk.ChemFile) IChemFile(org.openscience.cdk.interfaces.IChemFile) Bond(org.openscience.cdk.Bond) IBond(org.openscience.cdk.interfaces.IBond) Reaction(org.openscience.cdk.Reaction) IReaction(org.openscience.cdk.interfaces.IReaction) IAtom(org.openscience.cdk.interfaces.IAtom) Atom(org.openscience.cdk.Atom) AtomContainerSet(org.openscience.cdk.AtomContainerSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) Before(org.junit.Before)

Example 14 with ChemModel

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));
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) IBond(org.openscience.cdk.interfaces.IBond) IChemModel(org.openscience.cdk.interfaces.IChemModel) Reaction(org.openscience.cdk.Reaction) IReaction(org.openscience.cdk.interfaces.IReaction) IAtom(org.openscience.cdk.interfaces.IAtom) Atom(org.openscience.cdk.Atom) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) ReactionSet(org.openscience.cdk.ReactionSet) ChemModel(org.openscience.cdk.ChemModel) IChemModel(org.openscience.cdk.interfaces.IChemModel) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IReaction(org.openscience.cdk.interfaces.IReaction) Bond(org.openscience.cdk.Bond) IBond(org.openscience.cdk.interfaces.IBond) IAtom(org.openscience.cdk.interfaces.IAtom) Test(org.junit.Test)

Example 15 with ChemModel

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());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ChemModel(org.openscience.cdk.ChemModel) IChemModel(org.openscience.cdk.interfaces.IChemModel) ChemObject(org.openscience.cdk.ChemObject) IChemObject(org.openscience.cdk.interfaces.IChemObject) InputStream(java.io.InputStream) MDLRXNV2000Reader(org.openscience.cdk.io.MDLRXNV2000Reader) Test(org.junit.Test)

Aggregations

ChemModel (org.openscience.cdk.ChemModel)16 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)12 IChemModel (org.openscience.cdk.interfaces.IChemModel)12 AtomContainer (org.openscience.cdk.AtomContainer)10 Test (org.junit.Test)9 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)9 Reaction (org.openscience.cdk.Reaction)8 InputStream (java.io.InputStream)6 IReaction (org.openscience.cdk.interfaces.IReaction)6 Atom (org.openscience.cdk.Atom)5 Bond (org.openscience.cdk.Bond)5 ChemFile (org.openscience.cdk.ChemFile)5 ReactionSet (org.openscience.cdk.ReactionSet)5 IAtom (org.openscience.cdk.interfaces.IAtom)5 IBond (org.openscience.cdk.interfaces.IBond)5 IChemObject (org.openscience.cdk.interfaces.IChemObject)5 IReactionSet (org.openscience.cdk.interfaces.IReactionSet)5 AtomContainerSet (org.openscience.cdk.AtomContainerSet)4 Before (org.junit.Before)3 ChemObject (org.openscience.cdk.ChemObject)3