def test_create_ncs_domain_pdb_files(self):
    """ check that files are created for each NCS group as expected """
    # it should create 3 files (by number of found NCS groups) and write
    # there all atoms from NCS groups except chains excluded in exclude_chains
    if have_phenix:
      fn = 'SimpleNCSFromPDB_test.pdb'
      open(fn,'w').write(pdb_str_3)
      prefix = 'test_create_ncs_domain_pdb_files'
      obj = simple_ncs_from_pdb.run(
        args=["pdb_in=%s" % fn,
              "write_ncs_domain_pdb=True",
              "ncs_domain_pdb_stem=%s" % prefix])

      fn_gr0 = prefix + '_group_1.pdb'
      fn_gr1 = prefix + '_group_2.pdb'
      fn_gr2 = prefix + '_group_3.pdb'

      self.assertEqual(obj.ncs_obj.number_of_ncs_groups,3)
      pdb_inp_0 = pdb.input(file_name=fn_gr0)
      pdb_inp_1 = pdb.input(file_name=fn_gr1)
      pdb_inp_2 = pdb.input(file_name=fn_gr2)
      self.assertEqual(pdb_inp_0.atoms().size(),12)
      self.assertEqual(pdb_inp_1.atoms().size(),8)
      self.assertEqual(pdb_inp_2.atoms().size(),8)
    else:
      print "phenix not available, skipping test_create_ncs_domain_pdb_files()"
      pass
Ejemplo n.º 2
0
def cablam_align_wrapper(pdb_1,
                         pdb_2,
                         window_size,
                         threshold,
                         chain_1=None,
                         chain_2=None,
                         pdb_name_1=None,
                         pdb_name_2=None):

    # {{{ get pdb hierarchies
    if pdb_name_1 == None: pdb_name_1 = os.path.basename(pdb_1)[:-4]
    if pdb_name_2 == None: pdb_name_2 = os.path.basename(pdb_2)[:-4]
    pdb_io = pdb.input(pdb_1)
    hierarchy_1 = pdb_io.construct_hierarchy()
    pdb_io = pdb.input(pdb_2)
    hierarchy_2 = pdb_io.construct_hierarchy()

    # get chain selections
    if chain_1 != None: hierarchy_1 = get_chain_selection(hierarchy_1, chain_1)
    if chain_2 != None: hierarchy_2 = get_chain_selection(hierarchy_2, chain_2)
    # }}}

    return AlignCablamMeasures(hierarchy_1=hierarchy_1,
                               hierarchy_2=hierarchy_2,
                               pdb_name_1=pdb_name_1,
                               pdb_name_2=pdb_name_2,
                               window_size=window_size,
                               threshold=threshold)
    def test_create_ncs_domain_pdb_files(self):
        """ check that files are created for each NCS group as expected """
        # it should create 3 files (by number of found NCS groups) and write
        # there all atoms from NCS groups except chains excluded in exclude_chains
        if have_phenix:
            fn = 'SimpleNCSFromPDB_test.pdb'
            open(fn, 'w').write(pdb_str_3)
            prefix = 'test_create_ncs_domain_pdb_files'
            obj = simple_ncs_from_pdb.run(args=[
                "pdb_in=%s" % fn, "write_ncs_domain_pdb=True",
                "ncs_domain_pdb_stem=%s" % prefix
            ])

            fn_gr0 = prefix + '_group_1.pdb'
            fn_gr1 = prefix + '_group_2.pdb'
            fn_gr2 = prefix + '_group_3.pdb'

            self.assertEqual(obj.ncs_obj.number_of_ncs_groups, 3)
            pdb_inp_0 = pdb.input(file_name=fn_gr0)
            pdb_inp_1 = pdb.input(file_name=fn_gr1)
            pdb_inp_2 = pdb.input(file_name=fn_gr2)
            self.assertEqual(pdb_inp_0.atoms().size(), 12)
            self.assertEqual(pdb_inp_1.atoms().size(), 8)
            self.assertEqual(pdb_inp_2.atoms().size(), 8)
        else:
            print "phenix not available, skipping test_create_ncs_domain_pdb_files()"
            pass
Ejemplo n.º 4
0
def test_solvent_model():

  # correct values
  p = pdb.input(source_info='string',lines=test_pdb)
  sr = p.xray_structure_simple().scattering_type_registry()

  # test values
  p1 = pdb.input(source_info='string',lines=test_pdb)
  mls = server.server()
  el = server.ener_lib()
  ip = pdb_interpretation.process(mon_lib_srv=mls,ener_lib=el,pdb_inp=p1)
  sg = structure_generator()
  sg.add_species(p,1)
  sm = solvent_model()
  sm.interpreted_pdb = ip
  sm.xyz = sg.species[0].xyz

  new_sr = sm.add_bulk_solvent(sr)
  assert(new_sr.sum_of_scattering_factors_at_diffraction_angle_0() <
         sr.sum_of_scattering_factors_at_diffraction_angle_0())
  sm.bulk_solvent_scale = 0.0
  new_sr = sm.add_bulk_solvent(sr)
  assert(approx_equal(sr.sum_of_scattering_factors_at_diffraction_angle_0(),
                      new_sr.sum_of_scattering_factors_at_diffraction_angle_0()))

  sm.boundary_layer_scale = 0.0
  new_sr = sm.add_boundary_layer_solvent(new_sr)
  assert(approx_equal(sr.sum_of_scattering_factors_at_diffraction_angle_0(),
                      new_sr.sum_of_scattering_factors_at_diffraction_angle_0()))
  sm.boundary_layer_scale = 0.6
  new_sr = sm.add_boundary_layer_solvent(new_sr)
  assert(new_sr.sum_of_scattering_factors_at_diffraction_angle_0() >
         sr.sum_of_scattering_factors_at_diffraction_angle_0())
Ejemplo n.º 5
0
def exercise_pdb_input_error_handling():
    from libtbx.test_utils import open_tmp_file
    from libtbx.test_utils import Exception_expected
    bad_pdb_string = """\
ATOM   1  CB  LYS 109  16.113   7.345  47.084  1.00 20.00      A
ATOM   2  CG  LYS 109  17.058   6.315  47.703  1.00 20.00      A
ATOM   3  CB  LYS 109  26.721   1.908  15.275  1.00 20.00      B
ATOM   4  CG  LYS 109  27.664   2.793  16.091  1.00 20.00      B
"""
    f = open_tmp_file(suffix="bad.pdb")
    f.write(bad_pdb_string)
    f.close()
    try:
        pdb_inp = pdb.input(file_name=f.name, source_info=None)
    except ValueError as e:
        err_message = str(e)
        assert bad_pdb_string.splitlines()[0] in err_message
    else:
        raise Exception_expected
    bad_cif_loop_string = """\
data_cif
loop_
  _atom_site.group_PDB
  _atom_site.id
  _atom_site.label_atom_id
  _atom_site.label_alt_id
  _atom_site.label_comp_id
  _atom_site.auth_asym_id
  _atom_site.auth_seq_id
  _atom_site.pdbx_PDB_ins_code
  _atom_site.Cartn_x
  _atom_site.Cartn_y
  _atom_site.Cartn_z
  _atom_site.occupancy
  _atom_site.B_iso_or_equiv
  _atom_site.type_symbol
  _atom_site.pdbx_formal_charge
  _atom_site.label_asym_id
  _atom_site.label_entity_id
  _atom_site.label_seq_id
  #_atom_site.pdbx_PDB_model_num
ATOM  47  CA . THR  C   22  ?   -7.12300  19.28700  -2.26800  1.000   8.32783  C   ? B  ?  11  1
ATOM  52  CA . ASN  C   25  ?  -11.06500  18.97000  -5.48100  1.000   8.20531  C   ? C  ?  12  1
ATOM  60  CA . VAL  C   26  ?  -12.16900  22.54800  -4.78000  1.000   8.45988  C   ? C  ?  13  1
"""
    f = open_tmp_file(suffix="bad.cif")
    f.write(bad_cif_loop_string)
    f.close()
    try:
        pdb_inp = pdb.input(file_name=f.name, source_info=None)
    except iotbx.cif.CifParserError as e:
        err_message = str(e)
        assert err_message == \
               "Wrong number of data items for loop containing _atom_site.group_PDB"
    else:
        raise Exception_expected
Ejemplo n.º 6
0
def exercise_03():
    """
  Verify that there are no errors processing the write command
  No inception of the output is done. Just making sure it does not break
  """
    pdb_inp = pdb.input(source_info=None, lines=pdb_str_1)
    transform_info = pdb_inp.process_MTRIX_records()
    transforms_obj = iotbx.ncs.input(hierarchy=pdb_inp.construct_hierarchy())
    pdb_inp = pdb.input(source_info=None, lines=pdb_str_1)
    transforms_obj.get_ncs_info_as_spec()
 def setUp(self):
   """ Create temporary folder for temp files produced during test """
   self.currnet_dir = os.getcwd()
   now = datetime.now().strftime("%I%p_%m_%d_%Y")
   self.tempdir = 'TestNcsGroupPreprocessing_{}'.format(now)
   if not os.path.isdir(self.tempdir):
     os.mkdir(self.tempdir)
   os.chdir(self.tempdir)
   # self.pdb_obj = pdb.hierarchy.input(pdb_string=test_pdb_ncs_spec)
   self.pdb_inp = pdb.input(source_info=None, lines=test_pdb_ncs_spec)
   self.ph = self.pdb_inp.construct_hierarchy()
   self.pdb_inp = pdb.input(source_info=None, lines=test_pdb_ncs_spec)
 def setUp(self):
   """ Create temporary folder for temp files produced during test """
   self.currnet_dir = os.getcwd()
   now = datetime.now().strftime("%I%p_%m_%d_%Y")
   self.tempdir = 'TestNcsGroupPreprocessing_{}'.format(now)
   if not os.path.isdir(self.tempdir):
     os.mkdir(self.tempdir)
   os.chdir(self.tempdir)
   # self.pdb_obj = pdb.hierarchy.input(pdb_string=test_pdb_ncs_spec)
   self.pdb_inp = pdb.input(source_info=None, lines=test_pdb_ncs_spec)
   self.ph = self.pdb_inp.construct_hierarchy()
   self.pdb_inp = pdb.input(source_info=None, lines=test_pdb_ncs_spec)
Ejemplo n.º 9
0
 def __init__(self,standard_camera,pdb_code=None,pdb_file=None):
   self.limiting_resolution = 1.E10*standard_camera.corner_resolution() # in Angstroms
   self.pdb_code = pdb_code
   from iotbx import pdb
   if pdb_file != None:
     pdb_inp = pdb.input(file_name = pdb_file)
   elif pdb_code != None:
     import iotbx.pdb.fetch
     pdb_url = iotbx.pdb.fetch.fetch(id=pdb_code)
     pdb_inp = pdb.input(source_info=None,lines=pdb_url.readlines())
   self.xray_structure = pdb_inp.xray_structure_simple()
   primitive_xray_structure = self.xray_structure.primitive_setting()
   self.P1_primitive_xray_structure = primitive_xray_structure.expand_to_p1()
Ejemplo n.º 10
0
 def __init__(self,standard_camera,pdb_code=None,pdb_file=None):
   self.limiting_resolution = 1.E10*standard_camera.corner_resolution() # in Angstroms
   self.pdb_code = pdb_code
   from iotbx import pdb
   if pdb_file != None:
     pdb_inp = pdb.input(file_name = pdb_file)
   elif pdb_code != None:
     import iotbx.pdb.fetch
     pdb_url = iotbx.pdb.fetch.fetch(id=pdb_code)
     pdb_inp = pdb.input(source_info=None,lines=pdb_url.readlines())
   self.xray_structure = pdb_inp.xray_structure_simple()
   primitive_xray_structure = self.xray_structure.primitive_setting()
   self.P1_primitive_xray_structure = primitive_xray_structure.expand_to_p1()
Ejemplo n.º 11
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
Ejemplo n.º 12
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(hierarchy=pdb.input(source_info=None, lines=s).construct_hierarchy())
     print "ncs_obj.number_of_ncs_groups", ncs_obj.number_of_ncs_groups
     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)
     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)
Ejemplo n.º 13
0
def tst_ssm():
    import libtbx.load_env
    from iotbx import pdb
    from libtbx.test_utils import approx_equal
    ssm_pdb1 = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/pdb/ssm1.pdb", test=os.path.isfile)
    if (ssm_pdb1 is None):
        print(
            "Skipping exercise_regression(): input pdb (ssm1.pdb) not available"
        )
        return
    ssm_pdb2 = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/pdb/ssm2.pdb", test=os.path.isfile)
    if (ssm_pdb2 is None):
        print(
            "Skipping exercise_regression(): input pdb (ssm2.pdb) not available"
        )
        return
    pdb_io1 = pdb.input(file_name=ssm_pdb1)
    pdb_hierarchy1 = pdb_io1.construct_hierarchy()
    pdb_hierarchy1.reset_i_seq_if_necessary()
    pdb_io2 = pdb.input(file_name=ssm_pdb2)
    pdb_hierarchy2 = pdb_io2.construct_hierarchy()
    pdb_hierarchy2.reset_i_seq_if_necessary()

    reference_chain = None
    moving_chain = None

    #get reference_chain
    for chain in pdb_hierarchy1.chains():
        if chain.id.strip() == "H":
            reference_chain = chain
            break

    #get moving chain
    for chain in pdb_hierarchy2.chains():
        if chain.id.strip() == "B":
            moving_chain = chain
            break

    assert reference_chain is not None
    assert moving_chain is not None

    ssm = ccp4io_adaptbx.SecondaryStructureMatching(reference=reference_chain,
                                                    moving=moving_chain)
    assert ssm.ssm.n_align == 53
    assert approx_equal(ssm.ssm.rmsd, 4.68912136041)

    ssm_alignment = ccp4io_adaptbx.SSMAlignment.residue_groups(match=ssm)
    assert len(ssm_alignment.stats) == 230
Ejemplo n.º 14
0
def exercise_08():
    """
  Test for MTRIX record when copies already present in file
  """
    pdb_inp = pdb.input(source_info=None, lines=pdb_str_8)
    h = pdb_inp.construct_hierarchy_MTRIX_expanded()
    assert approx_equal(pdb_inp.atoms().extract_xyz(), h.atoms().extract_xyz())
def test_normal_pdb():
    fn = get_fn('4lzt/4lzt.not_les.pdb')
    tn = get_fn('4lzt/4lzt.parm7')
    rst7 = get_fn('4lzt/4lzt.rst7')

    pdb_input = pdb.input(fn)
    symm = pdb_input.crystal_symmetry()
    pdb_hc = pdb_input.construct_hierarchy()

    phenix_coords_uc = expand_coord_to_unit_cell(pdb_hc.atoms().extract_xyz(),
                                                 symm)

    indices_dict = get_indices_convert_dict(fn)
    p2a_indices = indices_dict['p2a']
    a2p_indices = indices_dict['a2p']
    parm = pmd.load_file(tn, rst7)

    a0 = reorder_coords_phenix_to_amber(phenix_coords_uc, p2a_indices)

    # make sure phenix and amber read the same coordinates
    aa_eq(pdb_input.atoms().extract_xyz(), parm.coordinates, decimal=2)
    aa_eq(a0, parm.coordinates, decimal=2)

    # make sure the a2p_indices and p2a_indices are identical for non-LES
    indices_dict = get_indices_convert_dict_from_array(
        pdb_input.atoms().extract_xyz(), parm.coordinates)
    p2a_indices = indices_dict['p2a']
    a2p_indices = indices_dict['a2p']
    eq(a2p_indices, p2a_indices)
Ejemplo n.º 16
0
def calculate_fobs(resolution   = 1.0,
                   algorithm = "direct"):
  pdb_file = libtbx.env.find_in_repositories(
                              relative_path="phenix_regression/pdb/enk_gbr.pdb", test=os.path.isfile)
  xray_structure = pdb.input(file_name=pdb_file).xray_structure_simple()
  xray_structure.scattering_type_registry(table = "wk1995")
  f_calc = xray_structure.structure_factors(
                                        d_min          = resolution,
                                        anomalous_flag = False,
                                        cos_sin_table  = False,
                                        algorithm      = algorithm).f_calc()
  f_calc = abs(f_calc.structure_factors_from_scatterers(
                                     xray_structure = xray_structure).f_calc())
  r_free_flags = f_calc.generate_r_free_flags(fraction = 0.01,
                                              max_free = 200000)

  mtz_dataset = f_calc.as_mtz_dataset(column_root_label = "FOBS")

  mtz_dataset.add_miller_array(miller_array      = r_free_flags,
                               column_root_label = "TEST")

  sigmas = r_free_flags.array(data = flex.double(r_free_flags.data().size(),1))
  mtz_dataset.add_miller_array(miller_array      = sigmas,
                               column_root_label = "SIGMA")

  mtz_object = mtz_dataset.mtz_object()
  mtz_object.write(file_name = "enk_gbr.mtz")
Ejemplo n.º 17
0
 def test_transform_update(self):
   """ Test update of rotation and translation using selection """
   ncs_obj = ncs.input(pdb_string=pdb_answer_0)
   pdb_inp = 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))
Ejemplo n.º 18
0
def exercise_clashscore():
    if (not libtbx.env.has_module(name="probe")):
        print "Skipping exercise_clashscore(): probe not configured"
        return

    pdb_io = pdb.input(source_info=None, lines=pdb_str_1)
    pdb_hierarchy = pdb_io.construct_hierarchy()
    cs = clashscore.clashscore(pdb_hierarchy=pdb_hierarchy,
                               fast=False,
                               condensed_probe=True,
                               out=null_out())
    for unpickle in [False, True]:
        if unpickle:
            cs = loads(dumps(cs))
        c_score = cs.get_clashscore()
        assert approx_equal(c_score, 35.29, eps=0.01)
        bad_clashes_list = cs.results
        assert ([c.format_old() for c in bad_clashes_list] == [
            ' A  72  ARG  HG2  A  72  ARG  O   :1.048',
            ' A  71  LEU  HA   A  71  LEU HD12 :0.768',
            ' A  72  ARG  CG   A  72  ARG  O   :0.720'
        ]), [c.format_old() for c in bad_clashes_list]

    #test nuclear distances
    cs = clashscore.clashscore(pdb_hierarchy=pdb_hierarchy,
                               fast=False,
                               condensed_probe=True,
                               nuclear=True)
    for unpickle in [False, True]:
        if (unpickle):
            cs = loads(dumps(cs))
        c_score = cs.get_clashscore()
        assert approx_equal(c_score, 58.82, eps=0.01)
        bad_clashes_list = cs.results
        assert ([c.format_old() for c in bad_clashes_list] == [
            ' A  72  ARG  HG2  A  72  ARG  O   :1.085',
            ' A  71  LEU  HA   A  71  LEU HD12 :0.793',
            ' A  72  ARG  CG   A  72  ARG  O   :0.720',
            ' A  72  ARG  HD3  A  72  ARG HH11 :0.669',
            ' A  72  ARG  HB3  A  72  ARG  HE  :0.647'
        ]), [c.format_old() for c in bad_clashes_list]

    #test B factor cutoff
    cs = clashscore.clashscore(pdb_hierarchy=pdb_hierarchy,
                               fast=False,
                               condensed_probe=True,
                               b_factor_cutoff=40)
    for unpickle in [False, True]:
        if (unpickle):
            cs = loads(dumps(cs))
        c_score = cs.get_clashscore()
        assert approx_equal(c_score, 35.29, eps=0.01)
        c_score_b_cutoff = cs.get_clashscore_b_cutoff()
        assert approx_equal(c_score_b_cutoff, 39.47, eps=0.01)
        bad_clashes_list = cs.results
        assert ([c.format_old() for c in bad_clashes_list] == [
            ' A  72  ARG  HG2  A  72  ARG  O   :1.048',
            ' A  71  LEU  HA   A  71  LEU HD12 :0.768',
            ' A  72  ARG  CG   A  72  ARG  O   :0.720'
        ]), [c.format_old() for c in bad_clashes_list]
def main(filename=None):
    if filename is None:
        filename = 'ala_term.pdb'
        with open(filename, 'w') as f:
            f.write(pdb_str)
    pdb_inp = pdb.input(filename)
    hierarchy = pdb_inp.construct_hierarchy()
    params = mmtbx.model.manager.get_default_pdb_interpretation_params()
    params.pdb_interpretation.use_neutron_distances = True
    params.pdb_interpretation.restraints_library.cdl = False
    print(len(hierarchy.atoms()))
    asc = hierarchy.atom_selection_cache()
    sel = asc.selection("element H or element D")
    print('sel len', len(sel))
    print(len(hierarchy.atoms()))
    hierarchy.show()

    model = mmtbx.model.manager(
        model_input=None,
        pdb_hierarchy=hierarchy,
        crystal_symmetry=pdb_inp.crystal_symmetry(),
        log=null_out(),
    )
    print('m1', len(model.get_hierarchy().atoms()))
    for atom in model.get_hierarchy().atoms():
        print(atom.format_atom_record())
    model.process(make_restraints=True,
                  grm_normalization=True,
                  pdb_interpretation_params=params)
    print('m2', len(model.get_hierarchy().atoms()))
    for atom in model.get_hierarchy().atoms():
        print(atom.format_atom_record())
    model.idealize_h_riding()
    model.set_occupancies(0., selection=sel)
def run(args):
  master_phil = torsion_ncs.torsion_ncs_params
  import iotbx.utils
  input_objects = iotbx.utils.process_command_line_inputs(
    args=args,
    master_phil=master_phil,
    input_types=("pdb", "cif"))
  work_phil = master_phil.fetch(sources=input_objects["phil"])
  params = work_phil.extract()
  if len(input_objects["pdb"]) != 1:
    raise Sorry("mmtbx.find_torsion_angle_ncs_groups requires "+
                "one PDB files as input")
  else:
    file_obj = input_objects["pdb"][0]
    file_name = file_obj.file_name
    pdb_io = pdb.input(file_name)
    pdb_hierarchy = pdb_io.construct_hierarchy()
    pdb_hierarchy.atoms().reset_i_seq()
  ncs_groups = torsion_ncs.determine_ncs_groups(
                 pdb_hierarchy=pdb_hierarchy,
                 params=params)
  if len(ncs_groups) == 0:
    print "No NCS groups found"
  for i, group in enumerate(ncs_groups):
    print "Group %d:" % (i+1)
    for chain in group:
      print "  "+chain
    print
Ejemplo n.º 21
0
def calculate_fobs(resolution=1.0, algorithm="direct"):
    pdb_file = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/pdb/enk_gbr.pdb", test=os.path.isfile)
    xray_structure = pdb.input(file_name=pdb_file).xray_structure_simple()
    xray_structure.scattering_type_registry(table="wk1995")
    f_calc = xray_structure.structure_factors(d_min=resolution,
                                              anomalous_flag=False,
                                              cos_sin_table=False,
                                              algorithm=algorithm).f_calc()
    f_calc = abs(
        f_calc.structure_factors_from_scatterers(
            xray_structure=xray_structure).f_calc())
    r_free_flags = f_calc.generate_r_free_flags(fraction=0.01, max_free=200000)

    mtz_dataset = f_calc.as_mtz_dataset(column_root_label="FOBS")

    mtz_dataset.add_miller_array(miller_array=r_free_flags,
                                 column_root_label="TEST")

    sigmas = r_free_flags.array(
        data=flex.double(r_free_flags.data().size(), 1))
    mtz_dataset.add_miller_array(miller_array=sigmas,
                                 column_root_label="SIGMA")

    mtz_object = mtz_dataset.mtz_object()
    mtz_object.write(file_name="enk_gbr.mtz")
Ejemplo n.º 22
0
def exercise_cablam():
  regression_pdb = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/pdb/pdb103l.ent",
    test=os.path.isfile) #This is the same file used for tst_kinemage.py
  if (regression_pdb is None):
    print "Skipping exercise_cablam(): input pdb (pdb103l.ent) not available"
    return
  #-----
  pdb_io = pdb.input(regression_pdb)
  pdbid = os.path.basename(regression_pdb)
  hierarchy = pdb_io.construct_hierarchy()

  oneline_test = cablam_test_string()
  cablam_validate.oneline(hierarchy, peptide_cutoff=0.05,
    peptide_bad_cutoff=0.01, ca_cutoff=0.005, pdbid=pdbid,
    writeto=oneline_test)

  text_test = cablam_test_string()
  outliers = cablam_validate.analyze_pdb(hierarchy, outlier_cutoff=0.05, pdbid=pdbid)
  cablam_validate.give_text(outliers, writeto=text_test)

  #print '|',oneline_test.output,'|'
  #print '|',ref_cablam_give_oneline,'|'
  #print '|',text_test.output,'|'
  #print '|',ref_cablam_give_text,'|'

  assert not show_diff(oneline_test.output , ref_cablam_give_oneline)
  assert not show_diff(text_test.output , ref_cablam_give_text)
 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 get_C2_structures():
  # section 1. C2 models.  a) whole pdb, b) no Fe, c) FE1 only, d) FE2 only
  pdb_text = local_data.get("pdb_lines")# parsing PDB structure 1M2A
  tokens = pdb_text.split("\n")
  btokens = []; ctokens = []; dtokens = []
  for token in tokens:
    splits = token.split()
    if len(splits)==12:
      if splits[11]!="FE": btokens.append(token)
    else: btokens.append(token)
    if token.find("ATOM")==0: continue
    if token.find("HETATM")==0:
      if splits[3]!="FES" or splits[2].find("FE")!=0: continue
      if splits[2]=="FE1": ctokens.append(token); continue
      if splits[2]=="FE2": dtokens.append(token); continue
    ctokens.append(token); dtokens.append(token)
  pdb_text_b = "\n".join(btokens); print (len(tokens),len(btokens),len(ctokens),len(dtokens))
  pdb_text_c = "\n".join(ctokens);
  pdb_text_d = "\n".join(dtokens);
  from iotbx import pdb
  C2_structures = []
  for tag,lines in zip(["pdb_text", "pdb_text_b", "pdb_text_c", "pdb_text_d"],
                       [pdb_text, pdb_text_b, pdb_text_c, pdb_text_d]):
    pdb_inp = pdb.input(source_info=None,lines = lines)
    xray_structure = pdb_inp.xray_structure_simple()
    xray_structure.show_summary(prefix="%s "%tag)
    C2_structures.append(xray_structure)
  return C2_structures
Ejemplo n.º 25
0
def get_mmtbx_icalc(code,d_min, anomalous_flag = False):

    #pdbtools.run([file, "high_resolution=%f"%self.d_min, "label=f-obs-nks"
    #              "k_sol=0.35", "b_sol=60", "b_cart=1 2 -3 0 0 0", "--f_model", "r_free=0.1"])
    # get xray_structure

    pdb_url = iotbx.pdb.fetch.fetch(id=code)
    pdb_input = pdb.input(source_info=None,lines=pdb_url.readlines())

    xray_structure = pdb_input.xray_structure_simple()

    phil2 = mmtbx.command_line.fmodel.fmodel_from_xray_structure_master_params
    params2 = phil2.extract()
    # adjust the cutoff of the generated intensities to assure that
    # statistics will be reported to the desired high-resolution limit
    # even if the observed unit cell differs slightly from the reference.
    ISO_ALLOWANCE = 0.1 # isomorphous recip cell volume changes no more than 10%
    params2.high_resolution = d_min / math.pow( (1.+ISO_ALLOWANCE),(1./3.) )
    params2.output.type = "real"
    if True :
      params2.fmodel.k_sol = 0.35
      params2.fmodel.b_sol = 46
    f_model = mmtbx.utils.fmodel_from_xray_structure(
      xray_structure = xray_structure,
      f_obs          = None,
      add_sigmas     = True,
      params         = params2).f_model
    i_model = f_model.as_intensity_array()


    return  i_model.map_to_asu()
Ejemplo n.º 26
0
    def fcalc_from_pdb(self, resolution=None, algorithm=None, wavelength=0.9):
        ''' Generate FCalc from PDB-formatted coordinates '''

        with open(self.params.reference_coordinates, 'r') as pdb_file:
            pdb_lines = pdb_file.readlines()

        # Read in coordinates
        pdb_inp = pdb.input(source_info=None, lines=pdb_lines)
        xray_structure = pdb_inp.xray_structure_simple()

        # take a detour to insist on calculating anomalous contribution of every atom
        scatterers = xray_structure.scatterers()
        for sc in scatterers:
            expected_henke = henke.table(
                sc.element_symbol()).at_angstrom(wavelength)
            sc.fp = expected_henke.fp()
            sc.fdp = expected_henke.fdp()

        # how do we do bulk solvent?
        primitive_xray_structure = xray_structure.primitive_setting()
        P1_primitive_xray_structure = primitive_xray_structure.expand_to_p1()
        fcalc = P1_primitive_xray_structure.structure_factors(
            d_min=resolution, anomalous_flag=True,
            algorithm=algorithm).f_calc()
        return fcalc.amplitudes()
Ejemplo n.º 27
0
 def read_model(self, file_name=None, log=sys.stdout):
     print("Reading model from %s " % (file_name), file=log)
     from iotbx.pdb import input
     inp = input(file_name=file_name)
     from mmtbx.model import manager as model_manager
     model = model_manager(model_input=inp)
     self.add_model(model, log=log)
Ejemplo n.º 28
0
def get_spacegroup_info(struct_file):
    """Get info from PDB of mmCIF file"""

    # print "get_spacegroup_info", struct_file, os.getcwd()

    struct_file = convert_unicode(struct_file)

    if struct_file[-3:].lower() == "cif":
        fail = False
        cif_spacegroup = False

        try:
            input_file = open(struct_file, "r").read(20480)
            for line in input_file.split('\n'):
                if "_symmetry.space_group_name_H-M" in line:
                    cif_spacegroup = line[32:].strip()[1:-1].upper().replace(
                        " ", "")
                    # print cif_spacegroup
                if "_pdbx_database_status.pdb_format_compatible" in line:
                    if line.split()[1] == "N":
                        fail = True
        except IOError:
            return False
        if fail:
            return False
        else:
            return cif_spacegroup
    else:
        return str(
            iotbx_pdb.input(struct_file).crystal_symmetry().space_group_info()
        ).upper().replace(" ", "")
Ejemplo n.º 29
0
def exercise_cablam():
    regression_pdb = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/pdb/pdb103l.ent",
        test=os.path.isfile)  #This is the same file used for tst_kinemage.py
    if (regression_pdb is None):
        print "Skipping exercise_cablam(): input pdb (pdb103l.ent) not available"
        return
    #-----
    pdb_io = pdb.input(regression_pdb)
    pdbid = os.path.basename(regression_pdb)
    hierarchy = pdb_io.construct_hierarchy()

    output_holder = cablam_test_string()

    cablamalyze = cablam.cablamalyze(pdb_hierarchy=hierarchy,
                                     outliers_only=False,
                                     out=output_holder,
                                     quiet=False)

    cablamalyze.as_oneline()
    assert not show_diff(output_holder.output, ref_cablam_oneline)

    output_holder.output = ""

    cablamalyze.as_text()
    assert not show_diff(output_holder.output, ref_cablam_text)
Ejemplo n.º 30
0
def exercise_08():
    """
  Test for MTRIX record when copies already present in file
  """
    pdb_inp = pdb.input(source_info=None, lines=pdb_str_8)
    model = mmtbx.model.manager(pdb_inp)
    assert model.get_number_of_atoms() == 7
Ejemplo n.º 31
0
  def create_asu(self,ncs_filename,asu_filename,crystal_symmetry=None):
    """ (str,str) -> crystal_symmetry object
    Create P1 crystal_symmetry that fit the ASU.
    Create ASU from NCS and save the new pdb file
    with CRYST1 and SCALE records in local directory

    Argument:
    ---------
    ncs_filename : NCS to be used to create the ASU
    asu_filename : ASU file name
    crystal_symmetry : Allow forcing other crystal_symmetry

    Returns:
    --------
    crystal_symmetry
    """
    m = multimer(
      file_name=ncs_filename,
      reconstruction_type='cau',error_handle=True,eps=1e-2)
    msg = 'Number of transforms is {0} instead of {1}'\
      .format(m.number_of_transforms,2)
    assert m.number_of_transforms == 2, msg
    m.write(asu_filename)
    pdb_inp = pdb.input(file_name = asu_filename)
    xrs = pdb_inp.xray_structure_simple()
    xrs_unit_cell = xrs.orthorhombic_unit_cell_around_centered_scatterers(
    buffer_size=2)
    if not crystal_symmetry:
      crystal_symmetry = xrs_unit_cell.crystal_symmetry()
    pdb_inp.write_pdb_file(file_name = asu_filename, crystal_symmetry = crystal_symmetry)
    return crystal_symmetry
def run(args):
    master_phil = torsion_ncs.torsion_ncs_params
    import iotbx.utils
    input_objects = iotbx.utils.process_command_line_inputs(
        args=args, master_phil=master_phil, input_types=("pdb", "cif"))
    work_phil = master_phil.fetch(sources=input_objects["phil"])
    params = work_phil.extract()
    if len(input_objects["pdb"]) != 1:
        raise Sorry("mmtbx.find_torsion_angle_ncs_groups requires " +
                    "one PDB files as input")
    else:
        file_obj = input_objects["pdb"][0]
        file_name = file_obj.file_name
        pdb_io = pdb.input(file_name)
        pdb_hierarchy = pdb_io.construct_hierarchy()
        pdb_hierarchy.atoms().reset_i_seq()
    ncs_groups = torsion_ncs.determine_ncs_groups(pdb_hierarchy=pdb_hierarchy,
                                                  params=params)
    if len(ncs_groups) == 0:
        print "No NCS groups found"
    for i, group in enumerate(ncs_groups):
        print "Group %d:" % (i + 1)
        for chain in group:
            print "  " + chain
        print
Ejemplo n.º 33
0
def get_mmtbx_icalc(code, d_min, anomalous_flag=False):

    #pdbtools.run([file, "high_resolution=%f"%self.d_min, "label=f-obs-nks"
    #              "k_sol=0.35", "b_sol=60", "b_cart=1 2 -3 0 0 0", "--f_model", "r_free=0.1"])
    # get xray_structure

    pdb_url = iotbx.pdb.fetch.fetch(id=code)
    pdb_input = pdb.input(source_info=None, lines=pdb_url.readlines())

    xray_structure = pdb_input.xray_structure_simple()

    phil2 = mmtbx.command_line.fmodel.fmodel_from_xray_structure_master_params
    params2 = phil2.extract()
    # adjust the cutoff of the generated intensities to assure that
    # statistics will be reported to the desired high-resolution limit
    # even if the observed unit cell differs slightly from the reference.
    ISO_ALLOWANCE = 0.1  # isomorphous recip cell volume changes no more than 10%
    params2.high_resolution = d_min / math.pow((1. + ISO_ALLOWANCE), (1. / 3.))
    params2.output.type = "real"
    if True:
        params2.fmodel.k_sol = 0.35
        params2.fmodel.b_sol = 46
    f_model = mmtbx.utils.fmodel_from_xray_structure(
        xray_structure=xray_structure,
        f_obs=None,
        add_sigmas=True,
        params=params2).f_model
    i_model = f_model.as_intensity_array()

    return i_model.map_to_asu()
Ejemplo n.º 34
0
  def setUp(self):
    '''
    create a temporary folder with files for testing, based
    on ncs_0_copy (see below)

    1) Create ncs0.pdb, with complete Asymmetric Unit (ASU)
    2) Create ncs1.pdb, pertubed (shaken) version of ncs0_pdb,
       with a single NCS and MTRIX info
    3) Create asu0.pdb, A complete ASU produced form ncs0
    4) Create asu1.pdb, A complete ASU produced form ncs1
    '''

    self.set_folder_and_files()
    # Write NCS file with MTRIX record and generate ASU.
    # This is the answer-strucure
    open(self.ncs0_filename,'w').write(ncs_0_copy)
    crystal_symmetry = self.write_ncs_asu(
      ncs_filename = self.ncs0_filename,
      asu_filename=self.asu0_filename)

    # Shake structure - subject to refinement input
    pdb_inp_ncs = pdb.input(file_name = self.ncs0_filename)
    # Create xrs from the single ncs
    xrs = pdb_inp_ncs.xray_structure_simple()
    ph = pdb_inp_ncs.construct_hierarchy()
    xrs_shaken = xrs.deep_copy_scatterers()
    xrs_shaken.shake_sites_in_place(mean_distance=0.3)
    ph.adopt_xray_structure(xrs_shaken)
    ph.write_pdb_file(file_name=self.ncs1_filename)
    self.add_MTRIX_to_pdb(self.ncs1_filename, record=ncs_0_copy)
    # use the crystal_symmetry from the answer-structure
    self.write_ncs_asu(
      ncs_filename = self.ncs1_filename,
      asu_filename=self.asu1_filename,
      crystal_symmetry=crystal_symmetry)
Ejemplo n.º 35
0
def get_spacegroup_info(cif_file):
    """Get info from PDB of mmCIF file"""

    # print "get_spacegroup_info", cif_file, os.getcwd()

    cif_file = convert_unicode(cif_file)

    if cif_file[-3:].lower() == "cif":
        fail = False
        cif_spacegroup = False

        try:
            input_file = open(cif_file, "r").read(20480)
            for line in input_file.split('\n'):
                if "_symmetry.space_group_name_H-M" in line:
                    cif_spacegroup = line[32:].strip()[1:-1].upper().replace(" ", "")
                if "_pdbx_database_status.pdb_format_compatible" in line:
                    if line.split()[1] == "N":
                        fail = True
        except IOError:
            return False
        if fail:
            return False
        else:
            return cif_spacegroup
    else:
        return str(iotbx_pdb.input(cif_file).crystal_symmetry().space_group_info()).upper().replace(" ", "")
Ejemplo n.º 36
0
def run(model_filename=None):
    import mmtbx.monomer_library.pdb_interpretation as pdb_inter
    #print_restraints(database)
    if model_filename is not None:
        from iotbx import pdb
        pdb_inp = pdb.input(model_filename)
        pdb_hierarchy = pdb_inp.construct_hierarchy()
        #pdb_hierarchy.show()
        pdb_processed_file = pdb_inter.run(
            args=[model_filename],
            assume_hydrogens_all_missing=False,
            hard_minimum_nonbonded_distance=0.0,
            nonbonded_distance_threshold=None,
            substitute_non_crystallographic_unit_cell_if_necessary=True,
        )
        grm = pdb_processed_file.geometry_restraints_manager()
        xrs = pdb_processed_file.xray_structure()
        sites_cart = xrs.sites_cart()
        site_labels = xrs.scatterers().extract_labels()
        pair_proxies = grm.pair_proxies(sites_cart=sites_cart,
                                        site_labels=site_labels)
        proxies_info_nonbonded = pair_proxies.nonbonded_proxies.get_sorted(
            by_value="delta", sites_cart=sites_cart, site_labels=site_labels)
        rc = get_metal_coordination_proxies(
            pdb_hierarchy,
            pair_proxies.nonbonded_proxies,
        )
        bonds, angles = get_proxies(rc)
        print('\n\tbonds, angles : %d, %d\n\n' % (len(bonds), len(angles)))
Ejemplo n.º 37
0
def exercise_cablam():
    regression_pdb = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/pdb/pdb103l.ent",
        test=os.path.isfile)  #This is the same file used for tst_kinemage.py
    if (regression_pdb is None):
        print(
            "Skipping exercise_cablam(): input pdb (pdb103l.ent) not available"
        )
        return
    #-----
    pdb_io = pdb.input(regression_pdb)
    pdbid = os.path.basename(regression_pdb)
    hierarchy = pdb_io.construct_hierarchy()

    oneline_test = cablam_test_string()
    cablam_validate.oneline(hierarchy,
                            peptide_cutoff=0.05,
                            peptide_bad_cutoff=0.01,
                            ca_cutoff=0.005,
                            pdbid=pdbid,
                            writeto=oneline_test)

    text_test = cablam_test_string()
    outliers = cablam_validate.analyze_pdb(hierarchy,
                                           outlier_cutoff=0.05,
                                           pdbid=pdbid)
    cablam_validate.give_text(outliers, writeto=text_test)

    #print '|',oneline_test.output,'|'
    #print '|',ref_cablam_give_oneline,'|'
    #print '|',text_test.output,'|'
    #print '|',ref_cablam_give_text,'|'

    assert not show_diff(oneline_test.output, ref_cablam_give_oneline)
    assert not show_diff(text_test.output, ref_cablam_give_text)
Ejemplo n.º 38
0
	def extract_tls_information(self):

		pdb_inp = pdb.input(file_name=self.pdb)
  		h = pdb_inp.construct_hierarchy()

  		self.unit_cell = pdb_inp.crystal_symmetry_from_cryst1()

  		pdb_obj = pdb.hierarchy.input(file_name=self.pdb)
  		remark_3_records = pdb_inp.extract_remark_iii_records(3)
  		tls_extract = mmtbx.tls.tools.tls_from_pdb_inp(
    		remark_3_records = remark_3_records, 
    		pdb_hierarchy = h)

  		self.tls_segments = list()
  		self.tls_objects = list()
  		for i, tls_object in enumerate(tls_extract.tls_params):
  			self.tls_segments.append(tls_object.selection_string)
  			self.tls_objects.append(tls_object)

  		count = 0

  		self.atom_files = list()

		for group in self.tls_segments:

			sel = h.atom_selection_cache().selection(string = group)
			h_new = h.select(sel)

			#Write atomic coordinates of each 
			h_new.write_pdb_file(file_name='model_%d.pdb' %count)

			self.atom_files.append('model_%d.pdb' %count)

			count += 1
Ejemplo n.º 39
0
def create_asu(ncs_filename,asu_filename,crystal_symmetry=None):
  ''' (str,str) -> crystal_symmetry object
  Create ASU from NCS and save the new pdb file
  with CRYST1 and SCALE records in local directory

  Argument:
  ---------
  ncs_filename : NCS to be used to create the ASU
  asu_filename : ASU file name
  crystal_symmetry : Allow forcing other crystal_symmetry

  Returns:
  --------
  crystal_symmetry
  '''
  m = multimer(ncs_filename,'cau',error_handle=True,eps=1e-2)
  if m.number_of_transforms == 0:
    print 'Number of transforms is zero'
  m.write(asu_filename)
  pdb_inp = pdb.input(file_name = asu_filename)
  xrs = pdb_inp.xray_structure_simple()
  if not crystal_symmetry:
    crystal_symmetry = xrs.crystal_symmetry()
  pdb_inp.write_pdb_file(file_name = asu_filename, crystal_symmetry = crystal_symmetry)
  return crystal_symmetry
Ejemplo n.º 40
0
def fcalc_from_pdb(resolution,
                   algorithm=None,
                   wavelength=0.9,
                   anom=True,
                   ucell=None,
                   symbol=None,
                   as_amplitudes=True):
    pdb_lines = 'HEADER TEST\nCRYST1   50.000   60.000   70.000  90.00  90.00  90.00 P 1\nATOM      1  O   HOH A   1      56.829   2.920  55.702  1.00 20.00           O\nATOM      2  O   HOH A   2      49.515  35.149  37.665  1.00 20.00           O\nATOM      3  O   HOH A   3      52.667  17.794  69.925  1.00 20.00           O\nATOM      4  O   HOH A   4      40.986  20.409  18.309  1.00 20.00           O\nATOM      5  O   HOH A   5      46.896  37.790  41.629  1.00 20.00           O\nATOM      6 SED  MSE A   6       1.000   2.000   3.000  1.00 20.00          SE\nEND\n'
    from iotbx import pdb
    pdb_inp = pdb.input(source_info=None, lines=pdb_lines)
    xray_structure = pdb_inp.xray_structure_simple()
    if ucell is not None:
        assert symbol is not None
        from cctbx.xray import structure
        from cctbx import crystal
        crystal_sym = crystal.symmetry(unit_cell=ucell,
                                       space_group_symbol=symbol)
        xray_structure = structure(scatterers=(xray_structure.scatterers()),
                                   crystal_symmetry=crystal_sym)
    scatterers = xray_structure.scatterers()
    if anom:
        from cctbx.eltbx import henke
        for sc in scatterers:
            expected_henke = henke.table(
                sc.element_symbol()).at_angstrom(wavelength)
            sc.fp = expected_henke.fp()
            sc.fdp = expected_henke.fdp()

    primitive_xray_structure = xray_structure.primitive_setting()
    P1_primitive_xray_structure = primitive_xray_structure.expand_to_p1()
    fcalc = P1_primitive_xray_structure.structure_factors(
        d_min=resolution, anomalous_flag=anom, algorithm=algorithm).f_calc()
    if as_amplitudes:
        fcalc = fcalc.amplitudes().set_observation_type_xray_amplitude()
    return fcalc
Ejemplo n.º 41
0
    def __init__(self, resolution, pdb_text, algorithm=None, wavelength=0.9):
        from iotbx import pdb
        pdb_inp = pdb.input(source_info=None, lines=pdb_text)
        xray_structure = pdb_inp.xray_structure_simple()
        xray_structure.show_summary(prefix="Input structure ")
        #
        # take a detour to insist on calculating anomalous contribution of every atom
        scatterers = xray_structure.scatterers()
        for sc in scatterers:
            from cctbx.eltbx import sasaki, henke
            #expected_sasaki = sasaki.table(sc.element_symbol()).at_angstrom(wavelength)
            expected_henke = henke.table(
                sc.element_symbol()).at_angstrom(wavelength)
            sc.fp = expected_henke.fp()
            sc.fdp = expected_henke.fdp()

        import mmtbx.command_line.fmodel
        phil2 = mmtbx.command_line.fmodel.fmodel_from_xray_structure_master_params
        params2 = phil2.extract()
        # adjust the cutoff of the generated intensities to assure that
        # statistics will be reported to the desired high-resolution limit
        # even if the observed unit cell differs slightly from the reference.
        params2.output.type = "complex"
        params2.high_resolution = resolution
        params2.fmodel.k_sol = 0.35
        params2.fmodel.b_sol = 46.
        params2.structure_factors_accuracy.algorithm = algorithm
        self.params2 = params2
        self.xray_structure = xray_structure
  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)
Ejemplo n.º 43
0
def raw_LINK_data(PDB_files_paths,write_to_file=False):
  '''(list) -> list
  Collect raw info from all PDB files containing LINK info
  add file name to raw data

  Arguments:
  PDB_files_paths: list of all PDB files
  write_to_file: if True, list of file name will be also writen in a file
                 'pdb_file_raw_data.txt'
  '''
  if write_to_file:
    f2 = open('pdb_file_raw_data.txt','w')

  files_with_link_records = []
  for file_name in PDB_files_paths:
    pdb_inp = pdb.input(file_name=file_name)
    link_data = pdb_inp.extract_LINK_records()
    if link_data != []:
      files_with_link_records.append(file_name)
      file_name = file_name.split('/')[-1]
      if write_to_file:
        # add the file name to the end of each data line
        f2.writelines([x+' '+file_name+'\n' for x in link_data])
        f2.writelines('='*30+'\n')

  if write_to_file:
    f2.close()
  return files_with_link_records
Ejemplo n.º 44
0
def exercise_cablam():
  regression_pdb = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/pdb/pdb103l.ent",
    test=os.path.isfile) #This is the same file used for tst_kinemage.py
  if (regression_pdb is None):
    print "Skipping exercise_cablam(): input pdb (pdb103l.ent) not available"
    return
  #-----
  pdb_io = pdb.input(regression_pdb)
  pdbid = os.path.basename(regression_pdb)
  hierarchy = pdb_io.construct_hierarchy()

  output_holder = cablam_test_string()

  cablamalyze = cablam.cablamalyze(
    pdb_hierarchy = hierarchy,
    outliers_only=False,
    out=output_holder,
    quiet=False)

  cablamalyze.as_oneline()
  assert not show_diff(output_holder.output , ref_cablam_oneline)

  output_holder.output = ""

  cablamalyze.as_text()
  assert not show_diff(output_holder.output , ref_cablam_text)
Ejemplo n.º 45
0
def sfgen(wavelen_A, pdb_name, algo='fft', dmin=1.5, ano_flag=True):
    """
    generate the structure factors from a pdb
    for use with LD91
    :param wavelen_A:
    :param pdb_name:
    :param algo:
    :param dmin:
    :param ano_flag:
    :return:
    """
    pdb_in = pdb.input(pdb_name)
    xray_structure = pdb_in.xray_structure_simple()
    scatts = xray_structure.scatterers()

    Yb = Yb_scatter()  # reads in values from the Hendrickson plot

    for sc in scatts:
        if sc.element_symbol() == "Yb":
            sc.fp = Yb.fp(wavelen_A)
            sc.fdp = Yb.fdp(wavelen_A)
        else:
            expected_henke = henke.table(
                sc.element_symbol()).at_angstrom(wavelen_A)
            sc.fp = expected_henke.fp()
            sc.fdp = expected_henke.fdp()

    fcalc = xray_structure.structure_factors(d_min=dmin,
                                             algorithm=algo,
                                             anomalous_flag=ano_flag)
    return fcalc.f_calc()
Ejemplo n.º 46
0
Archivo: t3.py Proyecto: youdar/work
def run(sf_file_name,pdb_file_name):
  # check if files exist
  if not isfile(sf_file_name): raise Sorry('{} is not a file'.format(sf_file_name))
  if not isfile(pdb_file_name): raise Sorry('{} is not a file'.format(pdb_file_name))
  # start processing file
  # convert cif to mtz and process mtz file
  file_name_mtz = sf_file_name + '.mtz'
  # creates file in current folder
  easy_run.call("phenix.cif_as_mtz %s"%sf_file_name)
  mtz_object = mtz.object(file_name=file_name_mtz)
  # Process the mtz_object
  miller_arrays_dict = mtz_object.as_miller_arrays_dict()
  miller_arrays = mtz_object.as_miller_arrays()
  for x in miller_arrays_dict:
    print x
    print '+'*60
    #print miller_arrays_dict[x].show_array()
    print '='*60

  # read pdb info
  pdb_inp = pdb.input(file_name=pdb_file_name)          	# read the pdb file data
  structure = pdb_inp.xray_structure_simple()
  xray_structure_simple = pdb_inp.xray_structures_simple()	# a list of structure factors
  f_miller = xray_structure_simple[0].structure_factors(d_min=2.85).f_calc()

  # delete file
  os.remove(file_name_mtz)

  #


  print 'wait here'
Ejemplo n.º 47
0
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
Ejemplo n.º 48
0
def run():
    filename = 'tst_multi.pdb'
    f = open(filename, 'w')
    f.write(pdb_lines)
    f.close()
    pdb_inp = pdb.input(filename)
    pdb_hierarchy = pdb_inp.construct_hierarchy()
    from mmtbx.conformation_dependent_library.tst_rdl import \
        get_geometry_restraints_manager
    geometry_restraints_manager = get_geometry_restraints_manager(filename)
    pdb_hierarchy.reset_i_seq_if_necessary()
    refine = [
        False,  # -179
        True,  # -44
        False,  # 86
        True,  # -22
        False,  # -179
    ]
    refine += [True] * 5
    refine += [False] * 14
    omegalyze = [
        False,
        False,
        False,
        True,
        False,
    ]
    omegalyze += [True] * 3
    omegalyze += [False] * 16
    from mmtbx.conformation_dependent_library import generate_protein_threes
    for i, threes in enumerate(
            generate_protein_threes(
                pdb_hierarchy,
                geometry_restraints_manager,
                cdl_class=True,
                #verbose=verbose,
            )):
        print(i, threes)
        print('  omega   %5.1f' % threes.get_omega_value())
        print("  cis?    %-5s %s" %
              (threes.cis_group(), threes.cis_group(limit=30)))
        print("  trans?  %-5s %s" %
              (threes.trans_group(), threes.trans_group(limit=30)))
        print("  rama    %s" % threes.get_ramalyze_key())
        print('  conf    %s' % threes.is_pure_main_conf())
        assert threes.cis_group() == refine[i], '%s!=%s' % (threes.cis_group(),
                                                            refine[i])
        assert threes.cis_group(limit=30) == omegalyze[i]

    for j in range(0, 181, 10):
        i += 1
        print("  %3d %-5s %-8s %-5s" % (
            j,
            threes._define_omega_a_la_duke_using_limit(j) == 'cis',
            threes._define_omega_a_la_duke_using_limit(j, limit=30),
            refine[i],
        ))
        assert (threes._define_omega_a_la_duke_using_limit(j) == 'cis'
                ) == refine[i]
Ejemplo n.º 49
0
 def test_iselection_asu_to_ncs(self):
   # print sys._getframe().f_code.co_name
   pdb_inp = pdb.input(lines=pdb_answer_0,source_info=None)
   ph = pdb_inp.construct_hierarchy()
   isel_asu = flex.size_t([8,9,13])
   isel_ncs = isel_asu - 7
   results = nu.iselection_asu_to_ncs(isel_asu,'B',ph)
   self.assertEqual(list(isel_ncs),list(results))
Ejemplo n.º 50
0
def run(pdb_filename):
  from iotbx import pdb
  print pdb_filename
  pdb_inp = pdb.input(pdb_filename)
  pdb_hieratchy = pdb_inp.construct_hierarchy()
  for residue_group in pdb_hieratchy.residue_groups():
    for atom_group in residue_groups.atom_groups():
      print get_histidine_protonation(atom_group)
Ejemplo n.º 51
0
Archivo: test2.py Proyecto: youdar/work
def get_sites_protions(pdb_file_name,chain_ID,limit):
  '''(str,str,int) -> pdb_hierarchy,pdb_hierarchy
  create a pdb_hierarchy from pdb_file_name, takes a chain,
  with chain_ID, and devides it to two, at the limit position.


  Example:
  >>>pdb_heavy_var, pdb_heavy_const = get_pdb_protions(pdb_file_name='1bbd',chain_ID='H',limit=113)

  Arguments:
  ----------
  pdb_file_name : pdb file name
  chain_ID : PDB chain ID
  limit : the cutoff between the Variable and the Constant FAB domains

  Returns:
  --------
  sites_var,sites_const
  sites_var : atoms sites of 0 to limit portion of the pdb_hierarchy
  sites_const : atoms sites of limit to end portion of the pdb_hierarchy
  '''
  fn = check_pdb_file_name(pdb_file_name)
  pdb_inp = pdb.input(file_name=fn)
  pdb_hierarchy = pdb_inp.construct_hierarchy()
  xrs = pdb_inp.xray_structure_simple()
  sites_cart_all = xrs.sites_cart()
  chains = pdb_hierarchy.models()[0].chains()
  chain_names = [x.id for x in chains]
  # check if correct name is given and find the correct chain
  if chain_ID in chain_names:
    # get the chain residue group, to check its length
    indx = chain_names.index(chain_ID)
    # get the chain with the chain_ID and index indx
    chain_res = pdb_hierarchy.models()[0].chains()[indx].residue_groups()
    chain_length = len(chain_res)
    selection_var = 'chain {0} resseq {1}:{2}'.format(chain_ID,1,limit)
    selection_const = 'chain {0} resseq {1}:{2}'.format(chain_ID,limit,chain_length)
    pdb_var_selection = pdb_hierarchy.atom_selection_cache().selection(string=selection_var)
    pdb_const_selection = pdb_hierarchy.atom_selection_cache().selection(string=selection_const)
    # get atoms
    params = superpose_pdbs.master_params.extract()
    x = superpose_pdbs.manager(
      params,
      log='log.txt',
      pdb_hierarchy_moving=pdb_const_selection,
      pdb_hierarchy_fixed=pdb_var_selection)

    sites_var = sites_cart_all.select(pdb_var_selection)
    sites_const = sites_cart_all.select(pdb_const_selection)

    chain = chain_res = pdb_hierarchy.models()[0].chains()[indx]

    x1 = superpose_pdbs.manager.extract_sequence_and_sites_chain(chain,'resseq 0:113')
    x2 = superpose_pdbs.manager.extract_sequence_and_sites_chain(chain,'resseq 113:190')
  else:
    raise Sorry('The is not chain with {0} name in {1}'.format(chain_ID,fn))

  return sites_var,sites_const,selection_var,selection_const
Ejemplo n.º 52
0
def amplitudes_from_pdb(resolution,algorithm=None,anomalous=False):
  from iotbx import pdb
  pdb_inp = pdb.input(source_info=None,lines = pdb_lines)
  xray_structure = pdb_inp.xray_structure_simple()
  primitive_xray_structure = xray_structure.primitive_setting()
  P1_primitive_xray_structure = primitive_xray_structure.expand_to_p1()
  fcalc = P1_primitive_xray_structure.structure_factors(
    d_min=resolution, anomalous_flag=anomalous, algorithm=algorithm).f_calc()
  return fcalc.amplitudes()
Ejemplo n.º 53
0
    def load_refinement(self, ref, stats):
        hkl = hklf.reader(open(ref.replace('.dat', '.hkl')))
        pdbf = pdb.input(file_name=ref.replace('.dat', '.pdb'))
        pdbt = PDBTools(file_name=ref.replace('.dat', '.pdb'))
        
        cs = crystal_symmetry_from_ins.extract_from(ref.replace('.dat', '.ins'))
        ma = hkl.as_miller_arrays(crystal_symmetry=cs)
        
        mp = pdbf.xray_structure_simple().scatterers()[0].multiplicity()
        s = pdbt.get_s()
        vm = cs.unit_cell().volume() / (pdbt.get_rmm() * mp)
        
        c = ma[0].completeness(d_max=stats['res'])
        dmin = stats['res']
        r = stats['r']
        rfree = stats['rfree']

        self._mv.SetLabel('%.2f' % vm)
        self._s.SetLabel('%.2f' % s)
        self._dmin.SetLabel('%.2f' % dmin)
        self._c.SetLabel('%.1f' % (c*100))
        self._r.SetLabel('%.3f' % r)
        self._rfree.SetLabel('%.3f' % rfree)
        
        sigxr = self._sigx_r(s, vm, c, r, dmin)
        self._sigxr.SetLabel('%.4f' % sigxr)
        sigxrf = self._sigx_rfree(s, vm, c, rfree, dmin)
        self._sigxrf.SetLabel('%.4f' % sigxrf)
        
        x = np.linspace(dmin+0.5,dmin-0.5, 20)
        ys = [[],[],[],[],[],[]]
        for i in x:
            sr = self._sigx_r(s, vm, c, r, i)
            ys[0].append(sr)
            ys[1].append(sr*1.15)
            ys[2].append(sr*0.85)
            
            sr = self._sigx_rfree(s, vm, c, rfree, i)
            ys[3].append(sr)
            ys[4].append(sr*1.15)
            ys[5].append(sr*0.85)
    
        self.ax1.plot(x, ys[0], 'b-', label='R')
        self.ax1.fill_between(x, ys[1], ys[2], alpha=0.1, facecolor='blue')

        self.ax1.plot(x, ys[3], 'g-', label='Rfree')
        self.ax1.fill_between(x, ys[4], ys[5], alpha=0.1, facecolor='green')
                
        al = self.ax1.axis()
        yam = al[3]-al[2]
        xam = al[1]-al[0]

        self.ax1.axhline(y=0.0236, color='purple', label='3sig (ASP)')
                
        self.ax1.axvline(x=dmin, ymin=0, ymax=(sigxr-al[2])/yam, color='0.7', label='Actual')
        self.ax1.axhline(y=sigxr, xmin=0, xmax=(dmin-al[0])/xam, color='0.7')
        self.ax1.legend(prop={'size':8}, numpoints=1, loc='best', fancybox=True)
Ejemplo n.º 54
0
 def test_1nl0(self):
   '''Compare to published value'''
   fn = '1nl0'
   pdb_fn = fetch.get_pdb (fn,data_type='pdb',mirror='rcsb',log=null_out())
   ph = pdb.input(file_name=pdb_fn).construct_hierarchy()
   fab = fab_elbow_angle(pdb_hierarchy=ph,limit_light=107,limit_heavy=113)
   calculated = fab.fab_elbow_angle
   expected = 220
   msg = 'FAB angle for {0} is {1:3.0f} instead of {2}'.format(fn,calculated,expected)
   self.assertAlmostEqual(calculated,expected,delta=self.delta,msg=msg)
Ejemplo n.º 55
0
def exercise_mtrix(regression_pdb):
    pdb_inp = pdb.input(file_name=op.join(regression_pdb, "pdb1a1q.ent"))
    mtrix_info = pdb_inp.process_mtrix_records()
    assert len(mtrix_info.r) == len(mtrix_info.t) == 2
    assert approx_equal(
        mtrix_info.r[0], [-0.952060, 0.305556, -0.014748, -0.305663, -0.952124, 0.005574, -0.012339, 0.009815, 0.999876]
    )
    assert approx_equal(mtrix_info.t[0], [-22.67001, 73.03197, 0.78307])
    assert mtrix_info.coordinates_present.count(True) == 2
    assert mtrix_info.serial_number == ["  1", "  2"]
def run(args, command_name="iotbx.pdb.link_as_geometry_restraints_edits"):
  for file_name in args:
    section = pdb.input(file_name=file_name).connectivity_annotation_section()
    print "refinement.geometry_restraints.edits {"
    for line in section:
      if (not line.startswith("LINK  ")): continue
      link = link_record(line=line)
      assert link.symops[0].strip() == "" # not implemented
      assert link.symops[1].strip() == "" # not implemented
      sys.stdout.write(link.as_geometry_restraints_edits())
    print "}"
Ejemplo n.º 57
0
def model_reverse(files):

	alternate = 0

	for file in files:
		if alternate%2 == 0:

			pdb_obj = pdb.input(file_name=file)
			h = pdb_obj.construct_hierarchy()

			models = []
			n_mod = 0

			for m in h.models():
				models.append(m)
				n_mod += 1


			#Define new PDB hierarchy
			output = pdb.hierarchy.ext.root()

			count = 0

			for i in range(0,n_mod):

				m_num = n_mod-count-1

				mod = models[m_num].detached_copy()
				#c = n_mod-count-1
				mod.id = models[count].id

				output.append_model(mod)

				count += 1


			output.write_pdb_file(file_name='output.pdb')


			fin = open('output.pdb', 'r')
			fout = open(file, 'w')

			lines = fin.readlines()

			for line in lines:
				data = line.split()
				if data[0] != 'BREAK':
					fout.write(line)

			fin.close()
			fout.close()
		alternate += 1

	return
Ejemplo n.º 58
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
    ncs_inp = ncs.input(pdb_string=pdb_poor_0)
    ncs_restraints_group_list = ncs_inp.get_ncs_restraints_group_list()

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

    pdb_inp_answer = 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)
Ejemplo n.º 59
0
def run(pdb_filename):
  from iotbx import pdb
  print pdb_filename
  pdb_inp = pdb.input(pdb_filename)
  pdb_hieratchy = pdb_inp.construct_hierarchy()
  for residue_group in pdb_hieratchy.residue_groups():
    rotamer_name, chis, value = get_rotamer_data(residue_group,
                                                 sa,
                                                 rotamer_evaluator,
                                                 rotamer_id,
      )
    print rotamer_name
Ejemplo n.º 60
0
def run(filename):
  print filename
  if 0:
    print "RDL"
    for aa in sorted(rdl_database):
      print "  %s" % aa
      for key, value in rdl_database[aa].items():
        print "    %s" % key
        for names, values in rdl_database[aa][key].items():
          print "      %s : %s" % (names, values)
    assert 0
  #
  if filename=="3sgs.pdb":
    from libtbx import easy_run
    f=file("mse.pdb", "wb")
    f.write(pdbs["mse.pdb"])
    f.close()
    f=file("met.pdb", "wb")
    f.write(pdbs["met.pdb"])
    f.close()
    cmd="phenix.pdb_interpretation rdl=True write_geo=1 mse.pdb"
    print cmd
    easy_run.call(cmd)
    cmd="phenix.pdb_interpretation rdl=True write_geo=1 met.pdb"
    print cmd
    easy_run.call(cmd)
  #
  pdb_inp = pdb.input(filename)
  pdb_hierarchy = pdb_inp.construct_hierarchy()
  geometry_restraints_manager = get_geometry_restraints_manager(filename)
  pdb_hierarchy.reset_i_seq_if_necessary()
  rdl.update_restraints(pdb_hierarchy,
                        geometry_restraints_manager,
                        assert_rotamer_found=True,
                        verbose=True,
    )
  print "OK"


  mmtbx_dir = libtbx.env.dist_path("mmtbx")
  props = os.path.join(mmtbx_dir,"rotamer","rotamer_names.props")
  f=file(props, "rb")
  props = f.readlines()
  f.close()
  for prop in props:
    print prop
    key = prop.split("=")[0]
    residue, rotamer_name = key.split()
    residue = residue.upper()
    if residue in ["MSE"]: continue
    assert residue in rdl_database
    assert rotamer_name in rdl_database[residue]