private String useMoleculeVariables(String s, int frame) {
		if (model.molecules == null)
			return s;
		int n = model.molecules.size();
		if (n <= 0)
			return s;
		int lb = s.indexOf("%molecule[");
		int rb = s.indexOf("].", lb);
		String v;
		int i;
		Molecule mol;
		while (lb != -1 && rb != -1) {
			v = s.substring(lb + 10, rb);
			double x = parseMathExpression(v);
			if (Double.isNaN(x))
				break;
			i = (int) Math.round(x);
			if (i < 0 || i >= n) {
				out(ScriptEvent.FAILED, "Molecule " + i + " does not exist.");
				break;
			}
			v = escapeMetaCharacters(v);
			mol = model.molecules.get(i);
			int nmol = mol.getAtomCount();
			if (frame < 0) {
				Point3f com = mol.getCenterOfMass();
				s = replaceAll(s, "%molecule\\[" + v + "\\]\\.x", com.x);
				s = replaceAll(s, "%molecule\\[" + v + "\\]\\.y", com.y);
				s = replaceAll(s, "%molecule\\[" + v + "\\]\\.z", com.z);
			}
			else {
				float xc = 0, yc = 0, zc = 0;
				Atom at = null;
				for (int k = 0; k < nmol; k++) {
					at = mol.getAtom(k);
					xc += at.rQ.getQueue1().getData(frame);
					yc += at.rQ.getQueue2().getData(frame);
					zc += at.rQ.getQueue3().getData(frame);
				}
				xc /= nmol;
				yc /= nmol;
				zc /= nmol;
				s = replaceAll(s, "%molecule\\[" + v + "\\]\\.x", xc);
				s = replaceAll(s, "%molecule\\[" + v + "\\]\\.y", yc);
				s = replaceAll(s, "%molecule\\[" + v + "\\]\\.z", zc);
			}
			s = replaceAll(s, "%molecule\\[" + v + "\\]\\.n", nmol);
			lb = s.indexOf("%molecule[");
			rb = s.indexOf("].", lb);
		}
		return s;
	}