Ejemplo n.º 1
0
def tst_detwin():
  tmp = rs.xray_structure(sgtbx.space_group_info( 'P4' ),
                          elements=['C']*310,
                          n_scatterers=310)

  sfs = abs( tmp.structure_factors( False, 2.5  ).f_calc() )
  tmp_detwin = xray.hemihedral_detwinner(
     hkl_obs = sfs.indices() ,
     hkl_calc= sfs.indices(),
     space_group = sfs.space_group(),
     anomalous_flag = False,
     twin_law = [-1,0,0,  0,1,0,  0,0,-1] )#"-h,k,-l" )

  sfs = sfs.f_as_f_sq()

  tf = [0.1,0.2,0.3,0.4,0.49]
  for t in tf:
    i,s = tmp_detwin.twin_with_twin_fraction( i_obs = sfs.data(),
                                              sigma_obs = sfs.sigmas(),
                                              twin_fraction = t )
    diff = sfs.data() - i
    diff = flex.sum( flex.abs(diff) )
    assert diff>1e-3
    #check what happen when no sigmas ae passed in
    dti,dts = tmp_detwin.detwin_with_twin_fraction( i_obs = i,
                                                    sigma_obs = None,
                                                    twin_fraction= t )


    dti,dts = tmp_detwin.detwin_with_twin_fraction( i_obs = i,
                                                    sigma_obs = s,
                                                    twin_fraction= t )
    diff = sfs.data() - dti
    diff = flex.sum( flex.abs(diff) ) # / flex.sum( sfs.data() )
    assert approx_equal( diff, 0, eps=1e-5 )
    permut = tmp_detwin.obs_to_twin_obs()
    ind = range( permut.size() )
    for ii, jj, kk, pp, mm  in zip( sfs.data(), i, dti, ind, permut ):
      no = (1-t)*sfs.data()[pp] + t*sfs.data()[mm]
      assert approx_equal( jj-no, 0, eps=1e-5)
      assert approx_equal( ii-kk, 0, eps=1e-5)
Ejemplo n.º 2
0
def tst_detwin():
  tmp = rs.xray_structure(sgtbx.space_group_info( 'P4' ),
                          elements=['C']*310,
                          n_scatterers=310)

  sfs = abs( tmp.structure_factors( False, 2.5  ).f_calc() )
  tmp_detwin = xray.hemihedral_detwinner(
     hkl_obs = sfs.indices() ,
     hkl_calc= sfs.indices(),
     space_group = sfs.space_group(),
     anomalous_flag = False,
     twin_law = [-1,0,0,  0,1,0,  0,0,-1] )#"-h,k,-l" )

  sfs = sfs.f_as_f_sq()

  tf = [0.1,0.2,0.3,0.4,0.49]
  for t in tf:
    i,s = tmp_detwin.twin_with_twin_fraction( i_obs = sfs.data(),
                                              sigma_obs = sfs.sigmas(),
                                              twin_fraction = t )
    diff = sfs.data() - i
    diff = flex.sum( flex.abs(diff) )
    assert diff>1e-3
    #check what happen when no sigmas ae passed in
    dti,dts = tmp_detwin.detwin_with_twin_fraction( i_obs = i,
                                                    sigma_obs = None,
                                                    twin_fraction= t )


    dti,dts = tmp_detwin.detwin_with_twin_fraction( i_obs = i,
                                                    sigma_obs = s,
                                                    twin_fraction= t )
    diff = sfs.data() - dti
    diff = flex.sum( flex.abs(diff) ) # / flex.sum( sfs.data() )
    assert approx_equal( diff, 0, eps=1e-5 )
    permut = tmp_detwin.obs_to_twin_obs()
    ind = range( permut.size() )
    for ii, jj, kk, pp, mm  in zip( sfs.data(), i, dti, ind, permut ):
      no = (1-t)*sfs.data()[pp] + t*sfs.data()[mm]
      assert approx_equal( jj-no, 0, eps=1e-5)
      assert approx_equal( ii-kk, 0, eps=1e-5)
Ejemplo n.º 3
0
 def __init__(self):
   self.structure = xray.structure(
     crystal_symmetry=crystal.symmetry(
     unit_cell=(7.6338, 7.6338, 9.8699, 90, 90, 120),
     space_group_symbol='hall:  P 3 -2c'),
     scatterers=flex.xray_scatterer((
       xray.scatterer( #0
     label='LI',
     site=(0.032717, 0.241544, 0.254924),
     u=(0.000544, 0.000667, 0.000160,
        0.000326, 0.000072, -0.000030)),
       xray.scatterer( #1
     label='NA',
     site=(0.033809, 0.553123, 0.484646),
     u=(0.000554, 0.000731, 0.000174,
        0.000212, 0.000032, -0.000015)),
       xray.scatterer( #2
     label='S1',
     site=(0.000000, 0.000000, -0.005908),
     u=(0.000370, 0.000370, 0.000081,
        0.000185, 0.000000, 0.000000)),
       xray.scatterer( #3
     label='S2',
     site=(0.333333, 0.666667, 0.211587),
     u=(0.000244, 0.000244, 0.000148,
        0.000122, 0.000000, 0.000000)),
       xray.scatterer( #4
     label='S3',
     site=(0.666667, 0.333333, 0.250044),
     u=(0.000349, 0.000349, 0.000094,
        0.000174, 0.000000, 0.000000)),
       xray.scatterer( #5
     label='O1',
     site=(0.000000, -0.000000, 0.154207),
     u=(0.000360, 0.000360, 0.000149,
        0.000180, 0.000000, 0.000000),
     occupancy=0.999000),
       xray.scatterer( #6
     label='O2',
     site=(0.333333, 0.666667, 0.340665),
     u=(0.000613, 0.000613, 0.000128,
        0.000306, 0.000000, 0.000000)),
       xray.scatterer( #7
     label='O3',
     site=(0.666667, 0.333333, 0.112766),
     u=(0.000724, 0.000724, 0.000118,
        0.000362, 0.000000, 0.000000)),
       xray.scatterer( #8
     label='O4',
     site=(0.225316, 0.110088, -0.035765),
     u=(0.000477, 0.000529, 0.000213,
        0.000230, 0.000067, -0.000013)),
       xray.scatterer( #9
     label='O5',
     site=(0.221269, 0.442916, 0.153185),
     u=(0.000767, 0.000286, 0.000278,
        0.000210, 0.000016, -0.000082)),
       xray.scatterer( #10
     label='O6',
     site=(0.487243, 0.169031, 0.321690),
     u=(0.000566, 0.000582, 0.000354,
        0.000007, 0.000022, 0.000146))
     )))
   self.twin_laws = (sgtbx.rot_mx((0,1,0,1,0,0,0,0,-1)),)
   self.twin_fractions = flex.double((flex.random_double(),))
   self.scale_factor = 0.05 + 10 * flex.random_double()
   self.crystal_symmetry = self.structure.crystal_symmetry()
   mi = self.crystal_symmetry.build_miller_set(anomalous_flag=False,
                                               d_min=0.5)
   fo_sq = mi.structure_factors_from_scatterers(
     self.structure, algorithm="direct").f_calc().norm()
   fo_sq = fo_sq.customized_copy(
     data=fo_sq.data()*self.scale_factor,
     sigmas=flex.double(fo_sq.size(), 1))
   twin_completion = xray.twin_completion(
     mi.indices(),
     mi.space_group(),
     mi.anomalous_flag(),
     self.twin_laws[0].as_double())
   sigmas = flex.double(fo_sq.size(), 1)
   from cctbx import miller
   twin_complete_set = miller.set(
     crystal_symmetry=self.crystal_symmetry,
     indices=twin_completion.twin_complete(),
     anomalous_flag=mi.anomalous_flag()).map_to_asu()
   detwinner = xray.hemihedral_detwinner(
     hkl_obs=fo_sq.indices(),
     hkl_calc=twin_complete_set.indices(),
     space_group=mi.space_group(),
     anomalous_flag=mi.anomalous_flag(),
     twin_law=self.twin_laws[0].as_double())
   twinned_i, twinned_s = detwinner.twin_with_twin_fraction(
     fo_sq.data(),
     sigmas,
     twin_fraction=self.twin_fractions[0])
   self.fo_sq = fo_sq.customized_copy(data=twinned_i, sigmas=twinned_s)