private int autoBond(BitSet bsA, BitSet bsB) {
		if (atomCount == 0)
			return 0;
		// null values for bitsets means "all"
		if (maxBondingRadius == Float.MIN_VALUE)
			findMaxRadii();
		float bondTolerance = viewer.getBondTolerance();
		float minBondDistance = viewer.getMinBondDistance();
		float minBondDistance2 = minBondDistance * minBondDistance;
		short mad = viewer.getMadBond();
		// char chainLast = '?';
		// int indexLastCA = -1;
		// Atom atomLastCA = null;
		int nNew = 0;
		initializeBspf();

		long timeBegin = 0;
		if (showRebondTimes)
			timeBegin = System.currentTimeMillis();
		/*
		 * miguel 2006 04 02 note that the way that these loops + iterators are constructed, everything assumes that all
		 * possible pairs of atoms are going to be looked at. for example, the hemisphere iterator will only look at
		 * atom indexes that are >= (or <= ?) the specified atom. if we are going to allow arbitrary sets bsA and bsB,
		 * then this will not work. so, for now I will do it the ugly way. maybe enhance/improve in the future.
		 */
		for (int i = atomCount; --i >= 0;) {
			boolean isAtomInSetA = (bsA == null || bsA.get(i));
			boolean isAtomInSetB = (bsB == null || bsB.get(i));
			if (!isAtomInSetA & !isAtomInSetB)
				continue;
			Atom atom = atoms[i];
			// Covalent bonds
			float myBondingRadius = atom.getBondingRadiusFloat();
			if (myBondingRadius == 0)
				continue;
			float searchRadius = myBondingRadius + maxBondingRadius + bondTolerance;
			SphereIterator iter = bspf.getSphereIterator(atom.modelIndex);
			iter.initializeHemisphere(atom, searchRadius);
			while (iter.hasMoreElements()) {
				Atom atomNear = (Atom) iter.nextElement();
				if (atomNear == atom)
					continue;
				int atomIndexNear = atomNear.atomIndex;
				boolean isNearInSetA = (bsA == null || bsA.get(atomIndexNear));
				boolean isNearInSetB = (bsB == null || bsB.get(atomIndexNear));
				if (!isNearInSetA & !isNearInSetB)
					continue;
				if (!(isAtomInSetA & isNearInSetB || isAtomInSetB & isNearInSetA))
					continue;
				short order = getBondOrder(atom, myBondingRadius, atomNear, atomNear.getBondingRadiusFloat(), iter
						.foundDistance2(), minBondDistance2, bondTolerance);
				if (order > 0) {
					checkValencesAndBond(atom, atomNear, order, mad);
					nNew++;
				}
			}
			iter.release();
		}
		if (showRebondTimes) {
			long timeEnd = System.currentTimeMillis();
			Logger.debug("Time to autoBond=" + (timeEnd - timeBegin));
		}

		return nNew;
	}