Beispiel #1
0
def run(args):
    assert len(args) == 1
    # Read file into pdb_input class
    inp = iotbx.pdb.input(file_name=args[0])

    # create a model manager
    model = mmtbx.model.manager(model_input=inp)

    # get number of atoms in the input model
    n_atoms = model.get_number_of_atoms()

    # extract atom coordinates
    old_sites_cart = model.get_sites_cart()
    # generate random additions
    random_addition = flex.vec3_double(
        flex.random_double(size=n_atoms * 3) - 0.5)
    # actually add them to old coordinates
    new_xyz = old_sites_cart + random_addition

    # Update coordinates in model manager
    model.set_sites_cart(sites_cart=new_xyz)

    # get xray structure
    xrs = model.get_xray_structure()

    # reset B-factors (min=1, max=20)
    # generate array of new B-factors
    new_b = flex.random_double(size=n_atoms, factor=19) + 1
    # set them in xray structure
    xrs.set_b_iso(values=new_b)
    # update model manager with this xray structure
    model.set_xray_structure(xrs)
    # output result in PDB format to the screen
    print model.model_as_pdb()
    print "END"
def exercise3(pdb_str, type_list_known):
  pdb_inp = iotbx.pdb.input(lines=pdb_str.split("\n"), source_info=None)
  model = mmtbx.model.manager(
    model_input = pdb_inp,
    build_grm   = True)

  pdb_hierarchy = model.get_hierarchy()
  sites_cart = model.get_sites_cart()
  atoms = pdb_hierarchy.atoms()

  model.setup_riding_h_manager()
  riding_h_manager = model.get_riding_h_manager()

  h_para = riding_h_manager.h_parameterization

  diagnostics = riding_h_manager.diagnostics(
    sites_cart = sites_cart,
    threshold  = 0.05)
  h_distances   = diagnostics.h_distances
  type_list     = diagnostics.type_list

  number_h = model.get_hd_selection().count(True)
  number_h_para = len(h_para) - h_para.count(None)

  assert (number_h_para == number_h-2), 'Not all H atoms are parameterized'

  for ih in h_distances:
    labels = atoms[ih].fetch_labels()
    assert (h_distances[ih] < 0.2), \
      'distance too large: %s  atom: %s (%s) residue: %s ' \
      % (h_para[ih].htype, atoms[ih].name, ih, labels.resseq.strip())

  for type1, type2 in zip(type_list, type_list_known):
    assert (type1 == type2)
def run(args):
    log = sys.stdout
    if (len(args) == 0): args = ["--help"]
    command_line = (option_parser(usage="%s [options] pdb_file" %
                                  libtbx.env.dispatcher_name).option(
                                      None,
                                      "--buffer_layer",
                                      action="store",
                                      type="float",
                                      default=5)).process(args=args, nargs=1)
    pdb_inp = iotbx.pdb.input(file_name=command_line.args[0])
    model = mmtbx.model.manager(model_input=pdb_inp)
    box = uctbx.non_crystallographic_unit_cell_with_the_sites_in_its_center(
        sites_cart=model.get_sites_cart(),
        buffer_layer=command_line.options.buffer_layer)
    model.set_sites_cart(box.sites_cart)
    # Bad hack, never repeat. In fact, all the boxing functionality should
    # go into mmtbx.model.manager
    model._crystal_symmetry = box.crystal_symmetry()
    print('REMARK %s --buffer-layer=%.6g %s' %
          (libtbx.env.dispatcher_name, command_line.options.buffer_layer,
           show_string(command_line.args[0])),
          file=log)
    print('REMARK %s' % date_and_time(), file=log)
    print(model.model_as_pdb(), file=log)
def exercise1(pdb_str, cif_str):
    model = prepare_inputs(pdb_str, cif_str)
    riding_h_manager = model.get_riding_h_manager()
    atoms = model.get_hierarchy().atoms()

    h_para = riding_h_manager.h_parameterization

    diagnostics = riding_h_manager.diagnostics(
        sites_cart=model.get_sites_cart(), threshold=0.05)
    h_distances = diagnostics.h_distances
    type_list = diagnostics.type_list

    # number of H atoms
    number_h = model.get_hd_selection().count(True)
    number_h_para = len(h_para) - h_para.count(None)

    assert (number_h_para == number_h), 'Not all H atoms are parameterized'

    for ih in h_distances:
        # One atom is expected to be moved
        if (ih == 16):
            continue
        labels = atoms[ih].fetch_labels()
        assert (h_distances[ih] < 0.1), \
          'distance too large: %s  atom: %s (%s) residue: %s ' \
          % (h_para[ih].htype, atoms[ih].name, ih, labels.resseq.strip())

    for type1, type2 in zip(type_list, type_list_known1):
        assert (type1 == type2)
Beispiel #5
0
def exercise_1():
    pdb_inp = iotbx.pdb.input(lines=flex.std_string(pdb_str_1.splitlines()),
                              source_info=None)
    model = mmtbx.model.manager(model_input=pdb_inp)
    model.process(make_restraints=True)
    grm = model.get_restraints_manager().geometry
    pdb_hierarchy = model.get_hierarchy()
    sites_cart = model.get_sites_cart()
    # c-beta restraints are added by default!!!
    assert len(grm.get_c_beta_torsion_proxies()) == 4

    #test global selection and removing c-beta restraints
    tst_boolsel = pdb_hierarchy.atom_selection_cache().selection("resname TYR")
    tst_iselection = tst_boolsel.iselection()
    #test global selection
    grm2 = grm.select(iselection=tst_iselection)
    assert len(grm2.get_c_beta_torsion_proxies()) == 2
    grm2 = grm.select(selection=tst_boolsel)
    assert len(grm2.get_c_beta_torsion_proxies()) == 2
    #remove a selection
    grm.remove_c_beta_torsion_restraints_in_place(selection=tst_iselection)
    assert len(grm.get_c_beta_torsion_proxies()) == 2
    #add a selection
    grm.remove_c_beta_torsion_restraints_in_place()
    assert len(grm.get_c_beta_torsion_proxies()) == 0
    c_beta_torsion_proxies = c_beta.get_c_beta_torsion_proxies(
        pdb_hierarchy, selection=tst_iselection, sigma=2.5)
    assert len(c_beta_torsion_proxies) == 2
Beispiel #6
0
def exercise(pdb_str):
    pdb_inp = iotbx.pdb.input(lines=pdb_str.split("\n"), source_info=None)
    model = mmtbx.model.manager(model_input=pdb_inp, log=null_out())
    model.process(make_restraints=True)
    pdb_hierarchy = model.get_hierarchy()
    sites_cart = model.get_sites_cart()
    atoms = pdb_hierarchy.atoms()

    model.setup_riding_h_manager()
    riding_h_manager = model.get_riding_h_manager()

    h_parameterization = riding_h_manager.h_parameterization

    diagnostics = riding_h_manager.diagnostics(sites_cart=sites_cart,
                                               threshold=0.05)

    diagnostics = riding_h_manager.diagnostics(sites_cart=sites_cart,
                                               threshold=0.05)
    h_distances = diagnostics.h_distances

    number_h = model.get_hd_selection().count(True)
    number_h_para = len(h_parameterization) - h_parameterization.count(None)

    # There are 90 H atoms in pdb_string, check if all of them are recognized
    assert (number_h_para == number_h), 'Not all H atoms are parameterized'

    for ih in h_distances:
        labels = atoms[ih].fetch_labels()
        assert (h_distances[ih] < 0.01), \
          'distance too large: %s  atom: %s (%s) residue: %s ' \
          % (h_parameterization[ih].htype, atoms[ih].name, ih, labels.resseq.strip())
def exercise(pdb_str, use_ideal_bonds_angles):
    # --------------------------------------------------------------
    #          code to switch off CDL
    # --------------------------------------------------------------
    #params_line = grand_master_phil_str
    #params = iotbx.phil.parse(
    #    input_string=params_line, process_includes=True).extract()
    #params.pdb_interpretation.restraints_library.cdl=False
    # ---------------------------------------------------------------

    pdb_inp = iotbx.pdb.input(lines=pdb_str.split("\n"), source_info=None)
    model = mmtbx.model.manager(model_input=pdb_inp,
                                log=null_out(),
                                build_grm=True)

    pdb_hierarchy = model.get_hierarchy()
    geometry_restraints = model.get_restraints_manager().geometry
    xray_structure = model.get_xray_structure()

    sites_cart = model.get_sites_cart()

    grf = cctbx.geometry_restraints.flags.flags(default=True)
    minimized = mmtbx.refinement.geometry_minimization.lbfgs(
        sites_cart=sites_cart,
        correct_special_position_tolerance=1.0,
        geometry_restraints_manager=geometry_restraints,
        geometry_restraints_flags=grf,
        lbfgs_termination_params=scitbx.lbfgs.termination_parameters(
            max_iterations=500))
    xray_structure.set_sites_cart(sites_cart)
    pdb_hierarchy.adopt_xray_structure(xray_structure)
    atoms = pdb_hierarchy.atoms()
    sites_cart = xray_structure.sites_cart()

    riding_h_manager = riding.manager(
        pdb_hierarchy=pdb_hierarchy,
        geometry_restraints=geometry_restraints,
        use_ideal_bonds_angles=use_ideal_bonds_angles)

    h_parameterization = riding_h_manager.h_parameterization

    diagnostics = riding_h_manager.diagnostics(sites_cart=sites_cart,
                                               threshold=0.05)
    h_distances = diagnostics.h_distances

    number_h = model.get_hd_selection().count(True)
    number_h_para = len(h_parameterization) - h_parameterization.count(None)

    assert (number_h_para == number_h), 'Not all H atoms are parameterized'

    for ih in h_distances:
        labels = atoms[ih].fetch_labels()
        if use_ideal_bonds_angles:
            assert (h_distances[ih] < 0.03), \
              'distance too large: %s  atom: %s (%s) residue: %s ' \
              % (h_parameterization[ih].htype, atoms[ih].name, ih, labels.resseq.strip())
        else:
            assert (h_distances[ih] < 1e-7), \
              'distance too large: %s  atom: %s (%s) residue: %s  distance %s' \
              % (h_parameterization[ih].htype, atoms[ih].name, ih, labels.resseq.strip(), h_distances[ih])
Beispiel #8
0
def get_bounds_around_model(
    map_manager=None,
    model=None,
    box_cushion=None,
):
    '''
      Calculate the lower and upper bounds to box around a model
      Allow bounds to go outside the available box (this has to be
        dealt with at the boxing stage)
    '''

    # get items needed to do the shift
    cs = map_manager.crystal_symmetry()
    uc = cs.unit_cell()
    sites_cart = model.get_sites_cart()
    sites_frac = uc.fractionalize(sites_cart)
    map_data = map_manager.map_data()
    # convert box_cushion into fractional vector
    cushion_frac = flex.double(uc.fractionalize((box_cushion, ) * 3))
    # find fractional corners
    frac_min = sites_frac.min()
    frac_max = sites_frac.max()
    frac_max = list(flex.double(frac_max) + cushion_frac)
    frac_min = list(flex.double(frac_min) - cushion_frac)
    # find corner grid nodes
    all_orig = map_data.all()

    lower_bounds = [ifloor(f * n) for f, n in zip(frac_min, all_orig)]
    upper_bounds = [iceil(f * n) for f, n in zip(frac_max, all_orig)]
    return group_args(
        lower_bounds=lower_bounds,
        upper_bounds=upper_bounds,
    )
Beispiel #9
0
def run(pdb_file_name):
  pdb_inp = iotbx.pdb.input(file_name=pdb_file_name)
  params =  mmtbx.model.manager.get_default_pdb_interpretation_params()
  model = mmtbx.model.manager(
    model_input       = pdb_inp,
    pdb_interpretation_params = params,
    build_grm         = True,
    stop_for_unknowns = False,
    log               = null_out())
  pdb_hierarchy = model.get_hierarchy()
  sites_cart_dc = model.get_sites_cart().deep_copy()
  angle = 0.
#  points_i_seqs = [483]
#  axis = [479,482]
  points_i_seqs = [559]
  axis = [556,557]
  while angle <= 360:  
    atoms_xyz_tmp  = flex.vec3_double(len(points_i_seqs))
    atom_xyz_new = rotate_point_around_axis(
        axis_point_1 = sites_cart_dc[axis[0]],
        axis_point_2 = sites_cart_dc[axis[1]],
        point        = sites_cart_dc[points_i_seqs[0]],
        angle        = angle,
        deg          = True)
    print (atom_xyz_new)
    atoms_xyz_tmp[0] = atom_xyz_new
    sites_cart_dc[points_i_seqs] = atoms_xyz_tmp[0]
    model.set_sites_cart(sites_cart = sites_cart_dc)      

    with open(str(angle)+".pdb", "w") as of:
      print (model.model_as_pdb(),file=of)
    angle += 30.
Beispiel #10
0
def exercise(pdb_str):
    params = mmtbx.model.manager.get_default_pdb_interpretation_params()
    params.pdb_interpretation.use_neutron_distances = True

    pdb_inp = iotbx.pdb.input(lines=pdb_str.split("\n"), source_info=None)
    model = mmtbx.model.manager(model_input=pdb_inp, log=null_out())
    model.process(pdb_interpretation_params=params, make_restraints=True)

    pdb_hierarchy = model.get_hierarchy()
    sites_cart = model.get_sites_cart()
    atoms = pdb_hierarchy.atoms()

    model.setup_riding_h_manager()
    riding_h_manager = model.get_riding_h_manager()

    h_parameterization = riding_h_manager.h_parameterization

    diagnostics = riding_h_manager.diagnostics(sites_cart=sites_cart,
                                               threshold=0.05)
    h_distances = diagnostics.h_distances

    number_h = model.get_hd_selection().count(True)
    number_h_para = len(h_parameterization) - h_parameterization.count(None)

    if (pdb_str != pdb_str_02):
        assert (number_h_para == number_h), 'Not all H atoms are parameterized'


# For each H atom, check if distance between computed H and that in input model is
# not too large
    for ih in h_distances:
        labels = atoms[ih].fetch_labels()
        assert (h_distances[ih] < 0.1), \
          'distance too large: %s  atom: %s (%s) residue: %s ' \
          % (h_parameterization[ih].htype, atoms[ih].name, ih, labels.resseq.strip())
Beispiel #11
0
def exclude_h_on_SS(model):
    rm = model.get_restraints_manager()
    bond_proxies_simple, asu = rm.geometry.get_all_bond_proxies(
        sites_cart=model.get_sites_cart())
    els = model.get_hierarchy().atoms().extract_element()
    ss_i_seqs = []
    all_proxies = [p for p in bond_proxies_simple]
    for proxy in asu:
        all_proxies.append(proxy)
    for proxy in all_proxies:
        if (isinstance(proxy, ext.bond_simple_proxy)): i, j = proxy.i_seqs
        elif (isinstance(proxy, ext.bond_asu_proxy)):
            i, j = proxy.i_seq, proxy.j_seq
        else:
            assert 0  # never goes here
        if ([els[i], els[j]
             ].count("S") == 2):  # XXX may be coordinated if metal edits used
            ss_i_seqs.extend([i, j])
    sel_remove = flex.size_t()
    for proxy in all_proxies:
        if (isinstance(proxy, ext.bond_simple_proxy)): i, j = proxy.i_seqs
        elif (isinstance(proxy, ext.bond_asu_proxy)):
            i, j = proxy.i_seq, proxy.j_seq
        else:
            assert 0  # never goes here
        if (els[i] in ["H", "D"] and j in ss_i_seqs): sel_remove.append(i)
        if (els[j] in ["H", "D"] and i in ss_i_seqs): sel_remove.append(j)
    return model.select(~flex.bool(model.size(), sel_remove))
Beispiel #12
0
def run(maxnum_residues_in_cluster):
  result = []
  for clustering in [True, False]:
    if 0: print("  clustering", clustering, "-"*30)
    model = get_model()
    fq = from_cctbx(restraints_manager = model.get_restraints_manager())
    if(clustering):
      fm = fragments(
       working_folder             = os.path.split("./ase/tmp_ase.pdb")[0]+ "/",
       clustering_method          = betweenness_centrality_clustering,
       maxnum_residues_in_cluster = maxnum_residues_in_cluster,
       altloc_method              = "subtract",
       charge_embedding           = False,
       two_buffers                = False,
       clustering                 = clustering,
       pdb_hierarchy              = model.get_hierarchy().deep_copy(),
       qm_engine_name             = "mopac",
       fast_interaction           = True,
       crystal_symmetry           = model.crystal_symmetry())
    else:
      fc = fq
    fc = from_cluster(
      restraints_manager = fq,
      fragment_manager   = fm,
      parallel_params    = get_master_phil().extract())
    energy, gradients = fc.target_and_gradients(sites_cart=model.get_sites_cart())
    gradients = gradients.as_double()
    result.append(gradients.deep_copy())
  diff = flex.abs(result[0] - result[1])
  max_diff = flex.max(diff)
  #print "  max(diff_grad):", max_diff
  assert max_diff < 1.e-9
Beispiel #13
0
def exercise3(pdb_str, type_list_known):
    pdb_inp = iotbx.pdb.input(lines=pdb_str.split("\n"), source_info=None)
    params = mmtbx.model.manager.get_default_pdb_interpretation_scope(
    ).extract()
    params.pdb_interpretation.allow_polymer_cross_special_position = True
    model = mmtbx.model.manager(model_input=pdb_inp, log=null_out())
    model.process(pdb_interpretation_params=params, make_restraints=True)
    pdb_hierarchy = model.get_hierarchy()
    sites_cart = model.get_sites_cart()
    atoms = pdb_hierarchy.atoms()

    model.setup_riding_h_manager()
    riding_h_manager = model.get_riding_h_manager()

    h_para = riding_h_manager.h_parameterization

    diagnostics = riding_h_manager.diagnostics(sites_cart=sites_cart,
                                               threshold=0.05)
    h_distances = diagnostics.h_distances
    type_list = diagnostics.type_list

    number_h = model.get_hd_selection().count(True)
    number_h_para = len(h_para) - h_para.count(None)

    assert (number_h_para == number_h - 2), 'Not all H atoms are parameterized'

    for ih in h_distances:
        labels = atoms[ih].fetch_labels()
        assert (h_distances[ih] < 0.2), \
          'distance too large: %s  atom: %s (%s) residue: %s ' \
          % (h_para[ih].htype, atoms[ih].name, ih, labels.resseq.strip())

    for type1, type2 in zip(type_list, type_list_known):
        assert (type1 == type2)
Beispiel #14
0
    def __init__(self,
                 map_manager,
                 model,
                 box_cushion,
                 wrapping=None,
                 log=sys.stdout):

        self._map_manager = map_manager
        self._model = model

        self._force_wrapping = wrapping
        if wrapping is None:
            wrapping = self.map_manager().wrapping()
        self.basis_for_boxing_string = 'using_model, wrapping = %s' % (
            wrapping)

        # safeguards
        assert isinstance(map_manager, iotbx.map_manager.map_manager)
        assert isinstance(model, mmtbx.model.manager)
        assert self._map_manager.map_data().accessor().origin() == (0, 0, 0)

        # Make sure working model and map_manager crystal_symmetry match

        assert map_manager.is_compatible_model(model)

        assert box_cushion >= 0

        if self.map_manager().wrapping():  # map must be entire unit cell
            assert map_manager.unit_cell_grid == map_manager.map_data().all()

        # NOTE: We are going to use crystal_symmetry and sites_frac based on
        #   the map_manager (the model could still have different crystal_symmetry)

        # get items needed to do the shift
        cs = map_manager.crystal_symmetry()
        uc = cs.unit_cell()
        sites_cart = model.get_sites_cart()
        sites_frac = uc.fractionalize(sites_cart)
        map_data = map_manager.map_data()
        # convert box_cushion into fractional vector
        cushion_frac = flex.double(uc.fractionalize((box_cushion, ) * 3))
        # find fractional corners
        frac_min = sites_frac.min()
        frac_max = sites_frac.max()
        frac_max = list(flex.double(frac_max) + cushion_frac)
        frac_min = list(flex.double(frac_min) - cushion_frac)
        # find corner grid nodes
        all_orig = map_data.all()
        self.gridding_first = [
            ifloor(f * n) for f, n in zip(frac_min, all_orig)
        ]
        self.gridding_last = [iceil(f * n) for f, n in zip(frac_max, all_orig)]

        # Ready with gridding...set up shifts and box crystal_symmetry
        self.set_shifts_and_crystal_symmetry()

        # Apply boxing to model, ncs, and map (if available)
        self.apply_to_model_ncs_and_map()
Beispiel #15
0
def run(model,
        max_cutoff=4.0,
        min_cutoff=1.5,
        hd=["H", "D"],
        acceptors=["O", "N", "S", "F", "CL"],
        protein_only=True):
    atoms = list(model.get_hierarchy().atoms())
    sites_cart = model.get_sites_cart()
    crystal_symmetry = model.crystal_symmetry()
    fm = crystal_symmetry.unit_cell().fractionalization_matrix()
    om = crystal_symmetry.unit_cell().orthogonalization_matrix()
    pg = get_pair_generator(crystal_symmetry=crystal_symmetry,
                            buffer_thickness=max_cutoff,
                            sites_cart=sites_cart)
    get_class = iotbx.pdb.common_residue_names_get_class
    for p in pg.pair_generator:
        i, j = p.i_seq, p.j_seq
        ei, ej = atoms[i].element, atoms[j].element
        altloc_i = atoms[i].parent().altloc
        altloc_j = atoms[j].parent().altloc
        resseq_i = atoms[i].parent().parent().resseq
        resseq_j = atoms[j].parent().parent().resseq
        # pre-screen candidates begin
        one_is_hd = ei in hd or ej in hd
        other_is_acceptor = ei in acceptors or ej in acceptors
        dist = math.sqrt(p.dist_sq)
        assert dist <= max_cutoff
        is_candidate = one_is_hd and other_is_acceptor and dist >= min_cutoff and \
          altloc_i == altloc_j and resseq_i != resseq_j
        if (protein_only):
            for it in [i, j]:
                resname = atoms[it].parent().resname
                is_candidate &= get_class(name=resname) == "common_amino_acid"
        if (not is_candidate): continue
        # pre-screen candidates end
        rt_mx_i = pg.conn_asu_mappings.get_rt_mx_i(p)
        rt_mx_j = pg.conn_asu_mappings.get_rt_mx_j(p)
        rt_mx_ji = rt_mx_i.inverse().multiply(rt_mx_j)
        print "%5.3f"%math.sqrt(p.dist_sq), \
          "<", atoms[i].parent().resname, resseq_i, ei, atoms[i].name, ">", \
          "<", atoms[j].parent().resname, resseq_j, ej, atoms[j].name, ">", \
          rt_mx_ji, i, j,
        ### re-confirm distance between pairs
        ai = atoms[i]
        aj = atoms[j]
        if (str(rt_mx_ji) == "x,y,z"):
            d = math.sqrt((ai.xyz[0] - aj.xyz[0])**2 +
                          (ai.xyz[1] - aj.xyz[1])**2 +
                          (ai.xyz[2] - aj.xyz[2])**2)
        else:
            t1 = fm * flex.vec3_double([aj.xyz])
            t2 = rt_mx_ji * t1[0]
            t3 = om * flex.vec3_double([t2])
            d = math.sqrt((ai.xyz[0] - t3[0][0])**2 +
                          (ai.xyz[1] - t3[0][1])**2 +
                          (ai.xyz[2] - t3[0][2])**2)
        print "dist=%5.3f" % d
Beispiel #16
0
def run():
    rmsd_dirs = ["0.3/", "0.6/", "0.9/", "1.2/", "1.5/"]
    base_names = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
    ref = get_reference()
    tmp_cntr1 = 0
    print "Hbond analysis"
    print "model     min     max     mean   recovered  bond_rmsd  rama_favored clashscore"
    for sub_root in [
            "./perturbed/", "./cctbx_opt/", "./xtb_opt_stpmax_0.3/",
            "./xtb_opt_stpmax_0.4/", "./xtb_opt_stpmax_0.5/",
            "./terachem_opt_final/"
    ]:
        print sub_root
        for rmsd_dir in rmsd_dirs:
            h_bonds = flex.double()
            rmsd_bonds = flex.double()
            rama_fav = flex.double()
            clashscore = flex.double()
            cntr = 0
            for fn in base_names:
                file_name = sub_root + rmsd_dir + fn + ".pdb"
                if (not os.path.exists(file_name)): assert 0, file_name
                model = get_model(file_name)
                assert ref.h.is_similar_hierarchy(model.get_hierarchy())
                g = model.geometry_statistics(use_hydrogens=False).result()
                rmsd_bonds.append(g.bond.mean)
                rama_fav.append(g.ramachandran.favored)
                clashscore.append(g.clash.score)
                #print g.bond.mean, g.clash.score, g.rotamer.outliers, g.c_beta.outliers, \
                #  g.ramachandran.outliers, g.ramachandran.allowed, g.ramachandran.favored
                sites_cart = model.get_sites_cart()
                if (sub_root.count("perturbed") > 0):
                    tmp_cntr1 += 1
                    assert approx_equal(
                        float(rmsd_dir.replace("/", "")),
                        flex.mean(
                            flex.sqrt((ref.sites_cart - sites_cart).dot())),
                        0.01)
                for pair in ref.h_bonds_i_seqs:
                    d = dist(sites_cart[pair[0]], sites_cart[pair[1]])
                    h_bonds.append(d)
                cntr += 1
            assert cntr == 10, cntr
            sel = h_bonds < 2.3
            sel &= h_bonds > 1.6
            if (h_bonds.size() > 0):
                print rmsd_dir, "%8.3f %8.3f %8.3f"%h_bonds.min_max_mean().as_tuple(), \
                  " %7.2f"%(sel.count(True)*100./(len(ref.h_bonds_i_seqs)*cntr)),\
                  "    %6.4f    %7.2f     %4.2f"%(flex.mean(rmsd_bonds), flex.mean(rama_fav), flex.mean(clashscore))
            else:
                print rmsd_dir, "N/A"
    #
    assert tmp_cntr1 == 50, tmp_cntr1
Beispiel #17
0
def compare_XH_bond_length_to_ideal(model):
    geometry = model.get_restraints_manager().geometry
    atoms = model.get_hierarchy().atoms()
    sites_cart = model.get_sites_cart()
    bond_proxies_simple, asu = \
      geometry.get_all_bond_proxies(sites_cart = sites_cart)
    hd_selection = model.get_hd_selection()
    for bp in bond_proxies_simple:
        i, j = bp.i_seqs
        if hd_selection[i] or hd_selection[j]:
            assert approx_equal(atoms[i].distance(atoms[j]),
                                bp.distance_ideal,
                                eps=0.001)
Beispiel #18
0
def exercise1():
  pdb_inp = iotbx.pdb.input(lines=pdb_str.split("\n"), source_info=None)
  model = mmtbx.model.manager(
    model_input = pdb_inp,
    log         = null_out())
  model.process(make_restraints=True)
  pdb_hierarchy = model.get_hierarchy()
  sites_cart = model.get_sites_cart()
  atoms = pdb_hierarchy.atoms()

  model.setup_riding_h_manager()
  riding_h_manager = model.get_riding_h_manager()

  h_parameterization = riding_h_manager.h_parameterization
  number_h = model.get_hd_selection().count(True)
  number_h_para = len(h_parameterization) - h_parameterization.count(None)

  assert (number_h_para == number_h-1), 'Not all H atoms are parameterized'

  rc = h_parameterization[20]

  new_manager = riding_h_manager.deep_copy()
  new_h_parameterization = new_manager.h_parameterization
  rc_new = new_h_parameterization[20]

  assert (rc_new.htype == rc.htype)
  assert (rc_new.ih    == rc.ih)
  assert (rc_new.a0    == rc.a0)
  assert (rc_new.a1    == rc.a1)
  assert (rc_new.a2    == rc.a2)
  assert (rc_new.a3    == rc.a3)
  assert (rc_new.a     == rc.a)
  assert (rc_new.b     == rc.b)
  assert (rc_new.h     == rc.h)
  assert (rc_new.n     == rc.n)
  assert (rc_new.disth == rc.disth)

  rc_new.htype = 'unk'
  rc_new.ih    = 0
  rc_new.a0    = 1
  rc_new.a1    = 2
  rc_new.a2    = 3
  rc_new.a3    = 4

  assert (rc_new.htype != rc.htype)
  assert (rc_new.ih != rc.ih)
  assert (rc_new.a0 != rc.a0)
  assert (rc_new.a1 != rc.a1)
  assert (rc_new.a2 != rc.a2)
  assert (rc_new.a3 != rc.a3)
def get_CNCO_bond_angle(model):
    geometry = model.get_restraints_manager()
    bond_proxies_simple, asu = geometry.geometry.get_all_bond_proxies(
        sites_cart=model.get_sites_cart())
    bps_dict = {}
    [bps_dict.setdefault(p.i_seqs, True) for p in bond_proxies_simple]
    hierarchy = model.get_hierarchy()
    atom1s = []
    atom2s = []
    atom3s = []
    results = []
    for a in hierarchy.atoms():
        if (not a.parent().resname == "MTN"): continue
        if a.element.strip().upper() == "C":
            atom1s.append(a)
        if a.element.strip().upper() == "N":
            atom2s.append(a)
        if a.element.strip().upper() == "O":
            atom3s.append(a)
    for i, a1 in enumerate(atom1s):
        for a2 in atom2s:
            if (not a1.is_in_same_conformer_as(a2)): continue
            if (not is_bonded(a1, a2, bps_dict)): continue
            for j, a4 in enumerate(atom1s):
                if (j <= i): continue
                if (not a4.is_in_same_conformer_as(a2)): continue
                if (not is_bonded(a4, a2, bps_dict)): continue
                if (not a1.is_in_same_conformer_as(a4)): continue
                if (is_bonded(a1, a4, bps_dict)): continue
                for a3 in atom3s:
                    if (not a2.is_in_same_conformer_as(a3)): continue
                    if (not is_bonded(a3, a2, bps_dict)): continue
                    d12 = a1.distance(a2)
                    d23 = a2.distance(a3)
                    d24 = a2.distance(a4)
                    angle123 = a2.angle(a1, a3, deg=True)
                    angle124 = a2.angle(a1, a4, deg=True)
                    angle324 = a2.angle(a3, a4, deg=True)
                    result = group_args(atom_1=a1,
                                        atom_2=a2,
                                        atom_3=a3,
                                        atom_4=a4,
                                        d_C_L_N=d12,
                                        d_O_N=d23,
                                        d_C_R_N=d24,
                                        a_C_L_N_O=angle123,
                                        a_C_N_C=angle124,
                                        a_C_R_N_O=angle324)
                    if (result is not None): results.append(result)
    return results
Beispiel #20
0
def run(prefix):
    """
  Exercise combined energy and gradients from cluster qm.
  """
    for restraints in ["cctbx", "qm"]:
        if 0:
            print("Using restraints:", restraints)
        result = []
        for clustering in [True, False]:
            if 0:
                print("  clustering", clustering, "-" * 30)
            model = get_model()
            if (restraints == "qm"):
                fq = from_qm(pdb_hierarchy=model.get_hierarchy(),
                             qm_engine_name="mopac",
                             method="PM3",
                             crystal_symmetry=model.crystal_symmetry(),
                             clustering=clustering)
            else:
                fq = from_cctbx(
                    restraints_manager=model.get_restraints_manager())
            if (clustering):
                fm = fragments(
                    working_folder=os.path.split("./ase/tmp_ase.pdb")[0] + "/",
                    clustering_method=betweenness_centrality_clustering,
                    maxnum_residues_in_cluster=8,
                    charge_embedding=False,
                    two_buffers=False,
                    fast_interaction=True,
                    pdb_hierarchy=model.get_hierarchy().deep_copy(
                    ),  # deep copy just in case
                    qm_engine_name="mopac",
                    crystal_symmetry=model.crystal_symmetry())
                fc = from_cluster(restraints_manager=fq,
                                  fragment_manager=fm,
                                  parallel_params=get_master_phil().extract())
            else:
                fc = fq
            energy, gradients = fc.target_and_gradients(
                sites_cart=model.get_sites_cart())
            if (restraints == "qm"):
                energy = energy * (kcal / mol) * (kcal / mol) / Hartree
                gradients = gradients * (kcal / mol) * (kcal / mol) * (Bohr /
                                                                       Hartree)
            gradients = gradients.as_double()
            result.append(gradients.deep_copy())
        #
        diff = flex.abs(result[0] - result[1])
        max_diff = flex.max(diff)
def exercise2(pdb_str, cif_str):
    model = prepare_inputs(pdb_str, cif_str)
    riding_h_manager = model.get_riding_h_manager()
    atoms = model.get_hierarchy().atoms()

    h_para = riding_h_manager.h_parameterization

    diagnostics = riding_h_manager.diagnostics(
        sites_cart=model.get_sites_cart(), threshold=0.05)
    h_distances = diagnostics.h_distances
    type_list = diagnostics.type_list

    # number of H atoms
    number_h = model.get_hd_selection().count(True)
    number_h_para = len(h_para) - h_para.count(None)

    assert (number_h_para == 0), 'Not all H atoms are parameterized'
def exercise():
  pdb_inp = iotbx.pdb.input(lines=pdb_str.split("\n"), source_info=None)
  model = mmtbx.model.manager(
    model_input = pdb_inp,
    build_grm   = True)

  pdb_hierarchy = model.get_hierarchy()
  sites_cart = model.get_sites_cart()
  atoms = pdb_hierarchy.atoms()

  model.setup_riding_h_manager()
  riding_h_manager = model.get_riding_h_manager()

  h_parameterization = riding_h_manager.h_parameterization

  diagnostics = riding_h_manager.diagnostics(
    sites_cart         = sites_cart,
    threshold          = 0.05)

  h_distances        = diagnostics.h_distances
  type_list          = diagnostics.type_list

# number of H atoms in model
  number_h = model.get_hd_selection().count(True)
# number of H in parameterization
  number_h_para = len(h_parameterization) - h_parameterization.count(None)

# There are 152 H atoms in pdb_string, check if all of them are parameterized
  assert (number_h_para == number_h), 'Not all H atoms are parameterized'

# For each H atom, check if distance compared to input model is not > 0.05
# 0.0014 = uncertainty for distance if uncertainty of coordinate = 0.001
  for ih in h_distances:
    labels = atoms[ih].fetch_labels()
    assert (h_distances[ih] < 0.05), \
      'distance too large: %s  atom: %s (%s) residue: %s ' \
      % (h_parameterization[ih].htype, atoms[ih].name, ih, labels.resseq.strip())

# KEEP: useful for debugging
  #for ih in h_parameterization.keys():
  #  hp = h_parameterization[ih]
  #  print "'"+hp.htype+"'"+',',

  for type1, type2 in zip(type_list, type_list_known):
    assert (type1 == type2)
Beispiel #23
0
def exclude_h_on_coordinated_S(model): # XXX if edits used it should be like in exclude_h_on_SS
  rm = model.get_restraints_manager().geometry
  els = model.get_hierarchy().atoms().extract_element()
  # Find possibly coordinated S
  exclusion_list = ["H","D","T","S","O","P","N","C","SE"]
  sel_s = []
  for proxy in rm.pair_proxies().nonbonded_proxies.simple:
    i,j = proxy.i_seqs
    if(els[i] == "S" and not els[j] in exclusion_list): sel_s.append(i)
    if(els[j] == "S" and not els[i] in exclusion_list): sel_s.append(j)
  # Find H attached to possibly coordinated S
  bond_proxies_simple, asu = rm.get_all_bond_proxies(
    sites_cart = model.get_sites_cart())
  sel_remove = flex.size_t()
  for proxy in bond_proxies_simple:
    i,j = proxy.i_seqs
    if(els[i] in ["H","D"] and j in sel_s): sel_remove.append(i)
    if(els[j] in ["H","D"] and i in sel_s): sel_remove.append(j)
  return model.select(~flex.bool(model.size(), sel_remove))
Beispiel #24
0
def exercise():
    pdb_inp = iotbx.pdb.input(lines=pdb_str.split("\n"), source_info=None)
    cif_object = iotbx.cif.reader(input_string=cif_str).model()
    # bla.cif does not exist, but cif_objects needs a filename in first position
    # of the tuple
    cif_objects = [('bla.cif', cif_object)]

    model = mmtbx.model.manager(model_input=pdb_inp,
                                build_grm=True,
                                restraint_objects=cif_objects)

    pdb_hierarchy = model.get_hierarchy()
    sites_cart = model.get_sites_cart()
    atoms = pdb_hierarchy.atoms()

    model.setup_riding_h_manager()
    riding_h_manager = model.get_riding_h_manager()

    h_para = riding_h_manager.h_parameterization

    diagnostics = riding_h_manager.diagnostics(sites_cart=sites_cart,
                                               threshold=0.05)
    h_distances = diagnostics.h_distances
    type_list = diagnostics.type_list

    # number of H atoms
    number_h = model.get_hd_selection().count(True)
    number_h_para = len(h_para) - h_para.count(None)

    assert (number_h_para == number_h), 'Not all H atoms are parameterized'

    for ih in h_distances:
        # One atom is expected to be moved
        if (ih == 16):
            continue
        labels = atoms[ih].fetch_labels()
        assert (h_distances[ih] < 0.1), \
          'distance too large: %s  atom: %s (%s) residue: %s ' \
          % (h_para[ih].htype, atoms[ih].name, ih, labels.resseq.strip())

    for type1, type2 in zip(type_list, type_list_known):
        assert (type1 == type2)
Beispiel #25
0
def validate(pdb_str, threshold_bonds=0.02 * 4, threshold_angles=2.5 * 4):
    pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_str)
    params = mmtbx.model.manager.get_default_pdb_interpretation_params()
    params.pdb_interpretation.use_neutron_distances = True
    params.pdb_interpretation.restraints_library.cdl = False
    model = mmtbx.model.manager(
        model_input=pdb_inp,
        build_grm=True,
        stop_for_unknowns=True,  #False,
        pdb_interpretation_params=params,
        log=null_out())
    grm = model.get_restraints_manager().geometry
    sites_cart = model.get_sites_cart()
    b_deltas = flex.abs(
        grm.get_all_bond_proxies()[0].deltas(sites_cart=sites_cart))
    b_outl = b_deltas.select(b_deltas > threshold_bonds)
    if (b_outl.size() > 0): return None
    a_deltas = flex.abs(
        grm.get_all_angle_proxies().deltas(sites_cart=sites_cart))
    a_outl = a_deltas.select(a_deltas > threshold_angles)
    if (a_outl.size() > 0): return None
    return pdb_str
def exercise():
  pdb_inp = iotbx.pdb.input(lines=pdb_str.split("\n"), source_info=None)
  model = mmtbx.model.manager(
    model_input = pdb_inp,
    build_grm   = True,
    log         = null_out())

  pdb_hierarchy = model.get_hierarchy()
  sites_cart = model.get_sites_cart()
  atoms = pdb_hierarchy.atoms()

  model.setup_riding_h_manager()
  riding_h_manager = model.get_riding_h_manager()

  h_parameterization = riding_h_manager.h_parameterization

  diagnostics = riding_h_manager.diagnostics(
    sites_cart = sites_cart,
    threshold  = 0.05)
  h_distances   = diagnostics.h_distances
  type_list     = diagnostics.type_list

  number_h = model.get_hd_selection().count(True)
  number_h_para = len(h_parameterization) - h_parameterization.count(None)

# There are 90 H atoms in pdb_string, check if all of them are recognized
  assert (number_h_para == number_h), 'Not all H atoms are parameterized'

# For every H , check if distance between computed H and H in input model is
# < 0.03 A
  for ih in h_distances:
    labels = atoms[ih].fetch_labels()
    assert (h_distances[ih] < 0.03), 'distance too large: %s  atom: %s (%s) residue: %s ' \
      % (h_parameterization[ih].htype, atoms[ih].name, ih, labels.resseq.strip())

# Check if parameterization types are correct
  for type1, type2 in zip(type_list, type_list_known):
    assert (type1 == type2)
Beispiel #27
0
def exercise1():

    pdb_str = """
CRYST1   21.850   24.325   24.603  90.00  90.00  90.00 P 1
SCALE1      0.045767  0.000000  0.000000        0.00000
SCALE2      0.000000  0.041110  0.000000        0.00000
SCALE3      0.000000  0.000000  0.040645        0.00000
ATOM      1  N   CYS D  37       8.132  18.794  15.343  1.00143.27      D    N
ANISOU    1  N   CYS D  37    26762  17628  10046  -3652   3033    538  D    N
ATOM      2  CA  CYS D  37       9.229  18.179  14.592  1.00143.16      D    C
ANISOU    2  CA  CYS D  37    26739  17512  10144  -3661   2916    574  D    C
ATOM      3  C   CYS D  37      10.551  18.924  14.744  1.00143.18      D    C
ANISOU    3  C   CYS D  37    26760  17474  10166  -3627   2815    455  D    C
ATOM      4  O   CYS D  37      11.615  18.295  14.696  1.00141.47      D    O
ANISOU    4  O   CYS D  37    26571  17211   9972  -3636   2700    489  D    O
ATOM      5  CB  CYS D  37       8.857  18.048  13.112  1.00144.61      D    C
ANISOU    5  CB  CYS D  37    26841  17595  10509  -3672   2948    608  D    C
ATOM      6  SG  CYS D  37       7.159  17.517  12.843  1.00142.64      D    S
ANISOU    6  SG  CYS D  37    26553  17390  10253  -3704   3086    716  D    S
ATOM      7  H   CYS D  37       7.635  19.325  14.885  1.00172.08      D    H
ATOM      8  HA  CYS D  37       9.365  17.282  14.934  1.00171.95      D    H
ATOM      9  HB2 CYS D  37       8.970  18.910  12.683  1.00173.69      D    H
ATOM     10  HB3 CYS D  37       9.442  17.394  12.699  1.00173.69      D    H
ATOM     11  N   CYS D  40      13.775  17.698  16.644  1.00154.41      D    N
ANISOU   11  N   CYS D  40    28359  18912  11399  -3629   2475    474  D    N
ATOM     12  CA  CYS D  40      14.636  16.639  16.128  1.00149.28      D    C
ANISOU   12  CA  CYS D  40    27712  18183  10825  -3653   2369    564  D    C
ATOM     13  C   CYS D  40      15.084  16.830  14.685  1.00148.00      D    C
ANISOU   13  C   CYS D  40    27476  17888  10868  -3647   2342    540  D    C
ATOM     14  O   CYS D  40      16.158  16.339  14.335  1.00149.38      D    O
ANISOU   14  O   CYS D  40    27657  17989  11113  -3652   2233    563  D    O
ATOM     15  CB  CYS D  40      13.921  15.279  16.208  1.00140.80      D    C
ANISOU   15  CB  CYS D  40    26653  17143   9703  -3698   2398    729  D    C
ATOM     16  SG  CYS D  40      13.262  14.779  17.830  1.00136.64      D    S
ANISOU   16  SG  CYS D  40    26211  16771   8936  -3714   2439    794  D    S
ATOM     17  H   CYS D  40      13.032  17.777  16.218  1.00185.45      D    H
ATOM     18  HA  CYS D  40      15.432  16.588  16.680  1.00179.29      D    H
ATOM     19  HB2 CYS D  40      13.174  15.295  15.590  1.00169.12      D    H
ATOM     20  HB3 CYS D  40      14.548  14.592  15.932  1.00169.12      D    H
HETATM   21  NB  HEC D1001       9.421  13.220  11.858  1.00140.59           N
ANISOU   21  NB  HEC D1001    26354  16953  10112  -3810   2765   1093       N
HETATM   22  ND  HEC D1001      12.886  11.034  12.753  1.00144.24           N
ANISOU   22  ND  HEC D1001    26954  17334  10517  -3839   2396   1214       N
HETATM   23  C1A HEC D1001      12.227  10.592   9.833  1.00139.00           C
ANISOU   23  C1A HEC D1001    26141  16470  10203  -3864   2452   1283       C
HETATM   24  C1B HEC D1001       8.860  13.248  10.595  1.00143.63           C
ANISOU   24  C1B HEC D1001    26666  17264  10645  -3817   2816   1110       C
HETATM   25  C1C HEC D1001      10.125  13.804  14.697  1.00139.27           C
ANISOU   25  C1C HEC D1001    26337  16981   9599  -3780   2714   1003       C
HETATM   26  C1D HEC D1001      13.435  10.960  14.028  1.00134.69           C
ANISOU   26  C1D HEC D1001    25819  16201   9156  -3833   2339   1204       C
HETATM   27  C2A HEC D1001      11.928  10.386   8.429  1.00142.28           C
ANISOU   27  C2A HEC D1001    26487  16789  10784  -3875   2476   1314       C
HETATM   28  C2B HEC D1001       7.789  14.214  10.617  1.00141.94           C
ANISOU   28  C2B HEC D1001    26417  17097  10418  -3798   2937   1044       C
HETATM   29  C2C HEC D1001      10.451  14.023  16.100  1.00140.94           C
ANISOU   29  C2C HEC D1001    26625  17289   9635  -3766   2687    965       C
HETATM   30  C2D HEC D1001      14.546  10.022  13.991  1.00142.48           C
ANISOU   30  C2D HEC D1001    26834  17133  10168  -3850   2214   1270       C
HETATM   31  C3A HEC D1001      10.804  11.059   8.149  1.00136.41           C
ANISOU   31  C3A HEC D1001    25701  16075  10056  -3866   2591   1279       C
HETATM   32  C3B HEC D1001       7.744  14.781  11.826  1.00143.82           C
ANISOU   32  C3B HEC D1001    26706  17431  10509  -3780   2957    983       C
HETATM   33  C3C HEC D1001      11.528  13.271  16.400  1.00137.87           C
ANISOU   33  C3C HEC D1001    26282  16879   9224  -3777   2567   1011       C
HETATM   34  C3D HEC D1001      14.632   9.534  12.538  1.00144.35           C
ANISOU   34  C3D HEC D1001    27005  17250  10590  -3867   2201   1319       C
HETATM   35  C4A HEC D1001      10.358  11.714   9.366  1.00144.69           C
ANISOU   35  C4A HEC D1001    26789  17236  10949  -3849   2645   1224       C
HETATM   36  C4B HEC D1001       8.768  14.145  12.649  1.00137.78           C
ANISOU   36  C4B HEC D1001    26012  16687   9651  -3787   2848   1015       C
HETATM   37  C4C HEC D1001      11.920  12.537  15.214  1.00134.63           C
ANISOU   37  C4C HEC D1001    25826  16356   8971  -3798   2515   1081       C
HETATM   38  C4D HEC D1001      13.570  10.218  11.849  1.00138.72           C
ANISOU   38  C4D HEC D1001    26232  16533   9944  -3858   2317   1280       C
HETATM   39  CAA HEC D1001      12.769   9.532   7.451  1.00132.04           C
ANISOU   39  CAA HEC D1001    25171  15378   9621  -3893   2385   1376       C
HETATM   40  CAB HEC D1001       6.719  15.866  12.240  1.00138.71           C
ANISOU   40  CAB HEC D1001    26042  16858   9803  -3757   3079    901       C
HETATM   41  CAC HEC D1001      12.297  13.190  17.738  1.00135.76           C
ANISOU   41  CAC HEC D1001    26101  16686   8794  -3768   2488    993       C
HETATM   42  CAD HEC D1001      15.637   8.535  11.925  1.00138.75           C
ANISOU   42  CAD HEC D1001    26295  16445   9980  -3888   2089   1394       C
HETATM   43  CBA HEC D1001      11.998   8.251   7.139  1.00132.66           C
ANISOU   43  CBA HEC D1001    25237  15456   9711  -3938   2416   1524       C
HETATM   44  CBB HEC D1001       5.650  15.212  13.142  1.00135.28           C
ANISOU   44  CBB HEC D1001    25642  16531   9227  -3784   3158    997       C
HETATM   45  CBC HEC D1001      11.427  12.956  18.987  1.00146.99           C
ANISOU   45  CBC HEC D1001    27580  18242  10026  -3778   2561   1040       C
HETATM   46  CBD HEC D1001      14.919   7.222  11.642  1.00139.54           C
ANISOU   46  CBD HEC D1001    26386  16545  10089  -3933   2120   1549       C
HETATM   47  CGA HEC D1001      12.527   7.624   5.875  1.00128.84           C
ANISOU   47  CGA HEC D1001    24714  14851   9389  -3953   2359   1570       C
HETATM   48  CGD HEC D1001      15.891   6.207  11.098  1.00141.03           C
ANISOU   48  CGD HEC D1001    26575  16642  10368  -3955   2011   1625       C
HETATM   49  CHA HEC D1001      13.299  10.063  10.513  1.00146.02           C
ANISOU   49  CHA HEC D1001    27088  17363  11029  -3868   2342   1305       C
HETATM   50  CHB HEC D1001       9.227  12.490   9.500  1.00144.37           C
ANISOU   50  CHB HEC D1001    26723  17255  10876  -3837   2764   1179       C
HETATM   51  CHC HEC D1001       9.083  14.384  13.975  1.00144.74           C
ANISOU   51  CHC HEC D1001    26964  17660  10370  -3774   2826    976       C
HETATM   52  CHD HEC D1001      12.978  11.644  15.133  1.00137.25           C
ANISOU   52  CHD HEC D1001    26183  16634   9330  -3815   2394   1143       C
HETATM   53  CMA HEC D1001      10.090  11.136   6.782  1.00134.85           C
ANISOU   53  CMA HEC D1001    25424  15802  10009  -3872   2656   1294       C
HETATM   54  CMB HEC D1001       6.909  14.580   9.402  1.00138.00           C
ANISOU   54  CMB HEC D1001    25835  16541  10059  -3798   3022   1038       C
HETATM   55  CMC HEC D1001       9.714  15.017  17.030  1.00140.17           C
ANISOU   55  CMC HEC D1001    26549  17298   9410  -3741   2781    878       C
HETATM   56  CMD HEC D1001      15.472   9.587  15.143  1.00143.64           C
ANISOU   56  CMD HEC D1001    27061  17330  10186  -3851   2112   1287       C
HETATM   57  NA  HEC D1001      11.246  11.403  10.381  1.00142.02           N
ANISOU   57  NA  HEC D1001    26521  16938  10501  -3848   2558   1228       N
HETATM   58  NC  HEC D1001      11.031  12.874  14.214  1.00135.40           N
ANISOU   58  NC  HEC D1001    25852  16413   9183  -3799   2607   1074       N
HETATM   59  O1A HEC D1001      13.768   7.499   5.723  1.00127.91           O
ANISOU   59  O1A HEC D1001    24612  14669   9319  -3944   2254   1548       O
HETATM   60  O1D HEC D1001      15.705   5.000  11.405  1.00143.73           O
ANISOU   60  O1D HEC D1001    26943  17007  10662  -3991   1995   1754       O
HETATM   61  O2A HEC D1001      11.708   7.243   5.000  1.00126.20           O
ANISOU   61  O2A HEC D1001    24330  14482   9138  -3973   2418   1629       O
HETATM   62  O2D HEC D1001      16.850   6.595  10.375  1.00138.38           O
ANISOU   62  O2D HEC D1001    26214  16212  10153  -3936   1943   1558       O
HETATM   63 FE   HEC D1001      11.115  12.157  12.415  1.00158.39          Fe
ANISOU   63 FE   HEC D1001    28683  19178  12321  -3824   2585   1151      Fe
HETATM   64  HAB HEC D1001       6.266  16.109  11.430  1.00166.61           H
HETATM   65  HAC HEC D1001      13.016  12.556  17.688  1.00163.06           H
HETATM   66  HHA HEC D1001      13.931   9.523   9.993  1.00175.38           H
HETATM   67  HHB HEC D1001       8.617  12.507   8.733  1.00173.40           H
HETATM   68  HHC HEC D1001       8.518  15.025  14.454  1.00173.84           H
HETATM   69  HHD HEC D1001      13.462  11.479  15.969  1.00164.85           H
HETATM   70 HAA1 HEC D1001      13.619   9.309   7.860  1.00158.61           H
HETATM   71 HAA2 HEC D1001      12.922  10.028   6.632  1.00158.61           H
HETATM   72 HAD1 HEC D1001      16.364   8.380  12.549  1.00166.66           H
HETATM   73 HAD2 HEC D1001      15.991   8.897  11.097  1.00166.66           H
HETATM   74 HBA1 HEC D1001      11.058   8.462   7.024  1.00159.35           H
HETATM   75 HBA2 HEC D1001      12.100   7.627   7.874  1.00159.35           H
HETATM   76 HBB1 HEC D1001       5.203  14.504  12.651  1.00162.49           H
HETATM   77 HBB2 HEC D1001       5.000  15.880  13.409  1.00162.49           H
HETATM   78 HBB3 HEC D1001       6.076  14.841  13.930  1.00162.49           H
HETATM   79 HBC1 HEC D1001      11.697  12.130  19.419  1.00176.54           H
HETATM   80 HBC2 HEC D1001      10.495  12.894  18.725  1.00176.54           H
HETATM   81 HBC3 HEC D1001      11.541  13.696  19.603  1.00176.54           H
HETATM   82 HBD1 HEC D1001      14.216   7.374  10.991  1.00167.61           H
HETATM   83 HBD2 HEC D1001      14.529   6.885  12.463  1.00167.61           H
HETATM   84 HMA1 HEC D1001       9.181  10.779   6.867  1.00161.97           H
HETATM   85 HMA2 HEC D1001      10.588  10.607   6.123  1.00161.97           H
HETATM   86 HMA3 HEC D1001      10.048  12.069   6.487  1.00161.97           H
HETATM   87 HMB1 HEC D1001       7.003  15.525   9.208  1.00165.76           H
HETATM   88 HMB2 HEC D1001       5.981  14.382   9.604  1.00165.76           H
HETATM   89 HMB3 HEC D1001       7.190  14.061   8.632  1.00165.76           H
HETATM   90 HMC1 HEC D1001       9.327  14.535  17.777  1.00168.36           H
HETATM   91 HMC2 HEC D1001       9.010  15.463  16.534  1.00168.36           H
HETATM   92 HMC3 HEC D1001      10.343  15.677  17.362  1.00168.36           H
HETATM   93 HMD1 HEC D1001      16.399   9.817  14.922  1.00172.53           H
HETATM   94 HMD2 HEC D1001      15.399   8.618  15.274  1.00172.53           H
HETATM   95 HMD3 HEC D1001      15.209  10.048  15.966  1.00172.53           H
TER
END
  """

    edits = """
geometry_restraints.edits {
  bond {
    atom_selection_1 = chain D and resseq 40 and name SG
    atom_selection_2 = chain D and resseq 1001 and name CAC
    distance_ideal = 1.81
    sigma = 0.05
  }
  bond {
    atom_selection_1 = chain D and resseq 37 and name SG
    atom_selection_2 = chain D and resseq 1001 and name CAB
    distance_ideal = 1.81
    sigma = 0.05
  }
  angle {
    atom_selection_1 = chain D and resseq 40 and name SG
    atom_selection_2 = chain D and resseq 1001 and name CAC
    atom_selection_3 = chain D and resseq 1001 and name CBC
    angle_ideal = 109
    sigma = 2
  }
  angle {
    atom_selection_1 = chain D and resseq 40 and name SG
    atom_selection_2 = chain D and resseq 1001 and name CAC
    atom_selection_3 = chain D and resseq 1001 and name C3C
    angle_ideal = 109
    sigma = 2
  }
  angle {
    atom_selection_1 = chain D and resseq 37 and name SG
    atom_selection_2 = chain D and resseq 1001 and name CAB
    atom_selection_3 = chain D and resseq 1001 and name CBB
    angle_ideal = 109
    sigma = 2
  }
  angle {
    atom_selection_1 = chain D and resseq 1001 and name HAB
    atom_selection_2 = chain D and resseq 1001 and name CAB
    atom_selection_3 = chain D and resseq 37 and name SG
    angle_ideal = 109
    sigma = 1.1
  }
  angle {
    atom_selection_1 = chain D and resseq 1001 and name HAC
    atom_selection_2 = chain D and resseq 1001 and name CAC
    atom_selection_3 = chain D and resseq 40 and name SG
    angle_ideal = 109
    sigma = 1.1
  }
}
  """

    gm_phil = iotbx.phil.parse(input_string=grand_master_phil_str,
                               process_includes=True)
    edits_phil = iotbx.phil.parse(edits)
    working_phil = gm_phil.fetch(edits_phil)
    params = working_phil.extract()

    # Make sure the angle edit is present
    assert (params.geometry_restraints.edits.angle[3].atom_selection_1 == \
      "chain D and resseq 1001 and name HAB")

    pdb_inp = iotbx.pdb.input(lines=pdb_str.split("\n"), source_info=None)

    model = mmtbx.model.manager(model_input=pdb_inp,
                                build_grm=True,
                                pdb_interpretation_params=params)

    pdb_hierarchy = model.get_hierarchy()
    sites_cart = model.get_sites_cart()
    atoms = pdb_hierarchy.atoms()

    model.setup_riding_h_manager()
    riding_h_manager = model.get_riding_h_manager()

    h_para = riding_h_manager.h_parameterization

    diagnostics = riding_h_manager.diagnostics(sites_cart=sites_cart,
                                               threshold=0.05)
    h_distances = diagnostics.h_distances
    type_list = diagnostics.type_list

    number_h = model.get_hd_selection().count(True)
    number_h_para = len(h_para) - h_para.count(None)

    for rc in h_para:
        if rc:
            assert (rc.ih != 63), 'Wrong atom not recognized.'

# Test if number of paramterized H atoms is correct
    assert (number_h == number_h_para + 1), 'Not all H atoms are parameterized'

    type_list_known = [
        'alg1b', '3neigbs', '2tetra', '2tetra', 'alg1b', '3neigbs', '2tetra',
        '2tetra', '3neigbs', 'flat_2neigbs', 'flat_2neigbs', 'flat_2neigbs',
        'flat_2neigbs', '2tetra', '2tetra', '2tetra', '2tetra', '2tetra',
        '2tetra', 'prop', 'prop', 'prop', 'prop', 'prop', 'prop', '2tetra',
        '2tetra', 'prop', 'prop', 'prop', 'prop', 'prop', 'prop', 'prop',
        'prop', 'prop', 'prop', 'prop', 'prop'
    ]

    for ih in h_distances:
        # One H atom is expected to be far (HAC)
        if (ih == 64):
            continue
        labels = atoms[ih].fetch_labels()
        if (h_distances[ih] > 0.1):
            assert (h_distances[ih] < 0.1), \
              'distance too large: %s  atom: %s (%s) residue: %s ' \
              % (h_para[ih].htype, atoms[ih].name, ih, labels.resseq.strip())


#
    for type1, type2 in zip(type_list, type_list_known):
        assert (type1 == type2)
Beispiel #28
0
def exercise2():
    pdb_str = """
CRYST1   16.660   12.742   18.240  90.00  90.00  90.00 P 1
SCALE1      0.060024  0.000000  0.000000        0.00000
SCALE2      0.000000  0.078481  0.000000        0.00000
SCALE3      0.000000  0.000000  0.054825        0.00000
ATOM      1  N   TYR A   7       9.837   5.000   6.625  1.00 15.00           N
ATOM      2  CA  TYR A   7      10.084   6.426   6.798  1.00 15.00           C
ATOM      3  C   TYR A   7      11.431   6.813   6.197  1.00 15.00           C
ATOM      4  O   TYR A   7      11.660   6.642   5.000  1.00 15.00           O
ATOM      5  CB  TYR A   7      10.042   6.803   8.281  1.00 15.00           C
ATOM      6  CG  TYR A   7       8.697   6.593   8.948  1.00 15.00           C
ATOM      7  CD1 TYR A   7       7.540   6.413   8.198  1.00 15.00           C
ATOM      8  CD2 TYR A   7       8.586   6.575  10.332  1.00 15.00           C
ATOM      9  CE1 TYR A   7       6.315   6.222   8.807  1.00 15.00           C
ATOM     10  CE2 TYR A   7       7.364   6.384  10.950  1.00 15.00           C
ATOM     11  CZ  TYR A   7       6.233   6.208  10.183  1.00 15.00           C
ATOM     12  OH  TYR A   7       5.015   6.018  10.794  1.00 15.00           O
ATOM     13  HA  TYR A   7       9.398   6.930   6.331  1.00 15.00           H
ATOM     14  HB2 TYR A   7      10.693   6.264   8.757  1.00 15.00           H
ATOM     15  HB3 TYR A   7      10.270   7.742   8.369  1.00 15.00           H
ATOM     16  HD1 TYR A   7       7.589   6.422   7.269  1.00 15.00           H
ATOM     17  HD2 TYR A   7       9.347   6.694  10.853  1.00 15.00           H
ATOM     18  HE1 TYR A   7       5.550   6.103   8.292  1.00 15.00           H
ATOM     19  HE2 TYR A   7       7.306   6.375  11.878  1.00 15.00           H
ATOM     20  HH  TYR A   7       5.000   6.415  11.534  1.00 15.00           H
TER
HETATM   21  O   HOH B   1       5.307   7.545  13.240  1.00 30.00           O
TER
END
  """

    edits = """
geometry_restraints.edits {
  bond {
    atom_selection_1 = chain A and resseq 7 and name HH
    atom_selection_2 = chain B and resseq 1 and name O
    distance_ideal = 1.81
    sigma = 0.05
  }
}
  """

    type_list_known = [
        '3neigbs', '2tetra', '2tetra', 'flat_2neigbs', 'flat_2neigbs',
        'flat_2neigbs', 'flat_2neigbs', 'alg1b'
    ]

    gm_phil = iotbx.phil.parse(input_string=grand_master_phil_str,
                               process_includes=True)
    edits_phil = iotbx.phil.parse(edits)
    working_phil = gm_phil.fetch(edits_phil)
    params = working_phil.extract()

    # Make sure the angle edit is present
    assert (params.geometry_restraints.edits.bond[0].atom_selection_1 == \
      "chain A and resseq 7 and name HH")

    pdb_inp = iotbx.pdb.input(lines=pdb_str.split("\n"), source_info=None)

    model = mmtbx.model.manager(model_input=pdb_inp,
                                build_grm=True,
                                pdb_interpretation_params=params)

    pdb_hierarchy = model.get_hierarchy()
    sites_cart = model.get_sites_cart()
    atoms = pdb_hierarchy.atoms()

    model.setup_riding_h_manager()
    riding_h_manager = model.get_riding_h_manager()

    h_para = riding_h_manager.h_parameterization

    diagnostics = riding_h_manager.diagnostics(sites_cart=sites_cart,
                                               threshold=0.05)
    h_distances = diagnostics.h_distances
    type_list = diagnostics.type_list

    number_h = model.get_hd_selection().count(True)
    number_h_para = len(h_para) - h_para.count(None)

    connectivity_manager = connectivity.determine_connectivity(
        pdb_hierarchy=pdb_hierarchy,
        geometry_restraints=model.get_restraints_manager().geometry)
    double_H = connectivity_manager.double_H

    # Test if number of paramterized H atoms is correct
    assert (number_h == number_h_para), 'Not all H atoms are parameterized'
    assert (double_H[19] == [11,
                             20]), 'H bound to two atoms wrongly recognized'
    assert (number_h_para == 8), 'Not all H atoms are parameterized'

    for ih in h_distances:
        labels = atoms[ih].fetch_labels()
        if (h_distances[ih] > 0.1):
            assert (h_distances[ih] < 0.1), \
              'distance too large: %s  atom: %s (%s) residue: %s ' \
              % (h_para[ih].htype, atoms[ih].name, ih, labels.resseq.strip())

    for type1, type2 in zip(type_list, type_list_known):
        assert (type1 == type2)
Beispiel #29
0
 def __init__(
         self,
         model,
         Hs=["H", "D"],
         As=["O", "N", "S", "F", "CL"],
         Ds=["O", "N", "S"],
         d_HA_cutoff=[1.4, 3.0],  # original: [1.4, 2.4],
         d_DA_cutoff=[2.5, 3.5],  # not used
         a_DHA_cutoff=120,  # should be greater than this
         a_YAH_cutoff=[90, 180],  # should be within this interval, not used
         protein_only=False):
     self.result = []
     self.atoms = model.get_hierarchy().atoms()
     geometry = model.get_restraints_manager()
     bond_proxies_simple, asu = geometry.geometry.get_all_bond_proxies(
         sites_cart=model.get_sites_cart())
     h_bonded_to = {}
     for p in bond_proxies_simple:
         i, j = p.i_seqs
         ei, ej = self.atoms[p.i_seqs[0]].element, self.atoms[
             p.i_seqs[1]].element
         if (ei in Hs): h_bonded_to[i] = self.atoms[j]
         if (ej in Hs): h_bonded_to[j] = self.atoms[i]
     #
     sites_cart = model.get_sites_cart()
     crystal_symmetry = model.crystal_symmetry()
     fm = crystal_symmetry.unit_cell().fractionalization_matrix()
     om = crystal_symmetry.unit_cell().orthogonalization_matrix()
     pg = get_pair_generator(crystal_symmetry=crystal_symmetry,
                             buffer_thickness=d_HA_cutoff[1],
                             sites_cart=sites_cart)
     get_class = iotbx.pdb.common_residue_names_get_class
     for p in pg.pair_generator:
         i, j = p.i_seq, p.j_seq
         ei, ej = self.atoms[i].element, self.atoms[j].element
         altloc_i = self.atoms[i].parent().altloc
         altloc_j = self.atoms[j].parent().altloc
         resseq_i = self.atoms[i].parent().parent().resseq
         resseq_j = self.atoms[j].parent().parent().resseq
         # pre-screen candidates begin
         one_is_Hs = ei in Hs or ej in Hs
         other_is_acceptor = ei in As or ej in As
         d_HA = math.sqrt(p.dist_sq)
         assert d_HA <= d_HA_cutoff[1]
         is_candidate = one_is_Hs and other_is_acceptor and \
           d_HA >= d_HA_cutoff[0] and \
           altloc_i == altloc_j and resseq_i != resseq_j
         if (protein_only):
             for it in [i, j]:
                 resname = self.atoms[it].parent().resname
                 is_candidate &= get_class(
                     name=resname) == "common_amino_acid"
         if (not is_candidate): continue
         if (ei in Hs and not h_bonded_to[i].element in As): continue
         if (ej in Hs and not h_bonded_to[j].element in As): continue
         # pre-screen candidates end
         rt_mx_i = pg.conn_asu_mappings.get_rt_mx_i(p)
         rt_mx_j = pg.conn_asu_mappings.get_rt_mx_j(p)
         rt_mx_ji = rt_mx_i.inverse().multiply(rt_mx_j)
         #
         if (ei in Hs):
             H = self.atoms[i]
             D = self.atoms[h_bonded_to[H.i_seq].i_seq]
             A = self.atoms[j]
             if (str(rt_mx_ji) != "x,y,z"):
                 A = apply_symop_to_copy(A, rt_mx_ji, fm, om)
         if (ej in Hs):
             H = self.atoms[j]
             D = self.atoms[h_bonded_to[H.i_seq].i_seq]
             A = self.atoms[i]
             if (str(rt_mx_ji) != "x,y,z"):
                 H = apply_symop_to_copy(H, rt_mx_ji, fm, om)
                 D = apply_symop_to_copy(D, rt_mx_ji, fm, om)
         assert H.distance(D) < 1.15
         # filter by a_DHA
         a_DHA = H.angle(A, D, deg=True)
         if (a_DHA < a_DHA_cutoff): continue
         #
         assert approx_equal(d_HA, H.distance(A), 1.e-3)
         self.result.append(
             group_args(i=i,
                        j=j,
                        symop=rt_mx_ji,
                        d_HA=d_HA,
                        a_DHA=a_DHA,
                        d_AD=A.distance(D)))
Beispiel #30
0
def run(args, command_name="phenix.tls"):
    if (len(args) == 0): args = ["--help"]
    usage_fmt = "%s pdb_file [parameters: file or command line string]"
    des_fmt = "Example: %s model.pdb fit_tls_to.selection='%s' fit_tls_to.selection='%s'"
    command_line = (iotbx_option_parser(
        usage=usage_fmt % command_name, description=banner).option(
            "--show_defaults",
            action="store_true",
            help="Do not output to the screen (except errors).").option(
                "--silent",
                action="store_true",
                help="Suppress output to the screen.")).process(args=args)
    #
    log = sys.stdout
    if (not command_line.options.silent):
        utils.print_header("TLS tools", out=log)
    if (command_line.options.show_defaults):
        master_params.show(out=log)
        print(file=log)
        return
    if (not command_line.options.silent):
        print(banner, file=log)
    #
    processed_args = utils.process_command_line_args(
        args=command_line.args, master_params=master_params, log=log)
    reflection_files = processed_args.reflection_files
    if (processed_args.crystal_symmetry is None):
        raise Sorry("No crystal symmetry found.")
    if (len(processed_args.pdb_file_names) == 0):
        raise Sorry("No PDB file found.")
    params = processed_args.params
    if (not command_line.options.silent):
        utils.print_header("Input parameters", out=log)
        params.show(out=log)
    params = params.extract()
    #
    if (processed_args.crystal_symmetry.unit_cell() is None
            or processed_args.crystal_symmetry.space_group() is None):
        raise Sorry("No CRYST1 record found.")

    pdb_combined = iotbx.pdb.combine_unique_pdb_files(
        file_names=processed_args.pdb_file_names)
    pdb_combined.report_non_unique(out=log)
    if (len(pdb_combined.unique_file_names) == 0):
        raise Sorry("No coordinate file given.")
    raw_records = pdb_combined.raw_records
    try:
        pdb_inp = iotbx.pdb.input(source_info=None,
                                  lines=flex.std_string(raw_records))
    except ValueError as e:
        raise Sorry("Model format (PDB or mmCIF) error:\n%s" % str(e))

    model = mmtbx.model.manager(
        model_input=pdb_inp,
        restraint_objects=processed_args.cif_objects,
        crystal_symmetry=processed_args.crystal_symmetry,
        log=log)
    if (not command_line.options.silent):
        utils.print_header("TLS groups from PDB file header", out=log)
    pdb_inp_tls = mmtbx.tls.tools.tls_from_pdb_inp(
        remark_3_records=model._model_input.extract_remark_iii_records(3),
        pdb_hierarchy=model.get_hierarchy())
    #
    tls_groups = []
    if (pdb_inp_tls.tls_present):
        if (pdb_inp_tls.error_string is not None):
            raise Sorry(pdb_inp_tls.error_string)
        pdb_tls = mmtbx.tls.tools.extract_tls_from_pdb(pdb_inp_tls=pdb_inp_tls,
                                                       model=model)
        tls_groups = pdb_tls.pdb_inp_tls.tls_params
    #
    tls_selections_strings = []
    #
    if (len(tls_groups) == 0 and not command_line.options.silent):
        print("No TLS groups found in PDB file header.", file=log)
    else:
        for i_seq, tls_group in enumerate(tls_groups):
            tls_selections_strings.append(tls_group.selection_string)
            if (not command_line.options.silent):
                print("TLS group %d: %s" %
                      (i_seq + 1, tls_group.selection_string),
                      file=log)
                mmtbx.tls.tools.show_tls_one_group(tlso=tls_group, out=log)
                print(file=log)
    #
    if (len(tls_selections_strings) > 0 and len(params.selection) > 0):
        raise Sorry(
            "Two TLS selection sources found: PDB file header and parameters.")
    if (len(params.selection) > 0):
        tls_selections_strings = params.selection
    if ([params.combine_tls, params.extract_tls].count(True) > 1):
        raise Sorry(
            "Cannot simultaneously pereform: combine_tls and extract_tls")
    if ([params.combine_tls, params.extract_tls].count(True) > 0):
        if (len(tls_selections_strings) == 0):
            raise Sorry("No TLS selections found.")
    #
    if (len(tls_selections_strings)):
        if (not command_line.options.silent):
            utils.print_header("TLS groups selections", out=log)
        selections = utils.get_atom_selections(
            model=model, selection_strings=tls_selections_strings)
        if (not command_line.options.silent):
            print("Number of TLS groups: ", len(selections), file=log)
            print("Number of atoms: %d" % model.get_number_of_atoms(),
                  file=log)
        n_atoms_in_tls = 0
        for sel_a in selections:
            n_atoms_in_tls += sel_a.size()
        if (not command_line.options.silent):
            print("Number of atoms in TLS groups: %d" % n_atoms_in_tls,
                  file=log)
            print(file=log)
        assert len(tls_selections_strings) == len(selections)
        if (not command_line.options.silent):
            for sel_a, sel_s in zip(selections, tls_selections_strings):
                print("Selection string:\n%s" % sel_s, file=log)
                print("selects %d atoms." % sel_a.size(), file=log)
                print(file=log)
            print("Ready-to-use in phenix.refine:\n", file=log)
            for sel_a, sel_s in zip(selections, tls_selections_strings):
                print(sel_s, file=log)
    #
    ofn = params.output_file_name
    if (ofn is None):
        ofn = os.path.splitext(
            os.path.basename(processed_args.pdb_file_names[0]))[0]
        if (len(processed_args.pdb_file_names) > 1):
            ofn = ofn + "_el_al"
        if (params.combine_tls):
            ofn = ofn + "_combine_tls.pdb"
        elif (params.extract_tls):
            ofn = ofn + "_extract_tls.pdb"
        else:
            ofn = None
    if (ofn is not None):
        ofo = open(ofn, "w")
    #
    if (params.extract_tls):
        utils.print_header(
            "Fit TLS matrices to B-factors of selected sets of atoms", out=log)
        tlsos = mmtbx.tls.tools.generate_tlsos(
            selections=selections,
            xray_structure=model.get_xray_structure(),
            value=0.0)
        for rt, rl, rs in [[1, 0, 1], [1, 1, 1], [0, 1, 1], [1, 0, 0],
                           [0, 1, 0], [0, 0, 1], [1, 1, 1], [0, 0, 1]] * 10:
            tlsos = mmtbx.tls.tools.tls_from_uanisos(
                xray_structure=model.get_xray_structure(),
                selections=selections,
                tlsos_initial=tlsos,
                number_of_macro_cycles=10,
                max_iterations=100,
                refine_T=rt,
                refine_L=rl,
                refine_S=rs,
                enforce_positive_definite_TL=params.
                enforce_positive_definite_TL,
                verbose=-1,
                out=log)
            mmtbx.tls.tools.show_tls(tlsos=tlsos, out=log)
        u_cart_from_tls = mmtbx.tls.tools.u_cart_from_tls(
            sites_cart=model.get_sites_cart(),
            selections=selections,
            tlsos=tlsos)
        unit_cell = model.get_xray_structure().unit_cell()
        for i_seq, sc in enumerate(model.get_xray_structure().scatterers()):
            if (u_cart_from_tls[i_seq] != (0, 0, 0, 0, 0, 0)):
                u_star_tls = adptbx.u_cart_as_u_star(
                    unit_cell, tuple(u_cart_from_tls[i_seq]))
                sc.u_star = tuple(
                    flex.double(sc.u_star) - flex.double(u_star_tls))
        for sel in selections:
            model.get_xray_structure().convert_to_isotropic(selection=sel)
        mmtbx.tls.tools.remark_3_tls(tlsos=tlsos,
                                     selection_strings=tls_selections_strings,
                                     out=ofo)
    #
    if (params.combine_tls):
        utils.print_header("Combine B_tls with B_residual", out=log)
        mmtbx.tls.tools.combine_tls_and_u_local(
            xray_structure=model.get_xray_structure(),
            tls_selections=selections,
            tls_groups=tls_groups)
        print("All done.", file=log)
    #
    if (ofn is not None):
        utils.print_header("Write output PDB file %s" % ofn, out=log)
        model.set_sites_cart_from_xrs()
        pdb_str = model.model_as_pdb()
        ofo.write(pdb_str)
        ofo.close()
        print("All done.", file=log)