private void collide(int i, int j) {

		if (type instanceof Reaction.A2_B2__2AB) {

			int idA = ((Reaction.A2_B2__2AB) type).getIDA();
			int idB = ((Reaction.A2_B2__2AB) type).getIDB();

			if ((atom[i].getID() == idA || atom[i].getID() == idB)
					&& (atom[j].getID() == idA || atom[j].getID() == idB)) {

				if (atom[i].isRadical() && atom[j].isRadical()) {

					/* if both i and j are free radicals */

					vvi.setX(atom[i].vx);
					vvi.setY(atom[i].vy);
					vvj.setX(atom[j].vx);
					vvj.setY(atom[j].vy);
					vrij.setX(xij);
					vrij.setY(yij);
					if (willCollide(vvi, vvj, vrij))
						makeBond(i, j);

				}
				else {

					/* if at least one atom is not radical */

					if (!checkBond(i, j)) {

						vvi.setX(atom[i].vx);
						vvi.setY(atom[i].vy);
						vvj.setX(atom[j].vx);
						vvj.setY(atom[j].vy);
						vrij.setX(xij);
						vrij.setY(yij);
						if (willCollide(vvi, vvj, vrij))
							breakAndMakeBonds(i, j);

					}

				}

			}

		}

		else if (type instanceof Reaction.A2_B2_C__2AB_C) {

			int idA = ((Reaction.A2_B2_C__2AB_C) type).getIDA();
			int idB = ((Reaction.A2_B2_C__2AB_C) type).getIDB();
			int idC = ((Reaction.A2_B2_C__2AB_C) type).getIDC();

			if ((atom[i].getID() == idA && atom[j].getID() == idA)
					|| (atom[i].getID() == idB && atom[j].getID() == idB)
					|| (atom[i].getID() == idA && atom[j].getID() == idB)
					|| (atom[i].getID() == idB && atom[j].getID() == idA)
					|| (atom[i].getID() == idA && atom[j].getID() == idC)
					|| (atom[i].getID() == idC && atom[j].getID() == idA)
					|| (atom[i].getID() == idB && atom[j].getID() == idC)
					|| (atom[i].getID() == idC && atom[j].getID() == idB)) {

				if (atom[i].isRadical() && atom[j].isRadical()) {

					/* if both i and j are free radicals */

					vvi.setX(atom[i].vx);
					vvi.setY(atom[i].vy);
					vvj.setX(atom[j].vx);
					vvj.setY(atom[j].vy);
					vrij.setX(xij);
					vrij.setY(yij);
					if (willCollide(vvi, vvj, vrij))
						makeBond(i, j);

				}
				else {

					/* if at least one atom is not radical */

					if (!checkBond(i, j)) {

						vvi.setX(atom[i].vx);
						vvi.setY(atom[i].vy);
						vvj.setX(atom[j].vx);
						vvj.setY(atom[j].vy);
						vrij.setX(xij);
						vrij.setY(yij);
						if (willCollide(vvi, vvj, vrij))
							breakAndMakeBonds(i, j);

					}

				}

			}

		}

		else if (type instanceof Reaction.nA__An) {

			// in a polymerization reaction, monomers stick to only the ends of the chain
			if (!molecules.sameMolecule(atom[i], atom[j]) && bonds.getBondedPartnerCount(atom[i]) <= 1
					&& bonds.getBondedPartnerCount(atom[j]) <= 1) {

				vvi.setX(atom[i].vx);
				vvi.setY(atom[i].vy);
				vvj.setX(atom[j].vx);
				vvj.setY(atom[j].vy);
				vrij.setX(xij);
				vrij.setY(yij);
				if (willCollide(vvi, vvj, vrij))
					makeBond(i, j);

			}

		}

		else if (type instanceof Reaction.O2_2H2__2H2O) {

			int idH = ((Reaction.O2_2H2__2H2O) type).getIDH();
			int idO = ((Reaction.O2_2H2__2H2O) type).getIDO();

			if ((atom[i].getID() == idH || atom[i].getID() == idO)
					&& (atom[j].getID() == idH || atom[j].getID() == idO)) {

				if (atom[i].isRadical() && atom[j].isRadical()) {

					/* if both i and j are free radicals, chain termination. */

					vvi.setX(atom[i].vx);
					vvi.setY(atom[i].vy);
					vvj.setX(atom[j].vx);
					vvj.setY(atom[j].vy);
					vrij.setX(xij);
					vrij.setY(yij);
					if (willCollide(vvi, vvj, vrij))
						makeBond(i, j);

				}
				else {

					/* if at least one atom is not radical */

					if (((atom[i].getID() == idH && atom[j].getID() == idO) || (atom[j].getID() == idH && atom[i]
							.getID() == idO))
							&& !checkBond(i, j)) {

						vvi.setX(atom[i].vx);
						vvi.setY(atom[i].vy);
						vvj.setX(atom[j].vx);
						vvj.setY(atom[j].vy);
						vrij.setX(xij);
						vrij.setY(yij);
						if (willCollide(vvi, vvj, vrij)) {
							Atom[] at1 = bonds.getBondedPartners(atom[i], false);
							Atom[] at2 = bonds.getBondedPartners(atom[j], false);
							if (at1.length == 1 && at2.length == 1) {
								if (at1[0].getID() == idH && at2[0].getID() == idH) {
									if (atom[i].getID() == idO) {
										OH_H2(atom[i], at1[0], atom[j], at2[0]);
									}
									else {
										OH_H2(atom[j], at2[0], atom[i], at1[0]);
									}
								}
							}
							else if (at1.length == 1 && at2.length == 0 && atom[i].getID() == idO
									&& at1[0].getID() == idH) {
								H_OH(atom[i], atom[j], at1[0]);
							}
							else if (at1.length == 0 && at2.length == 1 && atom[j].getID() == idO
									&& at2[0].getID() == idH) {
								H_OH(atom[j], atom[i], at2[0]);
							}
							else {
								if (at1.length < 2 && at2.length < 2)
									breakAndMakeBonds(i, j);
							}
						}

					}

				}

			}

		}

	}