示例#1
0
 def set_points_and_lines(self):
   self.sim_as = simulation()
   self.sim_ac = simulation()
   self.points = flex.vec3_double(self.sim_as.sites_cart_moved_F01)
   self.points.extend(flex.vec3_double(self.sim_ac.sites_cart_moved_F01))
   self.points.extend(flex.vec3_double(self.sim_as.sites_cart_wells_F01))
   def add_line(i, j, color):
     line = (i,j)
     self.line_i_seqs.append(line)
     self.line_colors[line] = color
   self.labels = []
   n = len(self.sim_as.sites_cart_F1)
   offs = 0
   for prefix,color in [("S",(1,0,0)),("C",(0,0,1)),("W",(0,1,0))]:
     for i in range(n):
       add_line(offs+i, offs+(i+1)%n, color)
       self.labels.append(prefix+str(i))
     offs += n
   mcs = minimum_covering_sphere(self.points, epsilon=1.e-2)
   self.minimum_covering_sphere = sphere_3d(
     center=mcs.center(), radius=mcs.radius()*1.3)
   self.flag_show_minimum_covering_sphere = False
   self.flag_show_rotation_center = False
   self.steps_per_tab = 8
   print("Press and hold Tab key to run the simulation.")
   print("Press Shift-Tab to increase speed.")
   print("Press Ctrl-Tab  to decrease speed.")
示例#2
0
 def set_points_and_lines(self):
   self.sim_as = simulation()
   self.sim_ac = simulation()
   self.points = flex.vec3_double(self.sim_as.sites_cart_moved_F01)
   self.points.extend(flex.vec3_double(self.sim_ac.sites_cart_moved_F01))
   self.points.extend(flex.vec3_double(self.sim_as.sites_cart_wells_F01))
   def add_line(i, j, color):
     line = (i,j)
     self.line_i_seqs.append(line)
     self.line_colors[line] = color
   self.labels = []
   n = len(self.sim_as.sites_cart_F1)
   offs = 0
   for prefix,color in [("S",(1,0,0)),("C",(0,0,1)),("W",(0,1,0))]:
     for i in xrange(n):
       add_line(offs+i, offs+(i+1)%n, color)
       self.labels.append(prefix+str(i))
     offs += n
   mcs = minimum_covering_sphere(self.points, epsilon=1.e-2)
   self.minimum_covering_sphere = sphere_3d(
     center=mcs.center(), radius=mcs.radius()*1.3)
   self.flag_show_minimum_covering_sphere = False
   self.flag_show_rotation_center = False
   self.steps_per_tab = 8
   print "Press and hold Tab key to run the simulation."
   print "Press Shift-Tab to increase speed."
   print "Press Ctrl-Tab  to decrease speed."
示例#3
0
def exercise_featherstone_FDab(out):
    def check():
        model = featherstone_system_model(
            m=sim.m, I=sim.I_F1, J=six_dof_joint_euler_params_featherstone(qE=sim.J1.qE, qr=sim.J1.qr)
        )
        q = [None]  # already stored in J1 as qE and qr
        qd = [sim.qd]
        tau = None
        f_ext = [matrix.col((sim.nc_F1, sim.f_F1)).resolve_partitions()]
        grav_accn = [0, 0, 0]
        qdd = featherstone.FDab(model, q, qd, tau, f_ext, grav_accn)
        if i_step % 10 == 0:
            print >> out, "ang acc 3D:", sim.wd_F1.elems
            print >> out, "        6D:", qdd[0].elems[:3]
            print >> out
            print >> out, "lin acc 3D:", sim.as_F1.elems
            print >> out, "        6D:", qdd[0].elems[3:]
            print >> out
        assert approx_equal(qdd[0].elems[:3], sim.wd_F1)
        assert approx_equal(qdd[0].elems[3:], sim.as_F1)

    sim = fmri.simulation()
    for i_step in xrange(100):
        check()
        sim.dynamics_step(delta_t=0.1)  # large time step to sample
    check()  # diverse configurations
示例#4
0
def exercise_reference_impl_long(n_dynamics_steps, out):
    sim = fmri.simulation()
    e_tots = flex.double([sim.e_tot])
    print >> out, "i_step, [e_pot, e_kin_ang, e_kin_lin, e_kin, e_tot]"

    def show(i_step):
        print >> out, i_step, [sim.e_pot, sim.e_kin_ang, sim.e_kin_lin, sim.e_kin, sim.e_tot]
        out.flush()

    n_show = max(1, n_dynamics_steps // 10)
    for i_step in xrange(n_dynamics_steps):
        sim.dynamics_step(delta_t=0.001)
        e_tots.append(sim.e_tot)
        if i_step % n_show == 0:
            show(i_step)
    show(n_dynamics_steps)
    print >> out
    print >> out, "number of dynamics steps:", n_dynamics_steps
    print >> out, "e_tot start:", e_tots[0]
    print >> out, "      final:", e_tots[-1]
    print >> out, "        min:", flex.min(e_tots)
    print >> out, "        max:", flex.max(e_tots)
    print >> out, "    max-min:", flex.max(e_tots) - flex.min(e_tots)
    print >> out
    out.flush()
示例#5
0
def exercise_featherstone_FDab(out):
    def check():
        model = featherstone_system_model(
            m=sim.m,
            I=sim.I_F1,
            J=six_dof_joint_euler_params_featherstone(qE=sim.J1.qE,
                                                      qr=sim.J1.qr))
        q = [None]  # already stored in J1 as qE and qr
        qd = [sim.qd]
        tau = None
        f_ext = [matrix.col((sim.nc_F1, sim.f_F1)).resolve_partitions()]
        grav_accn = [0, 0, 0]
        qdd = featherstone.FDab(model, q, qd, tau, f_ext, grav_accn)
        if (i_step % 10 == 0):
            print("ang acc 3D:", sim.wd_F1.elems, file=out)
            print("        6D:", qdd[0].elems[:3], file=out)
            print(file=out)
            print("lin acc 3D:", sim.as_F1.elems, file=out)
            print("        6D:", qdd[0].elems[3:], file=out)
            print(file=out)
        assert approx_equal(qdd[0].elems[:3], sim.wd_F1)
        assert approx_equal(qdd[0].elems[3:], sim.as_F1)

    sim = fmri.simulation()
    for i_step in range(100):
        check()
        sim.dynamics_step(delta_t=0.1)  # large time step to sample
    check()  # diverse configurations
示例#6
0
def exercise_reference_impl_long(n_dynamics_steps, out):
    sim = fmri.simulation()
    e_tots = flex.double([sim.e_tot])
    print("i_step, [e_pot, e_kin_ang, e_kin_lin, e_kin, e_tot]", file=out)

    def show(i_step):
        print(i_step,
              [sim.e_pot, sim.e_kin_ang, sim.e_kin_lin, sim.e_kin, sim.e_tot],
              file=out)
        out.flush()

    n_show = max(1, n_dynamics_steps // 10)
    for i_step in range(n_dynamics_steps):
        sim.dynamics_step(delta_t=0.001)
        e_tots.append(sim.e_tot)
        if (i_step % n_show == 0):
            show(i_step)
    show(n_dynamics_steps)
    print(file=out)
    print("number of dynamics steps:", n_dynamics_steps, file=out)
    print("e_tot start:", e_tots[0], file=out)
    print("      final:", e_tots[-1], file=out)
    print("        min:", flex.min(e_tots), file=out)
    print("        max:", flex.max(e_tots), file=out)
    print("    max-min:", flex.max(e_tots) - flex.min(e_tots), file=out)
    print(file=out)
    out.flush()
示例#7
0
def exercise_reference_impl_quick():
    sites_cart = fmri.create_triangle_with_center_of_mass_at_origin()
    assert approx_equal(flex.vec3_double(sites_cart).mean(), (0, 0, 0))
    inertia1 = fmri.body_inertia(sites_cart=sites_cart)
    inertia2 = matrix.sym(sym_mat3=scitbx.math.inertia_tensor(
        points=flex.vec3_double(sites_cart), pivot=(0, 0, 0)))
    assert approx_equal(inertia1, inertia2)
    #
    for use_classical_accel in [False, True]:
        sim = fmri.simulation()
        assert approx_equal(
            [sim.e_pot, sim.e_kin_ang, sim.e_kin_lin, sim.e_kin, sim.e_tot], [
                0.64030878777041611, 0.012310594130384761, 0.02835,
                0.04066059413038476, 0.68096938190080092
            ])
        for i in range(100):
            sim.dynamics_step(delta_t=0.01,
                              use_classical_accel=use_classical_accel)
        expected = [[
            0.028505221929112364, 0.091503230553568404, 0.56329655444242244,
            0.65479978499599079, 0.6833050069251031
        ],
                    [
                        0.053276067541032097, 0.091503230553568404,
                        0.53805622991666513, 0.62955946047023348,
                        0.68283552801126557
                    ]][int(use_classical_accel)]
        assert approx_equal(
            [sim.e_pot, sim.e_kin_ang, sim.e_kin_lin, sim.e_kin, sim.e_tot],
            expected)
示例#8
0
def exercise_reference_impl_quick():
    sites_cart = fmri.create_triangle_with_center_of_mass_at_origin()
    assert approx_equal(flex.vec3_double(sites_cart).mean(), (0, 0, 0))
    inertia1 = fmri.body_inertia(sites_cart=sites_cart)
    inertia2 = matrix.sym(sym_mat3=scitbx.math.inertia_tensor(points=flex.vec3_double(sites_cart), pivot=(0, 0, 0)))
    assert approx_equal(inertia1, inertia2)
    #
    for use_classical_accel in [False, True]:
        sim = fmri.simulation()
        assert approx_equal(
            [sim.e_pot, sim.e_kin_ang, sim.e_kin_lin, sim.e_kin, sim.e_tot],
            [0.64030878777041611, 0.012310594130384761, 0.02835, 0.04066059413038476, 0.68096938190080092],
        )
        for i in xrange(100):
            sim.dynamics_step(delta_t=0.01, use_classical_accel=use_classical_accel)
        expected = [
            [0.028505221929112364, 0.091503230553568404, 0.56329655444242244, 0.65479978499599079, 0.6833050069251031],
            [0.053276067541032097, 0.091503230553568404, 0.53805622991666513, 0.62955946047023348, 0.68283552801126557],
        ][int(use_classical_accel)]
        assert approx_equal([sim.e_pot, sim.e_kin_ang, sim.e_kin_lin, sim.e_kin, sim.e_tot], expected)