public void assignTemperature(double temperature) {
		if (numberOfAtoms == 0)
			return;
		if (temperature < ZERO)
			temperature = 0.0;
		double rtemp = Math.sqrt(temperature) * VT_CONVERSION_CONSTANT;
		double sumVx = 0.0;
		double sumVy = 0.0;
		double sumMass = 0.0;
		if (numberOfAtoms == 1) {
			atom[0].setRandomVelocity(rtemp);
		} else {
			for (int i = 0; i < numberOfAtoms; i++) {
				Atom a = atom[i];
				a.vx = rtemp * RANDOM.nextGaussian();
				a.vy = rtemp * RANDOM.nextGaussian();
				sumVx += a.vx * a.mass;
				sumVy += a.vy * a.mass;
				sumMass += a.mass;
			}
		}
		if (obstacles != null && !obstacles.isEmpty()) {
			RectangularObstacle obs = null;
			double mass = 1.0;
			synchronized (obstacles.getSynchronizationLock()) {
				for (Iterator it = obstacles.iterator(); it.hasNext();) {
					obs = (RectangularObstacle) it.next();
					if (obs.isMovable()) {
						obs.vx = rtemp * RANDOM.nextGaussian();
						obs.vy = rtemp * RANDOM.nextGaussian();
						mass = obs.getMass();
						sumVx += obs.vx * mass;
						sumVy += obs.vy * mass;
						sumMass += mass;
					}
				}
			}
		}
		if (sumMass > ZERO) {
			sumVx /= sumMass;
			sumVy /= sumMass;
			if (numberOfAtoms > 1) {
				for (int i = 0; i < numberOfAtoms; i++) {
					atom[i].vx -= sumVx;
					atom[i].vy -= sumVy;
				}
			}
			if (obstacles != null && !obstacles.isEmpty()) {
				RectangularObstacle obs = null;
				synchronized (obstacles.getSynchronizationLock()) {
					for (Iterator it = obstacles.iterator(); it.hasNext();) {
						obs = (RectangularObstacle) it.next();
						if (obs.isMovable()) {
							obs.vx -= sumVx;
							obs.vy -= sumVy;
						}
					}
				}
			}
			setTemperature(temperature);
		}
	}