private String evaluateNearestToAtomFunction(final String clause) {
		if (clause == null || clause.equals(""))
			return null;
		if (!(model instanceof MolecularModel))
			return null;
		MolecularModel mm = (MolecularModel) model;
		int noa = mm.getNumberOfAtoms();
		if (noa <= 1)
			return "" + (noa - 1);
		int i = clause.indexOf("(");
		int j = clause.lastIndexOf(")");
		if (i == -1 || j == -1) {
			out(ScriptEvent.FAILED, "function must be enclosed within parenthesis: " + clause);
			return null;
		}
		String s = clause.substring(i + 1, j);
		String[] t = s.split(",");
		int n = t.length;
		switch (n) {
		case 3: // nearesttoatom(id, atom, radius)
			float[] x = parseArray(3, t);
			if (x != null) {
				int id = (int) x[0];
				int iat = (int) x[1];
				if (iat < 0 || iat >= noa) {
					out(ScriptEvent.FAILED, "index of atom out of bound: " + iat + " , in " + clause);
					return null;
				}
				x[2] *= IR_CONVERTER;
				x[2] *= x[2];
				double dmin = Double.MAX_VALUE;
				int imin = -1;
				double r = 0;
				Atom a = null, b = mm.atom[iat];
				for (int k = 0; k < noa; k++) {
					a = mm.atom[k];
					if (a == b)
						continue;
					if (a.id == id || id == -1) {
						r = a.distanceSquare(b);
						if (r < x[2] && r < dmin) {
							dmin = r;
							imin = k;
						}
					}
				}
				return "" + imin;
			}
			break;
		case 4: // nearesttoatom(id, atom, radius, option)
			x = parseArray(4, t);
			if (x != null) {
				int id = (int) x[0];
				int iat = (int) x[1];
				if (iat < 0 || iat >= noa) {
					out(ScriptEvent.FAILED, "index of atom out of bound: " + iat + " , in " + clause);
					return null;
				}
				x[2] *= IR_CONVERTER;
				x[2] *= x[2];
				int option = Math.round(x[3]);
				double dmin = Double.MAX_VALUE;
				int imin = -1;
				double r = 0;
				Atom a = null, b = mm.atom[iat];
				Molecule mol = mm.molecules.getMolecule(b);
				for (int k = 0; k < noa; k++) {
					a = mm.atom[k];
					if (a == b)
						continue;
					if (a.id == id || id == -1) {
						r = a.distanceSquare(b);
						if (r < x[2] && r < dmin) {
							switch (option) {
							case 0: // all-atom search
								dmin = r;
								imin = k;
								break;
							case 1: // intermolecular search
								if (mol != mm.molecules.getMolecule(a)) {
									dmin = r;
									imin = k;
								}
								break;
							case 2: // intramolecular search
								if (mol == mm.molecules.getMolecule(a)) {
									dmin = r;
									imin = k;
								}
								break;
							}
						}
					}
				}
				return "" + imin;
			}
			break;
		case 6: // nearesttoatom(id, atom, rect_x, rect_y, rect_width, rect_height)
			x = parseArray(6, t);
			if (x != null) {
				int id = (int) x[0];
				int iat = (int) x[1];
				if (iat < 0 || iat >= noa) {
					out(ScriptEvent.FAILED, "index of atom out of bound: " + iat + " , in " + clause);
					return null;
				}
				for (int k = 2; k < x.length; k++)
					x[k] *= IR_CONVERTER;
				double dmin = Double.MAX_VALUE;
				int imin = -1;
				double r = 0;
				Atom a = null, b = mm.atom[iat];
				for (int k = 0; k < noa; k++) {
					a = mm.atom[k];
					if (a == b)
						continue;
					if (!a.isCenterOfMassContained(x[2], x[3], x[4], x[5]))
						continue;
					if (a.id == id || id == -1) {
						r = a.distanceSquare(b);
						if (r < dmin) {
							dmin = r;
							imin = k;
						}
					}
				}
				return "" + imin;
			}
			break;
		default:
			out(ScriptEvent.FAILED, "argument error: " + clause);
			return null;
		}
		return null;
	}