Search in sources :

Example 21 with IChemModel

use of org.openscience.cdk.interfaces.IChemModel in project cdk by cdk.

the class AbstractChemModelTest method testIsEmpty_ReactionSet.

@Test
public void testIsEmpty_ReactionSet() {
    IChemModel model = (IChemModel) newChemObject();
    IChemObjectBuilder builder = model.getBuilder();
    IAtomContainer molecule = builder.newInstance(IAtomContainer.class);
    IReaction reaction = builder.newInstance(IReaction.class);
    reaction.addReactant(molecule);
    IReactionSet set = builder.newInstance(IReactionSet.class);
    model.setReactionSet(set);
    Assert.assertTrue("model has an empty reaction set and should be empty", model.isEmpty());
    set.addReaction(reaction);
    Assert.assertFalse("model has a reaction set and should not be empty", model.isEmpty());
    model.setReactionSet(null);
    Assert.assertTrue("model has no reaction set", model.isEmpty());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) IChemModel(org.openscience.cdk.interfaces.IChemModel) IReaction(org.openscience.cdk.interfaces.IReaction) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder) Test(org.junit.Test)

Example 22 with IChemModel

use of org.openscience.cdk.interfaces.IChemModel in project cdk by cdk.

the class AbstractChemModelTest method testIsEmpty_MoleculeSet.

@Test
public void testIsEmpty_MoleculeSet() {
    IChemModel chemModel = (IChemModel) newChemObject();
    IChemObjectBuilder builder = chemModel.getBuilder();
    Assert.assertNotNull(chemModel);
    Assert.assertTrue(chemModel.isEmpty());
    IAtom atom = builder.newInstance(IAtom.class);
    IAtomContainer mol = builder.newInstance(IAtomContainer.class);
    IAtomContainerSet mset = builder.newInstance(IAtomContainerSet.class);
    mol.addAtom(atom);
    mset.addAtomContainer(mol);
    chemModel.setMoleculeSet(mset);
    Assert.assertFalse("chem model with a molecule set should not be empty", chemModel.isEmpty());
    mol.removeAtomOnly(atom);
    Assert.assertFalse("chem model with a (empty) molecule set should not be empty", chemModel.isEmpty());
    chemModel.setMoleculeSet(null);
    Assert.assertTrue("chemo model with no molecule set should be empty", chemModel.isEmpty());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IChemModel(org.openscience.cdk.interfaces.IChemModel) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder) IAtom(org.openscience.cdk.interfaces.IAtom) Test(org.junit.Test)

Example 23 with IChemModel

use of org.openscience.cdk.interfaces.IChemModel in project cdk by cdk.

the class AbstractChemModelTest method testClone_RingSet.

@Test
public void testClone_RingSet() throws Exception {
    IChemModel model = (IChemModel) newChemObject();
    IChemModel clone = (IChemModel) model.clone();
    Assert.assertNull(clone.getRingSet());
    model.setRingSet(model.getBuilder().newInstance(IRingSet.class));
    clone = (IChemModel) model.clone();
    Assert.assertNotNull(clone.getRingSet());
    Assert.assertNotSame(model.getRingSet(), clone.getRingSet());
}
Also used : IRingSet(org.openscience.cdk.interfaces.IRingSet) IChemModel(org.openscience.cdk.interfaces.IChemModel) Test(org.junit.Test)

Example 24 with IChemModel

use of org.openscience.cdk.interfaces.IChemModel in project cdk by cdk.

the class AbstractChemModelTest method testStateChanged_ButNotAfterRemoval_ReactionSet.

@Test
public void testStateChanged_ButNotAfterRemoval_ReactionSet() {
    ChemObjectListenerImpl listener = new ChemObjectListenerImpl();
    IChemModel chemObject = (IChemModel) newChemObject();
    chemObject.addListener(listener);
    IReactionSet reactionSet = chemObject.getBuilder().newInstance(IReactionSet.class);
    chemObject.setReactionSet(reactionSet);
    Assert.assertTrue(listener.changed);
    // remove the set from the IChemModel
    chemObject.setReactionSet(null);
    // reset the listener
    listener.reset();
    Assert.assertFalse(listener.changed);
    // changing the set must *not* trigger a change event in the IChemModel
    reactionSet.addReaction(chemObject.getBuilder().newInstance(IReaction.class));
    Assert.assertFalse(listener.changed);
}
Also used : IReactionSet(org.openscience.cdk.interfaces.IReactionSet) IChemModel(org.openscience.cdk.interfaces.IChemModel) IReaction(org.openscience.cdk.interfaces.IReaction) Test(org.junit.Test)

Example 25 with IChemModel

use of org.openscience.cdk.interfaces.IChemModel in project cdk by cdk.

the class MoleculeFactory method loadMolecule.

public static IAtomContainer loadMolecule(String inFile) {
    ChemFile chemFile;
    IChemSequence chemSequence;
    IChemModel chemModel;
    IAtomContainerSet setOfMolecules;
    IAtomContainer molecule = null;
    try (FileInputStream fis = new FileInputStream(inFile);
        MDLReader mr = new MDLReader(fis)) {
        chemFile = (ChemFile) mr.read((ChemObject) new ChemFile());
        mr.close();
        chemSequence = chemFile.getChemSequence(0);
        chemModel = chemSequence.getChemModel(0);
        setOfMolecules = chemModel.getMoleculeSet();
        molecule = setOfMolecules.getAtomContainer(0);
        for (int i = 0; i < molecule.getAtomCount(); i++) {
            molecule.getAtom(i).setPoint2d(null);
        }
    } catch (CDKException | IOException exc) {
        // we just return null if something went wrong
        logger.error("An exception occurred while loading a molecule: " + inFile);
        logger.debug(exc);
    }
    return molecule;
}
Also used : MDLReader(org.openscience.cdk.io.MDLReader) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) ChemFile(org.openscience.cdk.ChemFile) IChemModel(org.openscience.cdk.interfaces.IChemModel) IOException(java.io.IOException) IChemSequence(org.openscience.cdk.interfaces.IChemSequence) FileInputStream(java.io.FileInputStream)

Aggregations

IChemModel (org.openscience.cdk.interfaces.IChemModel)138 Test (org.junit.Test)97 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)85 IChemSequence (org.openscience.cdk.interfaces.IChemSequence)80 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)53 IChemFile (org.openscience.cdk.interfaces.IChemFile)50 InputStream (java.io.InputStream)46 ChemFile (org.openscience.cdk.ChemFile)30 CMLReader (org.openscience.cdk.io.CMLReader)26 IAtom (org.openscience.cdk.interfaces.IAtom)24 ICrystal (org.openscience.cdk.interfaces.ICrystal)21 IOException (java.io.IOException)19 IRingSet (org.openscience.cdk.interfaces.IRingSet)18 CDKException (org.openscience.cdk.exception.CDKException)17 IReaction (org.openscience.cdk.interfaces.IReaction)17 IReactionSet (org.openscience.cdk.interfaces.IReactionSet)17 MDLV2000Reader (org.openscience.cdk.io.MDLV2000Reader)13 SimpleChemObjectReaderTest (org.openscience.cdk.test.io.SimpleChemObjectReaderTest)12 AbstractChemModelTest (org.openscience.cdk.test.interfaces.AbstractChemModelTest)11 ChemObject (org.openscience.cdk.ChemObject)10