コード例 #1
0
  def test_compare_rotation_and_translation(self):
    print 'Running ',sys._getframe().f_code.co_name
    pdb_inp1 = iotbx.pdb.input(source_info=None, lines=test_pdb)
    pdb_inp2 = iotbx.pdb.input(source_info=None, lines=test_cif)
    trans_obj1 = ncs.input(
        hierarchy=pdb_inp1.construct_hierarchy(),
        transform_info=pdb_inp1.process_MTRIX_records())
    trans_obj2 = ncs.input(
        hierarchy=pdb_inp2.construct_hierarchy(),
        transform_info=pdb_inp2.process_MTRIX_records())

    # trans_obj1 = ncs.input(pdb_string=test_pdb)
    # trans_obj2 = ncs.input(cif_string=test_cif)
    #
    nrg1 = trans_obj1.get_ncs_restraints_group_list()
    nrg2 = trans_obj2.get_ncs_restraints_group_list()

    x1 = nu.concatenate_rot_tran(ncs_restraints_group_list=nrg1)
    x2 = nu.concatenate_rot_tran(ncs_restraints_group_list=nrg2)

    x = (x1 - x2).as_double()
    self.assertEqual(x.min_max_mean().as_tuple(), (0,0,0))
    #
    pdb_inp = iotbx.pdb.input(source_info=None, lines=test_cif)
    transform_info = pdb_inp.process_MTRIX_records()
    results = transform_info.as_pdb_string()

    pdb_inp = iotbx.pdb.input(source_info=None, lines=test_pdb)
    transform_info = pdb_inp.process_MTRIX_records()
    expected = transform_info.as_pdb_string()

    self.assertEqual(results,expected)
コード例 #2
0
 def test_finding_partial_ncs(self):
   # print sys._getframe().f_code.co_name
   ncs_inp = ncs.input(
     pdb_string=pdb_str,
     check_atom_order=True,
     min_percent=0.2)
   t = ncs_inp.ncs_to_asu_selection
   exp_t1 = {
     "(chain 'A' and (name N or name CA or name C or name O ))":
       ["chain 'B'",
        "(chain 'C' and (name N or name CA or name C or name O ))"]}
   self.assertEqual(t,exp_t1)
   #
   ncs_inp = ncs.input(
     pdb_string=pdb_str,
     check_atom_order=False,
     allow_different_size_res=False)
   t = ncs_inp.ncs_to_asu_selection
   exp_t2 = {"chain 'A'": ["chain 'C'"]}
   self.assertEqual(t,exp_t2)
   #
   ncs_inp = ncs.input(
     pdb_string=pdb_str,
     check_atom_order=False,
     allow_different_size_res=True)
   t = ncs_inp.ncs_to_asu_selection
   self.assertEqual(t,exp_t1)
   #
   self.assertRaises(Sorry,ncs.input,
                     pdb_string=pdb_str,
                     process_similar_chains=False)
コード例 #3
0
  def test_print_ncs_phil_param(self):
    """ Verify correct printout of NCS phil parameters.
    need to supply exclude_selection=None because model consist only from UNK
    residues. """
    # print sys._getframe().f_code.co_name
    pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_test_data2)
    phil_groups = ncs_group_master_phil.fetch(
        iotbx.phil.parse(pdb_test_data2_phil)).extract()
    trans_obj = ncs.input(
      ncs_phil_groups=phil_groups.ncs_group,
      hierarchy=pdb_inp.construct_hierarchy(),
      exclude_selection=None)
    result = trans_obj.print_ncs_phil_param(write=False)
    # print "="*50
    # print "resutl"
    # print result
    # print "="*50
    test = (pdb_test_data2_phil == result)
    test = test or (pdb_test_data2_phil_reverse == result)
    self.assertTrue(test)
    #


    spec_object = mmtbx.ncs.ncs.ncs()
    spec_object.read_ncs(lines=test_ncs_spec.splitlines())
    trans_obj = ncs.input(
      spec_ncs_groups=spec_object,
      hierarchy = self.pdb_inp.construct_hierarchy())
    result = trans_obj.print_ncs_phil_param(write=False)
    self.assertEqual(result,test_phil_3)
コード例 #4
0
    def test_print_ncs_phil_param(self):
        """ Verify correct printout of NCS phil parameters.
    need to supply exclude_selection=None because model consist only from UNK
    residues. """
        # print sys._getframe().f_code.co_name
        pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_test_data2)
        phil_groups = ncs_group_master_phil.fetch(
            iotbx.phil.parse(pdb_test_data2_phil)).extract()
        trans_obj = ncs.input(ncs_phil_groups=phil_groups.ncs_group,
                              hierarchy=pdb_inp.construct_hierarchy(),
                              exclude_selection=None)
        result = trans_obj.print_ncs_phil_param(write=False)
        # print "="*50
        # print "resutl"
        # print result
        # print "="*50
        test = (pdb_test_data2_phil == result)
        test = test or (pdb_test_data2_phil_reverse == result)
        self.assertTrue(test)
        #

        spec_object = mmtbx.ncs.ncs.ncs()
        spec_object.read_ncs(lines=test_ncs_spec.splitlines())
        trans_obj = ncs.input(spec_ncs_groups=spec_object,
                              hierarchy=self.pdb_inp.construct_hierarchy())
        result = trans_obj.print_ncs_phil_param(write=False)
        self.assertEqual(result, test_phil_3)
コード例 #5
0
  def test_spec_file_format(self):
    """ Verify that spec object are produced properly """
    # print sys._getframe().f_code.co_name

    multimer_data = multimer(
      pdb_str=pdb_test_data2,
      reconstruction_type='cau')
    pdb_inp = pdb.input(source_info=None, lines=pdb_test_data2)
    t_i = pdb_inp.process_mtrix_records()
    pdb_h = pdb_inp.construct_hierarchy()
    trans_obj = ncs.input(
        hierarchy=pdb_h,
        transform_info=t_i)
    pdb_hierarchy_asu = multimer_data.assembled_multimer
    # print "pdb_hierarchy_asu", pdb_hierarchy_asu.as_pdb_string()
    spec_output = trans_obj.get_ncs_info_as_spec(
      pdb_hierarchy_asu=pdb_hierarchy_asu)

    trans_obj2 = ncs.input(spec_ncs_groups=spec_output)

    # print "t1", trans_obj.ncs_transform
    # print "t2", trans_obj2.ncs_transform
    t1 = trans_obj.ncs_transform['0000000002'].r
    t2 = trans_obj2.ncs_transform['0000000002'].r
    self.assertEqual(t1,t2)
    self.assertEqual(len(trans_obj.ncs_transform),len(trans_obj2.ncs_transform))

    t1 = trans_obj.ncs_to_asu_selection
    t1_expected = {'chain A or chain B':
                     ['chain C or chain D', 'chain E or chain F']}
    self.assertEqual(t1,t1_expected)
    t2 = trans_obj2.ncs_to_asu_selection
    t2_expected = {
      'chain A and (resseq 1:3 or resseq 6:7)':
        ['chain C and (resseq 1:3 or resseq 6:7)',
         'chain E and (resseq 1:3 or resseq 6:7)'],
      'chain B and (resseq 4:5)':
        ['chain D and (resseq 4:5)', 'chain F and (resseq 4:5)']}
    self.assertEqual(t2,t2_expected)

    # print "trans_obj.tr_id_to_selection", trans_obj.tr_id_to_selection
    t1 = trans_obj.tr_id_to_selection['chain A_0000000003']
    t1_expected = ('chain A',
                   'chain E')
    self.assertEqual(t1,t1_expected)

    t2 = trans_obj2.tr_id_to_selection['chain A_0000000003']
    t2_expected = ('chain A and (resseq 1:3 or resseq 6:7)',
                   'chain E and (resseq 1:3 or resseq 6:7)')
    self.assertEqual(t2,t2_expected)
コード例 #6
0
 def test_rotaion_translation_input(self):
     """ Verify correct processing    """
     r1 = matrix.sqr([
         -0.955168, 0.257340, -0.146391, 0.248227, 0.426599, -0.869711,
         -0.161362, -0.867058, -0.471352
     ])
     r2 = matrix.sqr([
         -0.994267, -0.046533, -0.096268, -0.065414, -0.447478, 0.89189,
         -0.084580, 0.893083, 0.441869
     ])
     t1 = matrix.col([167.54320, -4.09250, 41.98070])
     t2 = matrix.col([176.73730, 27.41760, -5.85930])
     trans_obj = ncs.input(hierarchy=iotbx.pdb.input(
         source_info=None, lines=pdb_str2).construct_hierarchy(),
                           rotations=[r1, r2],
                           translations=[t1, t2])
     nrg = trans_obj.get_ncs_restraints_group_list()[0]
     self.assertEqual(list(nrg.master_iselection),
                      [0, 1, 2, 3, 4, 5, 6, 7, 8])
     c1 = nrg.copies[0]
     self.assertEqual(list(c1.iselection),
                      [9, 10, 11, 12, 13, 14, 15, 16, 17])
     c2 = nrg.copies[1]
     self.assertEqual(list(c2.iselection),
                      [18, 19, 20, 21, 22, 23, 24, 25, 26])
     #
     self.assertEqual(r1, c1.r)
     self.assertEqual(r2, c2.r)
     self.assertEqual(t1, c1.t)
     self.assertEqual(t2, c2.t)
コード例 #7
0
def test_transform_update():
    """ Test update of rotation and translation using selection """
    pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_answer_0)
    ncs_obj = ncs.input(hierarchy=pdb_inp.construct_hierarchy())
    pdb_inp = iotbx.pdb.input(lines=pdb_answer_0, source_info=None)
    nrgl = ncs_obj.get_ncs_restraints_group_list()
    asu_site_cart = pdb_inp.atoms().extract_xyz()
    # reference matrices
    r1 = nrgl[0].copies[0].r
    t1 = nrgl[0].copies[0].t
    r2 = nrgl[0].copies[1].r
    t2 = nrgl[0].copies[1].t
    # modify matrices in the ncs group list
    nrgl[0].copies[0].r = r1 + r2
    nrgl[0].copies[0].t = t1 + t2
    nrgl[0].copies[1].r = r1 + r2
    nrgl[0].copies[1].t = t1 + t2
    nrgl.recalculate_ncs_transforms(asu_site_cart)
    # Get the updated values
    r1_n = nrgl[0].copies[0].r
    t1_n = nrgl[0].copies[0].t
    r2_n = nrgl[0].copies[1].r
    t2_n = nrgl[0].copies[1].t
    #
    assert approx_equal(r1, r1_n, eps=0.001)
    assert approx_equal(t1, t1_n, eps=0.1)
    assert approx_equal(r2, r2_n, eps=0.001)
    assert approx_equal(t2, t2_n, eps=0.1)
コード例 #8
0
 def test_rotaion_translation_input(self):
   """ Verify correct processing    """
   r1 = matrix.sqr([-0.955168,0.257340,-0.146391,
                    0.248227,0.426599,-0.869711,
                    -0.161362,-0.867058,-0.471352])
   r2 = matrix.sqr([-0.994267,-0.046533,-0.096268,
                    -0.065414,-0.447478,0.89189,
                    -0.084580,0.893083,0.441869])
   t1 = matrix.col([167.54320,-4.09250,41.98070])
   t2 = matrix.col([176.73730,27.41760,-5.85930])
   trans_obj = ncs.input(
     hierarchy=iotbx.pdb.input(source_info=None, lines=pdb_str2).construct_hierarchy(),
     rotations=[r1,r2],
     translations=[t1,t2])
   nrg = trans_obj.get_ncs_restraints_group_list()[0]
   self.assertEqual(list(nrg.master_iselection),[0, 1, 2, 3, 4, 5, 6, 7, 8])
   c1 = nrg.copies[0]
   self.assertEqual(list(c1.iselection),[9,10,11,12,13,14,15,16,17])
   c2 = nrg.copies[1]
   self.assertEqual(list(c2.iselection),[18,19,20,21,22,23,24,25,26])
   #
   self.assertEqual(r1,c1.r)
   self.assertEqual(r2,c2.r)
   self.assertEqual(t1,c1.t)
   self.assertEqual(t2,c2.t)
コード例 #9
0
  def test_phil_processing(self):
    """ Verify that phil parameters are properly processed
    need to supply exclude_selection=None because model consist only from UNK
    residues. """
    # print sys._getframe().f_code.co_name
    # read file and create pdb object
    pdb_obj = pdb.hierarchy.input(pdb_string=pdb_test_data2)
    trans_obj = ncs.input(
        ncs_phil_string = pdb_test_data2_phil,
        pdb_hierarchy_inp=pdb_obj,
        exclude_selection=None)

    expected = '(chain A) or (chain B or chain C)'
    self.assertEqual(trans_obj.ncs_selection_str,expected)

    expected = {'chain A': ['chain D', 'chain G'],
                'chain B or chain C': ['chain E or chain F',
                                       'chain H or chain I']}
    self.assertEqual(trans_obj.ncs_to_asu_selection,expected)
    # check ncs_transform
    group_ids = [x.ncs_group_id for x in trans_obj.ncs_transform.itervalues()]
    tran_sn = {x.serial_num for x in trans_obj.ncs_transform.itervalues()}
    group_keys = {x for x in trans_obj.ncs_transform.iterkeys()}
    #
    self.assertEqual(len(group_ids),6)
    self.assertEqual(set(group_ids),{1,2})
    self.assertEqual(tran_sn,{1,2,3,4,5,6})
    self.assertEqual(group_keys,{'005','004','006','001','003','002'})
    self.assertEqual(trans_obj.ncs_atom_selection.count(True),4)
コード例 #10
0
 def test_transform_update(self):
   """ Test update of rotation and translation using selection """
   pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_answer_0)
   ncs_obj = ncs.input(hierarchy=pdb_inp.construct_hierarchy())
   pdb_inp = iotbx.pdb.input(lines=pdb_answer_0,source_info=None)
   nrgl = ncs_obj.get_ncs_restraints_group_list()
   asu_site_cart = pdb_inp.atoms().extract_xyz()
   # reference matrices
   r1 = nrgl[0].copies[0].r
   t1 = nrgl[0].copies[0].t
   r2 = nrgl[0].copies[1].r
   t2 = nrgl[0].copies[1].t
   # modify matrices in the ncs group list
   nrgl[0].copies[0].r = r1 + r2
   nrgl[0].copies[0].t = t1 + t2
   nrgl[0].copies[1].r = r1 + r2
   nrgl[0].copies[1].t = t1 + t2
   nu.recalculate_ncs_transforms(nrgl,asu_site_cart)
   # Get the updated values
   r1_n = nrgl[0].copies[0].r
   t1_n = nrgl[0].copies[0].t
   r2_n = nrgl[0].copies[1].r
   t2_n = nrgl[0].copies[1].t
   #
   self.assertTrue(is_same_transform(r1,t1,r1_n,t1_n))
   self.assertTrue(is_same_transform(r2,t2,r2_n,t2_n))
コード例 #11
0
 def test_superpos_pdb(self):
     """  verify creation of transformations using superpose_pdb
 need to supply exclude_selection=None because model consist only from UNK
 residues. """
     # print sys._getframe().f_code.co_name
     # read file and create pdb object
     pdb_inp = pdb.input(source_info=None, lines=pdb_test_data1)
     phil_groups = ncs_group_master_phil.fetch(
         iotbx.phil.parse(pdb_test_data1_phil)).extract()
     p = iotbx.ncs.input.get_default_params()
     p.ncs_search.exclude_selection = None
     p.ncs_search.minimum_number_of_atoms_in_copy = 0
     trans_obj = ncs.input(ncs_phil_groups=phil_groups.ncs_group,
                           hierarchy=pdb_inp.construct_hierarchy(),
                           params=p.ncs_search)
     nrgl = trans_obj.get_ncs_restraints_group_list()
     # nrgl._show()
     sels = nrgl.get_array_of_str_selections()
     assert sels == [["chain 'A'", "chain 'C'", "chain 'E'"],
                     ["chain 'B'", "chain 'D'", "chain 'F'"]]
     self.assertTrue(
         approx_equal(nrgl[0].copies[0].r,
                      matrix.sqr([
                          0.309017, -0.809017, 0.5, 0.809017, 0.5, 0.309017,
                          -0.5, 0.309017, 0.809017
                      ]),
                      eps=0.01))
コード例 #12
0
def exercise_3():
    """
  Same as 2, but also provide groups and don't check them allowing AC to be
  included
  """

    phil_str = """
ncs_group {
  reference = chain A
  selection = chain B
}
"""

    search_params = ncs.input.get_default_params()
    search_params.ncs_search.exclude_selection = "element H or element D"
    search_params.ncs_search.validate_user_supplied_groups = False
    phil_groups = ncs_group_master_phil.fetch(
        iotbx.phil.parse(phil_str)).extract()
    h = iotbx.pdb.input(lines=pdb_str_1,
                        source_info=None).construct_hierarchy()
    ncs_inp = ncs.input(hierarchy=h,
                        params=search_params.ncs_search,
                        ncs_phil_groups=phil_groups.ncs_group)
    ncs_groups = ncs_inp.get_ncs_restraints_group_list()
    assert len(ncs_groups) == 1
    assert ncs_groups[0].master_iselection.size(
    ) == 72, ncs_groups[0].master_iselection.size()
    assert ncs_groups[0].master_iselection.size(
    ) == ncs_groups[0].copies[0].iselection.size()
    assert h.atoms_size() == 72 * 2, h.atoms_size()  # covers whole model
コード例 #13
0
  def setUp(self):
    # set_test_matrix
    self.rot1 = flex.vec3_double([
      (-0.317946, -0.173437, 0.932111),
      ( 0.760735, -0.633422, 0.141629),
      ( 0.565855,  0.754120, 0.333333)])
    self.rot2 = flex.vec3_double([
      (0       ,  0       , 1),
      (0.784042, -0.620708, 0),
      (0.620708,  0.784042, 0)])
    self.rot3 = flex.vec3_double([
      ( 0       ,  0       , -1),
      ( 0.097445, -0.995241,  0),
      (-0.995241, -0.097445,  0)])
    # Angles for rot, in radians
    self.rot_angles1 = flex.double(
      (-0.4017753, 1.2001985, 2.6422171))
    self.rot_angles2 = flex.double(
      (-0.4017753, math.pi/2, 2.6422171))
    self.rot_angles3 = flex.double(
      (-0.4017753, -math.pi/2, 2.6422171))
    self.rot_angles1_deg = flex.double(
      (-0.4017753, 1.2001985, 2.6422171)) * 180/math.pi
    self.rotation1 = matrix.sqr(self.rot1.as_double())
    self.rotation2 = matrix.sqr(self.rot2.as_double())
    self.rotation3 = matrix.sqr(self.rot3.as_double())
    self.translation1 = matrix.rec((0.5,-0.5,0),(3,1))
    self.translation2 = matrix.rec((0,0,0),(3,1))
    self.translation3 = matrix.rec((0,1,2),(3,1))
    self.r_t = [[self.rotation1, self.translation1],
                [self.rotation2, self.translation2],
                [self.rotation3, self.translation3]]

    self.pdb_inp = iotbx.pdb.input(source_info=None, lines=test_pdb_str)
    self.tr_obj1 = ncs.input(
      hierarchy=self.pdb_inp.construct_hierarchy(),
      rotations=[self.rotation1,self.rotation2],
      translations=[self.translation1,self.translation2])
    self.tr_obj2 = ncs.input(
      hierarchy=self.pdb_inp.construct_hierarchy(),
      rotations=[self.rotation1,self.rotation2,self.rotation3],
      translations=[self.translation1,self.translation2,self.translation3])
    self.ncs_restraints_group_list = \
      self.tr_obj1.get_ncs_restraints_group_list()
コード例 #14
0
  def test_adding_transforms_directly(self):
    """
    Verify that processing of transforms provided manually is done properly """
    # print sys._getframe().f_code.co_name
    pdb_obj = pdb.hierarchy.input(pdb_string=pdb_test_data4)
    r = [matrix.sqr([0.1,1.0,1.0,0.2,0.5,0.6,0.7,0.8,0.9])]
    r.append(matrix.sqr([1.0,0.2,1.0,0.2,0.5,0.6,0.7,0.8,0.4]))
    t = [matrix.col([0,2,1])]
    t.append(matrix.col([-1,3,-2]))
    transforms_obj = ncs.input(
      hierarchy = pdb_obj.hierarchy,
      rotations=r,
      translations=t)

    result = transforms_obj.transform_to_ncs
    expected = {'0000000002': ['chain A_0000000002', 'chain B_0000000002'],
                '0000000003': ['chain A_0000000003', 'chain B_0000000003']}
    self.assertEqual(result,expected)
    result = transforms_obj.ncs_selection_str
    expected = 'chain A or chain B'
    self.assertEqual(result,expected)
    # check that if transforms are provided MTRIX record ignored
    pdb_obj = pdb.hierarchy.input(pdb_string=pdb_test_data2)
    pdb_h = pdb.input(source_info=None, lines=pdb_test_data2).construct_hierarchy()
    transforms_obj = ncs.input(
      hierarchy = pdb_h,
      rotations=r,
      translations=t)
    result = transforms_obj.transform_to_ncs
    expected = {'0000000002': ['chain A_0000000002', 'chain B_0000000002'],
                '0000000003': ['chain A_0000000003', 'chain B_0000000003']}
    self.assertEqual(result,expected)
    result = transforms_obj.ncs_selection_str
    expected = 'chain A or chain B'
    self.assertEqual(result,expected)
    # transforms that are not present
    result = transforms_obj.transform_to_ncs.keys()
    expected = ['0000000002', '0000000003']
    self.assertEqual(result,expected)
    # all transforms
    result = transforms_obj.ncs_transform.keys()
    expected = ['0000000001', '0000000002', '0000000003']
    result.sort()
    self.assertEqual(result,expected)
コード例 #15
0
  def test_spec_file_format(self):
    """ Verify that spec object are produced properly """
    # print sys._getframe().f_code.co_name

    multimer_data = multimer(
      pdb_str=pdb_test_data2,
      reconstruction_type='cau')

    trans_obj = ncs.input(pdb_string=pdb_test_data2)

    pdb_hierarchy_asu = multimer_data.assembled_multimer
    spec_output = trans_obj.get_ncs_info_as_spec(
      pdb_hierarchy_asu=pdb_hierarchy_asu,write=False)

    trans_obj2 = ncs.input(spec_ncs_groups=spec_output)

    t1 = trans_obj.ncs_transform['002'].r
    t2 = trans_obj2.ncs_transform['002'].r
    self.assertEqual(t1,t2)
    self.assertEqual(len(trans_obj.ncs_transform),len(trans_obj2.ncs_transform))

    t1 = trans_obj.ncs_to_asu_selection
    t1_expected = {'chain A or chain B':
                     ['chain E or chain F', 'chain C or chain D']}
    self.assertEqual(t1,t1_expected)
    t2 = trans_obj2.ncs_to_asu_selection
    t2_expected = {
      'chain A and (resseq 1:3 or resseq 6:7)':
        ['chain C and (resseq 1:3 or resseq 6:7)',
         'chain E and (resseq 1:3 or resseq 6:7)'],
      'chain B and (resseq 4:5)':
        ['chain D and (resseq 4:5)', 'chain F and (resseq 4:5)']}
    self.assertEqual(t2,t2_expected)

    t1 = trans_obj.tr_id_to_selection['chain A_003']
    t1_expected = ('chain A',
                   'chain E')
    self.assertEqual(t1,t1_expected)

    t2 = trans_obj2.tr_id_to_selection['chain A_003']
    t2_expected = ('chain A and (resseq 1:3 or resseq 6:7)',
                   'chain E and (resseq 1:3 or resseq 6:7)')
    self.assertEqual(t2,t2_expected)
コード例 #16
0
def exercise_01():
    """
  Verify that processing of transforms provided manually is done properly """
    pdb_obj = pdb.hierarchy.input(pdb_string=pdb_str_2)
    r = [matrix.sqr([0.1, 1.0, 1.0, 0.2, 0.5, 0.6, 0.7, 0.8, 0.9])]
    r.append(matrix.sqr([1.0, 0.2, 1.0, 0.2, 0.5, 0.6, 0.7, 0.8, 0.4]))
    t = [matrix.col([0, 2, 1])]
    t.append(matrix.col([-1, 3, -2]))
    transforms_obj = ncs.input(hierarchy=pdb_obj.hierarchy,
                               rotations=r,
                               translations=t)
    result = transforms_obj.transform_to_ncs
    expected = {
        '0000000002': ['chain A_0000000002', 'chain B_0000000002'],
        '0000000003': ['chain A_0000000003', 'chain B_0000000003']
    }
    assert result == expected
    result = transforms_obj.ncs_selection_str
    expected = 'chain A or chain B'
    assert result == expected
    # check that if transforms are provided MTRIX record ignored
    pdb_obj = pdb.hierarchy.input(pdb_string=pdb_str_1)
    pdb_h = pdb.input(source_info=None, lines=pdb_str_1).construct_hierarchy()
    transforms_obj = ncs.input(hierarchy=pdb_h, rotations=r, translations=t)
    result = transforms_obj.transform_to_ncs
    expected = {
        '0000000002': ['chain A_0000000002', 'chain B_0000000002'],
        '0000000003': ['chain A_0000000003', 'chain B_0000000003']
    }
    assert result == expected
    result = transforms_obj.ncs_selection_str
    expected = 'chain A or chain B'
    assert result == expected
    # transforms that are not present
    result = transforms_obj.transform_to_ncs.keys()
    expected = ['0000000002', '0000000003']
    assert result == expected
    # all transforms
    result = transforms_obj.ncs_transform.keys()
    expected = ['0000000001', '0000000002', '0000000003']
    result.sort()
    assert result == expected
コード例 #17
0
 def test_finding_partial_ncs(self):
   # print sys._getframe().f_code.co_name
   ncs_inp = ncs.input(
     hierarchy=iotbx.pdb.input(source_info=None, lines=pdb_str).construct_hierarchy(),
     chain_similarity_threshold=0.2)
   t = ncs_inp.ncs_to_asu_selection
   exp_t1 = {
     "(chain 'A' and (name N or name CA or name C or name O ))":
       ["chain 'B'",
        "(chain 'C' and (name N or name CA or name C or name O ))"]}
   self.assertEqual(t,exp_t1)
コード例 #18
0
 def test_phenix_refine_ncs_file(self):
   """ Check that we get file with "refinement.ncs.constraint_group"
   for phenix refine"""
   ncs_obj = ncs.input(pdb_string=pdb_str)
   self.assertTrue(ncs_obj.number_of_ncs_groups>0)
   ncs_obj.get_ncs_info_as_spec(
     write=True,
     log=null_out())
   file_data = open('simple_ncs_from_pdb.ncs','r').read().splitlines()
   test = ['ncs_group' in x for x in file_data]
   self.assertTrue(test.count(True)==1)
コード例 #19
0
 def test_ncs_group_iselection(self):
   """ selection of a complete NCS group """
   ncs_obj = ncs.input(pdb_string=test_pdb_str_2,ncs_phil_string=phil_str)
   nrgl = ncs_obj.get_ncs_restraints_group_list()
   self.assertEqual(len(nrgl),2)
   isel = nu.ncs_group_iselection(nrgl,1)
   expected = [4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23]
   self.assertEqual(list(isel),expected)
   isel = nu.ncs_group_iselection(nrgl,0)
   expected = [0, 1, 2, 3, 8, 9, 10, 11, 16, 17, 18, 19]
   self.assertEqual(list(isel),expected)
コード例 #20
0
 def test_print_ncs_phil_param(self):
   """ Verify correct printout of NCS phil parameters.
   need to supply exclude_selection=None because model consist only from UNK
   residues. """
   # print sys._getframe().f_code.co_name
   pdb_obj = pdb.hierarchy.input(pdb_string=pdb_test_data2)
   trans_obj = ncs.input(
     ncs_phil_string = pdb_test_data2_phil,
     pdb_hierarchy_inp=pdb_obj,
     exclude_selection=None)
   result = trans_obj.print_ncs_phil_param(write=False)
   test = (pdb_test_data2_phil == result)
   test = test or (pdb_test_data2_phil_reverse == result)
   self.assertTrue(test)
   #
   trans_obj = ncs.input(
     spec_file_str=test_ncs_spec,
     pdb_hierarchy_inp = self.pdb_obj)
   result = trans_obj.print_ncs_phil_param(write=False)
   self.assertEqual(result,test_phil_3)
コード例 #21
0
def test_selection():
    """
  test that a atom selection propagates correctly to ncs_restraints_group_list
  """
    pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_answer_0)
    ncs_obj_phil = ncs.input(hierarchy=pdb_inp.construct_hierarchy())
    nrg = ncs_obj_phil.get_ncs_restraints_group_list()

    m1 = list(nrg[0].master_iselection)
    c1 = list(nrg[0].copies[0].iselection)
    c2 = list(nrg[0].copies[1].iselection)

    assert len(m1) == len(
        c1)  #                                           renumbering
    assert m1 == [0, 1, 2, 3, 4, 5, 6]  #   0,  1, X,  3, X,  5, X | 0, 1, 3
    assert c1 == [7, 8, 9, 10, 11, 12,
                  13]  #   7,  8, 9,  X, X, 12, X | 4, 5, 7
    assert c2 == [14, 15, 16, 17, 18, 19,
                  20]  #  14, 15, X, 17, X, 19, X | 8, 9, 11

    selection1 = flex.size_t([0, 1, 5, 3, 100, 101])
    selection2 = flex.size_t([0, 1, 5, 3, 7, 8, 9, 12, 100, 101])
    selection3 = flex.size_t(
        [0, 1, 5, 3, 7, 8, 9, 12, 14, 15, 19, 17, 100, 101])
    # gone iseqs for selection3: 2,4,6,10,11,13,16,18,20-99

    new_nrg = nrg.select(flex.bool(102, selection1))
    # only atoms in master are selected
    mt = list(new_nrg[0].master_iselection)
    c1t = list(new_nrg[0].copies[0].iselection)

    assert mt == []
    assert c1t == []

    # atoms selected in both master and copies
    new_nrg = nrg.select(flex.bool(102, selection2))
    # only atoms in master are selected
    mt = list(new_nrg[0].master_iselection)
    c1t = list(new_nrg[0].copies[0].iselection)

    assert mt == []
    assert c1t == []

    new_nrg = nrg.select(flex.bool(102, selection3))
    # only atoms in master are selected
    mt = list(new_nrg[0].master_iselection)
    c1t = list(new_nrg[0].copies[0].iselection)
    c2t = list(new_nrg[0].copies[1].iselection)

    assert mt == [0, 1, 3], list(mt)
    assert c1t == [4, 5, 7], list(c1t)
    assert c2t == [8, 9, 11], list(c2t)
コード例 #22
0
def exercise_1():
    """
  Pure NCS search with AC and water that should be dropped
  """
    h = iotbx.pdb.input(lines=pdb_str_1,
                        source_info=None).construct_hierarchy()
    ncs_inp = ncs.input(hierarchy=h)
    ncs_groups = ncs_inp.get_ncs_restraints_group_list()
    assert len(ncs_groups) == 1
    assert ncs_groups[0].master_iselection.size(
    ) == 50, ncs_groups[0].master_iselection.size()
    assert ncs_groups[0].master_iselection.size(
    ) == ncs_groups[0].copies[0].iselection.size()
コード例 #23
0
 def test_check_ncs_group_list(self):
   """ Test that ncs_restraints_group_list test is working properly """
   ncs_obj_phil = ncs.input(
       pdb_string=test_pdb_str_2,
       ncs_phil_string=phil_str)
   nrgl = ncs_obj_phil.get_ncs_restraints_group_list()
   pdb_inp = pdb.input(lines=test_pdb_str_2,source_info=None)
   ph = pdb_inp.construct_hierarchy()
   # passing test
   self.assertTrue(nu.check_ncs_group_list(nrgl,ph,max_delta=1))
   # make sure test fails when it suppose to
   nrgl[0].copies[1].t = matrix.col([100, -89.7668, 5.8996])
   self.assertFalse(nu.check_ncs_group_list(nrgl,ph,max_delta=1))
コード例 #24
0
 def test_processing_of_asu_2(self):
   """ processing complete ASU
   If MTRIX records are present, they are ignored
   This maybe ncs.ncs - specific functionality, not clear yet.
   """
   # print sys._getframe().f_code.co_name
   # reading and processing the spec file
   trans_obj = ncs.input(hierarchy = self.pdb_inp.construct_hierarchy())
   nrgl = trans_obj.get_ncs_restraints_group_list()
   # nrgl._show()
   sels = nrgl.get_array_of_str_selections()
   assert sels == [["chain 'A'", "chain 'B'", "chain 'C'"],
       ["chain 'D'", "chain 'E'"]]
コード例 #25
0
 def test_finding_partial_ncs(self):
     # print sys._getframe().f_code.co_name
     ncs_inp = ncs.input(hierarchy=iotbx.pdb.input(
         source_info=None, lines=pdb_str).construct_hierarchy(),
                         chain_similarity_threshold=0.2)
     t = ncs_inp.ncs_to_asu_selection
     exp_t1 = {
         "(chain 'A' and (name N or name CA or name C or name O ))": [
             "chain 'B'",
             "(chain 'C' and (name N or name CA or name C or name O ))"
         ]
     }
     self.assertEqual(t, exp_t1)
コード例 #26
0
def exercise_06():
    """ Test that when building bio-molecule and then finding NCS relatin
  from it, we get the same rotation and translation"""
    pdb_strings = [pdb_str_4, pdb_str_5]
    for method, pdb_string in enumerate(pdb_strings):
        pdb_inp = pdb.input(source_info=None, lines=pdb_string)
        crystal_symmetry = pdb_inp.crystal_symmetry()
        # The exact transforms from pdb_string
        r1_expected = matrix.sqr([
            0.309017, -0.951057, 0.0, 0.951057, 0.309017, -0.0, 0.0, 0.0, 1.0
        ])
        r2_expected = matrix.sqr([
            -0.809017, -0.587785, 0.0, 0.587785, -0.809017, -0.0, 0.0, 0.0, 1.0
        ])
        t1_expected = matrix.col([0, 0, 7])
        t2_expected = matrix.col([0, 0, 0])
        # Look at biomt records retrieved from PDB file
        if method == 0:
            rec = pdb_inp.process_BIOMT_records()
            h = pdb_inp.construct_hierarchy_BIOMT_expanded()
        else:
            rec = pdb_inp.process_MTRIX_records()
            h = pdb_inp.construct_hierarchy_MTRIX_expanded()
        r1 = rec.r[1]
        r2 = rec.r[2]
        t1 = rec.t[1]
        t2 = rec.t[2]
        (the_same, transpose) = is_same_transform(r1, t1, r1_expected,
                                                  t1_expected)
        assert the_same
        (the_same, transpose) = is_same_transform(r2, t2, r2_expected,
                                                  t2_expected)
        assert the_same
        # Look at the rotation and translation found by the NCS search
        s = h.as_pdb_string(crystal_symmetry=crystal_symmetry)
        ncs_obj = ncs.input(hierarchy=pdb.input(source_info=None,
                                                lines=s).construct_hierarchy())
        r1 = ncs_obj.ncs_transform['0000000002'].r
        t1 = ncs_obj.ncs_transform['0000000002'].t
        r2 = ncs_obj.ncs_transform['0000000003'].r
        t2 = ncs_obj.ncs_transform['0000000003'].t
        (the_same, transpose) = is_same_transform(r1, t1, r1_expected,
                                                  t1_expected)
        assert the_same
        (the_same, transpose) = is_same_transform(r2, t2, r2_expected,
                                                  t2_expected)
        assert the_same
        if method == 0:
            assert ncs_obj.number_of_ncs_groups == 1
        elif method == 1:
            assert ncs_obj.number_of_ncs_groups == 2
コード例 #27
0
 def test_proper_biomat_application(self):
   """ Test that when building bio-molecule and then finding NCS relatin
   from it, we get the same rotation and translation"""
   pdb_strings = [pdb_test_data7,pdb_test_data8]
   methods = ['ba','cau']
   for method,pdb_string in zip(methods,pdb_strings):
     print "method:", method
     pdb_inp = pdb.input(source_info=None, lines=pdb_string)
     crystal_symmetry = pdb_inp.crystal_symmetry()
     m = multimer(
       pdb_str=pdb_string,
       round_coordinates=False,
       reconstruction_type=method,
       error_handle=True,eps=1e-2)
     # The exact transforms from pdb_string
     r1_expected = matrix.sqr(
       [0.309017, -0.951057, 0.0,0.951057, 0.309017,-0.0,0.0,0.0,1.0])
     r2_expected = matrix.sqr(
       [-0.809017,-0.587785,0.0,0.587785,-0.809017,-0.0,0.0,0.0,1.0])
     t1_expected = matrix.col([0,0,7])
     t2_expected = matrix.col([0,0,0])
     # Look at biomt records retrieved from PDB file
     if method == 'ba':
       rec = pdb_inp.process_BIOMT_records()
     else:
       rec = pdb_inp.process_mtrix_records()
     r1 = rec.r[1]
     r2 = rec.r[2]
     t1 = rec.t[1]
     t2 = rec.t[2]
     (the_same, transpose) = is_same_transform(r1,t1,r1_expected,t1_expected)
     self.assertTrue(the_same)
     (the_same, transpose)= is_same_transform(r2,t2,r2_expected,t2_expected)
     self.assertTrue(the_same)
     # Look at the rotation and translation found by the NCS search
     s = m.assembled_multimer.as_pdb_string(crystal_symmetry=crystal_symmetry)
     print "new h:", s
     ncs_obj = ncs.input(pdb_string=s)
     print "ncs_obj.number_of_ncs_groups", ncs_obj.number_of_ncs_groups
     r1 = ncs_obj.ncs_transform['002'].r
     t1 = ncs_obj.ncs_transform['002'].t
     r2 = ncs_obj.ncs_transform['003'].r
     t2 = ncs_obj.ncs_transform['003'].t
     (the_same, transpose) = is_same_transform(r1,t1,r1_expected,t1_expected)
     self.assertTrue(the_same)
     (the_same, transpose)= is_same_transform(r2,t2,r2_expected,t2_expected)
     self.assertTrue(the_same)
     if method == 'ba':
       self.assertEqual(ncs_obj.number_of_ncs_groups,1)
     elif method == 'cau':
       self.assertEqual(ncs_obj.number_of_ncs_groups,2)
コード例 #28
0
    def setUp(self):
        # set_test_matrix
        self.rot1 = flex.vec3_double([(-0.317946, -0.173437, 0.932111),
                                      (0.760735, -0.633422, 0.141629),
                                      (0.565855, 0.754120, 0.333333)])
        self.rot2 = flex.vec3_double([(0, 0, 1), (0.784042, -0.620708, 0),
                                      (0.620708, 0.784042, 0)])
        self.rot3 = flex.vec3_double([(0, 0, -1), (0.097445, -0.995241, 0),
                                      (-0.995241, -0.097445, 0)])
        # Angles for rot, in radians
        self.rot_angles1 = flex.double((-0.4017753, 1.2001985, 2.6422171))
        self.rot_angles2 = flex.double((-0.4017753, math.pi / 2, 2.6422171))
        self.rot_angles3 = flex.double((-0.4017753, -math.pi / 2, 2.6422171))
        self.rot_angles1_deg = flex.double(
            (-0.4017753, 1.2001985, 2.6422171)) * 180 / math.pi
        self.rotation1 = matrix.sqr(self.rot1.as_double())
        self.rotation2 = matrix.sqr(self.rot2.as_double())
        self.rotation3 = matrix.sqr(self.rot3.as_double())
        self.translation1 = matrix.rec((0.5, -0.5, 0), (3, 1))
        self.translation2 = matrix.rec((0, 0, 0), (3, 1))
        self.translation3 = matrix.rec((0, 1, 2), (3, 1))
        self.r_t = [[self.rotation1, self.translation1],
                    [self.rotation2, self.translation2],
                    [self.rotation3, self.translation3]]

        self.pdb_inp = iotbx.pdb.input(source_info=None, lines=test_pdb_str)
        self.tr_obj1 = ncs.input(
            hierarchy=self.pdb_inp.construct_hierarchy(),
            rotations=[self.rotation1, self.rotation2],
            translations=[self.translation1, self.translation2])
        self.tr_obj2 = ncs.input(
            hierarchy=self.pdb_inp.construct_hierarchy(),
            rotations=[self.rotation1, self.rotation2, self.rotation3],
            translations=[
                self.translation1, self.translation2, self.translation3
            ])
        self.ncs_restraints_group_list = \
          self.tr_obj1.get_ncs_restraints_group_list()
コード例 #29
0
  def test_compare_rotation_and_translation(self):
    print 'Running ',sys._getframe().f_code.co_name
    trans_obj1 = ncs.input(pdb_string=test_pdb)
    trans_obj2 = ncs.input(cif_string=test_cif)
    #
    nrg1 = trans_obj1.get_ncs_restraints_group_list()
    nrg2 = trans_obj2.get_ncs_restraints_group_list()

    x1 = nu.concatenate_rot_tran(ncs_restraints_group_list=nrg1)
    x2 = nu.concatenate_rot_tran(ncs_restraints_group_list=nrg2)

    x = (x1 - x2).as_double()
    self.assertEqual(x.min_max_mean().as_tuple(), (0,0,0))
    #
    pdb_hierarchy_inp = pdb.hierarchy.input(pdb_string=test_cif)
    transform_info = pdb_hierarchy_inp.input.process_mtrix_records()
    results = transform_info.as_pdb_string()

    pdb_hierarchy_inp = pdb.hierarchy.input(pdb_string=test_pdb)
    transform_info = pdb_hierarchy_inp.input.process_mtrix_records()
    expected = transform_info.as_pdb_string()

    self.assertEqual(results,expected)
コード例 #30
0
  def test_superpos_pdb(self):
    """  verify creation of transformations using superpose_pdb
    need to supply exclude_selection=None because model consist only from UNK
    residues. """
    # print sys._getframe().f_code.co_name
    # read file and create pdb object
    pdb_inp = pdb.input(source_info=None, lines=pdb_test_data1)
    phil_groups = ncs_group_master_phil.fetch(
        iotbx.phil.parse(pdb_test_data1_phil)).extract()
    trans_obj = ncs.input(
        ncs_phil_groups=phil_groups.ncs_group,
        hierarchy=pdb_inp.construct_hierarchy(),
        exclude_selection=None)

    # print "trans_obj.ncs_selection_str", trans_obj.ncs_selection_str
    # print "trans_obj.ncs_to_asu_selection", trans_obj.ncs_to_asu_selection
    self.assertEqual(trans_obj.ncs_selection_str,"(chain 'A') or (chain 'B')")
    expected = {"chain 'A'": ["chain 'C'", "chain 'E'"],
                "chain 'B'": ["chain 'D'", "chain 'F'"]}
    self.assertEqual(trans_obj.ncs_to_asu_selection,expected)
    # check ncs_transform
    group_ids = [x.ncs_group_id for x in trans_obj.ncs_transform.itervalues()]
    tran_sn = {x.serial_num for x in trans_obj.ncs_transform.itervalues()}
    group_keys = {x for x in trans_obj.ncs_transform.iterkeys()}
    r1 = trans_obj.ncs_transform['0000000004'].r
    r2 = trans_obj.ncs_transform['0000000002'].r
    #
    self.assertEqual(len(group_ids),6)
    self.assertEqual(set(group_ids),{1,2})
    self.assertEqual(tran_sn,{1,2,3,4,5,6})
    self.assertEqual(group_keys,{'0000000005','0000000004','0000000006','0000000001','0000000003','0000000002'})
    #
    self.assertTrue(r1.is_r3_identity_matrix())
    expected_r = matrix.sqr(
      [0.309017,-0.809017,0.5,0.809017,0.5,0.309017,-0.5,0.309017,0.809017])
    d = r2 - expected_r
    d = map(abs,d)
    self.assertTrue(max(d)<0.01)

    # test that ncs_asu does not contain the identity transforms
    expected = {"chain 'A'_0000000002", "chain 'A'_0000000003", "chain 'B'_0000000005", "chain 'B'_0000000006"}
    self.assertEqual(expected,set(trans_obj.ncs_to_asu_map.keys()))

    # test mapping of the different selection in the NCS
    self.assertEqual(list(trans_obj.asu_to_ncs_map["chain 'A'"]),[0,1])
    self.assertEqual(list(trans_obj.asu_to_ncs_map["chain 'B'"]),[2])

    # test that transform_chain_assignment contains all transforms
    self.assertEqual(expected,set(trans_obj.transform_chain_assignment))
コード例 #31
0
def exercise_2():
    """
  Same as 1, but include water
  """
    search_params = ncs.input.get_default_params()
    search_params.ncs_search.exclude_selection = "element H or element D"
    h = iotbx.pdb.input(lines=pdb_str_1,
                        source_info=None).construct_hierarchy()
    ncs_inp = ncs.input(hierarchy=h, params=search_params.ncs_search)
    ncs_groups = ncs_inp.get_ncs_restraints_group_list()
    assert len(ncs_groups) == 1
    assert ncs_groups[0].master_iselection.size(
    ) == 57, ncs_groups[0].master_iselection.size()
    assert ncs_groups[0].master_iselection.size(
    ) == ncs_groups[0].copies[0].iselection.size()
コード例 #32
0
 def test_ncs_group_iselection(self):
   """ selection of a complete NCS group """
   phil_groups = ncs_group_master_phil.fetch(
       iotbx.phil.parse(phil_str)).extract()
   pdb_inp = iotbx.pdb.input(source_info=None, lines=test_pdb_str_2)
   ncs_obj = ncs.input(hierarchy=pdb_inp.construct_hierarchy(),
       ncs_phil_groups=phil_groups.ncs_group)
   nrgl = ncs_obj.get_ncs_restraints_group_list()
   self.assertEqual(len(nrgl),2)
   isel = nu.ncs_group_iselection(nrgl,1)
   expected = [4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23]
   self.assertEqual(list(isel),expected)
   isel = nu.ncs_group_iselection(nrgl,0)
   expected = [0, 1, 2, 3, 8, 9, 10, 11, 16, 17, 18, 19]
   self.assertEqual(list(isel),expected)
コード例 #33
0
 def test_ncs_group_iselection(self):
     """ selection of a complete NCS group """
     phil_groups = ncs_group_master_phil.fetch(
         iotbx.phil.parse(phil_str)).extract()
     pdb_inp = iotbx.pdb.input(source_info=None, lines=test_pdb_str_2)
     ncs_obj = ncs.input(hierarchy=pdb_inp.construct_hierarchy(),
                         ncs_phil_groups=phil_groups.ncs_group)
     nrgl = ncs_obj.get_ncs_restraints_group_list()
     self.assertEqual(len(nrgl), 2)
     isel = nu.ncs_group_iselection(nrgl, 1)
     expected = [4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23]
     self.assertEqual(list(isel), expected)
     isel = nu.ncs_group_iselection(nrgl, 0)
     expected = [0, 1, 2, 3, 8, 9, 10, 11, 16, 17, 18, 19]
     self.assertEqual(list(isel), expected)
コード例 #34
0
def exercise_00():
    """ Verify that spec object are produced properly """
    pdb_inp = pdb.input(source_info=None, lines=pdb_str_1)
    t_i = pdb_inp.process_MTRIX_records()
    pdb_h = pdb_inp.construct_hierarchy()
    trans_obj = ncs.input(hierarchy=pdb_h, transform_info=t_i)
    pdb_inp = pdb.input(source_info=None, lines=pdb_str_1)
    spec_output = trans_obj.get_ncs_info_as_spec(
        pdb_hierarchy_asu=pdb_inp.construct_hierarchy_MTRIX_expanded())
    trans_obj2 = ncs.input(spec_ncs_groups=spec_output)
    t1 = trans_obj.ncs_transform['0000000002'].r
    t2 = trans_obj2.ncs_transform['0000000002'].r
    assert approx_equal(t1, t2)
    assert len(trans_obj.ncs_transform) == len(trans_obj2.ncs_transform)
    t1 = trans_obj.ncs_to_asu_selection
    t1_expected = {
        'chain A or chain B': ['chain C or chain D', 'chain E or chain F']
    }
    assert t1 == t1_expected
    t2 = trans_obj2.ncs_to_asu_selection
    t2_expected = {
        'chain A and (resseq 1:3 or resseq 6:7)': [
            'chain C and (resseq 1:3 or resseq 6:7)',
            'chain E and (resseq 1:3 or resseq 6:7)'
        ],
        'chain B and (resseq 4:5)':
        ['chain D and (resseq 4:5)', 'chain F and (resseq 4:5)']
    }
    assert t2 == t2_expected
    t1 = trans_obj.tr_id_to_selection['chain A_0000000003']
    t1_expected = ('chain A', 'chain E')
    assert t1 == t1_expected
    t2 = trans_obj2.tr_id_to_selection['chain A_0000000003']
    t2_expected = ('chain A and (resseq 1:3 or resseq 6:7)',
                   'chain E and (resseq 1:3 or resseq 6:7)')
    assert t2 == t2_expected
コード例 #35
0
 def test_finding_partial_ncs(self):
   # print sys._getframe().f_code.co_name
   params = ncs.input.get_default_params()
   params.ncs_search.chain_similarity_threshold = 0.2
   ncs_inp = ncs.input(
     hierarchy=iotbx.pdb.input(source_info=None, lines=pdb_str).construct_hierarchy(),
     params = params.ncs_search)
   nrgl = ncs_inp.get_ncs_restraints_group_list()
   # nrgl._show()
   sels = nrgl.get_array_of_str_selections()
   print sels
   assert sels == [[
       "(chain 'A' and (name N or name CA or name C or name O ))",
       "chain 'B'",
       "(chain 'C' and (name N or name CA or name C or name O ))"]]
コード例 #36
0
def test_ncs_selection():
    """
  verify that extended_ncs_selection, which include the master ncs copy and
  the portion of the protein we want to refine.
  """
    pdb_inp = iotbx.pdb.input(source_info=None, lines=test_pdb_str_2)
    ncs_obj_phil = ncs.input(hierarchy=pdb_inp.construct_hierarchy())
    ncs_restraints_group_list = ncs_obj_phil.get_ncs_restraints_group_list()
    # ncs_restraints_group_list._show()
    refine_selection = flex.size_t(range(30))
    result = ncs_restraints_group_list.get_extended_ncs_selection(
        refine_selection=refine_selection)
    # print list(result)
    expected = [0, 1, 2, 3, 4, 5, 6, 7, 24, 25, 26, 27, 28, 29]
    assert list(result) == expected
コード例 #37
0
def test_whole_group_iselection():
    """ selection of a complete NCS group """
    phil_groups = ncs_group_master_phil.fetch(
        iotbx.phil.parse(phil_str)).extract()
    pdb_inp = iotbx.pdb.input(source_info=None, lines=test_pdb_str_2)
    ncs_obj = ncs.input(hierarchy=pdb_inp.construct_hierarchy(),
                        ncs_phil_groups=phil_groups.ncs_group)
    nrgl = ncs_obj.get_ncs_restraints_group_list()
    assert len(nrgl) == nrgl.get_n_groups() == 2
    isel = nrgl[1].whole_group_iselection()
    expected = [4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23]
    assert list(isel) == expected
    isel = nrgl[0].whole_group_iselection()
    expected = [0, 1, 2, 3, 8, 9, 10, 11, 16, 17, 18, 19]
    assert list(isel) == expected
コード例 #38
0
 def test_check_ncs_group_list(self):
     """ Test that ncs_restraints_group_list test is working properly """
     phil_groups = ncs_group_master_phil.fetch(
         iotbx.phil.parse(phil_str)).extract()
     pdb_inp = iotbx.pdb.input(source_info=None, lines=test_pdb_str_2)
     ncs_obj_phil = ncs.input(hierarchy=pdb_inp.construct_hierarchy(),
                              ncs_phil_groups=phil_groups.ncs_group)
     nrgl = ncs_obj_phil.get_ncs_restraints_group_list()
     pdb_inp = iotbx.pdb.input(lines=test_pdb_str_2, source_info=None)
     ph = pdb_inp.construct_hierarchy()
     # passing test
     self.assertTrue(nu.check_ncs_group_list(nrgl, ph, chain_max_rmsd=1))
     # make sure test fails when it suppose to
     nrgl[0].copies[1].t = matrix.col([100, -89.7668, 5.8996])
     self.assertFalse(nu.check_ncs_group_list(nrgl, ph, chain_max_rmsd=1))
コード例 #39
0
 def test_check_ncs_group_list(self):
   """ Test that ncs_restraints_group_list test is working properly """
   phil_groups = ncs_group_master_phil.fetch(
       iotbx.phil.parse(phil_str)).extract()
   pdb_inp = iotbx.pdb.input(source_info=None, lines=test_pdb_str_2)
   ncs_obj_phil = ncs.input(
       hierarchy=pdb_inp.construct_hierarchy(),
       ncs_phil_groups=phil_groups.ncs_group)
   nrgl = ncs_obj_phil.get_ncs_restraints_group_list()
   pdb_inp = iotbx.pdb.input(lines=test_pdb_str_2,source_info=None)
   ph = pdb_inp.construct_hierarchy()
   # passing test
   self.assertTrue(nu.check_ncs_group_list(nrgl,ph,chain_max_rmsd=1))
   # make sure test fails when it suppose to
   nrgl[0].copies[1].t = matrix.col([100, -89.7668, 5.8996])
   self.assertFalse(nu.check_ncs_group_list(nrgl,ph,chain_max_rmsd=1))
コード例 #40
0
ファイル: tst_ncs.py プロジェクト: dials/cctbx
def exercise_06():
    """ Test that when building bio-molecule and then finding NCS relations
  from it, we get the same rotation and translation"""
    pdb_strings = [pdb_str_4, pdb_str_5]
    for method, pdb_string in enumerate(pdb_strings):
        pdb_inp = pdb.input(source_info=None, lines=pdb_string)
        model = mmtbx.model.manager(pdb_inp, expand_with_mtrix=False)
        crystal_symmetry = model.crystal_symmetry()
        # The exact transforms from pdb_string
        r1_expected = matrix.sqr([
            0.309017, -0.951057, 0.0, 0.951057, 0.309017, -0.0, 0.0, 0.0, 1.0
        ])
        r2_expected = matrix.sqr([
            -0.809017, -0.587785, 0.0, 0.587785, -0.809017, -0.0, 0.0, 0.0, 1.0
        ])
        t1_expected = matrix.col([0, 0, 7])
        t2_expected = matrix.col([0, 0, 0])
        # Look at biomt records retrieved from PDB file
        if method == 0:
            rec = model._model_input.process_BIOMT_records()
            model.expand_with_BIOMT_records()
            h = model.get_hierarchy()
        else:
            rec = model._model_input.process_MTRIX_records()
            model.expand_with_MTRIX_records()
            h = model.get_hierarchy()
        r1 = rec.r[1]
        r2 = rec.r[2]
        t1 = rec.t[1]
        t2 = rec.t[2]
        assert approx_equal(r1, r1_expected, eps=0.001)
        assert approx_equal(t1, t1_expected, eps=0.1)
        assert approx_equal(r2, r2_expected, eps=0.001)
        assert approx_equal(t2, t2_expected, eps=0.1)
        # Look at the rotation and translation found by the NCS search
        s = h.as_pdb_string(crystal_symmetry=crystal_symmetry)
        ncs_obj = ncs.input(hierarchy=pdb.input(source_info=None,
                                                lines=s).construct_hierarchy())
        nrgl = ncs_obj.get_ncs_restraints_group_list()
        assert approx_equal(r1_expected, nrgl[0].copies[0].r, eps=0.001)
        assert approx_equal(t1_expected, nrgl[0].copies[0].t, eps=0.1)
        assert approx_equal(r2_expected, nrgl[0].copies[1].r, eps=0.001)
        assert approx_equal(t2_expected, nrgl[0].copies[1].t, eps=0.1)
        if method == 0:
            assert nrgl.get_n_groups() == 1
        elif method == 1:
            assert nrgl.get_n_groups() == 2
コード例 #41
0
  def test_superpos_pdb(self):
    """  verify creation of transformations using superpose_pdb
    need to supply exclude_selection=None because model consist only from UNK
    residues. """
    # print sys._getframe().f_code.co_name
    # read file and create pdb object
    pdb_obj = pdb.hierarchy.input(pdb_string=pdb_test_data1)
    trans_obj = ncs.input(
        ncs_phil_string = pdb_test_data1_phil,
        pdb_hierarchy_inp=pdb_obj,
        exclude_selection=None)

    self.assertEqual(trans_obj.ncs_selection_str,'(chain A) or (chain B)')
    expected = {'chain A': ['chain C', 'chain E'],
                'chain B': ['chain D', 'chain F']}
    self.assertEqual(trans_obj.ncs_to_asu_selection,expected)
    # check ncs_transform
    group_ids = [x.ncs_group_id for x in trans_obj.ncs_transform.itervalues()]
    tran_sn = {x.serial_num for x in trans_obj.ncs_transform.itervalues()}
    group_keys = {x for x in trans_obj.ncs_transform.iterkeys()}
    r1 = trans_obj.ncs_transform['004'].r
    r2 = trans_obj.ncs_transform['002'].r
    #
    self.assertEqual(len(group_ids),6)
    self.assertEqual(set(group_ids),{1,2})
    self.assertEqual(tran_sn,{1,2,3,4,5,6})
    self.assertEqual(group_keys,{'005','004','006','001','003','002'})
    #
    self.assertTrue(r1.is_r3_identity_matrix())
    expected_r = matrix.sqr(
      [0.309017,-0.809017,0.5,0.809017,0.5,0.309017,-0.5,0.309017,0.809017])
    d = r2 - expected_r
    d = map(abs,d)
    self.assertTrue(max(d)<0.01)

    # test that ncs_asu does not contain the identity transforms
    expected = {'chain A_002', 'chain A_003', 'chain B_005', 'chain B_006'}
    self.assertEqual(expected,set(trans_obj.ncs_to_asu_map.keys()))

    # test mapping of the different selection in the NCS
    self.assertEqual(list(trans_obj.asu_to_ncs_map['chain A']),[0,1])
    self.assertEqual(list(trans_obj.asu_to_ncs_map['chain B']),[2])

    # test that transform_chain_assignment contains all transforms
    expected = {'chain A_002', 'chain A_003', 'chain B_005', 'chain B_006'}
    self.assertEqual(expected,set(trans_obj.transform_chain_assignment))
コード例 #42
0
 def test_identity_tranform_insertion(self):
   """
   Verify that insertion and reordering of the identity transform is done
   properly
   need to use exclude_selection=None because test pdb files contain only UNK
   residues.
   """
   # print sys._getframe().f_code.co_name
   for pdb_str in [pdb_test_data5,pdb_test_data6]:
     ncs_inp = ncs.input(pdb_string=pdb_str, exclude_selection=None)
     transform_info = ncs_inp.build_MTRIX_object()
     self.assertEqual(len(transform_info.r),3)
     self.assertEqual(len(transform_info.t),3)
     self.assertEqual(transform_info.r[0].is_r3_identity_matrix(),True)
     self.assertEqual(transform_info.t[0].is_col_zero(),True)
     sn = [int(x) for x in transform_info.serial_number]
     self.assertEqual(sn,[1,2,3])
コード例 #43
0
    def test_get_list_of_best_ncs_copy_map_correlation(self):
        """
    Verifying that we get a list of chain index for the chain with the best
    map correlation
    """
        # print sys._getframe().f_code.co_name

        d_min = 1.0
        pdb_inp = iotbx.pdb.input(lines=pdb_poor_0, source_info=None)
        ncs_inp = ncs.input(hierarchy=pdb_inp.construct_hierarchy())
        ncs_restraints_group_list = ncs_inp.get_ncs_restraints_group_list()

        pdb_inp_poor = iotbx.pdb.input(lines=pdb_poor_0, source_info=None)
        ph_poor = pdb_inp_poor.construct_hierarchy(sort_atoms=False)
        ph_poor.atoms().reset_i_seq()
        xrs_poor = pdb_inp_poor.xray_structure_simple()

        pdb_inp_answer = iotbx.pdb.input(lines=pdb_answer_0, source_info=None)
        ph_answer = pdb_inp_answer.construct_hierarchy()
        ph_answer.atoms().reset_i_seq()
        xrs_answer = pdb_inp_answer.xray_structure_simple()

        fc = xrs_answer.structure_factors(d_min=d_min,
                                          algorithm="direct").f_calc()
        fft_map = fc.fft_map(resolution_factor=0.25)
        fft_map.apply_sigma_scaling()
        map_data = fft_map.real_map_unpadded()

        selections = [
            flex.size_t([0, 1, 2, 3, 4, 5, 6]),
            flex.size_t([7, 8, 9, 10, 11, 12, 13]),
            flex.size_t([14, 15, 16, 17, 18, 19, 20])
        ]

        mp = mmtbx.maps.correlation.from_map_and_xray_structure_or_fmodel(
            xray_structure=xrs_poor, map_data=map_data, d_min=d_min)

        cc = mp.cc(selections=selections)

        nu.get_list_of_best_ncs_copy_map_correlation(
            ncs_groups=ncs_restraints_group_list,
            xray_structure=xrs_poor,
            map_data=map_data,
            d_min=d_min)
コード例 #44
0
 def test_phil_param_read(self):
   """ Verify that phil parameters are properly read   """
   # print sys._getframe().f_code.co_name
   # check correctness
   expected_ncs_selection =['(chain A)','(chain A) or (chain B)']
   expected_ncs_to_asu = [
     {'chain A': ['chain B', 'chain C']},
     {'chain A': ['chain C', 'chain E'], 'chain B': ['chain D', 'chain F']}]
   expected_ncs_chains = [['chain A'],['chain A', 'chain B']]
   for i,phil_case in enumerate([user_phil1,user_phil2]):
     trans_obj = ncs.input(
       ncs_phil_string = phil_case)
     self.assertEqual(trans_obj.ncs_selection_str,expected_ncs_selection[i])
     self.assertEqual(trans_obj.ncs_to_asu_selection,expected_ncs_to_asu[i])
     self.assertEqual(trans_obj.ncs_chain_selection,expected_ncs_chains[i])
   # error reporting
   for pc in [user_phil3,user_phil4,user_phil5]:
     self.assertRaises(
       IOError,ncs.input,ncs_phil_string=pc)
コード例 #45
0
  def test_get_list_of_best_ncs_copy_map_correlation(self):
    """
    Verifying that we get a list of chain index for the chain with the best
    map correlation
    """
    # print sys._getframe().f_code.co_name

    d_min = 1.0
    pdb_inp = iotbx.pdb.input(lines=pdb_poor_0,source_info=None)
    ncs_inp = ncs.input(hierarchy=pdb_inp.construct_hierarchy())
    ncs_restraints_group_list = ncs_inp.get_ncs_restraints_group_list()

    pdb_inp_poor = iotbx.pdb.input(lines=pdb_poor_0,source_info=None)
    ph_poor = pdb_inp_poor.construct_hierarchy(sort_atoms=False)
    ph_poor.atoms().reset_i_seq()
    xrs_poor = pdb_inp_poor.xray_structure_simple()

    pdb_inp_answer = iotbx.pdb.input(lines=pdb_answer_0,source_info=None)
    ph_answer = pdb_inp_answer.construct_hierarchy()
    ph_answer.atoms().reset_i_seq()
    xrs_answer = pdb_inp_answer.xray_structure_simple()

    fc = xrs_answer.structure_factors(d_min=d_min, algorithm="direct").f_calc()
    fft_map = fc.fft_map(resolution_factor = 0.25)
    fft_map.apply_sigma_scaling()
    map_data = fft_map.real_map_unpadded()

    selections = [flex.size_t([0,1,2,3,4,5,6]),flex.size_t([7,8,9,10,11,12,13]),
                flex.size_t([14,15,16,17,18,19,20])]

    mp = mmtbx.maps.correlation.from_map_and_xray_structure_or_fmodel(
      xray_structure = xrs_poor,
      map_data       = map_data,
      d_min          = d_min)

    cc = mp.cc(selections=selections)

    nu.get_list_of_best_ncs_copy_map_correlation(
      ncs_groups     = ncs_restraints_group_list,
      xray_structure = xrs_poor,
      map_data       = map_data,
      d_min          = d_min)
コード例 #46
0
def exercise_07():
    """
  Verify that insertion and reordering of the identity transform is done
  properly
  need to use exclude_selection=None because test pdb files contain only UNK
  residues.
  """
    for pdb_str in [pdb_str_6, pdb_str_7]:
        pdb_inp = pdb.input(source_info=None, lines=pdb_str)
        t_i = pdb_inp.process_MTRIX_records()
        pdb_h = pdb_inp.construct_hierarchy()
        ncs_inp = ncs.input(hierarchy=pdb_h,
                            exclude_selection=None,
                            transform_info=t_i)
        transform_info = ncs_inp.build_MTRIX_object()
        assert len(transform_info.r) == 3
        assert len(transform_info.t) == 3
        assert transform_info.r[0].is_r3_identity_matrix()
        assert transform_info.t[0].is_col_zero()
        sn = [int(x) for x in transform_info.serial_number]
        assert sn == [1, 2, 3]
コード例 #47
0
def test_identity_tranform_insertion():
  """
  Verify that insertion and reordering of the identity transform is done
  properly
  need to use exclude_selection=None because test pdb files contain only UNK
  residues.
  """
  for pdb_str in [pdb_test_data5,pdb_test_data6]:
    pdb_inp = pdb.input(source_info=None, lines=pdb_str)
    t_i=pdb_inp.process_mtrix_records()
    pdb_h = pdb_inp.construct_hierarchy()
    ncs_inp = ncs.input(
        hierarchy=pdb_h,
        exclude_selection=None,
        transform_info=t_i)
    transform_info = ncs_inp.build_MTRIX_object()
    assert len(transform_info.r) == 3
    assert len(transform_info.t) == 3
    assert transform_info.r[0].is_r3_identity_matrix()
    assert transform_info.t[0].is_col_zero()
    sn = [int(x) for x in transform_info.serial_number]
    assert sn == [1,2,3]
コード例 #48
0
 def test_print_ncs_phil_param(self):
     """ Verify correct printout of NCS phil parameters.
 need to supply exclude_selection=None because model consist only from UNK
 residues. """
     # print sys._getframe().f_code.co_name
     pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_test_data2)
     phil_groups = ncs_group_master_phil.fetch(
         iotbx.phil.parse(pdb_test_data2_phil)).extract()
     p = iotbx.ncs.input.get_default_params()
     p.ncs_search.exclude_selection = None
     p.ncs_search.minimum_number_of_atoms_in_copy = 0
     trans_obj = ncs.input(ncs_phil_groups=phil_groups.ncs_group,
                           hierarchy=pdb_inp.construct_hierarchy(),
                           params=p.ncs_search)
     result = trans_obj.print_ncs_phil_param(write=False)
     # print "="*50
     # print "resutl"
     # print result
     # print "="*50
     test = (pdb_test_data2_phil == result)
     test = test or (pdb_test_data2_phil_reverse == result)
     self.assertTrue(test)
コード例 #49
0
def test_split_by_chain():
    phil_groups = ncs_group_master_phil.fetch(
        iotbx.phil.parse(phil_str2)).extract()
    pdb_inp = iotbx.pdb.input(source_info=None, lines=test_pdb_str_2)
    pars = ncs.input.get_default_params()
    pars.ncs_search.chain_max_rmsd = 100
    h = pdb_inp.construct_hierarchy()
    ncs_obj_phil = ncs.input(hierarchy=h,
                             ncs_phil_groups=phil_groups.ncs_group,
                             params=pars.ncs_search)
    nrgl = ncs_obj_phil.get_ncs_restraints_group_list()
    assert nrgl.get_array_of_str_selections() == \
        [["chain 'Aa' or chain 'Ab'", "chain 'Ae' or chain 'Af'"]]
    splitted_nrgl = nrgl.split_by_chains(hierarchy=h)
    assert splitted_nrgl.get_n_groups() == 2
    for g in splitted_nrgl:
        assert g.get_number_of_copies() == 1
        assert approx_equal(g.copies[0].r, nrgl[0].copies[0].r)
        assert approx_equal(g.copies[0].t, nrgl[0].copies[0].t)
    splitted_nrgl.update_str_selections_if_needed(hierarchy=h)
    assert splitted_nrgl.get_array_of_str_selections() == \
       [["chain 'Aa'", "chain 'Ae'"], ["chain 'Ab'", "chain 'Af'"]]
コード例 #50
0
 def test_grads_one_ncs_to_asu(self):
   # No more NAGs in NCS selection
   # print sys._getframe().f_code.co_name
   pdb_inp = iotbx.pdb.input(lines=test_pdb_1,source_info=None)
   ncs_inp = ncs.input(hierarchy=pdb_inp.construct_hierarchy(),
       exclude_selection=None)
   pdb_inp = iotbx.pdb.input(source_info=None, lines=test_pdb_1)
   ph = pdb_inp.construct_hierarchy()
   xrs =  pdb_inp.xray_structure_simple()
   #
   nrgl = ncs_inp.get_ncs_restraints_group_list()
   asu_length = ncs_inp.total_asu_length
   #
   refine_selection = nu.get_refine_selection(number_of_atoms=asu_length)
   extended_ncs_selection =  nu.get_extended_ncs_selection(
     ncs_restraints_group_list=nrgl,
     refine_selection=refine_selection)
   #
   self.assertEqual(asu_length, ph.atoms_size())
   self.assertEqual(asu_length, 18)
   #
   xrs_one_ncs_copy = xrs.select(extended_ncs_selection)
   master_grad = xrs_one_ncs_copy.extract_u_iso_or_u_equiv()
   #
   g = grads_one_ncs_to_asu(
     ncs_restraints_group_list=nrgl,
     total_asu_length=asu_length,
     extended_ncs_selection=extended_ncs_selection,
     master_grad=master_grad)
   #
   self.assertEqual(g.size(),18)
   masters = [[0,1,12],[2, 3, 13]]
   copies = [[[4, 5, 14],[8, 9, 16]],[[6, 7, 15],[10, 11, 17]]]
   for m,cs in zip(masters,copies):
     ml = list(g.select(flex.size_t(m)))
     for c in cs:
       cl = list(g.select(flex.size_t(c)))
       self.assertEqual(ml,cl)
コード例 #51
0
  def test_transform_application_order(self):
    """
    Verify that transform order is kept even when chain selection is complex
    """
    # print sys._getframe().f_code.co_name
    pdb_inp = pdb.input(source_info=None, lines=pdb_test_data2)
    pdb_obj = pdb.hierarchy.input(pdb_string=pdb_test_data2)
    transform_info = pdb_inp.process_mtrix_records()
    transforms_obj = ncs.input(
      transform_info=transform_info,
      pdb_hierarchy_inp=pdb_obj)

    expected = ['chain A_002', 'chain B_002', 'chain A_003', 'chain B_003']
    self.assertEqual(transforms_obj.transform_chain_assignment,expected)

    expected = {
      'chain A_002': 'C','chain A_003': 'E','chain A_001': 'A',
      'chain B_002': 'D','chain B_003': 'F','chain B_001': 'B'}
    self.assertEqual(transforms_obj.ncs_copies_chains_names,expected)

    expected = [0, 1, 2, 5, 6]
    results = list(transforms_obj.asu_to_ncs_map['chain A'])
    self.assertEqual(results,expected)

    expected = [3, 4]
    results = list(transforms_obj.asu_to_ncs_map['chain B'])
    self.assertEqual(results,expected)

    expected = [7, 8, 9, 12, 13]
    results = list(transforms_obj.ncs_to_asu_map['chain A_002'])
    self.assertEqual(results,expected)

    expected = [17, 18]
    results = list(transforms_obj.ncs_to_asu_map['chain B_003'])
    self.assertEqual(results,expected)

    self.assertEqual(len(transforms_obj.ncs_atom_selection),21)
    self.assertEqual(transforms_obj.ncs_atom_selection.count(True),7)
コード例 #52
0
 def test_grads_one_ncs_to_asu(self):
     # No more NAGs in NCS selection
     # print sys._getframe().f_code.co_name
     pdb_inp = iotbx.pdb.input(lines=test_pdb_1, source_info=None)
     p = ncs.input.get_default_params()
     p.ncs_search.exclude_selection = None
     ncs_inp = ncs.input(hierarchy=pdb_inp.construct_hierarchy(),
                         params=p.ncs_search)
     pdb_inp = iotbx.pdb.input(source_info=None, lines=test_pdb_1)
     ph = pdb_inp.construct_hierarchy()
     xrs = pdb_inp.xray_structure_simple()
     #
     nrgl = ncs_inp.get_ncs_restraints_group_list()
     asu_length = ncs_inp.truncated_hierarchy.atoms_size()
     #
     refine_selection = nu.get_refine_selection(number_of_atoms=asu_length)
     extended_ncs_selection = nrgl.get_extended_ncs_selection(
         refine_selection=refine_selection)
     #
     self.assertEqual(asu_length, ph.atoms_size())
     self.assertEqual(asu_length, 18)
     #
     xrs_one_ncs_copy = xrs.select(extended_ncs_selection)
     master_grad = xrs_one_ncs_copy.extract_u_iso_or_u_equiv()
     #
     g = grads_one_ncs_to_asu(ncs_restraints_group_list=nrgl,
                              total_asu_length=asu_length,
                              extended_ncs_selection=extended_ncs_selection,
                              master_grad=master_grad)
     #
     self.assertEqual(g.size(), 18)
     masters = [[0, 1, 12], [2, 3, 13]]
     copies = [[[4, 5, 14], [8, 9, 16]], [[6, 7, 15], [10, 11, 17]]]
     for m, cs in zip(masters, copies):
         ml = list(g.select(flex.size_t(m)))
         for c in cs:
             cl = list(g.select(flex.size_t(c)))
             self.assertEqual(ml, cl)
コード例 #53
0
def test_center_of_coordinates_shift():
    """
  test shifting translation to and from the center of coordinates of the
  master ncs copy
  """
    # print sys._getframe().f_code.co_name
    # c = commons()

    pdb_inp = iotbx.pdb.input(source_info=None, lines=test_pdb_str_2)
    ncs_obj_phil = ncs.input(hierarchy=pdb_inp.construct_hierarchy())
    ncs_restraints_group_list = ncs_obj_phil.get_ncs_restraints_group_list()

    # ncs_restraints_group_list = c.ncs_restraints_group_list
    xrs = pdb_inp.xray_structure_simple()
    shifts = ncs_restraints_group_list.get_ncs_groups_centers(
        sites_cart=xrs.sites_cart())

    xyz = pdb_inp.atoms().extract_xyz()
    center_of_coor = (flex.vec3_double([xyz.sum()]) *
                      (1 / xyz.size())).round(8)
    # test shifts
    t1 = shifts[0].round(8)
    t2 = shifts[1].round(8)
    d1 = flex.sqrt((center_of_coor - t1).dot()).min_max_mean().as_tuple()
    d2 = flex.sqrt((center_of_coor - t2).dot()).min_max_mean().as_tuple()
    assert (d1 == d2)

    # test shift to center
    new_nrg = ncs_restraints_group_list.shift_translation_to_center(
        shifts=shifts)
    expected = (22.63275, 5.54625, 2.9375)
    assert (new_nrg[0].copies[0].t.round(5)).elems == expected
    # back to original coordinates system
    old_nrg = new_nrg.shift_translation_back_to_place(shifts=shifts)
    expected = (old_nrg[0].copies[0].t.round(5)).elems
    result = (ncs_restraints_group_list[0].copies[0].t.round(5)).elems
    assert result == expected
コード例 #54
0
def exercise_02():
    """
  Verify that transform order is kept even when chain selection is complex
  """
    pdb_inp = pdb.input(source_info=None, lines=pdb_str_1)
    pdb_obj = pdb.hierarchy.input(pdb_string=pdb_str_1)
    transform_info = pdb_inp.process_MTRIX_records()
    transforms_obj = ncs.input(transform_info=transform_info,
                               hierarchy=pdb_inp.construct_hierarchy())
    expected = [
        'chain A_0000000002', 'chain B_0000000002', 'chain A_0000000003',
        'chain B_0000000003'
    ]
    assert transforms_obj.transform_chain_assignment == expected
    expected = {
        'chain A_0000000002': 'C',
        'chain A_0000000003': 'E',
        'chain A_0000000001': 'A',
        'chain B_0000000002': 'D',
        'chain B_0000000003': 'F',
        'chain B_0000000001': 'B'
    }
    assert transforms_obj.ncs_copies_chains_names == expected
    expected = [0, 1, 2, 5, 6]
    results = list(transforms_obj.asu_to_ncs_map['chain A'])
    assert results == expected
    expected = [3, 4]
    results = list(transforms_obj.asu_to_ncs_map['chain B'])
    assert results == expected
    expected = [7, 8, 9, 12, 13]
    results = list(transforms_obj.ncs_to_asu_map['chain A_0000000002'])
    assert results == expected
    expected = [17, 18]
    results = list(transforms_obj.ncs_to_asu_map['chain B_0000000003'])
    assert results == expected
    assert len(transforms_obj.ncs_atom_selection) == 21
    assert transforms_obj.ncs_atom_selection.count(True) == 7
コード例 #55
0
  def test_spec_reading(self):
    """ verify creating and processing spec
    This is ncs.ncs - specific functionality
    """
    if have_phenix:
      xrs = self.pdb_inp.xray_structure_simple()
      xrs_unit_cell = xrs.orthorhombic_unit_cell_around_centered_scatterers(
        buffer_size=8)
      self.ph.adopt_xray_structure(xrs_unit_cell)
      of = open("test_ncs_spec.pdb", "w")
      print >> of, self.ph.as_pdb_string(crystal_symmetry=xrs.crystal_symmetry())
      of.close()
      # create a spec file
      ncs_from_pdb=simple_ncs_from_pdb.run(
        args=["pdb_in=test_ncs_spec.pdb", "write_spec_files=True"],
        log=null_out())

      # reading and processing the spec file

      spec_object = mmtbx.ncs.ncs.ncs()
      spec_object.read_ncs(file_name="test_ncs_spec_simple_ncs_from_pdb.ncs_spec")
      trans_obj = ncs.input(
        spec_ncs_groups=spec_object,
        # spec_file_str=test_ncs_spec,  # use output string directly
        hierarchy = self.pdb_inp.construct_hierarchy())

      # test created object
      self.assertEqual(len(trans_obj.transform_chain_assignment),3)
      expected = "(chain A and (resseq 151:159)) or (chain D and (resseq 1:7))"
      self.assertEqual(trans_obj.ncs_selection_str,expected)
      # check that static parts are included in NCS and ASU
      self.assertEqual(len(trans_obj.ncs_atom_selection),3*9+2*7+3+3)
      self.assertEqual(trans_obj.ncs_atom_selection.count(True),9+7+3+3)
      #
      expected = {
        "chain A and (resseq 151:159)":
          ["chain B and (resseq 151:159)","chain C and (resseq 151:159)"],
        "chain D and (resseq 1:7)":
          ["chain E and (resseq 1:7)"]}
      self.assertEqual(trans_obj.ncs_to_asu_selection,expected)

      # check ncs_transform
      group_ids = [x.ncs_group_id for x in trans_obj.ncs_transform.itervalues()]
      tran_sn = {x.serial_num for x in trans_obj.ncs_transform.itervalues()}
      group_keys = {x for x in trans_obj.ncs_transform.iterkeys()}
      r1 = trans_obj.ncs_transform['0000000004'].r
      r2 = trans_obj.ncs_transform['0000000002'].r
      #
      self.assertEqual(len(group_ids),5)
      self.assertEqual(set(group_ids),{1,2})
      self.assertEqual(tran_sn,{1,2,3,4,5})
      self.assertEqual(group_keys,{'0000000001', '0000000002', '0000000003', '0000000004', '0000000005'})
      #
      self.assertTrue(r1.is_r3_identity_matrix())
      expected_r = matrix.sqr(
        [0.4966,0.8679,-0.0102,-0.6436,0.3761,0.6666,0.5824,-0.3245,0.7453])
      d = r2 - expected_r.transpose()
      d = map(abs,d)
      self.assertTrue(max(d)<0.01)
    else:
      print "phenix not available, skipping test_spec_reading()"
      pass
コード例 #56
0
  def test_processing_of_asu_2(self):
    """ processing complete ASU
    If MTRIX records are present, they are ignored
    This maybe ncs.ncs - specific functionality, not clear yet.
    """
    # print sys._getframe().f_code.co_name
    # reading and processing the spec file
    trans_obj = ncs.input(hierarchy = self.pdb_inp.construct_hierarchy())

    # test created object
    self.assertEqual(len(trans_obj.transform_chain_assignment),3)
    expected = "(chain 'A') or (chain 'D')"
    self.assertEqual(trans_obj.ncs_selection_str,expected)
    # check that static parts are included in NCS and ASU
    self.assertEqual(len(trans_obj.ncs_atom_selection),3*9+2*7+3+3)
    self.assertEqual(trans_obj.ncs_atom_selection.count(True),9+7+3+3)
    #
    expected = {
      "chain 'A'": ["chain 'B'", "chain 'C'"],
      "chain 'D'": ["chain 'E'"]}
    self.assertEqual(trans_obj.ncs_to_asu_selection,expected)

    # check ncs_transform
    group_ids = [x.ncs_group_id for x in trans_obj.ncs_transform.itervalues()]
    tran_sn = {x.serial_num for x in trans_obj.ncs_transform.itervalues()}
    group_keys = {x for x in trans_obj.ncs_transform.iterkeys()}
    r1 = trans_obj.ncs_transform['0000000004'].r
    r2 = trans_obj.ncs_transform['0000000002'].r
    #
    self.assertEqual(len(group_ids),5)
    self.assertEqual(set(group_ids),{0,1})
    self.assertEqual(tran_sn,{1,2,3,4,5})
    self.assertEqual(group_keys,{'0000000001', '0000000002', '0000000003', '0000000004', '0000000005'})
    #
    self.assertTrue(r1.is_r3_identity_matrix())
    expected_r = matrix.sqr(
      [0.4966,0.8679,-0.0102,-0.6436,0.3761,0.6666,0.5824,-0.3245,0.7453])
    # the transformation in the spec files are from the copy to the master
    d = r2 - expected_r.transpose()
    d = map(abs,d)
    self.assertTrue(max(d)<0.01)

    # Verify that spec object are produced properly
    spec_output = trans_obj.get_ncs_info_as_spec(
      pdb_hierarchy_asu=self.ph)
    trans_obj2 = ncs.input(spec_ncs_groups=spec_output)

    t1 = trans_obj.ncs_transform['0000000002'].r
    t2 = trans_obj2.ncs_transform['0000000002'].r
    self.assertEqual(t1,t2)

    t1 = trans_obj.ncs_to_asu_selection
    t2 = trans_obj2.ncs_to_asu_selection
    # Selection does not include the resseq if all the chain is selected
    t1_exp = {"chain 'A'": ["chain 'B'", "chain 'C'"], "chain 'D'": ["chain 'E'"]}
    self.assertEqual(t1,t1_exp)
    t2_exp = {"chain A and (resseq 151:159)":
                ["chain B and (resseq 151:159)","chain C and (resseq 151:159)"],
              "chain D and (resseq 1:7)": ["chain E and (resseq 1:7)"]}
    self.assertEqual(t2,t2_exp)
    #
    # print "trans_obj.tr_id_to_selection", trans_obj.tr_id_to_selection
    # print "trans_obj2.tr_id_to_selection", trans_obj2.tr_id_to_selection
    # STOP()
    t1 = trans_obj.tr_id_to_selection["chain 'A'_0000000003"]
    t2 = trans_obj2.tr_id_to_selection["chain A_0000000003"]
    self.assertEqual(t1,("chain 'A'", "chain 'C'"))
    t2_exp = ("chain A and (resseq 151:159)", "chain C and (resseq 151:159)")
    self.assertEqual(t2,t2_exp)
コード例 #57
0
def run(prefix="tst", d_min=1.0):
    """
  NCS constraints: xyz, adp, and operators.
  """
    pdb_file_name_answer = "%s_answer.pdb" % prefix
    of = open(pdb_file_name_answer, "w")
    print >> of, pdb_str_answer
    of.close()
    #
    pdb_file_name_poor = "%s_poor.pdb" % prefix
    of = open(pdb_file_name_poor, "w")
    print >> of, pdb_str_poor
    of.close()
    #
    pdb_inp_answer = iotbx.pdb.input(file_name=pdb_file_name_answer)
    ph_answer = pdb_inp_answer.construct_hierarchy()
    ph_answer.atoms().reset_i_seq()
    xrs_answer = pdb_inp_answer.xray_structure_simple()
    #
    pdb_inp_poor = iotbx.pdb.input(file_name=pdb_file_name_poor)
    ph_poor = pdb_inp_poor.construct_hierarchy()
    ph_poor_obj = iotbx.pdb.input(source_info=None, lines=pdb_str_poor2)
    ph_poor.atoms().reset_i_seq()
    xrs_poor = pdb_inp_poor.xray_structure_simple()
    #
    ppf = mmtbx.utils.process_pdb_file_srv(log=False).process_pdb_files(
        raw_records=pdb_str_poor.splitlines())[0]
    mmtbx.utils.assert_xray_structures_equal(
        x1=ppf.xray_structure(show_summary=False), x2=xrs_poor)
    restraints_manager = mmtbx.restraints.manager(
        geometry=ppf.geometry_restraints_manager(show_energies=False),
        normalization=True)
    #
    fc = xrs_answer.structure_factors(d_min=d_min).f_calc()
    fft_map = fc.fft_map(resolution_factor=0.25)
    fft_map.apply_sigma_scaling()
    map_data = fft_map.real_map_unpadded()
    #
    ncs_obj_poor = mmtbx.ncs.asu_ncs_converter(pdb_hierarchy=ph_answer,
                                               add_identity=True)
    ncs_obj_poor.write_pdb_file(file_name="asu.pdb",
                                crystal_symmetry=xrs_poor.crystal_symmetry(),
                                mode="asu")
    # create transformation object
    transforms_obj = ncs.input(hierarchy=ph_answer)
    x = transforms_obj.get_ncs_restraints_group_list().concatenate_rot_tran()
    x = nu.shake_transformations(x=x,
                                 shake_angles_sigma=1 * math.pi / 180,
                                 shake_translation_sigma=0.1)
    nrgl = transforms_obj.get_ncs_restraints_group_list()
    nrgl.update_rot_tran(x=x)
    rm, tv = nrgl.get_rotation_translation_as_list()
    # just to see how result of shaking looks like
    rm_ = [rm[0]] + rm
    tv_ = [tv[0]] + tv
    ncs_obj_poor.back_rotation_matrices = rm_
    ncs_obj_poor.back_translation_vectors = tv_
    ncs_obj_poor.update_sites_cart(sites_cart_master_ncs_copy=ncs_obj_poor.
                                   ph_first_chain.atoms().extract_xyz())
    ncs_obj_poor.write_pdb_file(file_name="asu2.pdb",
                                crystal_symmetry=xrs_poor.crystal_symmetry(),
                                mode="asu")
    ncs_restraints_group_list = transforms_obj.get_ncs_restraints_group_list()
    refine_selection = flex.size_t(
        xrange(transforms_obj.truncated_hierarchy.atoms_size()))
    for i in xrange(5):
        data_weight = 1
        tfg_obj = mmtbx.refinement.minimization_ncs_constraints.\
          target_function_and_grads_real_space(
            map_data                   = map_data,
            xray_structure             = xrs_poor,
            ncs_restraints_group_list  = ncs_restraints_group_list,
            refine_selection           = refine_selection,
            real_space_gradients_delta = d_min/4,
            restraints_manager         = restraints_manager,
            data_weight                = data_weight,
            refine_sites               = True)
        minimized = mmtbx.refinement.minimization_ncs_constraints.lbfgs(
            target_and_grads_object=tfg_obj,
            xray_structure=xrs_poor,
            ncs_restraints_group_list=ncs_restraints_group_list,
            refine_selection=refine_selection,
            finite_grad_differences_test=False,
            max_iterations=60,
            refine_sites=True)
        xrs_poor = tfg_obj.xray_structure
        ph_poor.adopt_xray_structure(tfg_obj.xray_structure)
        #
        ncs_obj_poor = mmtbx.ncs.asu_ncs_converter(pdb_hierarchy=ph_poor,
                                                   add_identity=False)
        rm, tv = ncs_restraints_group_list.get_rotation_translation_as_list()
    #
    ph_poor.write_pdb_file(file_name="refined.pdb")
コード例 #58
0
def test_split_by_chain_2():
    """ Test of split_by_chains where chains are splitted, e.g.
  protein and ligand are separated by TER
  """
    pdb_str = """\
CRYST1  174.866  238.091  243.466  90.00  90.00  90.00 P 21 21 21
SCALE1      0.005719  0.000000  0.000000        0.00000
SCALE2      0.000000  0.004200  0.000000        0.00000
SCALE3      0.000000  0.000000  0.004107        0.00000
ATOM  15295  N   SER D  74      59.475 -46.773 121.838  1.00383.47           N
ATOM  15296  CA  SER D  74      59.914 -46.196 120.574  1.00383.24           C
ATOM  15297  C   SER D  74      59.605 -44.703 120.512  1.00379.51           C
ATOM  15298  O   SER D  74      58.830 -44.258 119.666  1.00374.31           O
ATOM  15299  CB  SER D  74      59.247 -46.915 119.397  1.00380.53           C
ATOM  15300  OG  SER D  74      59.544 -48.301 119.400  1.00383.68           O
ATOM  15301  N   ASN D  75      60.241 -43.943 121.402  1.00382.45           N
ATOM  15302  CA  ASN D  75      60.129 -42.482 121.464  1.00380.05           C
ATOM  15303  C   ASN D  75      58.725 -41.896 121.293  1.00372.68           C
ATOM  15304  O   ASN D  75      58.581 -40.746 120.881  1.00370.19           O
ATOM  15305  CB  ASN D  75      61.046 -41.855 120.418  1.00382.20           C
ATOM  15306  CG  ASN D  75      62.508 -42.175 120.656  1.00389.96           C
ATOM  15307  OD1 ASN D  75      62.958 -42.273 121.796  1.00394.06           O
ATOM  15308  ND2 ASN D  75      63.263 -42.322 119.575  1.00392.78           N
ATOM  15309  N   GLY D  76      57.703 -42.688 121.603  1.00369.47           N
ATOM  15310  CA  GLY D  76      56.321 -42.306 121.367  1.00362.43           C
ATOM  15311  C   GLY D  76      55.844 -41.019 122.011  1.00358.49           C
ATOM  15312  O   GLY D  76      56.116 -40.749 123.182  1.00360.25           O
ATOM  15313  N   ARG D  77      55.124 -40.219 121.235  1.00353.03           N
ATOM  15314  CA  ARG D  77      54.452 -39.045 121.771  1.00347.98           C
ATOM  15315  C   ARG D  77      53.192 -38.773 120.956  1.00340.73           C
ATOM  15316  O   ARG D  77      53.132 -39.072 119.764  1.00339.65           O
ATOM  15317  CB  ARG D  77      55.383 -37.824 121.801  1.00349.75           C
ATOM  15318  CG  ARG D  77      55.931 -37.385 120.451  1.00350.35           C
ATOM  15319  CD  ARG D  77      57.293 -37.995 120.136  1.00358.77           C
ATOM  15320  NE  ARG D  77      58.029 -37.121 119.227  1.00359.99           N
ATOM  15321  CZ  ARG D  77      59.247 -37.355 118.749  1.00366.18           C
ATOM  15322  NH1 ARG D  77      59.921 -38.437 119.111  1.00371.93           N
ATOM  15323  NH2 ARG D  77      59.809 -36.473 117.933  1.00366.55           N
TER
ATOM  15324  N   TYR D  78      52.166 -38.264 121.625  1.00335.62           N
ATOM  15325  CA  TYR D  78      50.919 -37.914 120.961  1.00328.66           C
ATOM  15326  C   TYR D  78      50.974 -36.476 120.456  1.00325.47           C
ATOM  15327  O   TYR D  78      50.504 -35.558 121.125  1.00322.51           O
ATOM  15328  CB  TYR D  78      49.734 -38.100 121.913  1.00324.55           C
ATOM  15329  CG  TYR D  78      49.238 -39.526 122.016  1.00325.38           C
ATOM  15330  CD1 TYR D  78      49.026 -40.289 120.877  1.00324.97           C
ATOM  15331  CD2 TYR D  78      48.973 -40.106 123.251  1.00326.27           C
ATOM  15332  CE1 TYR D  78      48.567 -41.589 120.962  1.00325.32           C
ATOM  15333  CE2 TYR D  78      48.514 -41.408 123.345  1.00326.09           C
ATOM  15334  CZ  TYR D  78      48.314 -42.144 122.197  1.00325.64           C
ATOM  15335  OH  TYR D  78      47.859 -43.439 122.280  1.00325.77           O
ATOM  19064  N   ASN E  75      29.075   5.259 120.437  1.00232.69           N
ATOM  19065  CA  ASN E  75      28.096   5.658 121.456  1.00227.54           C
ATOM  19066  C   ASN E  75      27.246   4.544 122.068  1.00223.14           C
ATOM  19067  O   ASN E  75      26.146   4.804 122.555  1.00219.10           O
ATOM  19068  CB  ASN E  75      27.159   6.709 120.876  1.00226.97           C
ATOM  19069  CG  ASN E  75      27.882   7.970 120.467  1.00230.84           C
ATOM  19070  OD1 ASN E  75      28.845   8.385 121.111  1.00232.56           O
ATOM  19071  ND2 ASN E  75      27.417   8.595 119.393  1.00233.24           N
ATOM  19072  N   GLY E  76      27.759   3.318 122.053  1.00224.32           N
ATOM  19073  CA  GLY E  76      26.998   2.150 122.461  1.00220.68           C
ATOM  19074  C   GLY E  76      26.384   2.164 123.847  1.00215.47           C
ATOM  19075  O   GLY E  76      27.013   2.573 124.823  1.00215.60           O
ATOM  19076  N   ARG E  77      25.135   1.722 123.922  1.00211.38           N
ATOM  19077  CA  ARG E  77      24.469   1.517 125.200  1.00206.91           C
ATOM  19078  C   ARG E  77      23.459   0.384 125.076  1.00203.78           C
ATOM  19079  O   ARG E  77      22.895   0.146 124.008  1.00203.81           O
ATOM  19080  CB  ARG E  77      23.800   2.801 125.707  1.00204.73           C
ATOM  19081  CG  ARG E  77      22.666   3.330 124.849  1.00204.05           C
ATOM  19082  CD  ARG E  77      23.143   4.321 123.799  1.00208.96           C
ATOM  19083  NE  ARG E  77      22.118   5.331 123.560  1.00208.57           N
ATOM  19084  CZ  ARG E  77      22.230   6.335 122.698  1.00211.78           C
ATOM  19085  NH1 ARG E  77      23.334   6.480 121.983  1.00215.57           N
ATOM  19086  NH2 ARG E  77      21.241   7.205 122.563  1.00211.19           N
TER
ATOM  19087  N   TYR E  78      23.286  -0.346 126.170  1.00201.65           N
ATOM  19088  CA  TYR E  78      22.334  -1.441 126.223  1.00198.95           C
ATOM  19089  C   TYR E  78      20.973  -0.908 126.642  1.00195.03           C
ATOM  19090  O   TYR E  78      20.616  -0.967 127.815  1.00193.71           O
ATOM  19091  CB  TYR E  78      22.813  -2.517 127.201  1.00199.92           C
ATOM  19092  CG  TYR E  78      23.854  -3.449 126.623  1.00204.23           C
ATOM  19093  CD1 TYR E  78      23.681  -4.014 125.369  1.00205.06           C
ATOM  19094  CD2 TYR E  78      25.014  -3.757 127.326  1.00208.09           C
ATOM  19095  CE1 TYR E  78      24.627  -4.863 124.832  1.00209.52           C
ATOM  19096  CE2 TYR E  78      25.969  -4.606 126.795  1.00212.29           C
ATOM  19097  CZ  TYR E  78      25.769  -5.155 125.547  1.00213.03           C
ATOM  19098  OH  TYR E  78      26.711  -6.001 125.009  1.00218.33           O
TER
  """
    pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_str)
    h = pdb_inp.construct_hierarchy()
    pars = ncs.input.get_default_params()
    pars.ncs_search.chain_similarity_threshold = 0.5

    ncs_obj = ncs.input(hierarchy=h, params=pars.ncs_search)
    spec = ncs_obj.get_ncs_info_as_spec()
    # ncs_obj.show(format='spec')
    assert len(spec.ncs_groups()) == 1
コード例 #59
0
 def __init__(self,
              n_macro_cycle,
              sites,
              u_iso,
              transformations,
              finite_grad_differences_test,
              use_geometry_restraints,
              shake_site_mean_distance = 1.5,
              d_min = 2,
              shake_angles_sigma = 0.035,
              shake_translation_sigma = 0.5):
   """ create temp test files and data for tests """
   adopt_init_args(self, locals())
   self.test_files_names = [] # collect names of files for cleanup
   # 1 NCS copy: starting template to generate whole asu; place into P1 box
   pdb_inp = iotbx.pdb.input(source_info=None, lines=ncs_1_copy)
   pdb_obj = iotbx.pdb.hierarchy.input(pdb_string=ncs_1_copy)
   mtrix_object = pdb_inp.process_mtrix_records()
   ph = pdb_inp.construct_hierarchy()
   xrs = pdb_inp.xray_structure_simple()
   xrs_one_ncs = xrs.orthorhombic_unit_cell_around_centered_scatterers(
     buffer_size=8)
   ph.adopt_xray_structure(xrs_one_ncs)
   of = open("one_ncs_in_asu.pdb", "w")
   print >> of, mtrix_object.as_pdb_string()
   print >> of, ph.as_pdb_string(crystal_symmetry=xrs_one_ncs.crystal_symmetry())
   of.close()
   # 1 NCS copy -> full asu (expand NCS). This is the answer-structure
   m = multimer(file_name="one_ncs_in_asu.pdb",
                round_coordinates=False,
                reconstruction_type='cau',error_handle=True,eps=1e-2)
   assert m.number_of_transforms == 2, m.number_of_transforms
   xrs_asu = m.assembled_multimer.extract_xray_structure(
     crystal_symmetry = xrs_one_ncs.crystal_symmetry())
   m.write("full_asu.pdb")
   # force ASU none-rounded coordinates into xray structure
   xrs_asu.set_sites_cart(m.sites_cart())
   assert xrs_asu.crystal_symmetry().is_similar_symmetry(
     xrs_one_ncs.crystal_symmetry())
   # Generate Fobs from answer structure
   f_obs = abs(xrs_asu.structure_factors(d_min=d_min, algorithm="direct").f_calc())
   r_free_flags = f_obs.generate_r_free_flags()
   mtz_dataset = f_obs.as_mtz_dataset(column_root_label="F-obs")
   mtz_dataset.add_miller_array(
     miller_array=r_free_flags,
     column_root_label="R-free-flags")
   mtz_object = mtz_dataset.mtz_object()
   mtz_object.write(file_name = "data.mtz")
   # Shake structure - subject to refinement input
   xrs_shaken = xrs_one_ncs.deep_copy_scatterers()
   if sites: xrs_shaken.shake_sites_in_place(
     mean_distance=shake_site_mean_distance)
   if self.u_iso:
     u_random = flex.random_double(xrs_shaken.scatterers().size())
     xrs_shaken = xrs_shaken.set_u_iso(values=u_random)
   if self.transformations:
     transforms_obj = ncs.input(
     transform_info = mtrix_object,
     pdb_hierarchy_inp = pdb_obj)
     x = nu.concatenate_rot_tran(transforms_obj=transforms_obj)
     x = nu.shake_transformations(
       x = x,
       shake_angles_sigma=self.shake_angles_sigma,
       shake_translation_sigma=self.shake_translation_sigma)
     transforms_obj = nu.update_rot_tran(x=x,transforms_obj=transforms_obj)
     mtrix_object = transforms_obj.build_MTRIX_object()
   ph.adopt_xray_structure(xrs_shaken)
   of = open("one_ncs_in_asu_shaken.pdb", "w")
   print >> of, mtrix_object.as_pdb_string()
   print >> of, ph.as_pdb_string(crystal_symmetry=xrs.crystal_symmetry())
   of.close()
   self.f_obs = f_obs
   self.r_free_flags = r_free_flags
   self.xrs_one_ncs = xrs_one_ncs
   # Get restraints manager
   self.grm = None
   pdb_str = m.assembled_multimer.as_pdb_string(
     crystal_symmetry=xrs_one_ncs.crystal_symmetry())
   self.iso_restraints = None
   if(self.use_geometry_restraints):
     self.grm = nu.get_restraints_manager(pdb_string=pdb_str)
     if(self.u_iso):
       temp = mmtbx.refinement.adp_refinement.adp_restraints_master_params
       self.iso_restraints = temp.extract().iso
コード例 #60
0
def get_inputs(prefix, pdb_answer, pdb_poor, ncs_params_str, real_space, d_min):
  pdb_file_name_answer = "answer_%s.pdb"%prefix
  of=open(pdb_file_name_answer, "w")
  print >> of, pdb_answer
  of.close()
  #
  pdb_file_name_poor = "poor_%s.pdb"%prefix
  of=open(pdb_file_name_poor, "w")
  print >> of, pdb_poor
  of.close()
  #
  pdb_inp_answer = iotbx.pdb.input(file_name=pdb_file_name_answer)
  ph_answer = pdb_inp_answer.construct_hierarchy()
  ph_answer.atoms().reset_i_seq()
  xrs_answer = pdb_inp_answer.xray_structure_simple()
  sites_cart_answer = xrs_answer.sites_cart()
  #
  pdb_inp_poor = iotbx.pdb.input(file_name=pdb_file_name_poor)
  ph_poor = pdb_inp_poor.construct_hierarchy()
  ph_poor.atoms().reset_i_seq()
  xrs_poor = pdb_inp_poor.xray_structure_simple()
  #
  ppf = mmtbx.utils.process_pdb_file_srv(log=False).process_pdb_files(
    raw_records=pdb_poor.splitlines())[0]
  mmtbx.utils.assert_xray_structures_equal(
    x1=ppf.xray_structure(show_summary = False),
    x2=xrs_poor)
  restraints_manager = mmtbx.restraints.manager(
    geometry      = ppf.geometry_restraints_manager(show_energies = False),
    normalization = True)
  restraints_manager.geometry.remove_c_beta_torsion_restraints_in_place()
  #
  phil_groups = ncs_group_master_phil.fetch(
      iotbx.phil.parse(ncs_params_str)).extract()

  pdb_inp = iotbx.pdb.input(lines=pdb_poor,source_info=None)
  ncs_inp = ncs.input(
      hierarchy=pdb_inp.construct_hierarchy(),
      ncs_phil_groups=phil_groups.ncs_group)
  ncs_groups = ncs_inp.get_ncs_restraints_group_list()
  # print "ncs_groups:", len(ncs_groups)
  # print "master isel:", list(ncs_groups[0].master_iselection)
  # for c in ncs_groups[0].copies:
  #   print "copy isel:", list(c.iselection)
  #
  set_scattering_dictionary(xray_structure = xrs_answer, d_min = d_min)
  set_scattering_dictionary(xray_structure = xrs_poor,   d_min = d_min)
  #
  #
  map_data, fmodel = None, None
  if(real_space):
    fc = xrs_answer.structure_factors(d_min=d_min, algorithm="direct").f_calc()
    fft_map = fc.fft_map(resolution_factor = 0.25)
    fft_map.apply_sigma_scaling()
    map_data = fft_map.real_map_unpadded()
  else:
    f_obs = abs(xrs_answer.structure_factors(d_min=d_min,
      algorithm="direct").f_calc())
    params = mmtbx.f_model.sf_and_grads_accuracy_master_params.extract()
    params.algorithm = "direct"
    fmodel = mmtbx.f_model.manager(
      f_obs                        = f_obs,
      xray_structure               = xrs_poor,
      sf_and_grads_accuracy_params = params,
      target_name                  = "ls_wunit_k1")
    if(1): print "d_min:", d_min
    if(1): print "r_work(start):", fmodel.r_work()
  return group_args(
    fmodel             = fmodel,
    map_data           = map_data,
    xrs_poor           = xrs_poor,
    d_min              = d_min,
    ncs_groups         = ncs_groups,
    restraints_manager = restraints_manager,
    ph                 = ph_poor)