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]):
         phil_groups = ncs_group_master_phil.fetch(
             iotbx.phil.parse(phil_case)).extract()
         trans_obj = iotbx.ncs.input(ncs_phil_groups=phil_groups.ncs_group)
         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]:
         phil_groups = ncs_group_master_phil.fetch(
             iotbx.phil.parse(pc)).extract()
         self.assertRaises(
             IOError,
             iotbx.ncs.input,
             # ncs_phil_string=pc
             ncs_phil_groups=phil_groups.ncs_group)
    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)
 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))
  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)
  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_inp = 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 = iotbx.ncs.input(
        ncs_phil_groups=phil_groups.ncs_group,
        hierarchy=pdb_inp.construct_hierarchy(),
        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,{'0000000005','0000000004','0000000006','0000000001','0000000003','0000000002'})
    self.assertEqual(trans_obj.ncs_atom_selection.count(True),4)
Пример #6
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
 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]):
     phil_groups = ncs_group_master_phil.fetch(iotbx.phil.parse(phil_case)).extract()
     trans_obj = iotbx.ncs.input(
       ncs_phil_groups=phil_groups.ncs_group)
     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]:
     phil_groups = ncs_group_master_phil.fetch(iotbx.phil.parse(pc)).extract()
     self.assertRaises(
       IOError,iotbx.ncs.input,
       # ncs_phil_string=pc
       ncs_phil_groups=phil_groups.ncs_group)
  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))
Пример #9
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))
Пример #10
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)
Пример #11
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)
Пример #12
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
Пример #13
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))
 def test_correct_grouping(self):
   """ test correct representation of groups in .ncs file"""
   pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_str_4)
   h = pdb_inp.construct_hierarchy()
   ncs_obj = iotbx.ncs.input(
       hierarchy=h,
       transform_info=pdb_inp.process_mtrix_records(eps=0.01))
   self.assertEqual(ncs_obj.number_of_ncs_groups,1)
   gr = ncs_obj.print_ncs_phil_param()
   self.assertEqual(gr,answer_4)
   phil_groups = ncs_group_master_phil.fetch(
       iotbx.phil.parse(answer_4)).extract()
   ncs_obj = iotbx.ncs.input(ncs_phil_groups=phil_groups.ncs_group)
   self.assertEqual(ncs_obj.number_of_ncs_groups,1)
   gr = ncs_obj.print_ncs_phil_param()
   self.assertEqual(gr,answer_4)
 def test_correct_grouping(self):
     """ test correct representation of groups in .ncs file"""
     pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_str_4)
     h = pdb_inp.construct_hierarchy()
     ncs_obj = iotbx.ncs.input(
         hierarchy=h,
         transform_info=pdb_inp.process_MTRIX_records(eps=0.01))
     self.assertEqual(ncs_obj.number_of_ncs_groups, 1)
     gr = ncs_obj.print_ncs_phil_param()
     self.assertEqual(gr, answer_4)
     phil_groups = ncs_group_master_phil.fetch(
         iotbx.phil.parse(answer_4)).extract()
     ncs_obj = iotbx.ncs.input(ncs_phil_groups=phil_groups.ncs_group)
     self.assertEqual(ncs_obj.number_of_ncs_groups, 1)
     gr = ncs_obj.print_ncs_phil_param()
     self.assertEqual(gr, answer_4)
 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_inp = 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 = iotbx.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 'D'", "chain 'G'"],
       ["chain 'B' or chain 'C'", "chain 'E' or chain 'F'", "chain 'H' or chain 'I'"]]
 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)
Пример #18
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'"]]
    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_inp = 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 = iotbx.ncs.input(ncs_phil_groups=phil_groups.ncs_group,
                                    hierarchy=pdb_inp.construct_hierarchy(),
                                    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, {
                '0000000005', '0000000004', '0000000006', '0000000001',
                '0000000003', '0000000002'
            })
        self.assertEqual(trans_obj.ncs_atom_selection.count(True), 4)
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)
    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))
Пример #22
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)