Пример #1
0
def get_pdb_hierarchy_from_restraints(code):
    from mmtbx.monomer_library import server
    from iotbx import pdb
    mon_lib_server = server.server()
    path = mon_lib_server.get_comp_comp_id_direct(code, return_filename=True)
    cif_obj = server.read_cif(path)
    ligand_inp = pdb.pdb_input(source_info="Model from %s" % path,
                               lines=flex.split_lines(""))
    ligand_hierarchy = ligand_inp.construct_hierarchy()
    model = pdb.hierarchy.model()
    chain = pdb.hierarchy.chain()
    chain.id = 'Z'
    rg = pdb.hierarchy.residue_group()
    ag = pdb.hierarchy.atom_group()
    for block, loops in cif_obj.blocks.items():
        if block == 'comp_list': continue
        for loop in loops.iterloops():
            for row in loop.iterrows():
                if '_chem_comp_atom.comp_id' not in row: break
                ag.resname = row['_chem_comp_atom.comp_id']
                atom = pdb.hierarchy.atom()
                atom.name = row['_chem_comp_atom.atom_id']
                atom.element = '%2s' % row['_chem_comp_atom.type_symbol']
                atom.xyz = (
                    float(row['_chem_comp_atom.x']),
                    float(row['_chem_comp_atom.y']),
                    float(row['_chem_comp_atom.z']),
                )
                ag.append_atom(atom)
    rg.append_atom_group(ag)
    chain.append_residue_group(rg)
    model.append_chain(chain)
    ligand_hierarchy.append_model(model)
    ligand_hierarchy.atoms().reset_i_seq()
    return ligand_hierarchy
Пример #2
0
def morph_models (params, out=None, debug=False) :
  assert len(params.morph.pdb_file) > 1
  assert (len(params.morph.frames) == (len(params.morph.pdb_file) - 1))
  if (out is None) : out = sys.stdout
  from mmtbx.monomer_library import pdb_interpretation, server
  from iotbx import file_reader
  pdb_hierarchies = []
  for pdb_file in params.morph.pdb_file :
    pdb_in = file_reader.any_file(pdb_file, force_type="pdb")
    pdb_in.check_file_type("pdb")
    hierarchy = pdb_in.file_object.hierarchy
    pdb_hierarchies.append(hierarchy)
  new_pdb = homogenize_structures(
    pdb_hierarchies=pdb_hierarchies,
    delete_waters=params.morph.delete_waters,
    debug=debug)
  mon_lib_srv = server.server()
  ener_lib = server.ener_lib()
  for cif_file in params.morph.cif_file :
    print "Loading CIF file %s" % cif_file
    cif_object = server.read_cif(file_name=cif_file)
    mon_lib_serv.process_cif_object(cif_object=cif_object, file_name=cif_file)
    ener_lib.process_cif_object(cif_object=cif_object, file_name=cif_file)
  if (params.morph.minimization.interpolate_dihedrals) :
    params.pdb_interpretation.peptide_link.discard_psi_phi = False
  processed_pdb_file = pdb_interpretation.process(
    mon_lib_srv=mon_lib_srv,
    ener_lib=ener_lib,
    params=params.pdb_interpretation,
    pdb_inp=new_pdb[0],
    substitute_non_crystallographic_unit_cell_if_necessary=True)
  all_chain_proxies = processed_pdb_file.all_chain_proxies
  static_coords = [ all_chain_proxies.pdb_hierarchy.atoms().extract_xyz() ]
  for pdb_inp in new_pdb[1:] :
    sites = pdb_inp.atoms().extract_xyz()
    static_coords.append(sites)
  if (params.morph.fitting.align_atoms is not None) :
    print >> out, "Superposing on initial structure..."
    selection_cache = all_chain_proxies.pdb_hierarchy.atom_selection_cache()
    selection = selection_cache.selection(params.morph.fitting.align_atoms)
    if (selection.count(True) == 0) :
      raise Sorry("No atoms in alignment selection!")
    i_ref = params.morph.fitting.reference_structure
    sites_fixed = static_coords[i_ref]
    j = 0
    while (j < len(static_coords)) :
      if (j != i_ref) :
        sites_moving = static_coords[j]
        assert (len(sites_moving) == len(sites_fixed) > 0)
        if (params.morph.fitting.sieve_fit) :
          from scitbx.math import superpose
          lsq_fit = superpose.sieve_fit(
            sites_fixed=sites_fixed,
            sites_moving=sites_moving,
            selection=selection)
          sites_moving_new = lsq_fit.r.elems * sites_moving + lsq_fit.t.elems
        else :
          sites_moving_new = fit_sites(
            sites_fixed=sites_fixed,
            sites_moving=sites_moving,
            selection=selection)
        assert (sites_moving_new.size() == sites_moving.size())
        static_coords[j] = sites_moving_new
      j += 1
  print >> out, "Ready to morph"
  morphs = []
  restraints_manager = processed_pdb_file.geometry_restraints_manager()
  for i in range(len(params.morph.pdb_file) - 1) :
    morph = adiabatic_mapping(
      pdb_hierarchy=all_chain_proxies.pdb_hierarchy,
      restraints_manager=restraints_manager,
      start_coords = static_coords[i],
      end_coords = static_coords[i+1],
      params = params.morph.minimization,
      nsteps = params.morph.frames[i],
      out=out)
    morphs.append(morph)
  serial = 1
  if (params.morph.output_directory is not None) :
    output_base = os.path.join(params.morph.output_directory,
      params.morph.output_prefix)
  else :
    output_base = params.morph.output_prefix
  for i, morph in enumerate(morphs) :
    serial = morph.write_pdb_files(
      output_base=output_base,
      serial=serial,
      serial_format=params.morph.serial_format,
      pause=params.morph.pause,
      pause_at_end=(i == (len(morphs) - 1)),
      log=out)
  f = open("%s.pml" % output_base, "w")
  for i in range(1, serial) :
    format_base = "%s_%s" % (output_base, params.morph.serial_format)
    print >> f, "load %s.pdb, morph" % (format_base % i)
  f.close()
  print >> out, "PyMOL script is %s.pml" % output_base