private static void replaceReferencesWithClones(final IChemModel chemModel)
			throws CDKException {
		// we make references in products/reactants clones, since same compounds
		// in different reactions need separate layout (different positions etc)
		if (chemModel.getReactionSet() != null) {
			for (final IReaction reaction : chemModel.getReactionSet()
					.reactions()) {
				int i = 0;
				final IAtomContainerSet products = reaction.getProducts();
				for (final IAtomContainer product : products.atomContainers()) {
					try {
						products.replaceAtomContainer(i, product.clone());
					} catch (final CloneNotSupportedException e) {
					}
					i++;
				}
				i = 0;
				final IAtomContainerSet reactants = reaction.getReactants();
				for (final IAtomContainer reactant : reactants.atomContainers()) {
					try {
						reactants.replaceAtomContainer(i, reactant.clone());
					} catch (final CloneNotSupportedException e) {
					}
					i++;
				}
			}
		}
	}
	private static void setReactionIDs(final IChemModel chemModel) {
		// we give all reactions an ID, in case they have none
		// IDs are needed for handling in JCP
		final IReactionSet reactionSet = chemModel.getReactionSet();
		if (reactionSet != null) {
			int i = 0;
			for (final IReaction reaction : reactionSet.reactions()) {
				if (reaction.getID() == null) {
					reaction.setID("Reaction " + ++i);
				}
			}
		}
	}
	private static void removeDuplicateAtomContainers(final IChemModel chemModel) {
		// we remove molecules which are in AtomContainerSet as well as in a
		// reaction
		final IReactionSet reactionSet = chemModel.getReactionSet();
		final IAtomContainerSet moleculeSet = chemModel.getMoleculeSet();
		if (reactionSet != null && moleculeSet != null) {
			final List<IAtomContainer> aclist = ReactionSetManipulator
					.getAllAtomContainers(reactionSet);
			for (int i = moleculeSet.getAtomContainerCount() - 1; i >= 0; i--) {
				for (int k = 0; k < aclist.size(); k++) {
					final String label = moleculeSet.getAtomContainer(i)
							.getID();
					if (aclist.get(k).getID().equals(label)) {
						chemModel.getMoleculeSet().removeAtomContainer(i);
						break;
					}
				}
			}
		}
	}
  private IReaction checkForXReactionFile(IChemFile chemFile, int numberOfReactions) {
    Assert.assertNotNull(chemFile);

    Assert.assertEquals(chemFile.getChemSequenceCount(), 1);
    org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0);
    Assert.assertNotNull(seq);

    Assert.assertEquals(seq.getChemModelCount(), 1);
    org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0);
    Assert.assertNotNull(model);

    IReactionSet reactionSet = model.getReactionSet();
    Assert.assertNotNull(reactionSet);

    Assert.assertEquals(reactionSet.getReactionCount(), numberOfReactions);
    IReaction reaction = null;
    for (int i = 0; i < numberOfReactions; i++) {
      reaction = reactionSet.getReaction(i);
      Assert.assertNotNull(reaction);
    }
    return reaction;
  }