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());
}
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());
}
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());
}
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);
}
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;
}
Aggregations