Make Fluxion with the speed squared of body i
553179
def flux_v2(v_vars: List[fl.Var], i: int):
    """"""
    # Index with the base of (v_x, v_y, v_z) for body i
    k = 3*i
    # The speed squared of body i
    return fl.square(v_vars[k+0]) + fl.square(v_vars[k+1]) + fl.square(v_vars[k+2])
1244907
def _direct_nbody_step(q,p,m,t,dt,pot,softening,softening_args):
    """"""
    #drift
    q12= [symplecticode.leapfrog_leapq(q[ii],p[ii],dt/2.) \
              for ii in range(len(q))]
    #kick
    force= _direct_nbody_force(q12,m,t+dt/2.,pot,softening,softening_args)
    #print(force)
    p= [symplecticode.leapfrog_leapp(p[ii],dt,force[ii]) \
            for ii in range(len(p))]
    #drift
    q= [symplecticode.leapfrog_leapq(q12[ii],p[ii],dt/2.) \
            for ii in range(len(q12))]
    return (q,p)
605681
def forward_kinematics(self, q):
        
        q = numpy.array(q).flatten()

        if len(q) != len(self.links):
            raise ValueError('q must contain as element as the number of links')

        tr = self.base.copy()

        l = []

        for link, theta in zip(self.links, q):
            tr = tr * link.get_transformation_matrix(theta)

            l.append(tr)

        tr = tr * self.tool
        l.append(tr)
        return tr, numpy.asarray(l)
444995
def energy(q, v):
    """"""
    
    # Number of points
    N: int = len(q)
    
    # Initialize arrays to zero of the correct size
    T: np.ndarray = np.zeros(N)
    U: np.ndarray = np.zeros(N)    
    
    # Add up kinetic energy of each body
    for i in range(B):
        # Kinetic energy is 1/2 mv^2
        m = mass[i]
        vi = v[:, slices[i]]
        T += 0.5 * m * np.sum(vi * vi, axis=1)
    
    # Add up potential energy of each pair of bodies
    for i in range(B):
        for j in range(i+1, B):
            # Masses of these two bodies
            mi = mass[i]
            mj = mass[j]
        
            # Positions of body i and j
            qi: np.ndarray = q[:, slices[i]]
            qj: np.ndarray = q[:, slices[j]]
        
            # Potential energy is -G m1 m2  / r
            dv_ij = qj - qi
            r_ij = np.linalg.norm(dv_ij, axis=1)
            U -= G * mi * mj * 1.0 / r_ij
    
    # Total energy H = T + U
    H = T + U
    
    return H, T, U
676152
def convert_body_frame(self, phi, theta, phiDot, thetaDot, psiDot):
        ''''''
        p = phiDot - psiDot*math.sin(theta)
        q = math.cos(phi)*thetaDot + math.sin(phi)*psiDot*math.cos(theta)
        r = math.cos(phi)*psiDot*math.cos(theta) - math.sin(phi)*thetaDot
        return (p, q, r)
705732
function (dt) {

        if (me.input.isKeyPressed("left")) {
            // update the entity velocity
            this.body.vel.x -= this.body.accel.x * me.timer.tick;
        } else if (me.input.isKeyPressed("right")) {
            // update the entity velocity
            this.body.vel.x += this.body.accel.x * me.timer.tick;
        } else {
            this.body.vel.x = 0;
        }
        if (me.input.isKeyPressed("up")) {
            // update the entity velocity
            this.body.vel.y -= this.body.accel.y * me.timer.tick;
        } else if (me.input.isKeyPressed("down")) {
            // update the entity velocity
            this.body.vel.y += this.body.accel.y * me.timer.tick;
        } else {
            this.body.vel.y = 0;
        }

        // apply physics to the body (this moves the entity)
        this.body.update(dt);

        // handle collisions against other shapes
        me.collision.check(this);

        // check if we moved (an "idle" animation would definitely be cleaner)
        if (this.body.vel.x !== 0 || this.body.vel.y !== 0) {
            this._super(me.Entity, "update", [dt]);
            return true;
        }
    }
372625
def flux_r(q_vars: List[fl.Var], i: int, j: int):
    """"""
    return fl.sqrt(flux_r2(q_vars, i, j))
87973
def flux_bound(self, reaction, direction):
        
        try:
            self.maximize({reaction: direction})
        except FluxBalanceError as e:
            if not e.result.unbounded:
                raise
            return direction * _INF
        else:
            return self.get_flux(reaction)
718946
def generateComponent(m):
    """"""
    freq = 25*np.random.random()
    phase = 2*np.pi*np.random.random()
    x = np.arange(m)
    return np.cos(x/freq-phase)**2
618598
def _meco_frequency(m1, m2, chi1, chi2):
    
    return velocity_to_frequency(meco_velocity(m1, m2, chi1, chi2), m1+m2)
643812
function getSetJ(h, lw, phi, dec, n, M, L) {

    var w = hourAngle(h, phi, dec),
        a = approxTransit(w, lw, n);
    return solarTransitJ(a, M, L);
}
395769
function _calculateDerivative(out, state, job, t, dt, d) {
  vec3.scaleAndAdd(state.position, state.position, d.velocity, dt);
  vec3.scaleAndAdd(state.momentum, state.momentum, d.force, dt);
  _geometry.scaleAndAddQuat(state.orientation, state.orientation, d.spin, dt);
  vec3.scaleAndAdd(state.angularMomentum, state.angularMomentum, d.torque, dt);

  state.updateDependentFields();

  out.velocity = state.velocity;
  out.spin = state.spin;
  vec3.set(out.force, 0, 0, 0);
  vec3.set(out.torque, 0, 0, 0);

  _forceApplierOutput.force = out.force;
  _forceApplierOutput.torque = out.torque;
  _forceApplierInput.state = state;
  _forceApplierInput.t = t + dt;
  _forceApplierInput.dt = dt;

  job.applyForces(_forceApplierOutput, _forceApplierInput);
}
455906
def iprotate(l, steps=1):
    

    """
    if len(l):
        steps %= len(l)
        if steps:
            firstPart = l[:steps]
            del l[:steps]
            l.extend(firstPart)
    return l
210661
def prepare_fluxseries(self, ramflag: bool = True) -> None:
        """"""
        for element in printtools.progressbar(self):
            element.prepare_fluxseries(ramflag)
964984
def major_flux(self, fraction=0.9):
        

        """
        (paths, pathfluxes) = self.pathways(fraction=fraction)
        return self._pathways_to_flux(paths, pathfluxes, n=self.nstates)
848424
def _newton(self, orb, step):
        

        date = orb.date + step

        new_body = zeros(6)
        new_body[:3] = orb[3:]

        for body in self.bodies:
            # retrieve the position of the body at the given date
            orb_body = body.propagate(date)
            orb_body.frame = orb.frame

            # Compute induced attraction to the object of interest
            diff = orb_body[:3] - orb[:3]
            norm = sqrt(sum(diff ** 2)) ** 3
            new_body[3:] += G * body.mass * diff / norm

        return new_body
1198237
def _integrate_fixed_trajectory(self, h, T, step, relax):
        """"""
        # initialize the solution using initial condition
        solution = np.hstack((self.t, self.y))

        while self.successful():

            self.integrate(self.t + h, step, relax)
            current_step = np.hstack((self.t, self.y))
            solution = np.vstack((solution, current_step))

            if (h > 0) and (self.t >= T):
                break
            elif (h < 0) and (self.t <= T):
                break
            else:
                continue

        return solution