private String evaluateNearestParticleFunction(final String clause) {
		if (clause == null || clause.equals(""))
			return null;
		int nop = model.getNumberOfParticles();
		if (nop <= 1)
			return "" + (nop - 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 2: // nearest(x, y)
			float[] x = parseArray(2, t);
			if (x != null) {
				for (int k = 0; k < x.length; k++)
					x[k] *= IR_CONVERTER;
				double dmin = Double.MAX_VALUE;
				int imin = -1;
				double r = 0;
				Particle p = null;
				for (int k = 0; k < nop; k++) {
					p = model.getParticle(k);
					r = distanceSquare(p.rx - x[0], p.ry - x[1]);
					if (r < dmin) {
						dmin = r;
						imin = k;
					}
				}
				return "" + imin;
			}
			break;
		case 3: // nearest(id, x, y)
			x = parseArray(3, t);
			if (x != null) {
				int id = (int) x[0];
				for (int k = 1; k < x.length; k++)
					x[k] *= IR_CONVERTER;
				double dmin = Double.MAX_VALUE;
				int imin = -1;
				double r = 0;
				Particle p = null;
				for (int k = 0; k < nop; k++) {
					p = model.getParticle(k);
					if (p instanceof Atom) {
						if (((Atom) p).id == id || id == -1) {
							r = distanceSquare(p.rx - x[1], p.ry - x[2]);
							if (r < dmin) {
								dmin = r;
								imin = k;
							}
						}
					} else if (p instanceof GayBerneParticle) {
						r = distanceSquare(p.rx - x[1], p.ry - x[2]);
						if (r < dmin) {
							dmin = r;
							imin = k;
						}
					}
				}
				return "" + imin;
			}
			break;
		case 4: // nearest(id, x, y, radius)
			x = parseArray(4, t);
			if (x != null) {
				int id = (int) x[0];
				for (int k = 1; k < x.length; k++)
					x[k] *= IR_CONVERTER;
				double dmin = Double.MAX_VALUE;
				int imin = -1;
				double r = 0;
				Particle p = null;
				x[3] *= x[3];
				for (int k = 0; k < nop; k++) {
					p = model.getParticle(k);
					if (p instanceof Atom) {
						if (((Atom) p).id == id || id == -1) {
							r = distanceSquare(p.rx - x[1], p.ry - x[2]);
							if (r < x[3] && r < dmin) {
								dmin = r;
								imin = k;
							}
						}
					} else if (p instanceof GayBerneParticle) {
						r = distanceSquare(p.rx - x[1], p.ry - x[2]);
						if (r < x[3] && r < dmin) {
							dmin = r;
							imin = k;
						}
					}
				}
				return "" + imin;
			}
			break;
		case 7: // nearest(id, x, y, xrect, yrect, wrect, hrect)
			x = parseArray(7, t);
			if (x != null) {
				int id = (int) x[0];
				for (int k = 1; k < x.length; k++)
					x[k] *= IR_CONVERTER;
				double dmin = Double.MAX_VALUE;
				int imin = -1;
				double r = 0;
				Particle p = null;
				for (int k = 0; k < nop; k++) {
					p = model.getParticle(k);
					if (!p.isCenterOfMassContained(x[3], x[4], x[5], x[6]))
						continue;
					if (p instanceof Atom) {
						if (((Atom) p).id == id || id == -1) {
							r = distanceSquare(p.rx - x[1], p.ry - x[2]);
							if (r < dmin) {
								dmin = r;
								imin = k;
							}
						}
					} else if (p instanceof GayBerneParticle) {
						r = distanceSquare(p.rx - x[1], p.ry - x[2]);
						if (r < dmin) {
							dmin = r;
							imin = k;
						}
					}
				}
				return "" + imin;
			}
			break;
		default:
			out(ScriptEvent.FAILED, "argument error: " + clause);
			return null;
		}
		return null;
	}