Effectively irreversible evolution

by WaterMolecule

HTML

<h4>Effectively irreversible evolution with reversible dynamics</h4>
<canvas id="screen" width="400px" height="300px"></canvas>
<p id="status">STATUS</p>

JavaScript

(function() {
  var World = function() {
    var screen = document.getElementById("screen").getContext("2d");

    this.num = 16; // number of atoms
    this.timestep = 2.0; // in femtoseconds
    this.scale = 10.0; // from angstroms to pixels
    this.mass = 20.017970; // in daltons
    this.lj_e = 0.08545; // repulsive Lennard-Jones energy in kcal/mol 
    this.lj_r = 3.06; // repulsive Lennard-Jones minimum-energy distance in angstroms
    this.radius = 0.5 * this.lj_r; // physical radius in angstroms
    this.wall_k = 20.0; // spring constant for walls in kcal/mol/angstrom^2
    this.init_r = 1.5 * this.lj_r;
    this.step = 0; // current time step
    this.run_steps = 10; // number of steps between display
    this.boltz = 0.001987191; // k_Boltzmann in kcal/mol/K

    // Size of system box.
    this.box = {
      x: screen.canvas.width / this.scale,
      y: screen.canvas.height / this.scale
    };
    this.lj_r2 = this.lj_r * this.lj_r;
    this.lj_r6 = Math.pow(this.lj_r, 6.0);
    this.lj_r12 = Math.pow(this.lj_r, 12.0);
    this.time_factor = 48.88821; // from sqrt(dalton*angstrom^2/(kcal/mol)) to fs
    this.dt = this.timestep / this.time_factor; // internal timestep in simulation units
    this.dt2 = this.dt * this.dt;
    this.ener_pot = 0.0;
    this.ener_kin = 0.0;
    this.ener_tot = 0.0;

    // Initial positions of the atoms.
    var x00 = 2 * this.init_r;
    var x0 = x00;
    var y0 = this.init_r;
    this.pos = [];
    for (var i = 0; i < this.num; i += 2) {
      var p = {
        x: x0,
        y: y0
      };
      this.pos.push(p);

      var p1 = {
        x: x0,
        y: y0 + this.init_r
      };
      this.pos.push(p1);

      x0 += 2 * this.init_r;
      if (i % 8 >= 6) {
        x0 = x00;
        y0 += 3 * this.init_r;
      }
    }

    // Previous positions based on a random velocity.
    this.pos0 = [];
    var vel_init = 0.003 * this.time_factor;
    for (var i = 0; i < this.num; i++) {
      var dx = vel_init * this.dt;
     ...