예제 #1
0
def exercise_2(small=1.e-9):
    m = [2, 1, 2, 0, 0, 0]
    n = [2, 2, 1, 0, 0, 0]
    m_dc = copy.deepcopy(m)
    n_dc = copy.deepcopy(n)
    qq = tools.common(n, m, small)
    assert approx_equal(m, m_dc)
    assert approx_equal(n, n_dc)
    assert qq.t() == (2.0, 1.0, 1.0, 0.0, 0.0, 0.0)
예제 #2
0
def exercise_2(small = 1.e-9):
  m = [2,1,2,0,0,0]
  n = [2,2,1,0,0,0]
  m_dc = copy.deepcopy(m)
  n_dc = copy.deepcopy(n)
  qq = tools.common(n,m,small)
  assert approx_equal(m,m_dc)
  assert approx_equal(n,n_dc)
  assert qq.t() == (2.0, 1.0, 1.0, 0.0, 0.0, 0.0)
예제 #3
0
def exercise(small=1.e-9):
    for symbol in ["P 1"]:
        space_group_info = sgtbx.space_group_info(symbol=symbol)
        random_xray_structure = random_structure.xray_structure(
            space_group_info=space_group_info,
            elements=["N"] * 10,
            volume_per_atom=50.0,
            random_u_iso=False,
            u_iso=adptbx.b_as_u(20.0))
        sg = random_xray_structure.space_group()
        uc = random_xray_structure.unit_cell()
        print(symbol, uc)
        print()
        sys.stdout.flush()
        counter = 0
        trials = 100000
        i = 0
        branch_0 = 0
        branch_1 = 0
        branch_1_1 = 0
        branch_1_2 = 0
        branch_1_2_1 = 0
        branch_1_2_2 = 0
        branch_1_2_3 = 0
        branch_1_2_3_1 = 0
        branch_1_2_3_2 = 0

        while i < trials:
            i += 1
            counter += 1
            r = random.random()
            if (r < 0.333):
                m = adptbx.random_u_cart(u_scale=20. * random.random(),
                                         u_min=0)
                n = adptbx.random_u_cart(u_scale=20. * random.random(),
                                         u_min=0)
                while 1:
                    for ind in range(6):
                        r = random.random()
                        m = flex.double(m)
                        if (r > 0.5):
                            m[ind] = n[ind]
                    m = list(m)
                    if (adptbx.is_positive_definite(m, 0)
                            and adptbx.is_positive_definite(n, 0)):
                        break
            elif (r >= 0.333 and r < 0.66):
                m, n = branch_3_mn()
            else:
                m, n = branch_2_mn(0)
            m_dc = copy.deepcopy(m)
            n_dc = copy.deepcopy(n)
            m = factor(list(m), i)
            n = factor(list(n), i)
            qq = tools.common(n, m, small)
            #assert approx_equal(m,m_dc)
            #assert approx_equal(n,n_dc)

            if (qq.branch_0()): branch_0 += 1
            if (qq.branch_1()): branch_1 += 1
            if (qq.branch_1_1()): branch_1_1 += 1
            if (qq.branch_1_2()): branch_1_2 += 1
            if (qq.branch_1_2_1()): branch_1_2_1 += 1
            if (qq.branch_1_2_2()): branch_1_2_2 += 1
            if (qq.branch_1_2_3()): branch_1_2_3 += 1
            if (qq.branch_1_2_3_1()): branch_1_2_3_1 += 1
            if (qq.branch_1_2_3_2()): branch_1_2_3_2 += 1

            if (counter >= 10000):
                counter = 0
                print("." * 30, symbol)
                print("i= ", i, "out of ", trials)
                print("branch_0       = ", branch_0)
                print("branch_1       = ", branch_1)
                print("branch_1_1     = ", branch_1_1)
                print("branch_1_2     = ", branch_1_2)
                print("branch_1_2_1   = ", branch_1_2_1)
                print("branch_1_2_2   = ", branch_1_2_2)
                print("branch_1_2_3   = ", branch_1_2_3)
                print("branch_1_2_3_1 = ", branch_1_2_3_1)
                print("branch_1_2_3_2 = ", branch_1_2_3_2)
                sys.stdout.flush()
예제 #4
0
def exercise_branch_2_1(small=1.e-9):
    m = [2, 1, 2, 0, 0, 0]
    n = [2, 1, 1, 0, 0, 0]
    counter = 0
    trials = 100000
    i = 0
    branch_0 = 0
    branch_1 = 0
    branch_1_1 = 0
    branch_1_2 = 0
    branch_1_2_1 = 0
    branch_1_2_2 = 0
    branch_1_2_3 = 0
    branch_1_2_3_1 = 0
    branch_1_2_3_2 = 0
    while i < trials:
        i += 1
        m = [2, 1, 2, 0, 0, 0]
        n = [2, 1, 1, 0, 0, 0]
        counter += 1
        c = scitbx.math.euler_angles_as_matrix(
            [random.uniform(0, 360) for j in range(3)], deg=True).elems
        r = random.random()
        if (r < 0.25):
            m = adptbx.c_u_c_transpose(c, m)
            n = adptbx.c_u_c_transpose(c, n)
        elif (r >= 0.25 and r < 0.5):
            m = adptbx.c_u_c_transpose(c, m)
        elif (r >= 0.5 and r < 0.75):
            n = adptbx.c_u_c_transpose(c, n)
        else:
            r = random.random()
            run_away = 1000
            while run_away > 0:
                run_away -= 1
                r = random.random()
                if (r < 0.33):
                    m = adptbx.c_u_c_transpose(c, m)
                    n = adptbx.c_u_c_transpose(c, n)
                elif (r >= 0.33 and r < 0.66):
                    m = adptbx.c_u_c_transpose(c, m)
                else:
                    n = adptbx.c_u_c_transpose(c, n)
                m = adptbx.c_u_c_transpose(c, m)
                n = adptbx.c_u_c_transpose(c, n)
                m = [
                    m[0], m[1], m[2], m[3] * random.choice((0, 1)),
                    m[4] * random.choice((0, 1)), m[5] * random.choice((0, 1))
                ]
                n = [
                    n[0], n[1], n[2], n[3] * random.choice((0, 1)),
                    n[4] * random.choice((0, 1)), n[5] * random.choice((0, 1))
                ]
                m = factor(list(m), i)
                n = factor(list(n), i)
                if (adptbx.is_positive_definite(m, small)
                        and adptbx.is_positive_definite(n, small)):
                    break

        m_dc = copy.deepcopy(m)
        n_dc = copy.deepcopy(n)
        qq = tools.common(n, m, small)
        #assert approx_equal(m,m_dc)
        #assert approx_equal(n,n_dc)

        if (qq.branch_0()): branch_0 += 1
        if (qq.branch_1()): branch_1 += 1
        if (qq.branch_1_1()): branch_1_1 += 1
        if (qq.branch_1_2()): branch_1_2 += 1
        if (qq.branch_1_2_1()): branch_1_2_1 += 1
        if (qq.branch_1_2_2()): branch_1_2_2 += 1
        if (qq.branch_1_2_3()): branch_1_2_3 += 1
        if (qq.branch_1_2_3_1()): branch_1_2_3_1 += 1
        if (qq.branch_1_2_3_2()): branch_1_2_3_2 += 1

        if (counter >= 10000):
            counter = 0
            print("." * 30)
            print("i= ", i, "out of ", trials)
            print("branch_0       = ", branch_0)
            print("branch_1       = ", branch_1)
            print("branch_1_1     = ", branch_1_1)
            print("branch_1_2     = ", branch_1_2)
            print("branch_1_2_1   = ", branch_1_2_1)
            print("branch_1_2_2   = ", branch_1_2_2)
            print("branch_1_2_3   = ", branch_1_2_3)
            print("branch_1_2_3_1 = ", branch_1_2_3_1)
            print("branch_1_2_3_2 = ", branch_1_2_3_2)
            sys.stdout.flush()
예제 #5
0
def exercise(small = 1.e-9):
  for symbol in ["P 1"]:
      space_group_info = sgtbx.space_group_info(symbol = symbol)
      random_xray_structure = random_structure.xray_structure(
                                       space_group_info  = space_group_info,
                                       elements          = ["N"]*10,
                                       volume_per_atom   = 50.0,
                                       random_u_iso      = False,
                                       u_iso             = adptbx.b_as_u(20.0))
      sg = random_xray_structure.space_group()
      uc = random_xray_structure.unit_cell()
      print symbol, uc
      print
      sys.stdout.flush()
      counter = 0
      trials = 100000
      i = 0
      branch_0       = 0
      branch_1       = 0
      branch_1_1     = 0
      branch_1_2     = 0
      branch_1_2_1   = 0
      branch_1_2_2   = 0
      branch_1_2_3   = 0
      branch_1_2_3_1 = 0
      branch_1_2_3_2 = 0

      while i < trials:
          i += 1
          counter += 1
          r = random.random()
          if(r < 0.333):
             m = adptbx.random_u_cart(u_scale=20.*random.random(), u_min=0)
             n = adptbx.random_u_cart(u_scale=20.*random.random(), u_min=0)
             while 1:
               for ind in xrange(6):
                   r = random.random()
                   m = flex.double(m)
                   if(r > 0.5):
                      m[ind] = n[ind]
               m = list(m)
               if(adptbx.is_positive_definite(m,0) and
                  adptbx.is_positive_definite(n,0)): break
          elif(r>=0.333 and r<0.66):
             m,n = branch_3_mn()
          else:
             m,n = branch_2_mn(0)
          m_dc = copy.deepcopy(m)
          n_dc = copy.deepcopy(n)
          m = factor(list(m), i)
          n = factor(list(n), i)
          qq = tools.common(n,m,small)
          #assert approx_equal(m,m_dc)
          #assert approx_equal(n,n_dc)

          if(qq.branch_0()      ):   branch_0       += 1
          if(qq.branch_1()      ):   branch_1       += 1
          if(qq.branch_1_1()    ):   branch_1_1     += 1
          if(qq.branch_1_2()    ):   branch_1_2     += 1
          if(qq.branch_1_2_1()  ):   branch_1_2_1   += 1
          if(qq.branch_1_2_2()  ):   branch_1_2_2   += 1
          if(qq.branch_1_2_3()  ):   branch_1_2_3   += 1
          if(qq.branch_1_2_3_1()):   branch_1_2_3_1 += 1
          if(qq.branch_1_2_3_2()):   branch_1_2_3_2 += 1


          if (counter >= 10000):
             counter = 0
             print "."*30, symbol
             print "i= ", i, "out of ", trials
             print "branch_0       = ", branch_0
             print "branch_1       = ", branch_1
             print "branch_1_1     = ", branch_1_1
             print "branch_1_2     = ", branch_1_2
             print "branch_1_2_1   = ", branch_1_2_1
             print "branch_1_2_2   = ", branch_1_2_2
             print "branch_1_2_3   = ", branch_1_2_3
             print "branch_1_2_3_1 = ", branch_1_2_3_1
             print "branch_1_2_3_2 = ", branch_1_2_3_2
             sys.stdout.flush()
예제 #6
0
def exercise_branch_2_1(small = 1.e-9):
  m = [2,1,2,0,0,0]
  n = [2,1,1,0,0,0]
  counter = 0
  trials = 100000
  i = 0
  branch_0       = 0
  branch_1       = 0
  branch_1_1     = 0
  branch_1_2     = 0
  branch_1_2_1   = 0
  branch_1_2_2   = 0
  branch_1_2_3   = 0
  branch_1_2_3_1 = 0
  branch_1_2_3_2 = 0
  while i < trials:
      i += 1
      m = [2,1,2,0,0,0]
      n = [2,1,1,0,0,0]
      counter += 1
      c = scitbx.math.euler_angles_as_matrix(
                    [random.uniform(0,360) for j in xrange(3)], deg=True).elems
      r = random.random()
      if(r<0.25):
         m = adptbx.c_u_c_transpose(c, m)
         n = adptbx.c_u_c_transpose(c, n)
      elif(r>=0.25 and r < 0.5):
         m = adptbx.c_u_c_transpose(c, m)
      elif(r>=0.5 and r < 0.75):
         n = adptbx.c_u_c_transpose(c, n)
      else:
         r = random.random()
         run_away = 1000
         while run_away > 0:
            run_away -= 1
            r = random.random()
            if(r<0.33):
               m = adptbx.c_u_c_transpose(c, m)
               n = adptbx.c_u_c_transpose(c, n)
            elif(r>=0.33 and r < 0.66):
               m = adptbx.c_u_c_transpose(c, m)
            else:
               n = adptbx.c_u_c_transpose(c, n)
            m = adptbx.c_u_c_transpose(c, m)
            n = adptbx.c_u_c_transpose(c, n)
            m = [m[0],m[1],m[2],m[3]*random.choice((0,1)),m[4]*random.choice((0,1)),m[5]*random.choice((0,1))]
            n = [n[0],n[1],n[2],n[3]*random.choice((0,1)),n[4]*random.choice((0,1)),n[5]*random.choice((0,1))]
            m = factor(list(m), i)
            n = factor(list(n), i)
            if(adptbx.is_positive_definite(m,small) and
               adptbx.is_positive_definite(n,small)): break


      m_dc = copy.deepcopy(m)
      n_dc = copy.deepcopy(n)
      qq = tools.common(n,m,small)
      #assert approx_equal(m,m_dc)
      #assert approx_equal(n,n_dc)

      if(qq.branch_0()      ):   branch_0       += 1
      if(qq.branch_1()      ):   branch_1       += 1
      if(qq.branch_1_1()    ):   branch_1_1     += 1
      if(qq.branch_1_2()    ):   branch_1_2     += 1
      if(qq.branch_1_2_1()  ):   branch_1_2_1   += 1
      if(qq.branch_1_2_2()  ):   branch_1_2_2   += 1
      if(qq.branch_1_2_3()  ):   branch_1_2_3   += 1
      if(qq.branch_1_2_3_1()):   branch_1_2_3_1 += 1
      if(qq.branch_1_2_3_2()):   branch_1_2_3_2 += 1

      if (counter >= 10000):
         counter = 0
         print "."*30
         print "i= ", i, "out of ", trials
         print "branch_0       = ", branch_0
         print "branch_1       = ", branch_1
         print "branch_1_1     = ", branch_1_1
         print "branch_1_2     = ", branch_1_2
         print "branch_1_2_1   = ", branch_1_2_1
         print "branch_1_2_2   = ", branch_1_2_2
         print "branch_1_2_3   = ", branch_1_2_3
         print "branch_1_2_3_1 = ", branch_1_2_3_1
         print "branch_1_2_3_2 = ", branch_1_2_3_2
         sys.stdout.flush()