Example #1
0
def test_2(fmodel,
           convention,
           phi=0.0,
           psi=0.0,
           the=0.0,
           trans=[0.0, 0.0, 0.0]):
    rot_obj = scitbx.rigid_body.euler(phi=phi,
                                      psi=psi,
                                      the=the,
                                      convention=convention)
    size = fmodel.xray_structure.scatterers().size()
    fmodel.xray_structure.apply_rigid_body_shift(rot=rot_obj.rot_mat(),
                                                 trans=trans)
    fmodel.update_xray_structure(update_f_calc=True)
    assert approx_equal(fmodel.r_work(), 0.0)
    params = mmtbx.refinement.rigid_body.master_params.extract()
    params.refine_rotation = True
    params.refine_translation = True
    params.target = "ls_wunit_k1"
    rb = mmtbx.refinement.rigid_body.manager(
        fmodel=fmodel,
        selections=[flex.bool(size, True).iselection()],
        params=params)
    assert approx_equal(rb.translation()[0], [0.0, 0.0, 0.0])
    assert approx_equal(rb.rotation()[0], [0.0, 0.0, 0.0])
    assert approx_equal(fmodel.r_work(), 0.0)
Example #2
0
def test_3(fmodel, convention, phi=1, psi=2, the=3, trans=[0, 0, 0]):
    rot_obj = scitbx.rigid_body.euler(phi=phi,
                                      psi=psi,
                                      the=the,
                                      convention=convention)
    size = fmodel.xray_structure.scatterers().size()
    fmodel.xray_structure.apply_rigid_body_shift(rot=rot_obj.rot_mat(),
                                                 trans=trans)
    fmodel.update_xray_structure(update_f_calc=True)
    assert fmodel.r_work() > 0.15
    params = mmtbx.refinement.rigid_body.master_params.extract()
    params.refine_rotation = True
    params.refine_translation = False
    params.high_resolution = 1.0
    params.max_iterations = 50
    params.lbfgs_line_search_max_function_evaluations = 50
    params.target = "ls_wunit_k1"
    rb = mmtbx.refinement.rigid_body.manager(
        fmodel=fmodel,
        selections=[flex.bool(size, True).iselection()],
        params=params)
    if (convention == "xyz"):
        assert approx_equal(rb.rotation()[0], [-1.0, -2.0, -3.0], 0.2)  # XXX
    assert approx_equal(rb.translation()[0], [0.0, 0.0, 0.0])
    assert approx_equal(fmodel.r_work(), 0.0)
Example #3
0
def test_5(fmodel, convention):
    size = fmodel.xray_structure.scatterers().size()
    sel1 = flex.bool()
    sel2 = flex.bool()
    for i in xrange(size):
        if (i < 500):
            sel1.append(True)
            sel2.append(False)
        else:
            sel1.append(False)
            sel2.append(True)
    selections = [sel1.iselection(), sel2.iselection()]
    rot_obj_1 = scitbx.rigid_body.euler(phi=1,
                                        psi=2,
                                        the=3,
                                        convention=convention)
    rot_obj_2 = scitbx.rigid_body.euler(phi=3,
                                        psi=2,
                                        the=1,
                                        convention=convention)
    fmodel.xray_structure.apply_rigid_body_shift(rot=rot_obj_1.rot_mat(),
                                                 trans=[0.5, 1.0, 1.5],
                                                 selection=sel1.iselection())
    fmodel.xray_structure.apply_rigid_body_shift(rot=rot_obj_2.rot_mat(),
                                                 trans=[1.5, 0.5, 1.0],
                                                 selection=sel2.iselection())
    fmodel.update_xray_structure(update_f_calc=True)
    assert fmodel.r_work() > 0.35
    params = mmtbx.refinement.rigid_body.master_params.extract()
    params.refine_rotation = True
    params.refine_translation = True
    params.high_resolution = 1.0
    params.target = "ls_wunit_k1"
    rb = mmtbx.refinement.rigid_body.manager(fmodel=fmodel,
                                             selections=selections,
                                             params=params)
    if (convention == "xyz"):
        assert approx_equal(rb.rotation()[0], [-1, -2, -3], 0.2)
        assert approx_equal(rb.rotation()[1], [-3, -2, -1], 0.2)
    assert approx_equal(rb.translation()[0], [-0.5, -1.0, -1.5], 1.e-4)
    assert approx_equal(rb.translation()[1], [-1.5, -0.5, -1.0], 1.e-4)
    assert approx_equal(fmodel.r_work(), 0.0, 0.0005)
    assert approx_equal(fmodel.r_free(), 0.0, 0.0005)
Example #4
0
def test_5(fmodel, convention):
  size = fmodel.xray_structure.scatterers().size()
  sel1 = flex.bool()
  sel2 = flex.bool()
  for i in xrange(size):
    if(i<500):
       sel1.append(True)
       sel2.append(False)
    else:
       sel1.append(False)
       sel2.append(True)
  selections = [sel1.iselection(), sel2.iselection()]
  rot_obj_1 = scitbx.rigid_body.euler(
    phi = 1, psi = 2, the = 3, convention = convention)
  rot_obj_2 = scitbx.rigid_body.euler(
    phi = 3, psi = 2, the = 1, convention = convention)
  fmodel.xray_structure.apply_rigid_body_shift(
    rot = rot_obj_1.rot_mat(),
    trans = [0.5,1.0,1.5],
    selection = sel1.iselection())
  fmodel.xray_structure.apply_rigid_body_shift(
    rot = rot_obj_2.rot_mat(),
    trans = [1.5,0.5,1.0],
    selection = sel2.iselection())
  fmodel.update_xray_structure(update_f_calc = True)
  assert fmodel.r_work() > 0.35
  params = mmtbx.refinement.rigid_body.master_params.extract()
  params.refine_rotation = True
  params.refine_translation = True
  params.high_resolution = 1.0
  params.target="ls_wunit_k1"
  rb = mmtbx.refinement.rigid_body.manager(fmodel     = fmodel,
                                           selections = selections,
                                           params     = params)
  if(convention == "xyz"):
    assert approx_equal(rb.rotation()[0], [-1,-2,-3], 0.2)
    assert approx_equal(rb.rotation()[1], [-3,-2,-1], 0.2)
  assert approx_equal(rb.translation()[0], [-0.5,-1.0,-1.5], 1.e-4)
  assert approx_equal(rb.translation()[1], [-1.5,-0.5,-1.0], 1.e-4)
  assert approx_equal(fmodel.r_work(), 0.0, 0.0005)
  assert approx_equal(fmodel.r_free(), 0.0, 0.0005)
Example #5
0
def test_2(fmodel, convention, phi = 0.0, psi = 0.0, the = 0.0,
           trans = [0.0,0.0,0.0]):
  rot_obj = scitbx.rigid_body.euler(
    phi = phi, psi = psi, the = the, convention = convention)
  size = fmodel.xray_structure.scatterers().size()
  fmodel.xray_structure.apply_rigid_body_shift(
    rot = rot_obj.rot_mat(),
    trans = trans)
  fmodel.update_xray_structure(update_f_calc = True)
  assert approx_equal(fmodel.r_work(), 0.0)
  params = mmtbx.refinement.rigid_body.master_params.extract()
  params.refine_rotation = True
  params.refine_translation = True
  params.target="ls_wunit_k1"
  rb = mmtbx.refinement.rigid_body.manager(
    fmodel     = fmodel,
    selections = [flex.bool(size,True).iselection()],
    params     = params)
  assert approx_equal(rb.translation()[0], [0.0,0.0,0.0])
  assert approx_equal(rb.rotation()[0], [0.0,0.0,0.0])
  assert approx_equal(fmodel.r_work(), 0.0)
Example #6
0
def test_4(fmodel, convention, phi =1, psi =2, the =3, trans =[0.5,1.0,1.5]):
  rot_obj = scitbx.rigid_body.euler(
    phi = phi, psi = psi, the = the, convention = convention)
  size = fmodel.xray_structure.scatterers().size()
  fmodel.xray_structure.apply_rigid_body_shift(
    rot = rot_obj.rot_mat(),
    trans = trans)
  fmodel.update_xray_structure(update_f_calc = True)
  assert fmodel.r_work() > 0.15
  params = mmtbx.refinement.rigid_body.master_params.extract()
  params.refine_rotation = True
  params.refine_translation = True
  params.high_resolution = 1.0
  params.target="ls_wunit_k1"
  rb = mmtbx.refinement.rigid_body.manager(
    fmodel     = fmodel,
    selections = [flex.bool(size,True).iselection()],
    params     = params)
  if(convention == "xyz"):
    assert approx_equal(rb.rotation()[0], [-1.0,-2.0,-3.0], 0.2) # XXX
  assert approx_equal(rb.translation()[0], [-0.5,-1.0,-1.5], 1.e-3)
  assert approx_equal(fmodel.r_work(), 0.0, 1.e-3)
Example #7
0
def finite_differences_test():
    print "finite_differences_test: "
    fmodel = get_fmodel_from_pdb(pdb_file_name="enk_rbr.pdb",
                                 algorithm="direct",
                                 d_min=2.0,
                                 target="ls_wunit_k1")
    xray.set_scatterer_grad_flags(
        scatterers=fmodel.xray_structure.scatterers(), site=True)
    for convention in ["zyz", "xyz"]:
        rot_obj = scitbx.rigid_body.euler(phi=0,
                                          psi=0,
                                          the=0,
                                          convention=convention)
        size = fmodel.xray_structure.scatterers().size()
        selections = [flex.bool(size, True).iselection()]
        fmodel.xray_structure.apply_rigid_body_shift(rot=rot_obj.rot_mat(),
                                                     trans=[1, 2, 3])
        fmodel.update_xray_structure(update_f_calc=True)
        fmodel_copy = fmodel.deep_copy()
        centers_of_mass = []
        for s in selections:
            xrs = fmodel_copy.xray_structure.select(s)
            centers_of_mass.append(xrs.center_of_mass())
        tg_obj = mmtbx.refinement.rigid_body.target_and_grads(
            centers_of_mass=centers_of_mass,
            sites_cart=fmodel_copy.xray_structure.sites_cart(),
            target_functor=fmodel_copy.target_functor(),
            rot_objs=[rot_obj],
            selections=selections,
            suppress_gradients=False)
        assert approx_equal(tg_obj.target(), fmodel_copy.target_w())
        g_rot, g_transl = tg_obj.gradients_wrt_r(), tg_obj.gradients_wrt_t()
        fd_transl = fd_translation(fmodel_copy, e=0.0001)
        assert approx_equal(list(g_transl[0]), fd_transl)
        fd_rot = fd_rotation(fmodel=fmodel_copy,
                             e=0.0001,
                             convention=convention)
        assert approx_equal(list(g_rot[0]), fd_rot)
Example #8
0
def finite_differences_test():
  print "finite_differences_test: "
  fmodel = get_fmodel_from_pdb(pdb_file_name = "enk_rbr.pdb",
                               algorithm = "direct",
                               d_min = 2.0,
                               target = "ls_wunit_k1")
  xray.set_scatterer_grad_flags(
    scatterers = fmodel.xray_structure.scatterers(),
    site       = True)
  for convention in ["zyz","xyz"]:
      rot_obj = scitbx.rigid_body.euler(
        phi = 0, psi = 0, the = 0, convention = convention)
      size = fmodel.xray_structure.scatterers().size()
      selections = [flex.bool(size, True).iselection()]
      fmodel.xray_structure.apply_rigid_body_shift(
        rot = rot_obj.rot_mat(), trans = [1,2,3])
      fmodel.update_xray_structure(update_f_calc = True)
      fmodel_copy = fmodel.deep_copy()
      centers_of_mass = []
      for s in selections:
        xrs = fmodel_copy.xray_structure.select(s)
        centers_of_mass.append(xrs.center_of_mass())
      tg_obj = mmtbx.refinement.rigid_body.target_and_grads(
        centers_of_mass = centers_of_mass,
        sites_cart      = fmodel_copy.xray_structure.sites_cart(),
        target_functor  = fmodel_copy.target_functor(),
        rot_objs        = [rot_obj],
        selections      = selections,
        suppress_gradients = False)
      assert approx_equal(tg_obj.target(),fmodel_copy.target_w())
      g_rot, g_transl = tg_obj.gradients_wrt_r(), tg_obj.gradients_wrt_t()
      fd_transl = fd_translation(fmodel_copy, e = 0.0001)
      assert approx_equal(list(g_transl[0]), fd_transl)
      fd_rot = fd_rotation(fmodel     = fmodel_copy,
                           e          = 0.0001,
                           convention = convention)
      assert approx_equal(list(g_rot[0]), fd_rot)