private BitSet selectAtoms(String str) {

		if ("selected".equalsIgnoreCase(str)) {
			return model.getAtomSelectionSet();
		}

		BitSet bs = genericSelect(str);
		if (bs != null)
			return bs;

		boolean found = false;
		int noa = model.getAtomCount();
		bs = new BitSet(noa);

		Matcher matcher = WITHIN_RADIUS.matcher(str);
		if (matcher.find()) {
			found = true;
			String s = str.substring(matcher.end()).trim();
			s = s.substring(0, s.indexOf(")"));
			if (RANGE.matcher(s).find()) {
				int lp = str.lastIndexOf("(");
				int rp = str.indexOf(")");
				s = str.substring(lp + 1, rp).trim();
				float r = Float.valueOf(s.substring(0, s.indexOf(",")).trim()).floatValue();
				r *= r;
				s = s.substring(s.indexOf(",") + 1);
				int i0 = Math.round(Float.valueOf(s.substring(0, s.indexOf("-")).trim()).floatValue());
				int i1 = Math.round(Float.valueOf(s.substring(s.indexOf("-") + 1).trim()).floatValue());
				if (i0 < noa && i0 >= 0 && i1 < noa && i1 >= 0 && i1 >= i0) {
					Atom c;
					for (int k = i0; k <= i1; k++) {
						bs.set(k);
						c = model.getAtom(k);
						for (int m = 0; m < i0; m++) {
							if (bs.get(m))
								continue;
							if (model.getAtom(m).distanceSquare(c) < r)
								bs.set(m);
						}
						for (int m = i1 + 1; m < noa; m++) {
							if (bs.get(m))
								continue;
							if (model.getAtom(m).distanceSquare(c) < r)
								bs.set(m);
						}
					}
				}
			}
			else {
				int lp = str.indexOf("(");
				int rp = str.indexOf(")");
				s = str.substring(lp + 1, rp).trim();
				float r = Float.valueOf(s.substring(0, s.indexOf(",")).trim()).floatValue();
				r *= r;
				int center = Math.round(Float.valueOf(s.substring(s.indexOf(",") + 1).trim()).floatValue());
				if (center < noa && center >= 0) {
					Atom c = model.getAtom(center);
					for (int k = 0; k < noa; k++) {
						if (k == center) {
							bs.set(k);
						}
						else {
							if (model.getAtom(k).distanceSquare(c) < r)
								bs.set(k);
						}
					}
				}
			}
		}

		if (!found) {
			matcher = RANGE.matcher(str);
			if (matcher.find()) {
				found = true;
				String[] s = str.split("-");
				int start = Math.round(Float.valueOf(s[0].trim()).floatValue());
				int end = Math.round(Float.valueOf(s[1].trim()).floatValue());
				start = start < 0 ? 0 : start;
				end = end < noa ? end : noa - 1;
				for (int k = start; k <= end; k++)
					bs.set(k);
			}
		}

		if (!found) {
			matcher = INTEGER_GROUP.matcher(str);
			if (matcher.find()) {
				found = true;
				int lp = str.lastIndexOf("(");
				int rp = str.indexOf(")");
				if (lp != -1 && rp != -1) {
					str = str.substring(lp + 1, rp).trim();
				}
				else {
					if (lp != -1 || rp != -1) {
						out(ScriptEvent.FAILED, "Unbalanced parenthesis: " + str);
						return null;
					}
				}
				String[] s = str.split(REGEX_SEPARATOR + "+");
				for (int k = 0; k < s.length; k++) {
					int x = -1;
					try {
						x = Math.round(Float.valueOf(s[k].trim()).floatValue());
					}
					catch (NumberFormatException e) {
						out(ScriptEvent.FAILED, s[k] + " cannot be parsed as an integer.");
						return null;
					}
					if (x >= 0 && x < noa)
						bs.set(x);
				}
			}
		}

		if (!found) {
			matcher = INDEX.matcher(str);
			if (matcher.find()) {
				found = true;
				int x = -1;
				try {
					x = Math.round(Float.valueOf(str.trim()).floatValue());
				}
				catch (NumberFormatException e) {
					out(ScriptEvent.FAILED, str + " cannot be parsed as an integer.");
					return null;
				}
				if (x >= 0 && x < noa)
					bs.set(x);
			}
		}

		if (found) {
			model.setAtomSelectionSet(bs);
		}
		else {
			out(ScriptEvent.FAILED, "Unrecognized expression: " + str);
		}

		return found ? bs : null;

	}