コード例 #1
0
def run(pdb_file, cif_file):
  from mmtbx.monomer_library import server
  import iotbx
  from mmtbx.monomer_library import pdb_interpretation
  pdb_inp = iotbx.pdb.input(file_name=pdb_file)
  pdb_hierarchy = pdb_inp.construct_hierarchy()
  raw_lines = pdb_hierarchy.as_pdb_string(
    crystal_symmetry=pdb_inp.crystal_symmetry())
  f=file(cif_file, "rb")
  ligand_cif = f.read()
  f.close()
  cif_object = iotbx.cif.model.cif()
  iotbx.cif.reader(input_string=ligand_cif,
                   cif_object=cif_object,
                   strict=False)
  mon_lib_srv = server.server()
  ener_lib = server.ener_lib()                   
  for srv in [mon_lib_srv, ener_lib]:
    srv.process_cif_object(cif_object=cif_object,
                           file_name="LIGAND")
  processed_pdb = pdb_interpretation.process(
    mon_lib_srv,
    ener_lib,
    raw_records=raw_lines)

  geometry_restraints_manager = processed_pdb.geometry_restraints_manager()
コード例 #2
0
ファイル: tst_motif.py プロジェクト: cctbx/cctbx-playground
def exercise():
  verbose = "--verbose" in sys.argv[1:]
  list_cif = server.mon_lib_list_cif()
  srv = server.server(list_cif=list_cif)
  open("tmp.cif", "w").write(tmp_cif)
  srv.process_cif(file_name="tmp.cif")
  comp_comp_id = srv.get_comp_comp_id_direct(comp_id="tst")
  motif = comp_comp_id.as_geometry_restraints_motif()
  out = StringIO()
  motif.show(out=out)
  if (verbose): sys.stdout.write(out.getvalue())
  assert not show_diff(out.getvalue(), expected_out_tst_comp)
  for link_link_id in srv.link_link_id_list:
    out = StringIO()
    link_link_id.as_geometry_restraints_motif_manipulation().show(out=out)
    if (verbose): sys.stdout.write(out.getvalue())
    if (link_link_id.chem_link.id == "tst_lnk"):
      assert not show_diff(out.getvalue(), expected_out_tst_lnk)
  for mod_mod_id in srv.mod_mod_id_list:
    out = StringIO()
    mod_mod_id.as_geometry_restraints_motif_manipulation().show(out=out)
    if (verbose): sys.stdout.write(out.getvalue())
    if (mod_mod_id.chem_mod.id == "tst_mod"):
      assert not show_diff(out.getvalue(), expected_out_tst_mod)
  print "OK"
コード例 #3
0
def run(args, command_name=libtbx.env.dispatcher_name):
    parser = argparse.ArgumentParser(
        prog=command_name,
        usage='%s pdb_file "atom_selection" [...]' % command_name)
    parser.add_argument("file_name",
                        nargs=1,
                        help="File name of the model file")
    parser.add_argument(
        "inselections",
        help="Atom selection strings",
        nargs='+',
    )
    parser.add_argument("--write-pdb-file",
                        action="store",
                        help="write selected atoms to new PDB file",
                        default=None)
    parser.add_argument(
        "--cryst1-replacement-buffer-layer",
        action="store",
        type=float,
        help="replace CRYST1 with pseudo unit cell covering the selected"
        " atoms plus a surrounding buffer layer",
        default=None)
    co = parser.parse_args(args)
    mon_lib_srv = server.server()
    ener_lib = server.ener_lib()
    processed_pdb_file = pdb_interpretation.process(mon_lib_srv=mon_lib_srv,
                                                    ener_lib=ener_lib,
                                                    file_name=co.file_name[0],
                                                    log=sys.stdout)
    print
    acp = processed_pdb_file.all_chain_proxies

    selection_cache = acp.pdb_hierarchy.atom_selection_cache()
    atoms = acp.pdb_atoms
    all_bsel = flex.bool(atoms.size(), False)
    for selection_string in co.inselections:
        print selection_string
        isel = acp.iselection(string=selection_string, cache=selection_cache)
        all_bsel.set_selected(isel, True)
        if (not co.write_pdb_file):
            print "  %d atom%s selected" % plural_s(isel.size())
            for atom in atoms.select(isel):
                print "    %s" % atom.format_atom_record()
    print
    if (co.write_pdb_file):
        print "Writing file:", show_string(co.write_pdb_file)
        sel_hierarchy = acp.pdb_hierarchy.select(all_bsel)
        if (co.cryst1_replacement_buffer_layer is None):
            crystal_symmetry = acp.special_position_settings
        else:
            import cctbx.crystal
            crystal_symmetry = cctbx.crystal.non_crystallographic_symmetry(
                sites_cart=sel_hierarchy.atoms().extract_xyz(),
                buffer_layer=co.cryst1_replacement_buffer_layer)
        write_whole_pdb_file(file_name=co.write_pdb_file,
                             processed_pdb_file=processed_pdb_file,
                             pdb_hierarchy=sel_hierarchy,
                             crystal_symmetry=crystal_symmetry)
        print
コード例 #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())
コード例 #5
0
ファイル: tst.py プロジェクト: dalekreitler/cctbx-playground
def exercise_model_utils () :
  pdb_in = get_1yjp_pdb()
  residue = pdb_in.hierarchy.only_model().chains()[0].residue_groups()[0].only_atom_group()
  sele = pdb_in.hierarchy.atom_selection_cache().selection("resname TYR")
  water_sel = building.get_nearby_water_selection(
    pdb_hierarchy=pdb_in.hierarchy,
    xray_structure=pdb_in.input.xray_structure_simple(),
    selection=sele)
  assert (list(water_sel.iselection()) == [59, 60, 61, 62, 63])
  from mmtbx.monomer_library import idealized_aa
  from mmtbx.monomer_library import server
  mon_lib_srv = server.server()
  ideal_dict = idealized_aa.residue_dict()
  for resname, hierarchy in ideal_dict.iteritems() :
    residue = hierarchy.only_model().only_chain().only_residue_group().only_atom_group()
    result = building.generate_sidechain_clusters(residue, mon_lib_srv)
    if (len(result) == 0) :
      # no side-chain clusters for UNK as well
      assert (residue.resname in ["ALA", "GLY", "UNK"]), residue.resname
  # show_chain_resseq_ranges
  resids = [ (1,''),(2,''),(2,'A'),(4,''),(5,''),(6,''),(10,'B') ]
  import iotbx.pdb.hierarchy
  chain = iotbx.pdb.hierarchy.chain(id='A')
  for (resseq, icode) in resids :
    rg = iotbx.pdb.hierarchy.residue_group(resseq="%4d" % resseq, icode=icode)
    chain.append_residue_group(rg)
  out = StringIO()
  building.show_chain_resseq_ranges(chain.residue_groups(), out=out,
    prefix="  ")
  assert out.getvalue() == """  chain 'A': 1-2A,4-6,10B\n""", out.getvalue()
コード例 #6
0
def run(args):
    list_cif = server.mon_lib_list_cif()
    srv = server.server(list_cif=list_cif)
    for comp_id in args:
        comp_comp_id = srv.get_comp_comp_id_direct(comp_id=comp_id)
        motif = comp_comp_id.as_geometry_restraints_motif()
        motif.show()
コード例 #7
0
def exercise_1():
  processed_pdb_file = pdb_interpretation.process(
    mon_lib_srv              = server.server(),
    ener_lib                 = server.ener_lib(),
    raw_records              = flex.std_string(pdb_str_1.splitlines()),
    strict_conflict_handling = True,
    force_symmetry           = True,
    log                      = None)
  grm = processed_pdb_file.geometry_restraints_manager()
  pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  sites_cart = pdb_hierarchy.atoms().extract_xyz()
  # 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
コード例 #8
0
def get_reference_dihedral_proxies(reference_hierarchy_list,
                                   reference_file_list,
                                   mon_lib_srv=None,
                                   ener_lib=None,
                                   crystal_symmetry=None,
                                   restraint_objects=None,
                                   monomer_parameters=None,
                                   log=None):
    from mmtbx.monomer_library import server
    if log is None:
        log = sys.stdout
    if mon_lib_srv is None:
        mon_lib_srv = server.server()
    if ener_lib is None:
        ener_lib = server.ener_lib()
    reference_dihedral_proxies = {}
    for file_name, pdb_hierarchy in zip(reference_file_list,
                                        reference_hierarchy_list):
        dihedral_proxies = get_complete_dihedral_proxies(
            pdb_hierarchy=pdb_hierarchy,
            mon_lib_srv=mon_lib_srv,
            ener_lib=ener_lib,
            crystal_symmetry=crystal_symmetry,
            restraint_objects=restraint_objects,
            monomer_parameters=monomer_parameters,
            log=log)
        reference_dihedral_proxies[file_name] = dihedral_proxies
    return reference_dihedral_proxies
コード例 #9
0
ファイル: tst.py プロジェクト: hainm/cctbx_project
def exercise_model_utils () :
  pdb_in = get_1yjp_pdb()
  residue = pdb_in.hierarchy.only_model().chains()[0].residue_groups()[0].only_atom_group()
  sele = pdb_in.hierarchy.atom_selection_cache().selection("resname TYR")
  water_sel = building.get_nearby_water_selection(
    pdb_hierarchy=pdb_in.hierarchy,
    xray_structure=pdb_in.input.xray_structure_simple(),
    selection=sele)
  assert (list(water_sel.iselection()) == [59, 60, 61, 62, 63])
  from mmtbx.monomer_library import idealized_aa
  from mmtbx.monomer_library import server
  mon_lib_srv = server.server()
  ideal_dict = idealized_aa.residue_dict()
  for resname, hierarchy in ideal_dict.iteritems() :
    residue = hierarchy.only_model().only_chain().only_residue_group().only_atom_group()
    result = building.generate_sidechain_clusters(residue, mon_lib_srv)
    if (len(result) == 0) :
      # no side-chain clusters for UNK as well
      assert (residue.resname in ["ALA", "GLY", "UNK"]), residue.resname
  # show_chain_resseq_ranges
  resids = [ (1,''),(2,''),(2,'A'),(4,''),(5,''),(6,''),(10,'B') ]
  import iotbx.pdb.hierarchy
  chain = iotbx.pdb.hierarchy.chain(id='A')
  for (resseq, icode) in resids :
    rg = iotbx.pdb.hierarchy.residue_group(resseq="%4d" % resseq, icode=icode)
    chain.append_residue_group(rg)
  out = StringIO()
  building.show_chain_resseq_ranges(chain.residue_groups(), out=out,
    prefix="  ")
  assert out.getvalue() == """  chain 'A': 1-2A,4-6,10B\n""", out.getvalue()
コード例 #10
0
def run (args, out=sys.stdout, quiet=False) :
  from mmtbx.monomer_library import pdb_interpretation
  from mmtbx.monomer_library import server
  import iotbx.pdb
  cmdline = iotbx.phil.process_command_line_with_files(
    args=args,
    master_phil=get_master_phil(),
    pdb_file_def="model",
    usage_string=usage_string)
  params = cmdline.work.extract()
  if (params.model is None) :
    raise Usage(usage_string)
  pdb_in = iotbx.pdb.input(source_info=params.model, file_name=params.model)
  mon_lib_srv = server.server()
  ener_lib = server.ener_lib()
  processed_pdb_file = pdb_interpretation.process(
    mon_lib_srv=mon_lib_srv,
    ener_lib=ener_lib,
    pdb_inp=pdb_in,
    substitute_non_crystallographic_unit_cell_if_necessary=True)
  pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  geometry = processed_pdb_file.geometry_restraints_manager()
  result = rna_validation(
    pdb_hierarchy=pdb_hierarchy,
    geometry_restraints_manager=geometry,
    params=params,
    outliers_only=params.outliers_only)
  result.show(out=out)
  return result
コード例 #11
0
def run(args):
  list_cif = server.mon_lib_list_cif()
  srv = server.server(list_cif=list_cif)
  for comp_id in args:
    comp_comp_id = srv.get_comp_comp_id_direct(comp_id=comp_id)
    motif = comp_comp_id.as_geometry_restraints_motif()
    motif.show()
コード例 #12
0
def exercise_1():
  processed_pdb_file = pdb_interpretation.process(
    mon_lib_srv              = server.server(),
    ener_lib                 = server.ener_lib(),
    raw_records              = flex.std_string(pdb_str_1.splitlines()),
    strict_conflict_handling = True,
    force_symmetry           = True,
    log                      = None)
  grm = processed_pdb_file.geometry_restraints_manager()
  pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  sites_cart = pdb_hierarchy.atoms().extract_xyz()
  # 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
コード例 #13
0
ファイル: utils.py プロジェクト: cctbx/cctbx-playground
def get_reference_dihedral_proxies(
      reference_hierarchy_list,
      reference_file_list,
      mon_lib_srv=None,
      ener_lib=None,
      crystal_symmetry=None,
      log=None):
  from mmtbx.monomer_library import server
  if log is None:
    log = sys.stdout
  if mon_lib_srv is None:
    mon_lib_srv = server.server()
  if ener_lib is None:
    ener_lib = server.ener_lib()
  reference_dihedral_proxies = {}
  for file_name, pdb_hierarchy in zip(reference_file_list,
                                      reference_hierarchy_list):
    dihedral_proxies = get_complete_dihedral_proxies(
                         pdb_hierarchy=pdb_hierarchy,
                         mon_lib_srv=mon_lib_srv,
                         ener_lib=ener_lib,
                         crystal_symmetry=crystal_symmetry,
                         log=log)
    reference_dihedral_proxies[file_name]=dihedral_proxies
  return reference_dihedral_proxies
コード例 #14
0
def run(args, out=sys.stdout, quiet=False):
  from mmtbx.monomer_library import pdb_interpretation
  from mmtbx.monomer_library import server
  import iotbx.pdb
  cmdline = iotbx.phil.process_command_line_with_files(
    args=args,
    master_phil=get_master_phil(),
    pdb_file_def="model",
    usage_string=usage_string)
  params = cmdline.work.extract()
  if (params.model is None):
    raise Usage(usage_string)
  pdb_in = iotbx.pdb.input(source_info=params.model, file_name=params.model)
  mon_lib_srv = server.server()
  ener_lib = server.ener_lib()
  processed_pdb_file = pdb_interpretation.process(
    mon_lib_srv=mon_lib_srv,
    ener_lib=ener_lib,
    pdb_inp=pdb_in,
    substitute_non_crystallographic_unit_cell_if_necessary=True)
  pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  geometry = processed_pdb_file.geometry_restraints_manager()
  result = rna_validation(
    pdb_hierarchy=pdb_hierarchy,
    geometry_restraints_manager=geometry,
    params=params,
    outliers_only=params.outliers_only)
  result.show(out=out)
  return result
コード例 #15
0
ファイル: mcl.py プロジェクト: oliserand/cctbx_project
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
コード例 #16
0
def exercise():
    verbose = "--verbose" in sys.argv[1:]
    list_cif = server.mon_lib_list_cif()
    srv = server.server(list_cif=list_cif)
    open("tmp.cif", "w").write(tmp_cif)
    srv.process_cif(file_name="tmp.cif")
    comp_comp_id = srv.get_comp_comp_id_direct(comp_id="tst")
    motif = comp_comp_id.as_geometry_restraints_motif()
    out = StringIO()
    motif.show(out=out)
    if (verbose): sys.stdout.write(out.getvalue())
    assert not show_diff(out.getvalue(), expected_out_tst_comp)
    for link_link_id in srv.link_link_id_list:
        out = StringIO()
        link_link_id.as_geometry_restraints_motif_manipulation().show(out=out)
        if (verbose): sys.stdout.write(out.getvalue())
        if (link_link_id.chem_link.id == "tst_lnk"):
            assert not show_diff(out.getvalue(), expected_out_tst_lnk)
    for mod_mod_id in srv.mod_mod_id_list:
        out = StringIO()
        mod_mod_id.as_geometry_restraints_motif_manipulation().show(out=out)
        if (verbose): sys.stdout.write(out.getvalue())
        if (mod_mod_id.chem_mod.id == "tst_mod"):
            assert not show_diff(out.getvalue(), expected_out_tst_mod)
    print "OK"
コード例 #17
0
def exercise_3():
    pdb_raw = """\
ATOM      1  CA  GLY A   1      -0.227   9.888 -15.197  1.00 54.04           C
ATOM      2  CA  GLY A   2      -0.227   9.888 -15.197  1.00 54.04           C
ATOM      3  CA  GLY A   3      -0.227   9.888 -15.197  1.00 54.04           C
ATOM      4  CA  GLY A   4      -0.227   9.888 -15.197  1.00 54.04           C
ATOM      5  CA  GLY A   5      -0.227   9.888 -15.197  1.00 54.04           C
ATOM      6  CA  GLY A   6      -0.227   9.888 -15.197  1.00 54.04           C
ATOM      7  CA  GLY A   7      -0.227   9.888 -15.197  1.00 54.04           C
ATOM      8  CA  GLY A   8      -0.227   9.888 -15.197  1.00 54.04           C
ATOM      9  CA  GLY A   9      -0.227   9.888 -15.197  1.00 54.04           C
ATOM     10  CA  GLY A  10      -0.227   9.888 -15.197  1.00 54.04           C
HETATM   11  N   SEP A  11      -2.112   0.368  -0.991  1.00 20.00      A    N
HETATM   12  CA  SEP A  11      -0.692   0.284  -0.951  1.00 20.00      A    C
HETATM   13  CB  SEP A  11      -0.234   0.166   0.485  1.00 20.00      A    C
HETATM   14  OG  SEP A  11       1.130  -0.184   0.515  1.00 20.00      A    O
HETATM   15  C   SEP A  11      -0.237  -0.930  -1.727  1.00 20.00      A    C
HETATM   16  O   SEP A  11      -0.767  -2.051  -1.509  1.00 20.00      A    O
HETATM   18  P   SEP A  11       1.922  -0.008   1.871  1.00 20.00      A    P
HETATM   19  O1P SEP A  11       2.139   1.462   2.140  1.00 20.00      A    O
HETATM   20  O2P SEP A  11       3.259  -0.703   1.767  1.00 20.00      A    O-1
HETATM   21  O3P SEP A  11       1.127  -0.614   3.002  1.00 20.00      A    O-1
END"""
    mon_lib_srv = server.server()
    ener_lib = server.ener_lib()
    pdb_in = iotbx.pdb.hierarchy.input(pdb_string=pdb_raw)
    xrs = pdb_in.input.xray_structure_simple()
    processed_pdb_file = pdb_interpretation.process(
        mon_lib_srv=mon_lib_srv,
        ener_lib=ener_lib,
        raw_records=pdb_in.hierarchy.as_pdb_string(crystal_symmetry=xrs),
        crystal_symmetry=xrs,
        log=null_out())
    pdb_in.hierarchy.atoms().reset_i_seq()
    ligand_sel = pdb_in.hierarchy.atom_selection_cache().selection(
        "resname SEP")
    mstats = model_properties.model_statistics(
        pdb_hierarchy=pdb_in.hierarchy,
        xray_structure=xrs,
        all_chain_proxies=processed_pdb_file.all_chain_proxies,
        ligand_selection=ligand_sel,
        ignore_hd=True)
    out = StringIO()
    mstats.show(out=out)
    assert (mstats.n_protein == 10)
    assert ("Ligands:" in out.getvalue())
    assert approx_equal(mstats.macromolecules.b_mean, 54.04)
    # now with just the raw selection string
    mstats = model_properties.model_statistics(
        pdb_hierarchy=pdb_in.hierarchy,
        xray_structure=xrs,
        all_chain_proxies=processed_pdb_file.all_chain_proxies,
        ligand_selection="resname SEP",
        ignore_hd=True)
    out = StringIO()
    mstats.show(out=out)
    assert (mstats.n_protein == 10)
    assert ("Ligands:" in out.getvalue())
コード例 #18
0
    def create_all_new_restraints(self, pdb_hierarchy, grm, log=sys.stdout):

        # initialize cache and monomer library server for underlying procedures
        if self.mon_lib_srv is None:
            from mmtbx.monomer_library import server
            self.mon_lib_srv = server.server()
        plane_cache = {}

        t0 = time.time()
        proteins_hbonds, prot_angle_proxies = self.create_protein_hbond_proxies(
            log=log, annotation=self.actual_sec_str)
        t1 = time.time()
        # print >> log, "    Time for creating protein proxies:%f" % (t1-t0)
        stacking_proxies = nucleic_acids.get_stacking_proxies(
            pdb_hierarchy=pdb_hierarchy,
            stacking_phil_params=self.params.secondary_structure.\
                nucleic_acid.stacking_pair,
            grm=grm,
            mon_lib_srv=self.mon_lib_srv,
            plane_cache=plane_cache)
        t2 = time.time()
        # print >> log, "    Time for creating stacking proxies:%f" % (t2-t1)
        (hb_bond_proxies, hb_angle_proxies, planarity_bp_proxies,
          parallelity_bp_proxies) = nucleic_acids.get_basepair_proxies(
              pdb_hierarchy=pdb_hierarchy,
              bp_phil_params=self.params.secondary_structure.nucleic_acid.base_pair,
              grm=grm,
              mon_lib_srv=self.mon_lib_srv,
              plane_cache=plane_cache,
              hbond_distance_cutoff=self.params.secondary_structure.\
                nucleic_acid.hbond_distance_cutoff,
              scale_bonds_sigma=self.params.secondary_structure.\
                nucleic_acid.scale_bonds_sigma)
        t4 = time.time()
        # print >> log, "    Time for creating basepair proxies (hbond, angle, planarity):%f" % (t4-t2)
        self.stats = {
            'n_protein_hbonds': 0,
            'n_na_hbonds': 0,
            'n_na_hbond_angles': 0,
            'n_na_basepairs': 0,
            'n_na_stacking_pairs': 0
        }
        print("    Restraints generated for nucleic acids:", file=log)
        print("      %d hydrogen bonds" % len(hb_bond_proxies), file=log)
        print("      %d hydrogen bond angles" % len(hb_angle_proxies),
              file=log)
        print("      %d basepair planarities" % len(planarity_bp_proxies),
              file=log)
        print("      %d basepair parallelities" % len(parallelity_bp_proxies),
              file=log)
        print("      %d stacking parallelities" % len(stacking_proxies),
              file=log)
        all_hbonds = proteins_hbonds.deep_copy()
        all_hbonds.extend(hb_bond_proxies)
        all_angle = prot_angle_proxies.deep_copy()
        all_angle.extend(hb_angle_proxies)
        return (all_hbonds, all_angle, planarity_bp_proxies,
                parallelity_bp_proxies + stacking_proxies)
コード例 #19
0
def run(args, residue_type, expected_results):
  verbose = "--verbose" in args
  debug = "--debug" in args
  pdb_files = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/%s_pdb_files" % residue_type,
    test=os.path.isdir)
  if (pdb_files is None):
    print "Skipping tst_%s_interpretation: input files not available" \
      % residue_type
    return
  mon_lib_srv = server.server()
  ener_lib = server.ener_lib()
  for file_name in os.listdir(pdb_files):
    if (file_name[-4:] not in [".ent", ".pdb"]): continue
    if (verbose):
      log = sys.stdout
    else:
      log = null_out()
    processed_pdb_file = pdb_interpretation.process(
      mon_lib_srv=mon_lib_srv,
      ener_lib=ener_lib,
      file_name=os.path.join(pdb_files, file_name),
      log=log)
    for mm in processed_pdb_file.all_chain_proxies.all_monomer_mappings:
      residue_name = mm.residue_name
      if (mm.classification == "RNA"):
        for c in ["2", "3"]:
          expected_mod = "%rna"+c+"p_pur"
          if (mm.residue_name.find(expected_mod) > 0):
            residue_name = mm.residue_name.replace(expected_mod, "")
            break
          expected_mod = "%rna"+c+"p_pyr"
          if (mm.residue_name.find(expected_mod) > 0):
            residue_name = mm.residue_name.replace(expected_mod, "")
            break
      assert len(mm.duplicate_atoms) == 0
      assert len(mm.ignored_atoms) == 0
      assert not mm.is_unusual
      unexpected_names = [atom.name for atom in mm.unexpected_atoms]
      result = [
        residue_name,
        len(mm.expected_atoms),
        unexpected_names,
        mm.classification,
        mm.is_terminus,
        mm.incomplete_info]
      key = file_name[:-4]
      if (debug):
        print '"%s":' % key
        print " ", str(result)+","
        print " ", str(expected_results[key])+","
      if (expected_results is not None):
        assert result == expected_results[key], "%s not %s" % (
          result,
          expected_results[key],
          )
  print "OK"
コード例 #20
0
def exercise () :
  from mmtbx.building.alternate_conformations import conformer_generation
  from mmtbx.monomer_library import server
  import iotbx.pdb.hierarchy
  generate_inputs()
  params = master_phil().extract()
  mon_lib_srv = server.server()
  pdb_in = iotbx.pdb.hierarchy.input(file_name="shear_frag_single.pdb")
  hierarchy = pdb_in.hierarchy
  pdb_atoms = hierarchy.atoms()
  pdb_atoms.reset_i_seq()
  sites_cart = pdb_atoms.extract_xyz()
  xrs = pdb_in.input.xray_structure_simple()
  models = []
  prev_res = next_res = next_next_res = None
  for chain in hierarchy.only_model().chains() :
    residue_groups = chain.residue_groups()
    n_rg = len(residue_groups) # should be 4
    for i_res, residue_group in enumerate(residue_groups) :
      sites_orig = sites_cart.deep_copy()
      next_res = next_next_res = None
      if (i_res < (n_rg - 1)) :
        next_res = residue_groups[i_res+1].atom_groups()[0]
      if (i_res < (n_rg - 2)) :
        next_next_res = residue_groups[i_res+2].atom_groups()[0]
      atom_groups = residue_group.atom_groups()
      primary_conf = atom_groups[0]
      out = StringIO()
      confs = []
      for conf in conformer_generation.generate_single_residue_confs(
        atom_group=primary_conf,
        sites_cart=sites_cart.deep_copy(),
        mon_lib_srv=mon_lib_srv,
        params=params.torsion_search,
        prev_residue=prev_res,
        next_residue=next_res,
        next_next_residue=next_next_res,
        backrub=False,
        shear=True) :
          conf.show_summary(out=out)
          confs.append(conf)
      prev_res = primary_conf
      if (confs is None) :
        continue
      if (i_res == 1) :
        assert ("""  A ILE   7     None     4.0      mt""")
      for conf in confs :
        sites_new = sites_cart.set_selected(conf.sites_selection,
          conf.sites_selected())
        pdb_atoms.set_xyz(sites_new)
        models.append(hierarchy.only_model().detached_copy())
  new_hierarchy = iotbx.pdb.hierarchy.root()
  for i_model, conf in enumerate(models) :
    conf.id = str(i_model + 1)
    new_hierarchy.append_model(conf)
  open("shear_frag_naive_ensemble.pdb", "w").write(
    new_hierarchy.as_pdb_string())
コード例 #21
0
def run(args, residue_type, expected_results):
    verbose = "--verbose" in args
    debug = "--debug" in args
    pdb_files = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/%s_pdb_files" % residue_type,
        test=os.path.isdir)
    if (pdb_files is None):
        print "Skipping tst_%s_interpretation: input files not available" \
          % residue_type
        return
    mon_lib_srv = server.server()
    ener_lib = server.ener_lib()
    for file_name in os.listdir(pdb_files):
        if (file_name[-4:] not in [".ent", ".pdb"]): continue
        if (verbose):
            log = sys.stdout
        else:
            log = null_out()
        processed_pdb_file = pdb_interpretation.process(
            mon_lib_srv=mon_lib_srv,
            ener_lib=ener_lib,
            file_name=os.path.join(pdb_files, file_name),
            log=log)
        for mm in processed_pdb_file.all_chain_proxies.all_monomer_mappings:
            residue_name = mm.residue_name
            if (mm.classification == "RNA"):
                for c in ["2", "3"]:
                    expected_mod = "%rna" + c + "p_pur"
                    if (mm.residue_name.find(expected_mod) > 0):
                        residue_name = mm.residue_name.replace(
                            expected_mod, "")
                        break
                    expected_mod = "%rna" + c + "p_pyr"
                    if (mm.residue_name.find(expected_mod) > 0):
                        residue_name = mm.residue_name.replace(
                            expected_mod, "")
                        break
            assert len(mm.duplicate_atoms) == 0
            assert len(mm.ignored_atoms) == 0
            assert not mm.is_unusual
            unexpected_names = [atom.name for atom in mm.unexpected_atoms]
            result = [
                residue_name,
                len(mm.expected_atoms), unexpected_names, mm.classification,
                mm.is_terminus, mm.incomplete_info
            ]
            key = file_name[:-4]
            if (debug):
                print '"%s":' % key
                print " ", str(result) + ","
                print " ", str(expected_results[key]) + ","
            if (expected_results is not None):
                assert result == expected_results[key], "%s not %s" % (
                    result,
                    expected_results[key],
                )
    print "OK"
コード例 #22
0
def exercise_3 () :
  pdb_raw = """\
ATOM      1  CA  GLY A   1      -0.227   9.888 -15.197  1.00 54.04           C
ATOM      2  CA  GLY A   2      -0.227   9.888 -15.197  1.00 54.04           C
ATOM      3  CA  GLY A   3      -0.227   9.888 -15.197  1.00 54.04           C
ATOM      4  CA  GLY A   4      -0.227   9.888 -15.197  1.00 54.04           C
ATOM      5  CA  GLY A   5      -0.227   9.888 -15.197  1.00 54.04           C
ATOM      6  CA  GLY A   6      -0.227   9.888 -15.197  1.00 54.04           C
ATOM      7  CA  GLY A   7      -0.227   9.888 -15.197  1.00 54.04           C
ATOM      8  CA  GLY A   8      -0.227   9.888 -15.197  1.00 54.04           C
ATOM      9  CA  GLY A   9      -0.227   9.888 -15.197  1.00 54.04           C
ATOM     10  CA  GLY A  10      -0.227   9.888 -15.197  1.00 54.04           C
HETATM   11  N   SEP A  11      -2.112   0.368  -0.991  1.00 20.00      A    N
HETATM   12  CA  SEP A  11      -0.692   0.284  -0.951  1.00 20.00      A    C
HETATM   13  CB  SEP A  11      -0.234   0.166   0.485  1.00 20.00      A    C
HETATM   14  OG  SEP A  11       1.130  -0.184   0.515  1.00 20.00      A    O
HETATM   15  C   SEP A  11      -0.237  -0.930  -1.727  1.00 20.00      A    C
HETATM   16  O   SEP A  11      -0.767  -2.051  -1.509  1.00 20.00      A    O
HETATM   18  P   SEP A  11       1.922  -0.008   1.871  1.00 20.00      A    P
HETATM   19  O1P SEP A  11       2.139   1.462   2.140  1.00 20.00      A    O
HETATM   20  O2P SEP A  11       3.259  -0.703   1.767  1.00 20.00      A    O-1
HETATM   21  O3P SEP A  11       1.127  -0.614   3.002  1.00 20.00      A    O-1
END"""
  mon_lib_srv = server.server()
  ener_lib = server.ener_lib()
  pdb_in = iotbx.pdb.hierarchy.input(pdb_string=pdb_raw)
  xrs = pdb_in.input.xray_structure_simple()
  processed_pdb_file = pdb_interpretation.process(
    mon_lib_srv=mon_lib_srv,
    ener_lib=ener_lib,
    raw_records=pdb_in.hierarchy.as_pdb_string(crystal_symmetry=xrs),
    crystal_symmetry=xrs,
    log=null_out())
  pdb_in.hierarchy.atoms().reset_i_seq()
  ligand_sel = pdb_in.hierarchy.atom_selection_cache().selection("resname SEP")
  mstats = model_properties.model_statistics(
    pdb_hierarchy=pdb_in.hierarchy,
    xray_structure=xrs,
    all_chain_proxies=processed_pdb_file.all_chain_proxies,
    ligand_selection=ligand_sel,
    ignore_hd=True)
  out = StringIO()
  mstats.show(out=out)
  assert (mstats.n_protein == 10)
  assert ("Ligands:" in out.getvalue())
  assert approx_equal(mstats.macromolecules.b_mean, 54.04)
  # now with just the raw selection string
  mstats = model_properties.model_statistics(
    pdb_hierarchy=pdb_in.hierarchy,
    xray_structure=xrs,
    all_chain_proxies=processed_pdb_file.all_chain_proxies,
    ligand_selection="resname SEP",
    ignore_hd=True)
  out = StringIO()
  mstats.show(out=out)
  assert (mstats.n_protein == 10)
  assert ("Ligands:" in out.getvalue())
コード例 #23
0
  def create_all_new_restraints(self,
      pdb_hierarchy,
      grm,
      log=sys.stdout):

    # initialize cache and monomer library server for underlying procedures
    if self.mon_lib_srv is None:
      from mmtbx.monomer_library import server
      self.mon_lib_srv = server.server()
    plane_cache = {}

    t0 = time.time()
    proteins_hbonds = self.create_protein_hbond_proxies(
        log=log,
        annotation=self.actual_sec_str)
    t1 = time.time()
    # print >> log, "    Time for creating protein proxies:%f" % (t1-t0)
    stacking_proxies = nucleic_acids.get_stacking_proxies(
        pdb_hierarchy=pdb_hierarchy,
        stacking_phil_params=self.params.secondary_structure.\
            nucleic_acid.stacking_pair,
        grm=grm,
        mon_lib_srv=self.mon_lib_srv,
        plane_cache=plane_cache)
    t2 = time.time()
    # print >> log, "    Time for creating stacking proxies:%f" % (t2-t1)
    planarity_bp_proxies, parallelity_bp_proxies = nucleic_acids.\
        get_basepair_plane_proxies(
        pdb_hierarchy=pdb_hierarchy,
        bp_phil_params=self.params.secondary_structure.nucleic_acid.base_pair,
        grm=grm,
        mon_lib_srv=self.mon_lib_srv,
        plane_cache=plane_cache)
    t3 = time.time()
    # print >> log, "    Time for creating planar/parall proxies:%f" % (t3-t2)
    hb_bond_proxies, hb_angle_proxies = nucleic_acids.\
        get_basepair_hbond_proxies(
        pdb_hierarchy=pdb_hierarchy,
        bp_phil_params=self.params.secondary_structure.nucleic_acid.base_pair,
        hbond_distance_cutoff=self.params.secondary_structure.\
            nucleic_acid.hbond_distance_cutoff)
    t4 = time.time()
    # print >> log, "    Time for creating hbond-angle proxies:%f" % (t4-t3)
    self.stats = {'n_protein_hbonds':0, 'n_na_hbonds':0, 'n_na_hbond_angles':0,
        'n_na_basepairs':0, 'n_na_stacking_pairs':0}
    print >> log, "    Restraints generated for nucleic acids:"
    print >> log, "      %d hydrogen bonds" % len(hb_bond_proxies)
    print >> log, "      %d hydrogen bond angles" % len(hb_angle_proxies)
    print >> log, "      %d basepair planarities" % len(planarity_bp_proxies)
    print >> log, "      %d basepair parallelities" % len(parallelity_bp_proxies)
    print >> log, "      %d stacking parallelities" % len(stacking_proxies)
    all_hbonds = proteins_hbonds.deep_copy()
    all_hbonds.extend(hb_bond_proxies)
    return (all_hbonds, hb_angle_proxies,
        planarity_bp_proxies, parallelity_bp_proxies+stacking_proxies)
コード例 #24
0
def exercise():
    list_cif = server.mon_lib_list_cif()
    srv = server.server(list_cif=list_cif)
    print("srv.root_path:", srv.root_path)
    table_of_contents = []
    n_get_comp_comp_id_successes = 0
    unknown_type_energy_counts = dict_with_default_0()
    missing_angle_definitions_counts = dict_with_default_0()
    missing_bond_values_counts = dict_with_default_0()
    missing_angle_values_counts = dict_with_default_0()
    for first_char in string.lowercase + string.digits:
        sub_dir = os.path.join(srv.root_path, first_char)
        if (not os.path.isdir(sub_dir)): continue
        for node in os.listdir(sub_dir):
            if (not node.lower().endswith(".cif")): continue
            comp_id = node[:-4]
            if (comp_id.endswith("_EL")): continue
            if (comp_id in ["CON_CON", "PRN_PRN"]):
                comp_id = comp_id[:3]
            if (comp_id.upper() != comp_id):
                print("Mixed case:", os.path.join(first_char, node))
            comp_comp_id = srv.get_comp_comp_id_direct(comp_id=comp_id)
            if (comp_comp_id is None):
                print("Error instantiating comp_comp_id %s (%s)" %
                      (comp_id, os.path.join(sub_dir, node)))
            else:
                n_get_comp_comp_id_successes += 1
                table_of_contents.append(" ".join(
                    [comp_id.upper(),
                     os.path.join(first_char, node)]))
                status = detect_unknown_type_energy(comp_id=comp_id,
                                                    comp_comp_id=comp_comp_id)
                unknown_type_energy_counts[status] += 1
                status = detect_missing_angle_definitions(
                    comp_id=comp_id, comp_comp_id=comp_comp_id)
                missing_angle_definitions_counts[status] += 1
                status = detect_missing_bond_values(comp_id=comp_id,
                                                    comp_comp_id=comp_comp_id)
                missing_bond_values_counts[status] += 1
                status = detect_missing_angle_values(comp_id=comp_id,
                                                     comp_comp_id=comp_comp_id)
                missing_angle_values_counts[status] += 1
                if (1 and status != "ok"):
                    print('svn rm "%s"' % os.path.join(first_char, node))
    print("number of cif files read successfully:",
          n_get_comp_comp_id_successes)
    print("unknown type_energy counts:", unknown_type_energy_counts)
    print("missing bond angle definitions counts:", \
      missing_angle_definitions_counts)
    print("missing bond values counts:", missing_bond_values_counts)
    print("missing angle values counts:", missing_angle_values_counts)
    print("writing file table_of_contents")
    open("table_of_contents", "w").write("\n".join(table_of_contents) + "\n")
コード例 #25
0
 def initialize(self, prefix):
   if (self.log is None) : self.log = sys.stdout
   if(len(self.args)==0):
     self.format_usage_message()
   parsed = self.master_params()
   self.inputs = mmtbx.utils.process_command_line_args(args = self.args,
     master_params = parsed)
   self.params = self.inputs.params.extract()
   if(self.params.silent): self.log = StringIO()
   broadcast(m=prefix, log = self.log)
   self.inputs.params.show(prefix="  ", out=self.log)
   if(len(self.args)==0): sys.exit(0)
   self.mon_lib_srv = server.server()
コード例 #26
0
def exercise():
  list_cif = server.mon_lib_list_cif()
  srv = server.server(list_cif=list_cif)
  print "srv.root_path:", srv.root_path
  table_of_contents = []
  n_get_comp_comp_id_successes = 0
  unknown_type_energy_counts = dict_with_default_0()
  missing_angle_definitions_counts = dict_with_default_0()
  missing_bond_values_counts = dict_with_default_0()
  missing_angle_values_counts = dict_with_default_0()
  for first_char in string.lowercase+string.digits:
    sub_dir = os.path.join(srv.root_path, first_char)
    if (not os.path.isdir(sub_dir)): continue
    for node in os.listdir(sub_dir):
      if (not node.lower().endswith(".cif")): continue
      comp_id = node[:-4]
      if (comp_id.endswith("_EL")): continue
      if (comp_id in ["CON_CON", "PRN_PRN"]):
        comp_id = comp_id[:3]
      if (comp_id.upper() != comp_id):
        print "Mixed case:", os.path.join(first_char, node)
      comp_comp_id = srv.get_comp_comp_id_direct(comp_id=comp_id)
      if (comp_comp_id is None):
        print "Error instantiating comp_comp_id %s (%s)" % (
          comp_id, os.path.join(sub_dir, node))
      else:
        n_get_comp_comp_id_successes += 1
        table_of_contents.append(
          " ".join([comp_id.upper(), os.path.join(first_char, node)]))
        status = detect_unknown_type_energy(
          comp_id=comp_id, comp_comp_id=comp_comp_id)
        unknown_type_energy_counts[status] += 1
        status = detect_missing_angle_definitions(
          comp_id=comp_id, comp_comp_id=comp_comp_id)
        missing_angle_definitions_counts[status] += 1
        status = detect_missing_bond_values(
          comp_id=comp_id, comp_comp_id=comp_comp_id)
        missing_bond_values_counts[status] += 1
        status = detect_missing_angle_values(
          comp_id=comp_id, comp_comp_id=comp_comp_id)
        missing_angle_values_counts[status] += 1
        if (1 and status != "ok"):
          print 'svn rm "%s"' % os.path.join(first_char, node)
  print "number of cif files read successfully:", n_get_comp_comp_id_successes
  print "unknown type_energy counts:", unknown_type_energy_counts
  print "missing bond angle definitions counts:", \
    missing_angle_definitions_counts
  print "missing bond values counts:", missing_bond_values_counts
  print "missing angle values counts:", missing_angle_values_counts
  print "writing file table_of_contents"
  open("table_of_contents", "w").write("\n".join(table_of_contents)+"\n")
コード例 #27
0
def reprocess_pdb(pdb_hierarchy, crystal_symmetry, cif_objects, out):
    from mmtbx.monomer_library import pdb_interpretation
    from mmtbx.monomer_library import server
    mon_lib_srv = server.server()
    ener_lib = server.ener_lib()
    for cif_object in cif_objects:
        for srv in [mon_lib_srv, ener_lib]:
            srv.process_cif_object(cif_object=cif_object)
    return pdb_interpretation.process(mon_lib_srv=mon_lib_srv,
                                      ener_lib=ener_lib,
                                      raw_records=pdb_hierarchy.as_pdb_string(
                                          crystal_symmetry=crystal_symmetry),
                                      crystal_symmetry=crystal_symmetry,
                                      log=out)
コード例 #28
0
ファイル: __init__.py プロジェクト: keitaroyam/cctbx_fork
def reprocess_pdb (pdb_hierarchy, crystal_symmetry, cif_objects, out) :
  from mmtbx.monomer_library import pdb_interpretation
  from mmtbx.monomer_library import server
  mon_lib_srv = server.server()
  ener_lib = server.ener_lib()
  for cif_object in cif_objects :
    for srv in [mon_lib_srv, ener_lib]:
      srv.process_cif_object(cif_object=cif_object)
  return pdb_interpretation.process(
    mon_lib_srv=mon_lib_srv,
    ener_lib=ener_lib,
    raw_records=pdb_hierarchy.as_pdb_string(crystal_symmetry=crystal_symmetry),
    crystal_symmetry=crystal_symmetry,
    log=out)
コード例 #29
0
def get_pdb_inputs(pdb_str):
    processed_pdb_file = pdb_interpretation.process(
        mon_lib_srv=server.server(),
        ener_lib=server.ener_lib(),
        raw_records=flex.std_string(pdb_str.splitlines()),
        strict_conflict_handling=True,
        force_symmetry=True,
        log=None)
    xrs = processed_pdb_file.xray_structure(show_summary=False)
    geometry_restraints_manager = geometry_minimization.\
        get_geometry_restraints_manager(processed_pdb_file, xrs)
    pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
    return group_args(ph=pdb_hierarchy,
                      grm=geometry_restraints_manager,
                      xrs=xrs)
コード例 #30
0
def get_pdb_inputs(pdb_str):
  processed_pdb_file = pdb_interpretation.process(
    mon_lib_srv              = server.server(),
    ener_lib                 = server.ener_lib(),
    raw_records              = flex.std_string(pdb_str.splitlines()),
    strict_conflict_handling = True,
    force_symmetry           = True,
    log                      = None)
  xrs = processed_pdb_file.xray_structure(show_summary = False)
  geometry_restraints_manager = geometry_minimization.\
      get_geometry_restraints_manager(processed_pdb_file, xrs)
  pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  return group_args(
    ph  = pdb_hierarchy,
    grm = geometry_restraints_manager,
    xrs = xrs)
コード例 #31
0
ファイル: utils.py プロジェクト: cctbx/cctbx-playground
def get_complete_dihedral_proxies(
      pdb_hierarchy=None,
      file_name=None,
      raw_records=None,
      mon_lib_srv=None,
      ener_lib=None,
      crystal_symmetry=None,
      log=None):
  #
  # This function is called only for reference files, that were not processed
  # yet. For the main file only get_dihedrals_and_phi_psi below is called.
  #
  assert [pdb_hierarchy,
          file_name,
          raw_records].count(None) == 2
  from mmtbx.monomer_library import server, pdb_interpretation
  import cStringIO
  if log is None:
    log = sys.stdout
  if mon_lib_srv is None:
    mon_lib_srv = server.server()
  if ener_lib is None:
    ener_lib = server.ener_lib()
  if pdb_hierarchy is not None:
    raw_records = pdb_hierarchy.as_pdb_string()
  if raw_records is not None:
    if (isinstance(raw_records, str)):
      raw_records = flex.split_lines(raw_records)
  work_params = pdb_interpretation.master_params.extract()
  work_params.c_beta_restraints=False
  work_params.automatic_linking.link_none=True
  work_params.clash_guard.nonbonded_distance_threshold = None

  processed_pdb_file_local = \
    pdb_interpretation.process(
      mon_lib_srv=mon_lib_srv,
      ener_lib=ener_lib,
      params=work_params,
      file_name=file_name,
      raw_records=raw_records,
      strict_conflict_handling=False,
      crystal_symmetry=crystal_symmetry,
      force_symmetry=True,
      log=cStringIO.StringIO(),
      substitute_non_crystallographic_unit_cell_if_necessary=True)
  return get_dihedrals_and_phi_psi(processed_pdb_file_local)
コード例 #32
0
def get_mstats(pdb_raw):
    mon_lib_srv = server.server()
    ener_lib = server.ener_lib()
    pdb_in = iotbx.pdb.hierarchy.input(pdb_string=pdb_raw)
    xrs = pdb_in.input.xray_structure_simple()
    processed_pdb_file = pdb_interpretation.process(
        mon_lib_srv=mon_lib_srv,
        ener_lib=ener_lib,
        raw_records=pdb_in.hierarchy.as_pdb_string(crystal_symmetry=xrs),
        crystal_symmetry=xrs,
        log=null_out())
    pdb_in.hierarchy.atoms().reset_i_seq()
    mstats = model_properties.model_statistics(
        pdb_hierarchy=pdb_in.hierarchy,
        xray_structure=xrs,
        all_chain_proxies=processed_pdb_file.all_chain_proxies,
        ignore_hd=True)
    return mstats
コード例 #33
0
 def __init__(self, pdb_file_name=None, raw_records=None):
     # assert count(pdb_file_name, raw_records)==1
     if pdb_file_name:
         self.pdb_inp = iotbx.pdb.input(file_name=pdb_file_name)
     else:
         self.pdb_inp = iotbx.pdb.input(lines=raw_records,
                                        source_info='raw_records')
     self.hierarchy = self.pdb_inp.construct_hierarchy()
     self.mon_lib_srv = server.server()
     self.ener_lib = server.ener_lib()
     self.processed_pdb = pdb_interpretation.process(
         self.mon_lib_srv,
         self.ener_lib,
         file_name=pdb_file_name,
         raw_records=raw_records)
     self.geometry_restraints_manager = self.processed_pdb.geometry_restraints_manager(
     )
     self.atom_elements = {}
コード例 #34
0
def get_complete_dihedral_proxies(
      pdb_hierarchy=None,
      file_name=None,
      raw_records=None,
      mon_lib_srv=None,
      ener_lib=None,
      crystal_symmetry=None,
      restraint_objects=None,
      monomer_parameters=None,
      log=None):
  #
  # This function is called only for reference files, that were not processed
  # yet. For the main file only get_dihedrals_and_phi_psi below is called.
  # Still used for reference model torsion restraints
  #
  import mmtbx.model
  assert [pdb_hierarchy,
          file_name,
          raw_records].count(None) == 2
  from mmtbx.monomer_library import server, pdb_interpretation
  if log is None:
    log = sys.stdout
  if mon_lib_srv is None:
    mon_lib_srv = server.server()
  if ener_lib is None:
    ener_lib = server.ener_lib()
  if pdb_hierarchy is not None:
    raw_records = pdb_hierarchy.as_pdb_string()
  if raw_records is not None:
    if (isinstance(raw_records, str)):
      raw_records = flex.split_lines(raw_records)
  work_params = mmtbx.model.manager.get_default_pdb_interpretation_params()
  work_params.pdb_interpretation.c_beta_restraints=False
  work_params.pdb_interpretation.automatic_linking.link_none=True
  work_params.pdb_interpretation.clash_guard.nonbonded_distance_threshold = None
  pdb_inp = input(lines=raw_records, source_info=None)
  model = mmtbx.model.manager(
      model_input = pdb_inp,
      build_grm = True,
      pdb_interpretation_params=work_params,
      restraint_objects=restraint_objects,
      monomer_parameters=monomer_parameters,
      log=null_out())
  return get_dihedrals_and_phi_psi(model)
コード例 #35
0
def get_complete_dihedral_proxies(pdb_hierarchy=None,
                                  file_name=None,
                                  raw_records=None,
                                  mon_lib_srv=None,
                                  ener_lib=None,
                                  crystal_symmetry=None,
                                  log=None):
    #
    # This function is called only for reference files, that were not processed
    # yet. For the main file only get_dihedrals_and_phi_psi below is called.
    # Still used for reference model torsion restraints
    #
    assert [pdb_hierarchy, file_name, raw_records].count(None) == 2
    from mmtbx.monomer_library import server, pdb_interpretation
    import cStringIO
    if log is None:
        log = sys.stdout
    if mon_lib_srv is None:
        mon_lib_srv = server.server()
    if ener_lib is None:
        ener_lib = server.ener_lib()
    if pdb_hierarchy is not None:
        raw_records = pdb_hierarchy.as_pdb_string()
    if raw_records is not None:
        if (isinstance(raw_records, str)):
            raw_records = flex.split_lines(raw_records)
    work_params = pdb_interpretation.master_params.extract()
    work_params.c_beta_restraints = False
    work_params.automatic_linking.link_none = True
    work_params.clash_guard.nonbonded_distance_threshold = None

    processed_pdb_file_local = \
      pdb_interpretation.process(
        mon_lib_srv=mon_lib_srv,
        ener_lib=ener_lib,
        params=work_params,
        file_name=file_name,
        raw_records=raw_records,
        strict_conflict_handling=False,
        crystal_symmetry=crystal_symmetry,
        force_symmetry=True,
        log=cStringIO.StringIO(),
        substitute_non_crystallographic_unit_cell_if_necessary=True)
    return get_dihedrals_and_phi_psi(processed_pdb_file_local)
コード例 #36
0
ファイル: test_rdl.py プロジェクト: cctbx/cctbx-playground
def get_geometry_restraints_manager(pdb_filename,
                                    #pdb_inp,
                                    #pdb_hierarchy,
                                    ):
  t0=time.time()
  from mmtbx.monomer_library import server
  from mmtbx.monomer_library import pdb_interpretation
  #lines = pdb_hierarchy.as_pdb_string(
  #  crystal_symmetry=pdb_inp.crystal_symmetry(),
  #  )
  mon_lib_srv = server.server()
  ener_lib = server.ener_lib()
  processed_pdb = pdb_interpretation.process(
    mon_lib_srv,
    ener_lib,
    #raw_records=lines,
    file_name=pdb_filename,
    )
  geometry_restraints_manager = processed_pdb.geometry_restraints_manager()
  print 'time',time.time()-t0
  return geometry_restraints_manager
コード例 #37
0
def get_geometry_restraints_manager(pdb_filename,
                                    #pdb_inp,
                                    #pdb_hierarchy,
                                    ):
    t0 = time.time()
    from mmtbx.monomer_library import server
    from mmtbx.monomer_library import pdb_interpretation
    #lines = pdb_hierarchy.as_pdb_string(
    #  crystal_symmetry=pdb_inp.crystal_symmetry(),
    #  )
    mon_lib_srv = server.server()
    ener_lib = server.ener_lib()
    processed_pdb = pdb_interpretation.process(
        mon_lib_srv,
        ener_lib,
        #raw_records=lines,
        file_name=pdb_filename,
    )
    geometry_restraints_manager = processed_pdb.geometry_restraints_manager()
    print 'time', time.time() - t0
    return geometry_restraints_manager
コード例 #38
0
 def init_afitt(self, params, pdb_hierarchy, log):
     if hasattr(params, "afitt"):
         use_afitt = params.afitt.use_afitt
         if (use_afitt):
             from mmtbx.geometry_restraints import afitt
             # this only seems to work for a single ligand
             # multiple ligands are using the monomers input
             if params.afitt.ligand_file_name is None:
                 ligand_paths = params.input.monomers.file_name
             else:
                 ligand_paths = [params.afitt.ligand_file_name]
             afitt.validate_afitt_params(params.afitt)
             ligand_names = params.afitt.ligand_names.split(',')
             if len(ligand_names) != len(ligand_paths) and len(
                     ligand_names) == 1:
                 # get restraints library instance of ligand
                 from mmtbx.monomer_library import server
                 for ligand_name in ligand_names:
                     result = server.server().get_comp_comp_id_direct(
                         ligand_name)
                     if result is not None:
                         so = result.source_info  # not the smartest way
                         if so.find("file:") == 0:
                             ligand_paths = [so.split(":")[1].strip()]
             if len(ligand_names) != len(ligand_paths):
                 raise Sorry("need restraint CIF files for each ligand")
             make_header("Initializing AFITT", out=log)
             #print >> log, "  ligands: %s" % params.afitt.ligand_file_name
             afitt_object = afitt.afitt_object(ligand_paths, ligand_names,
                                               pdb_hierarchy,
                                               params.afitt.ff,
                                               params.afitt.scale)
             print >> log, afitt_object
             afitt_object.check_covalent(self.geometry)
             # afitt log output
             afitt_object.initial_energies = afitt.get_afitt_energy(
                 ligand_paths, ligand_names, pdb_hierarchy, params.afitt.ff,
                 pdb_hierarchy.atoms().extract_xyz(), self.geometry)
             self.afitt_object = afitt_object
コード例 #39
0
def read_dummy_type(file_name=None, pdb_inp=None):
    assert ((file_name is not None) or (pdb_inp is not None))
    mon_lib_srv = server.server()
    ener_lib = server.ener_lib()

    if (pdb_inp is None):
        tmp_obj = pdb_interpretation.process(
            mon_lib_srv=mon_lib_srv, ener_lib=ener_lib,
            file_name=file_name).all_chain_proxies
    else:
        tmp_obj = pdb_interpretation.process(mon_lib_srv=mon_lib_srv,
                                             ener_lib=ener_lib,
                                             pdb_inp=pdb_inp).all_chain_proxies

    ats = tmp_obj.nonbonded_energy_type_registry.symbols
    els = tmp_obj.scattering_type_registry.symbols

    for i in range(ats.size()):
        if ats[i] == "":
            ats[i] = els[i]

    return ats
コード例 #40
0
ファイル: val_rna.py プロジェクト: rlabduke/PDB_mongodb
 def run_validation(self) :
   # get required elements to run:
   #   - pdb_hierarchy and geometry
   pdb_in = iotbx.pdb.input(file_name=self.pdb_file)
   mon_lib_srv = server.server()
   ener_lib = server.ener_lib()
   processed_pdb_file = pdb_interpretation.process(
     mon_lib_srv=mon_lib_srv,
     ener_lib=ener_lib,
     pdb_inp=pdb_in,
     substitute_non_crystallographic_unit_cell_if_necessary=True)
   pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
   geometry = processed_pdb_file.geometry_restraints_manager()
   #  - params
   import mmtbx.command_line.rna_validate
   params = mmtbx.command_line.rna_validate.get_master_phil().extract()
 
   # run rna_validation
   self.result = rna_validation(
     pdb_hierarchy=pdb_hierarchy,
     geometry_restraints_manager=geometry,
     params=params,
     outliers_only=False)
コード例 #41
0
def exercise_2 () :
  pdb_raw = """\
ATOM   6407  N   GLY A 388      -0.783   9.368 -16.436  1.00 51.96           N
ATOM   6408  CA  GLY A 388      -0.227   9.888 -15.197  1.00 54.04           C
ATOM   6409  C   GLY A 388      -0.637  11.320 -14.897  1.00 55.86           C
ATOM   6410  O   GLY A 388      -1.728  11.738 -15.347  1.00 56.70           O
ATOM   6411  OXT GLY A 388       0.129  12.024 -14.203  1.00 56.98           O
ATOM   6412  D   GLY A 388      -0.460   9.727 -17.309  1.00 51.44           D
ATOM   6413  HA2 GLY A 388      -0.561   9.258 -14.385  1.00 54.07           H
ATOM   6414  HA3 GLY A 388       0.843   9.835 -15.243  1.00 54.13           H
TER    6415      GLY A 388
HETATM 6416  D   D8U A 401     -12.236 -13.695 -42.992  1.00 15.23           D
HETATM 6417  O   DOD A1001      -4.151  -5.107 -38.592  1.00 13.40           O
HETATM 6418  D1  DOD A1001      -4.760  -5.026 -39.326  1.00 15.45           D
HETATM 6419  D2  DOD A1001      -4.625  -4.741 -37.845  1.00 14.81           D
"""
  mon_lib_srv = server.server()
  ener_lib = server.ener_lib()
  pdb_in = iotbx.pdb.hierarchy.input(pdb_string=pdb_raw)
  xrs = pdb_in.input.xray_structure_simple()
  processed_pdb_file = pdb_interpretation.process(
    mon_lib_srv=mon_lib_srv,
    ener_lib=ener_lib,
    raw_records=pdb_in.hierarchy.as_pdb_string(crystal_symmetry=xrs),
    crystal_symmetry=xrs,
    log=null_out())
  pdb_in.hierarchy.atoms().reset_i_seq()
  mstats = model_properties.model_statistics(
    pdb_hierarchy=pdb_in.hierarchy,
    xray_structure=xrs,
    all_chain_proxies=processed_pdb_file.all_chain_proxies,
    ignore_hd=True)
  out = StringIO()
  mstats.show(out=out)
  assert ("Ligands:" in out.getvalue())
  assert ("B_iso: mean =  15.2  max =  15.2  min =  15.2" in out.getvalue())
コード例 #42
0
 def initialize(self, prefix):
   if (self.log is None) : self.log = sys.stdout
   if(len(self.args)==0):
     self.format_usage_message()
   parsed = self.master_params()
   self.inputs = mmtbx.utils.process_command_line_args(args = self.args,
     master_params = parsed)
   self.params = self.inputs.params.extract()
   if(self.params.silent): self.log = StringIO()
   broadcast(m=prefix, log = self.log)
   self.inputs.params.show(prefix="  ", out=self.log)
   if(len(self.args)==0): sys.exit(0)
   self.mon_lib_srv = server.server()
   ##########################
   # adjust some parameters #
   ##########################
   if hasattr(self.params, "amber"):
     if self.params.amber.use_amber:
       self.params.pdb_interpretation.sort_atoms=False
       print >> self.log, "%s\n  %s\n%s" % (
         '-'*40,
         'Automatic sorting of atoms turned off.',
         '-'*40,
       )
コード例 #43
0
def exercise():
    verbose = "--verbose" in sys.argv[1:]
    quick = "--quick" in sys.argv[1:]
    list_cif = server.mon_lib_list_cif()
    srv = server.server(list_cif=list_cif)
    print("srv.root_path:", srv.root_path)
    default_switch = "--default_off" not in sys.argv[1:]
    if (False or default_switch):
        monomers_with_commas = {}
        atom_id_counts = dicts.with_default_value(0)
        for row_id in list_cif.cif["comp_list"]["_chem_comp.id"]:
            if (quick and random.random() < 0.95): continue
            if (verbose): print("id:", row_id)
            comp_comp_id = srv.get_comp_comp_id_direct(comp_id=row_id)
            if (comp_comp_id is None):
                print("Could not instantiating comp_comp_id(%s)" % row_id)
            else:
                has_primes = False
                has_commas = False
                for atom in comp_comp_id.atom_list:
                    atom_id_counts[atom.atom_id] += 1
                    if (atom.atom_id.find("'") >= 0):
                        has_primes = True
                    if (atom.atom_id.find(",") >= 0):
                        has_commas = True
                if (has_commas):
                    monomers_with_commas[
                        comp_comp_id.chem_comp.id] = has_primes
        print(monomers_with_commas)
        atom_ids = flex.std_string(list(atom_id_counts.keys()))
        counts = flex.size_t(list(atom_id_counts.values()))
        perm = flex.sort_permutation(data=counts, reverse=True)
        atom_ids = atom_ids.select(perm)
        counts = counts.select(perm)
        for atom_id, count in zip(atom_ids, counts):
            print(atom_id, count)
    if (False or default_switch):
        for row in list_cif.cif["comp_list"]["_chem_comp"].iterrows():
            if (quick and random.random() < 0.95): continue
            if (verbose): print("id:", row["_chem_comp.id"])
            comp_comp_id = srv.get_comp_comp_id_direct(
                comp_id=row["_chem_comp.id"])
            check_chem_comp(cif_types.chem_comp(**row), comp_comp_id)
        if ("--pickle" in sys.argv[1:]):
            easy_pickle.dump("mon_lib.pickle", srv)
    if (False or default_switch):
        comp = srv.get_comp_comp_id_direct("GLY")
        comp.show()
        mod = srv.mod_mod_id_dict["COO"]
        comp.apply_mod(mod).show()
    if (False or default_switch):
        comp = srv.get_comp_comp_id_direct("LYS")
        comp.show()
        mod = srv.mod_mod_id_dict["B2C"]
        comp.apply_mod(mod).show()
    if (False or default_switch):
        for row in list_cif.cif["comp_list"]["_chem_comp"].iterrows():
            if (quick and random.random() < 0.95): continue
            comp_comp_id = srv.get_comp_comp_id_direct(row["_chem_comp.id"])
            if (comp_comp_id is not None):
                if (comp_comp_id.classification == "peptide"):
                    print(comp_comp_id.chem_comp.id,
                          comp_comp_id.chem_comp.name,
                          end=' ')
                    print(row["_chem_comp.group"], end=' ')
                    grp = row["_chem_comp.group"].lower().strip()
                    if (grp not in ("l-peptide", "d-peptide", "polymer")):
                        print("LOOK", end=' ')
                        #if (not os.path.isdir("look")): os.makedirs("look")
                        #open("look/%s.cif" % row["_chem_comp.id"], "w").write(
                        #open(comp_comp_id.file_name).read())
                    print()
                elif (row["_chem_comp.group"].lower().find("peptide") >= 0
                      or comp_comp_id.chem_comp.group.lower().find("peptide")
                      >= 0):
                    print(comp_comp_id.chem_comp.id,
                          comp_comp_id.chem_comp.name,
                          end=' ')
                    print(row["_chem_comp.group"], "MISMATCH")
                if (comp_comp_id.classification in ("RNA", "DNA")):
                    print(comp_comp_id.chem_comp.id,
                          comp_comp_id.chem_comp.name,
                          end=' ')
                    print(row["_chem_comp.group"], end=' ')
                    if (comp_comp_id.classification !=
                            row["_chem_comp.group"].strip()):
                        print(comp_comp_id.classification, "MISMATCH", end=' ')
                    print()
                elif (row["_chem_comp.group"].lower().find("NA") >= 0
                      or comp_comp_id.chem_comp.group.lower().find("NA") >= 0):
                    print(comp_comp_id.chem_comp.id,
                          comp_comp_id.chem_comp.name,
                          end=' ')
                    print(row["_chem_comp.group"], "MISMATCH")
    if (False or default_switch):
        for row in list_cif.cif["comp_list"]["_chem_comp"].iterrows():
            if (quick and random.random() < 0.95): continue
            comp_comp_id = srv.get_comp_comp_id_direct(row["_chem_comp.id"])
            if (comp_comp_id is not None):
                planes = comp_comp_id.get_planes()
                for plane in planes:
                    dist_esd_dict = {}
                    for plane_atom in plane.plane_atoms:
                        dist_esd_dict[str(plane_atom.dist_esd)] = 0
                    # FIXME: might break compat for py2/3 because indexing a values call
                    if (len(dist_esd_dict) != 1
                            or list(dist_esd_dict.keys())[0] != "0.02"):
                        print(comp_comp_id.chem_comp.id,
                              plane.plane_id,
                              end=' ')
                        print(list(dist_esd_dict.keys()))
    if (False or default_switch):
        standard_amino_acids = [
            "GLY", "VAL", "ALA", "LEU", "ILE", "PRO", "MET", "PHE", "TRP",
            "SER", "THR", "TYR", "CYS", "ASN", "GLN", "ASP", "GLU", "LYS",
            "ARG", "HIS"
        ]
        for row in list_cif.cif["comp_list"]["_chem_comp"].iterrows():
            is_standard_aa = row["_chem_comp.id"] in standard_amino_acids
            if (1 and not is_standard_aa):
                continue
            comp_comp_id = srv.get_comp_comp_id_direct(row["_chem_comp.id"])
            if (is_standard_aa):
                assert comp_comp_id is not None
                assert comp_comp_id.chem_comp.group.strip() == "L-peptide"
            if (comp_comp_id is not None):
                print(comp_comp_id.chem_comp.id.strip(), end=' ')
                print(comp_comp_id.chem_comp.name.strip(), end=' ')
                print(comp_comp_id.chem_comp.group.strip())
                for tor in comp_comp_id.tor_list:
                    print("  tor:", tor.atom_id_1, tor.atom_id_2, end=' ')
                    print(tor.atom_id_3,
                          tor.atom_id_4,
                          tor.value_angle,
                          end=' ')
                    print(tor.value_angle_esd, tor.period)
                for chir in comp_comp_id.chir_list:
                    print("  chir:",
                          chir.atom_id_centre,
                          chir.atom_id_1,
                          end=' ')
                    print(chir.atom_id_2, chir.atom_id_3, chir.volume_sign)
    if (False or default_switch):
        elib = server.ener_lib()
        if (False or default_switch):
            for syn in elib.lib_synonym.items():
                print(syn)
        if (False or default_switch):
            for vdw in elib.lib_vdw:
                vdw.show()
    print("OK")
コード例 #44
0
def exercise_1 () :
  pdb_raw = """\
ATOM   1134  N   LYS A  82       5.933  36.285  21.572  1.00 70.94           N
ATOM   1135  CA  LYS A  82       6.564  37.423  20.931  1.00 76.69           C
ATOM   1136  C   LYS A  82       5.553  38.547  20.756  1.00 78.75           C
ATOM   1137  O   LYS A  82       5.325  39.038  19.654  1.00 86.47           O
ATOM   1138  CB  LYS A  82       7.179  37.024  19.583  1.00 82.32           C
ATOM   1139  CG  LYS A  82       8.190  38.035  19.048  0.00 70.34           C
ATOM   1140  CD  LYS A  82       9.429  38.129  19.944  0.00 67.69           C
ATOM   1141  CE  LYS A  82       9.983  39.545  20.014  0.00 64.44           C
ATOM   1142  NZ  LYS A  82      10.933  39.832  18.908  0.00 61.45           N
ATOM   1143  H   LYS A  82       5.139  36.115  21.291  1.00 85.12           H
ATOM   1144  HA  LYS A  82       7.279  37.749  21.501  1.00 92.03           H
ATOM   1145  HB2 LYS A  82       6.469  36.939  18.928  1.00 98.78           H
ATOM   1146  HB3 LYS A  82       7.636  36.175  19.687  1.00 98.78           H
ATOM   1147  HG2 LYS A  82       8.476  37.762  18.163  0.00 84.41           H
ATOM   1148  HG3 LYS A  82       7.775  38.912  19.011  0.00 84.41           H
ATOM   1149  HD2 LYS A  82       9.193  37.853  20.843  0.00 81.23           H
ATOM   1150  HD3 LYS A  82      10.122  37.551  19.589  0.00 81.23           H
ATOM   1151  HE2 LYS A  82       9.249  40.177  19.952  0.00 77.33           H
ATOM   1152  HE3 LYS A  82      10.453  39.662  20.854  0.00 77.33           H
ATOM   1153  HZ1 LYS A  82      11.237  40.666  18.977  0.00 73.75           H
ATOM   1154  HZ2 LYS A  82      10.523  39.738  18.123  0.00 73.75           H
ATOM   1155  HZ3 LYS A  82      11.621  39.269  18.944  0.00 73.75           H
ATOM   1156  N   LYS A  83       4.936  38.927  21.866  1.00 75.79           N
ATOM   1157  CA  LYS A  83       4.177  40.172  21.966  1.00 82.80           C
ATOM   1158  C   LYS A  83       4.081  40.508  23.460  1.00 86.23           C
ATOM   1159  O   LYS A  83       2.978  40.521  24.017  1.00 79.81           O
ATOM   1160  CB  LYS A  83       2.790  40.044  21.332  1.00 79.16           C
ATOM   1161  CG  LYS A  83       2.038  41.342  21.175  0.00 70.42           C
ATOM   1162  CD  LYS A  83       2.072  41.803  19.735  0.00 66.90           C
ATOM   1163  CE  LYS A  83       1.295  43.089  19.552  0.00 62.46           C
ATOM   1164  NZ  LYS A  83       1.004  43.350  18.118  0.00 60.73           N
ATOM   1165  H   LYS A  83       4.940  38.470  22.594  1.00 90.95           H
ATOM   1166  HA  LYS A  83       4.658  40.885  21.518  1.00 99.36           H
ATOM   1167  HB2 LYS A  83       2.251  39.459  21.887  1.00 95.00           H
ATOM   1168  HB3 LYS A  83       2.890  39.655  20.449  1.00 95.00           H
ATOM   1169  HG2 LYS A  83       1.113  41.213  21.435  0.00 84.51           H
ATOM   1170  HG3 LYS A  83       2.453  42.024  21.726  0.00 84.51           H
ATOM   1171  HD2 LYS A  83       2.992  41.962  19.471  0.00 80.28           H
ATOM   1172  HD3 LYS A  83       1.672  41.123  19.171  0.00 80.28           H
ATOM   1173  HE2 LYS A  83       0.452  43.024  20.027  0.00 74.95           H
ATOM   1174  HE3 LYS A  83       1.818  43.830  19.896  0.00 74.95           H
ATOM   1175  HZ1 LYS A  83       0.521  42.683  17.780  0.00 72.87           H
ATOM   1176  HZ2 LYS A  83       1.764  43.417  17.661  0.00 72.87           H
ATOM   1177  HZ3 LYS A  83       0.548  44.109  18.034  0.00 72.87           H
ATOM   3630  N   ASN A 242      -5.454  -3.027   1.145  0.00 67.69           N
ATOM   3631  CA  ASN A 242      -4.759  -2.535  -0.037  0.00 65.44           C
ATOM   3632  C   ASN A 242      -5.734  -2.397  -1.208  0.00 63.57           C
ATOM   3633  O   ASN A 242      -6.425  -3.357  -1.552  0.00 63.94           O
ATOM   3634  CB  ASN A 242      -3.626  -3.503  -0.392  0.00 63.13           C
ATOM   3635  CG  ASN A 242      -2.802  -3.044  -1.576  0.00 63.58           C
ATOM   3636  OD1 ASN A 242      -2.524  -1.862  -1.731  0.00 65.52           O
ATOM   3637  ND2 ASN A 242      -2.399  -3.988  -2.416  0.00 62.17           N
ATOM   3638  H   ASN A 242      -5.562  -3.880   1.129  0.00 81.22           H
ATOM   3639  HA  ASN A 242      -4.375  -1.665   0.151  0.00 78.53           H
ATOM   3640  HB2 ASN A 242      -3.032  -3.587   0.370  0.00 75.76           H
ATOM   3641  HB3 ASN A 242      -4.007  -4.368  -0.611  0.00 75.76           H
ATOM   3642 HD21 ASN A 242      -1.929  -3.779  -3.104  0.00 74.60           H
ATOM   3643 HD22 ASN A 242      -2.609  -4.810  -2.272  0.00 74.60           H
ATOM      2  CA ALYS A  32      10.574   8.177  11.768  0.40 71.49           C
ATOM      3  CB ALYS A  32       9.197   8.686  12.246  0.40 74.71           C
ATOM      2  CA BLYS A  32      10.574   8.177  11.768  0.40 71.49           C
ATOM      3  CB BLYS A  32       9.197   8.686  12.246  0.40 74.71           C
ATOM      5  CA AVAL A  33      11.708   5.617  14.332  0.50 71.42           C
ATOM      6  CB AVAL A  33      11.101   4.227  14.591  0.50 71.47           C
ATOM      5  CA BVAL A  33      11.708   5.617  14.332  0.40 71.42           C
ATOM      6  CB BVAL A  33      11.101   4.227  14.591  0.40 71.47           C
TER
ATOM      1  N   GLU X  18     -13.959  12.159  -6.598  1.00260.08           N
ATOM      2  CA  GLU X  18     -13.297  13.465  -6.628  1.00269.83           C
ATOM      3  C   GLU X  18     -11.946  13.282  -7.309  1.00269.18           C
ATOM      4  CB  GLU X  18     -13.128  14.035  -5.210  1.00261.96           C
ATOM      5  CG  GLU X  18     -14.455  14.401  -4.522  1.00263.56           C
ATOM      6  CD  GLU X  18     -14.291  15.239  -3.242  1.00264.89           C
ATOM      7  OE1 GLU X  18     -14.172  14.646  -2.143  1.00264.24           O
ATOM      8  OE2 GLU X  18     -14.309  16.498  -3.306  1.00264.37           O1-
HETATM  614  S   SO4 B 101      14.994  20.601  10.862  0.00  7.02           S
HETATM  615  O1  SO4 B 101      14.234  20.194  12.077  0.00  7.69           O
HETATM  616  O2  SO4 B 101      14.048  21.062   9.850  0.00  9.28           O
HETATM  617  O3  SO4 B 101      15.905  21.686  11.261  0.00  8.01           O
HETATM  618  O4  SO4 B 101      15.772  19.454  10.371  0.00  8.18           O
TER
HETATM  122  O   HOH S   1       5.334   8.357   8.032  1.00  0.00           O
HETATM  123  O   HOH S   2       5.396  15.243  10.734  1.00202.95           O
HETATM  124  O   HOH S   3     -25.334  18.357  18.032  0.00 20.00           O
"""
  mon_lib_srv = server.server()
  ener_lib = server.ener_lib()
  pdb_in = iotbx.pdb.hierarchy.input(pdb_string=pdb_raw)
  xrs = pdb_in.input.xray_structure_simple()
  processed_pdb_file = pdb_interpretation.process(
    mon_lib_srv=mon_lib_srv,
    ener_lib=ener_lib,
    raw_records=pdb_in.hierarchy.as_pdb_string(crystal_symmetry=xrs),
    crystal_symmetry=xrs,
    log=null_out())
  pdb_in.hierarchy.atoms().reset_i_seq()
  mstats = model_properties.model_statistics(
    pdb_hierarchy=pdb_in.hierarchy,
    xray_structure=xrs,
    all_chain_proxies=processed_pdb_file.all_chain_proxies,
    ignore_hd=True)
  out = StringIO()
  mstats.show(out=out)
  #print out.getvalue()
  assert not show_diff(out.getvalue(), """\
Overall:
  Number of atoms = 50  (anisotropic = 0)
  B_iso: mean =  96.0  max = 269.8  min =   0.0
  Occupancy: mean = 0.47  max = 1.00  min = 0.00
    warning: 22 atoms with zero occupancy
  67 total B-factor or occupancy problem(s) detected
  Atoms or residues with zero occupancy:
   LYS A  82   CG    occ=0.00
   LYS A  82   CD    occ=0.00
   LYS A  82   CE    occ=0.00
   LYS A  82   NZ    occ=0.00
   LYS A  83   CG    occ=0.00
   LYS A  83   CD    occ=0.00
   LYS A  83   CE    occ=0.00
   LYS A  83   NZ    occ=0.00
   ASN A 242  (all)  occ=0.00
   SO4 B 101  (all)  occ=0.00
   HOH S   3   O     occ=0.00
Macromolecules:
  Number of atoms = 42  (anisotropic = 0)
  B_iso: mean = 108.0  max = 269.8  min =  60.7
  Occupancy: mean = 0.51  max = 1.00  min = 0.00
    warning: 16 atoms with zero occupancy
  57 total B-factor or occupancy problem(s) detected
Ligands:
  Number of atoms = 5  (anisotropic = 0)
  B_iso: mean =   8.0  max =   9.3  min =   7.0
  Occupancy: mean = 0.00  max = 0.00  min = 0.00
    warning: 5 atoms with zero occupancy
  6 total B-factor or occupancy problem(s) detected
Waters:
  Number of atoms = 3  (anisotropic = 0)
  B_iso: mean =  74.3  max = 202.9  min =   0.0
  Occupancy: mean = 0.67  max = 1.00  min = 0.00
    warning: 1 atoms with zero occupancy
  4 total B-factor or occupancy problem(s) detected
(Hydrogen atoms not included in overall counts.)
""")
  assert (len(mstats.all.bad_adps) == 1)
  assert (mstats.all.n_zero_b == 1)
  mstats2 = loads(dumps(mstats))
  out1 = StringIO()
  out2 = StringIO()
  mstats.show(out=out1)
  mstats2.show(out=out2)
  assert (out1.getvalue() == out2.getvalue())
  # now with ignore_hd=False
  mstats3 = model_properties.model_statistics(
    pdb_hierarchy=pdb_in.hierarchy,
    xray_structure=xrs,
    all_chain_proxies=processed_pdb_file.all_chain_proxies,
    ignore_hd=False)
  out2 = StringIO()
  mstats3.show(out=out2)
  assert (out2.getvalue() != out.getvalue())
  assert ("""   LYS A  83   HZ3   occ=0.00""" in out2.getvalue())
  outliers = mstats3.all.as_gui_table_data(include_zoom=True)
  assert (len(outliers) == 84)
  # test with all_chain_proxies undefined
  mstats4 = model_properties.model_statistics(
    pdb_hierarchy=pdb_in.hierarchy,
    xray_structure=xrs,
    all_chain_proxies=None,
    ignore_hd=False)
  outliers = mstats4.all.as_gui_table_data(include_zoom=True)
  assert (len(outliers) == 84)
コード例 #45
0
def run(args):
  assert len(args) == 0
  srv = server.server()
  standard_amino_acids = [
    "GLY", "VAL", "ALA", "LEU", "ILE", "PRO", "MET", "PHE", "TRP", "SER",
    "THR", "TYR", "CYS", "ASN", "GLN", "ASP", "GLU", "LYS", "ARG", "HIS"]
  for comp_id in standard_amino_acids:
    comp_comp_id = srv.get_comp_comp_id_direct(comp_id)
    print comp_comp_id.chem_comp.id.strip(),
    print comp_comp_id.chem_comp.name.strip(),
    print comp_comp_id.chem_comp.group.strip()
    hydrogens = {}
    for atom in comp_comp_id.atom_list:
      if (atom.type_symbol == "H"):
        hydrogens[atom.atom_id] = 0
    bond_counts = dict(hydrogens)
    for bond in comp_comp_id.bond_list:
      for atom_id in [bond.atom_id_1, bond.atom_id_2]:
        if (atom_id in hydrogens):
          bond_counts[atom_id] += 1
    if (bond_counts.values() != [1] * len(bond_counts)):
      print "bad bond counts:", bond_counts
      raise AssertionError
    angle_counts = dict(hydrogens)
    for angle in comp_comp_id.angle_list:
      for atom_id in [angle.atom_id_1, angle.atom_id_2, angle.atom_id_3]:
        if (atom_id in hydrogens):
          angle_counts[atom_id] += 1
    #print angle_counts
    assert min(angle_counts.values()) > 0
    assert max(angle_counts.values()) <= 3
    for atom_id,count in angle_counts.items():
      if (count == 3):
        print "three angles:", atom_id
        for bond in comp_comp_id.bond_list:
          atom_ids = [bond.atom_id_1, bond.atom_id_2]
          if (atom_id in atom_ids):
            print "  bond:", atom_ids
        for angle in comp_comp_id.angle_list:
          atom_ids = [angle.atom_id_1, angle.atom_id_2, angle.atom_id_3]
          if (atom_id in atom_ids):
            print "  angle:", atom_ids, angle.value_angle
    tor_counts = dict(hydrogens)
    for tor in comp_comp_id.tor_list:
      for atom_id in [tor.atom_id_1,
                      tor.atom_id_2,
                      tor.atom_id_3,
                      tor.atom_id_4]:
        if (atom_id in hydrogens):
          tor_counts[atom_id] += 1
    #print tor_counts
    assert max(tor_counts.values()) <= 1
    print "no tor:", tor_counts.values().count(0)
    chir_counts = dict(hydrogens)
    for chir in comp_comp_id.chir_list:
      for atom_id in [chir.atom_id_centre,
                      chir.atom_id_1,
                      chir.atom_id_2,
                      chir.atom_id_3]:
        if (atom_id in hydrogens):
          chir_counts[atom_id] += 1
    #print chir_counts
    assert max(chir_counts.values()) == 0
    plane_counts = dict(hydrogens)
    for plane in comp_comp_id.get_planes():
      for plane_atom in plane.plane_atoms:
        if (plane_atom.atom_id in hydrogens):
          plane_counts[plane_atom.atom_id] += 1
    #print plane_counts
    assert max(plane_counts.values()) <= 1
    for atom_id,count in plane_counts.items():
      if (count == 0): continue
      assert angle_counts[atom_id] == 2
コード例 #46
0
def run (args, out=None ):
  if (out is None) : out = sys.stdout
  from mmtbx.building.alternate_conformations import density_sampling
  import mmtbx.maps.utils
  import mmtbx.utils
  from mmtbx.monomer_library import server
  import iotbx.pdb.hierarchy
  get_class = iotbx.pdb.common_residue_names_get_class
  mon_lib_srv = server.server()
  cmdline = mmtbx.utils.cmdline_load_pdb_and_data(
    args=args,
    master_phil=master_phil,
    process_pdb_file=False,
    scattering_table="n_gaussian")
  params = cmdline.params
  working_phil = master_phil.format(python_object=params)
  master_phil.fetch_diff(source=working_phil).show(out=out)
  fmodel = cmdline.fmodel
  hierarchy = cmdline.pdb_hierarchy
  sele_cache = hierarchy.atom_selection_cache()
  assert (params.selection is not None)
  selection = sele_cache.selection(params.selection)
  assert (selection.count(True) > 0)
  have_results = False
  pdb_atoms = hierarchy.atoms()
  sites_cart = pdb_atoms.extract_xyz()
  ensembles = []
  t1 = time.time()
  for chain in hierarchy.only_model().chains() :
    prev_residue = next_residue = None
    residue_groups = chain.residue_groups()
    n_groups = len(residue_groups)
    for i_res, residue_group in enumerate(residue_groups) :
      if (i_res < n_groups - 1) :
        next_residue = residue_groups[i_res+1].atom_groups()[0]
      i_seqs = residue_group.atoms().extract_i_seq()
      if (selection.select(i_seqs).all_eq(True)) :
        atom_group = residue_group.only_atom_group()
        if (get_class(atom_group.resname) != "common_amino_acid") :
          continue
        confs = density_sampling.screen_residue(
          residue=atom_group,
          prev_residue=prev_residue,
          next_residue=next_residue,
          sites_cart=sites_cart,
          fmodel=fmodel,
          mon_lib_srv=mon_lib_srv,
          params=params,
          map_file_name="map_coeffs.mtz",
          out=out)
        ensemble = []
        for conf in confs :
          conf_atoms = conf.set_atom_sites(pdb_atoms)
          pdb_lines = []
          for atom in conf_atoms :
            pdb_lines.append(atom.format_atom_record())
          ensemble.append("\n".join(pdb_lines))
        ensembles.append(ensemble)
      prev_residue = residue_group.atom_groups()[0]
  if (len(ensembles) == 0) :
    raise Sorry("No alternate conformations found.")
  t2 = time.time()
  print >> out, "search time: %.1fs" % (t2-t1)
  for i_ens, ensemble in enumerate(ensembles) :
    ensemble_hierarchy = iotbx.pdb.hierarchy.root()
    for k, model_str in enumerate(ensemble) :
      input = iotbx.pdb.hierarchy.input(pdb_string=model_str)
      model = input.hierarchy.only_model().detached_copy()
      model.id = str(k+1)
      ensemble_hierarchy.append_model(model)
    f = open("ensemble_%d.pdb" % (i_ens+1), "w")
    f.write(ensemble_hierarchy.as_pdb_string())
    f.close()
    print "wrote ensemble_%d.pdb" % (i_ens+1)
  if (params.coot) :
    easy_run.call("coot --pdb %s --auto map_coeffs.mtz --pdb ensemble.pdb" %
      params.input.pdb.file_name[0])
コード例 #47
0
    params = pdb_interpretation.master_params.fetch().extract()
    params.peptide_link.ramachandran_restraints = True
    processed_pdb_file = pdb_interpretation.process(
      mon_lib_srv=mon_lib_srv,
      ener_lib=ener_lib,
      params=params,
      raw_records=pdb_str.split("\n"),
      log=StringIO())
    grm = processed_pdb_file.geometry_restraints_manager()
    nprox = grm.ramachandran_manager.get_n_proxies()
    assert nprox == correct_nprox, ""+\
        "Want to get %d rama proxies, got %d" % (correct_nprox, nprox)

if __name__ == "__main__" :
  import time
  mon_lib_srv = server.server()
  ener_lib = server.ener_lib()

  t0 = time.time()
  exercise_basic()
  t1 = time.time()
  exercise_lbfgs_simple(mon_lib_srv, ener_lib,
      ("--verbose" in sys.argv) or ("-v" in sys.argv))
  t2 = time.time()
  if ("--full" in sys.argv):
    exercise_lbfgs_big(mon_lib_srv, ener_lib,
        ("--verbose" in sys.argv) or ("-v" in sys.argv))
  t3 = time.time()
  exercise_geo_output(mon_lib_srv, ener_lib)
  t4 = time.time()
  #
コード例 #48
0
def run(args):
    assert len(args) == 0
    srv = server.server()
    standard_amino_acids = [
        "GLY", "VAL", "ALA", "LEU", "ILE", "PRO", "MET", "PHE", "TRP", "SER",
        "THR", "TYR", "CYS", "ASN", "GLN", "ASP", "GLU", "LYS", "ARG", "HIS"
    ]
    for comp_id in standard_amino_acids:
        comp_comp_id = srv.get_comp_comp_id_direct(comp_id)
        print comp_comp_id.chem_comp.id.strip(),
        print comp_comp_id.chem_comp.name.strip(),
        print comp_comp_id.chem_comp.group.strip()
        hydrogens = {}
        for atom in comp_comp_id.atom_list:
            if (atom.type_symbol == "H"):
                hydrogens[atom.atom_id] = 0
        bond_counts = dict(hydrogens)
        for bond in comp_comp_id.bond_list:
            for atom_id in [bond.atom_id_1, bond.atom_id_2]:
                if (atom_id in hydrogens):
                    bond_counts[atom_id] += 1
        if (bond_counts.values() != [1] * len(bond_counts)):
            print "bad bond counts:", bond_counts
            raise AssertionError
        angle_counts = dict(hydrogens)
        for angle in comp_comp_id.angle_list:
            for atom_id in [angle.atom_id_1, angle.atom_id_2, angle.atom_id_3]:
                if (atom_id in hydrogens):
                    angle_counts[atom_id] += 1
        #print angle_counts
        assert min(angle_counts.values()) > 0
        assert max(angle_counts.values()) <= 3
        for atom_id, count in angle_counts.items():
            if (count == 3):
                print "three angles:", atom_id
                for bond in comp_comp_id.bond_list:
                    atom_ids = [bond.atom_id_1, bond.atom_id_2]
                    if (atom_id in atom_ids):
                        print "  bond:", atom_ids
                for angle in comp_comp_id.angle_list:
                    atom_ids = [
                        angle.atom_id_1, angle.atom_id_2, angle.atom_id_3
                    ]
                    if (atom_id in atom_ids):
                        print "  angle:", atom_ids, angle.value_angle
        tor_counts = dict(hydrogens)
        for tor in comp_comp_id.tor_list:
            for atom_id in [
                    tor.atom_id_1, tor.atom_id_2, tor.atom_id_3, tor.atom_id_4
            ]:
                if (atom_id in hydrogens):
                    tor_counts[atom_id] += 1
        #print tor_counts
        assert max(tor_counts.values()) <= 1
        print "no tor:", tor_counts.values().count(0)
        chir_counts = dict(hydrogens)
        for chir in comp_comp_id.chir_list:
            for atom_id in [
                    chir.atom_id_centre, chir.atom_id_1, chir.atom_id_2,
                    chir.atom_id_3
            ]:
                if (atom_id in hydrogens):
                    chir_counts[atom_id] += 1
        #print chir_counts
        assert max(chir_counts.values()) == 0
        plane_counts = dict(hydrogens)
        for plane in comp_comp_id.get_planes():
            for plane_atom in plane.plane_atoms:
                if (plane_atom.atom_id in hydrogens):
                    plane_counts[plane_atom.atom_id] += 1
        #print plane_counts
        assert max(plane_counts.values()) <= 1
        for atom_id, count in plane_counts.items():
            if (count == 0): continue
            assert angle_counts[atom_id] == 2
コード例 #49
0
ファイル: tst_server.py プロジェクト: cctbx/cctbx-playground
def exercise():
  verbose = "--verbose" in sys.argv[1:]
  quick = "--quick" in sys.argv[1:]
  list_cif = server.mon_lib_list_cif()
  srv = server.server(list_cif=list_cif)
  print "srv.root_path:", srv.root_path
  default_switch = "--default_off" not in sys.argv[1:]
  if (False or default_switch):
    monomers_with_commas = {}
    atom_id_counts = dicts.with_default_value(0)
    for row_id in list_cif.cif["comp_list"]["_chem_comp.id"]:
      if (quick and random.random() < 0.95): continue
      if (verbose): print "id:", row_id
      comp_comp_id = srv.get_comp_comp_id_direct(comp_id=row_id)
      if (comp_comp_id is None):
        print "Error instantiating comp_comp_id(%s)" % row_id
      else:
        has_primes = False
        has_commas = False
        for atom in comp_comp_id.atom_list:
          atom_id_counts[atom.atom_id] += 1
          if (atom.atom_id.find("'") >= 0):
            has_primes = True
          if (atom.atom_id.find(",") >= 0):
            has_commas = True
        if (has_commas):
          monomers_with_commas[comp_comp_id.chem_comp.id] = has_primes
    print monomers_with_commas
    atom_ids = flex.std_string(atom_id_counts.keys())
    counts = flex.size_t(atom_id_counts.values())
    perm = flex.sort_permutation(data=counts, reverse=True)
    atom_ids = atom_ids.select(perm)
    counts = counts.select(perm)
    for atom_id,count in zip(atom_ids, counts):
      print atom_id, count
  if (False or default_switch):
    for row in list_cif.cif["comp_list"]["_chem_comp"].iterrows():
      if (quick and random.random() < 0.95): continue
      if (verbose): print "id:", row["_chem_comp.id"]
      comp_comp_id = srv.get_comp_comp_id_direct(comp_id=row["_chem_comp.id"])
      check_chem_comp(cif_types.chem_comp(**row), comp_comp_id)
    if ("--pickle" in sys.argv[1:]):
      easy_pickle.dump("mon_lib.pickle", srv)
  if (False or default_switch):
    comp = srv.get_comp_comp_id_direct("GLY")
    comp.show()
    mod = srv.mod_mod_id_dict["COO"]
    comp.apply_mod(mod).show()
  if (False or default_switch):
    comp = srv.get_comp_comp_id_direct("LYS")
    comp.show()
    mod = srv.mod_mod_id_dict["B2C"]
    comp.apply_mod(mod).show()
  if (False or default_switch):
    for row in list_cif.cif["comp_list"]["_chem_comp"].iterrows():
      if (quick and random.random() < 0.95): continue
      comp_comp_id = srv.get_comp_comp_id_direct(row["_chem_comp.id"])
      if (comp_comp_id is not None):
        if (comp_comp_id.classification == "peptide"):
          print comp_comp_id.chem_comp.id, comp_comp_id.chem_comp.name,
          print row["_chem_comp.group"],
          grp = row["_chem_comp.group"].lower().strip()
          if (grp not in ("l-peptide", "d-peptide", "polymer")):
            print "LOOK",
            #if (not os.path.isdir("look")): os.makedirs("look")
            #open("look/%s.cif" % row["_chem_comp.id"], "w").write(
              #open(comp_comp_id.file_name).read())
          print
        elif (row["_chem_comp.group"].lower().find("peptide") >= 0
              or comp_comp_id.chem_comp.group.lower().find("peptide") >= 0):
          print comp_comp_id.chem_comp.id, comp_comp_id.chem_comp.name,
          print row["_chem_comp.group"], "MISMATCH"
        if (comp_comp_id.classification in ("RNA", "DNA")):
          print comp_comp_id.chem_comp.id, comp_comp_id.chem_comp.name,
          print row["_chem_comp.group"],
          if (comp_comp_id.classification != row["_chem_comp.group"].strip()):
            print comp_comp_id.classification, "MISMATCH",
          print
        elif (row["_chem_comp.group"].lower().find("NA") >= 0
              or comp_comp_id.chem_comp.group.lower().find("NA") >= 0):
          print comp_comp_id.chem_comp.id, comp_comp_id.chem_comp.name,
          print row["_chem_comp.group"], "MISMATCH"
  if (False or default_switch):
    for row in list_cif.cif["comp_list"]["_chem_comp"].iterrows():
      if (quick and random.random() < 0.95): continue
      comp_comp_id = srv.get_comp_comp_id_direct(row["_chem_comp.id"])
      if (comp_comp_id is not None):
        planes = comp_comp_id.get_planes()
        for plane in planes:
          dist_esd_dict = {}
          for plane_atom in plane.plane_atoms:
            dist_esd_dict[str(plane_atom.dist_esd)] = 0
          if (len(dist_esd_dict) != 1 or dist_esd_dict.keys()[0] != "0.02"):
            print comp_comp_id.chem_comp.id, plane.plane_id,
            print dist_esd_dict.keys()
  if (False or default_switch):
    standard_amino_acids = [
      "GLY", "VAL", "ALA", "LEU", "ILE", "PRO", "MET", "PHE", "TRP", "SER",
      "THR", "TYR", "CYS", "ASN", "GLN", "ASP", "GLU", "LYS", "ARG", "HIS"]
    for row in list_cif.cif["comp_list"]["_chem_comp"].iterrows():
      is_standard_aa = row["_chem_comp.id"] in standard_amino_acids
      if (1 and not is_standard_aa):
        continue
      comp_comp_id = srv.get_comp_comp_id_direct(row["_chem_comp.id"])
      if (is_standard_aa):
        assert comp_comp_id is not None
        assert comp_comp_id.chem_comp.group.strip() == "L-peptide"
      if (comp_comp_id is not None):
        print comp_comp_id.chem_comp.id.strip(),
        print comp_comp_id.chem_comp.name.strip(),
        print comp_comp_id.chem_comp.group.strip()
        for tor in comp_comp_id.tor_list:
          print "  tor:", tor.atom_id_1, tor.atom_id_2,
          print tor.atom_id_3, tor.atom_id_4, tor.value_angle,
          print tor.value_angle_esd, tor.period
        for chir in comp_comp_id.chir_list:
          print "  chir:", chir.atom_id_centre, chir.atom_id_1,
          print chir.atom_id_2, chir.atom_id_3, chir.volume_sign
  if (False or default_switch):
    elib = server.ener_lib()
    if (False or default_switch):
      for syn in elib.lib_synonym.items():
        print syn
    if (False or default_switch):
      for vdw in elib.lib_vdw:
        vdw.show()
  print "OK"
コード例 #50
0
ファイル: charges.py プロジェクト: rajeevroy09/qrefine
def get_mon_lib_server(ligand_cif_file_names=None):
    mon_lib_server = server.server()
    if ligand_cif_file_names:
        for fn in ligand_cif_file_names:
            mon_lib_server.process_cif(file_name=fn)
    return mon_lib_server
コード例 #51
0
def run(args, command_name=libtbx.env.dispatcher_name):
  if (len(args) == 0): args = ["--help"]
  command_line = (option_parser(
    usage='%s pdb_file "atom_selection" [...]' % command_name)
    .option(None, "--write_pdb_file",
      action="store",
      type="string",
      default=None,
      help="write selected atoms to new PDB file",
      metavar="FILE")
    .option(None, "--cryst1_replacement_buffer_layer",
      action="store",
      type="float",
      default=None,
      help="replace CRYST1 with pseudo unit cell covering the selected"
        " atoms plus a surrounding buffer layer",
      metavar="WIDTH")
  ).process(args=args, min_nargs=2)
  co = command_line.options
  mon_lib_srv = server.server()
  ener_lib = server.ener_lib()
  processed_pdb_file = pdb_interpretation.process(
    mon_lib_srv=mon_lib_srv,
    ener_lib=ener_lib,
    file_name=command_line.args[0],
    log=sys.stdout)
  print
  acp = processed_pdb_file.all_chain_proxies

  hierarchy=acp.pdb_hierarchy
  asc=hierarchy.atom_selection_cache()
  sel=asc.selection(string = "chain 'A' and resid 1 through 8 and icode ' '")
  h1=hierarchy.select(sel)  # keep original hierarchy too
  print h1.as_pdb_string()


  selection_cache = acp.pdb_hierarchy.atom_selection_cache()
  atoms = acp.pdb_atoms
  all_bsel = flex.bool(atoms.size(), False)
  for selection_string in command_line.args[1:]:
    print selection_string
    isel = acp.iselection(string=selection_string, cache=selection_cache)
    all_bsel.set_selected(isel, True)
    if (not co.write_pdb_file):
      print "  %d atom%s selected" % plural_s(isel.size())
      for atom in atoms.select(isel):
        print "    %s" % atom.format_atom_record()
  print
  if (co.write_pdb_file):
    print "Writing file:", show_string(co.write_pdb_file)
    sel_hierarchy = acp.pdb_hierarchy.select(all_bsel)
    if (co.cryst1_replacement_buffer_layer is None):
      crystal_symmetry = acp.special_position_settings
    else:
      import cctbx.crystal
      crystal_symmetry = cctbx.crystal.non_crystallographic_symmetry(
        sites_cart=sel_hierarchy.atoms().extract_xyz(),
        buffer_layer=co.cryst1_replacement_buffer_layer)
    write_whole_pdb_file(
        file_name=co.write_pdb_file,
        processed_pdb_file=processed_pdb_file,
        pdb_hierarchy=sel_hierarchy,
        crystal_symmetry=crystal_symmetry)
    print
コード例 #52
0
ファイル: interpolate.py プロジェクト: cctbx/cctbx-playground
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
コード例 #53
0
def adjust_geometry_proxies_registeries(hierarchy,
                                        #bond_params_table,
                                        #bond_asu_table,
                                        gpr,
                                        error_i_seqs,
                                        log=None,
                                        ):
  t0=time.time()
  mon_lib_srv = server.server()
  pdb_atoms = hierarchy.atoms()
  sites_cart = pdb_atoms.extract_xyz()
  resnames=[]
  bond_counters = [0,0]
  angle_counters = [0,0]
  checked=[]
  atoms_added={}
  for i_seq in error_i_seqs:
    atom = pdb_atoms[i_seq]
    ag = atom.parent()
    if ag.resname in checked: continue
    rg = ag.parent()
    # need to be able to check in user defined location
    monomer_restraints = mon_lib_srv.get_comp_comp_id_direct(
      ag.resname,
      pH_range="low",
      )
    checked.append(ag.resname)
    if monomer_restraints is None: continue
    atom_dict = monomer_restraints.atom_dict()
    resnames.append('"%s%s %s%5s"' % (' ',
                                      ag.resname,
                                      rg.parent().id,
                                      rg.resseq,
                                      ))
    for bond in monomer_restraints.bond_list:
      atom1 = ag.get_atom(bond.atom_id_1)
      if atom1 is None: continue
      atom2 = ag.get_atom(bond.atom_id_2)
      if atom2 is None: continue
      i_seqs = [atom1.i_seq, atom2.i_seq]
      i_seqs.sort()
      bond_table_entry = gpr.bond_simple.table[i_seqs[0]]
      if i_seqs[1] in bond_table_entry:
        bond_simple = gpr.bond_simple.proxies[i_seqs[0]]
        bond_simple.distance_ideal = bond.value_dist
        bond_simple.weight=1/bond.value_dist_esd**2
        bond_counters[0]+=1
      else:
        proxy = geometry_restraints.bond_simple_proxy(
          i_seqs=i_seqs,
          distance_ideal=bond.value_dist,
          weight=1/(bond.value_dist_esd**2),
          )
        gpr.bond_simple.proxies.append(proxy)
        atoms_added[atom1.i_seq] = atom_dict.get(atom1.name.strip(), None)
        atoms_added[atom2.i_seq] = atom_dict.get(atom2.name.strip(), None)
        bond_counters[1]+=1
    lookup={}
    for angle in monomer_restraints.angle_list:
      atom1 = ag.get_atom(angle.atom_id_1)
      if atom1 is None: continue
      atom2 = ag.get_atom(angle.atom_id_2)
      if atom2 is None: continue
      atom3 = ag.get_atom(angle.atom_id_3)
      if atom3 is None: continue
      i_seqs = (atom1.i_seq, atom2.i_seq, atom3.i_seq)
      lookup[i_seqs]=angle
      i_seqs = (atom3.i_seq, atom2.i_seq, atom1.i_seq)
      lookup[i_seqs]=angle
    for angle_proxy in gpr.angle.proxies:
      if angle_proxy.i_seqs in lookup:
        i_seqs = angle_proxy.i_seqs
        angle = lookup[i_seqs]
        angle_proxy.angle_ideal = angle.value_angle
        angle_proxy.weight = 1/angle.value_angle_esd**2
        angle_counters[0]+=1
        del lookup[i_seqs]
        i_seqs = list(i_seqs)
        i_seqs.reverse()
        del lookup[tuple(i_seqs)]
    if lookup:
      done = []
      for i_seqs in lookup:
        if i_seqs in done: continue
        proxy =  geometry_restraints.angle_proxy(
          i_seqs=i_seqs,
          angle_ideal=angle.value_angle,
          weight=1/angle.value_angle_esd**2,
          )
        gpr.angle.add_if_not_duplicated(proxy)
        angle_counters[1]+=1
        i_seqs=list(i_seqs)
        i_seqs.reverse()
        done.append(tuple(i_seqs))
  if resnames:
    print >> log, "\n  Adjusted restraints in %d residue(s) for low pH in %0.1fs" % (
      len(resnames),
      time.time()-t0,
      )
    print >> log, "    Residues changed"
    for resname in resnames:
      print >> log, "      %s" % resname
    print >> log, "    Changed %d bond restraint(s),  added %d bond restraint(s)" % (
      bond_counters[0],
      bond_counters[1],
      )
    print >> log, "    Changed %d angle restraint(s), added %d angle restraint(s)\n" % (
      angle_counters[0],
      angle_counters[1],
      )
  #else:
  #  print >> log, "  Time to perform restraint checks: %0.1f" % (time.time()-t0)
  return atoms_added
コード例 #54
0
        params.pdb_interpretation.ramachandran_plot_restraints.inject_emsley8k_into_oldfield_favored = False

        pdb_inp = iotbx.pdb.input(lines=pdb_str.split("\n"), source_info=None)
        model = mmtbx.model.manager(model_input=pdb_inp,
                                    pdb_interpretation_params=params,
                                    log=null_out(),
                                    build_grm=True)
        grm = model.get_restraints_manager().geometry
        nprox = grm.ramachandran_manager.get_n_proxies()
        assert nprox == correct_nprox, ""+\
            "Want to get %d rama proxies, got %d" % (correct_nprox, nprox)


if __name__ == "__main__":
    import time
    mon_lib_srv = server.server()
    ener_lib = server.ener_lib()
    t0 = time.time()
    exercise_basic()
    t1 = time.time()
    exercise_lbfgs_simple(mon_lib_srv, ener_lib, ("--verbose" in sys.argv)
                          or ("-v" in sys.argv))
    t2 = time.time()
    if ("--full" in sys.argv):
        exercise_lbfgs_big(mon_lib_srv, ener_lib, ("--verbose" in sys.argv)
                           or ("-v" in sys.argv))
    t3 = time.time()
    exercise_geo_output(mon_lib_srv, ener_lib)
    exercise_manager_selection(mon_lib_srv, ener_lib)
    t4 = time.time()
    exercise_ramachandran_selections(mon_lib_srv, ener_lib)
コード例 #55
0
def exercise():
    from mmtbx.building.alternate_conformations import density_sampling
    from mmtbx.utils import fmodel_simple
    from mmtbx.monomer_library import server
    from iotbx import file_reader
    import iotbx.pdb.hierarchy
    generate_inputs()
    fmodel_params = """
    high_resolution = 1.2
    r_free_flags_fraction = 0.1
    add_sigmas = True
    pdb_file = ser_frag.pdb
    output {
      label = F
      type = *real complex
      file_name = ser_frag.mtz
    }
    fmodel.k_sol = 0.3
    fmodel.b_sol = 20
    """
    open("ser_frag_fmodel.eff", "w").write(fmodel_params)
    assert (easy_run.fully_buffered("phenix.fmodel ser_frag_fmodel.eff").
            raise_if_errors().return_code == 0)
    assert os.path.isfile("ser_frag.mtz")
    mtz_in = file_reader.any_file("ser_frag.mtz")
    f_obs = mtz_in.file_server.miller_arrays[0]
    flags = mtz_in.file_server.miller_arrays[1]
    flags = flags.customized_copy(data=(flags.data() == 1))
    mon_lib_srv = server.server()
    pdb_in = iotbx.pdb.hierarchy.input(file_name="ser_frag_single.pdb")
    hierarchy = pdb_in.hierarchy
    pdb_atoms = hierarchy.atoms()
    pdb_atoms.reset_i_seq()
    sites_cart = pdb_atoms.extract_xyz()
    xrs = pdb_in.input.xray_structure_simple()
    fmodel = fmodel_simple(f_obs=f_obs,
                           xray_structures=[xrs],
                           scattering_table="n_gaussian",
                           r_free_flags=flags,
                           skip_twin_detection=True)
    models = []
    prev_res = next_res = next_next_res = None
    for chain in hierarchy.only_model().chains():
        residue_groups = chain.residue_groups()
        n_rg = len(residue_groups)
        for i_res, residue_group in enumerate(residue_groups):
            sites_orig = sites_cart.deep_copy()
            next_res = next_next_res = None
            if (i_res < (n_rg - 1)):
                next_res = residue_groups[i_res + 1].atom_groups()[0]
            if (i_res < (n_rg - 2)):
                next_next_res = residue_groups[i_res + 2].atom_groups()[0]
            atom_groups = residue_group.atom_groups()
            primary_conf = atom_groups[0]
            out = StringIO()
            confs = density_sampling.screen_residue(
                residue=primary_conf,
                prev_residue=prev_res,
                next_residue=next_res,
                next_next_residue=next_next_res,
                sites_cart=sites_cart,
                fmodel=fmodel,
                mon_lib_srv=mon_lib_srv,
                params=None,
                backrub=True,
                shear=False,
                verbose=True,
                out=out)
            prev_res = primary_conf
            if (confs is None):
                continue
            # TODO tweak density sampling to allow a backrubbed conformer with a
            # chi1 t rotamer for Ser 99
            if (i_res == 1):
                assert ("""  A SER  99     20.0    None       t"""
                        in out.getvalue())
            for conf in confs:
                sites_new = sites_cart.set_selected(conf.sites_selection,
                                                    conf.sites_selected())
                pdb_atoms.set_xyz(sites_new)
                models.append(hierarchy.only_model().detached_copy())
            confs = density_sampling.screen_residue(
                residue=primary_conf,
                prev_residue=prev_res,
                next_residue=next_res,
                next_next_residue=next_next_res,
                sites_cart=sites_cart,
                fmodel=fmodel,
                mon_lib_srv=mon_lib_srv,
                params=None,
                backrub=False,
                out=out)
            if (i_res == 1):
                print len(confs)
    new_hierarchy = iotbx.pdb.hierarchy.root()
    for i_model, conf in enumerate(models):
        conf.id = str(i_model + 1)
        new_hierarchy.append_model(conf)
    open("ser_frag_guided_ensemble.pdb",
         "w").write(new_hierarchy.as_pdb_string())
コード例 #56
0
def adjust_geometry_restraints_manager(hierarchy,
                                       grm,
                                       error_i_seqs,
                                       log=None,
                                       ):
  # obsolete
  t0=time.time()
  mon_lib_srv = server.server()
  pdb_atoms = hierarchy.atoms()
  sites_cart = pdb_atoms.extract_xyz()
  resnames=[]
  bond_counters = [0,0]
  angle_counters = [0,0]
  checked=[]
  for i_seq in error_i_seqs:
    atom = pdb_atoms[i_seq]
    ag = atom.parent()
    if ag.resname in checked: continue
    rg = ag.parent()
    # need to be able to check in user defined location
    monomer_restraints = mon_lib_srv.get_comp_comp_id_direct(
      ag.resname,
      pH_range="low",
      )
    checked.append(ag.resname)
    if monomer_restraints is None: continue
    resnames.append('"%s%s %s%5s"' % (' ',
                                      ag.resname,
                                      rg.parent().id,
                                      rg.resseq,
                                      ))
    for bond in monomer_restraints.bond_list:
      bond.show()
      atom1 = ag.get_atom(bond.atom_id_1)
      atom2 = ag.get_atom(bond.atom_id_2)
      i_seqs = (atom1.i_seq, atom2.i_seq)
      bond_param = grm.bond_params_table.lookup(*list(i_seqs))
      if bond_param:
        bond_param.distance_ideal = bond.value_dist
        bond_counters[0]+=1
      else:
        proxy = geometry_restraints.bond_simple_proxy(
          i_seqs=i_seqs,
          distance_ideal=bond.value_dist,
          weight=1/(bond.value_dist_esd**2),
          )
        grm.add_new_bond_restraints_in_place([proxy], sites_cart)
        bond_counters[1]+=1
    lookup={}
    for angle in monomer_restraints.angle_list:
      atom1 = ag.get_atom(angle.atom_id_1)
      atom2 = ag.get_atom(angle.atom_id_2)
      atom3 = ag.get_atom(angle.atom_id_3)
      i_seqs = (atom1.i_seq, atom2.i_seq, atom3.i_seq)
      lookup[i_seqs]=angle
      i_seqs = (atom3.i_seq, atom2.i_seq, atom1.i_seq)
      lookup[i_seqs]=angle
    for angle_proxy in grm.angle_proxies:
      if angle_proxy.i_seqs in lookup:
        i_seqs = angle_proxy.i_seqs
        angle = lookup[i_seqs]
        angle_proxy.angle_ideal = angle.value_angle
        angle_proxy.weight = 1/angle.value_angle_esd**2
        angle_counters[0]+=1
        del lookup[i_seqs]
        i_seqs = list(i_seqs)
        i_seqs.reverse()
        del lookup[tuple(i_seqs)]
    if lookup:
      done = []
      for i_seqs in lookup:
        if i_seqs in done: continue
        proxy =  geometry_restraints.angle_proxy(
          i_seqs=i_seqs,
          angle_ideal=angle.value_angle,
          weight=1/angle.value_angle_esd**2,
          )
        grm.add_angles_in_place([proxy])
        angle_counters[1]+=1
        i_seqs=list(i_seqs)
        i_seqs.reverse()
        done.append(tuple(i_seqs))
コード例 #57
0
def run (args, params=None, out=sys.stdout, log=sys.stderr) :
  # params keyword is for running program from GUI dialog
  if ( ((len(args) == 0) and (params is None)) or
       ((len(args) > 0) and ((args[0] == "-h") or (args[0] == "--help"))) ):
    show_usage()
    return

  # parse command-line arguments
  if (params is None):
    pcl = iotbx.phil.process_command_line_with_files(
      args=args,
      master_phil_string=master_phil_str,
      pdb_file_def="file_name")
    work_params = pcl.work.extract()
  # or use parameters defined by GUI
  else:
    work_params = params
  pdb_files = work_params.file_name

  work_params.secondary_structure.enabled=True
  assert work_params.format in ["phenix", "phenix_refine", "phenix_bonds",
      "pymol", "refmac", "kinemage", "pdb"]
  if work_params.quiet :
    out = cStringIO.StringIO()

  pdb_combined = iotbx.pdb.combine_unique_pdb_files(file_names=pdb_files)
  pdb_structure = iotbx.pdb.input(source_info=None,
    lines=flex.std_string(pdb_combined.raw_records))
  cs = pdb_structure.crystal_symmetry()

  corrupted_cs = False
  if cs is not None:
    if [cs.unit_cell(), cs.space_group()].count(None) > 0:
      corrupted_cs = True
      cs = None
    elif cs.unit_cell().volume() < 10:
      corrupted_cs = True
      cs = None

  if cs is None:
    if corrupted_cs:
      print >> out, "Symmetry information is corrupted, "
    else:
      print >> out, "Symmetry information was not found, "
    print >> out, "putting molecule in P1 box."
    from cctbx import uctbx
    atoms = pdb_structure.atoms()
    box = uctbx.non_crystallographic_unit_cell_with_the_sites_in_its_center(
      sites_cart=atoms.extract_xyz(),
      buffer_layer=3)
    atoms.set_xyz(new_xyz=box.sites_cart)
    cs = box.crystal_symmetry()
  from mmtbx.monomer_library import pdb_interpretation, server
  import mmtbx
  import mmtbx.command_line.geometry_minimization

  mon_lib_srv = server.server()
  ener_lib = server.ener_lib()
  defpars = mmtbx.command_line.geometry_minimization.master_params().extract()
  defpars.pdb_interpretation.automatic_linking.link_carbohydrates=False
  defpars.pdb_interpretation.c_beta_restraints=False
  defpars.pdb_interpretation.clash_guard.nonbonded_distance_threshold=None
  processed_pdb_file = pdb_interpretation.process(
    mon_lib_srv    = mon_lib_srv,
    ener_lib       = ener_lib,
    pdb_inp        = pdb_structure,
    crystal_symmetry = cs,
    params         = defpars.pdb_interpretation,
    force_symmetry = True)
  pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  geometry = processed_pdb_file.geometry_restraints_manager()
  geometry.pair_proxies(processed_pdb_file.xray_structure().sites_cart())
  pdb_hierarchy.atoms().reset_i_seq()
  if len(pdb_hierarchy.models()) != 1 :
    raise Sorry("Multiple models not supported.")
  ss_from_file = None
  if hasattr(pdb_structure, "extract_secondary_structure"):
    ss_from_file = pdb_structure.extract_secondary_structure()
  m = manager(pdb_hierarchy=pdb_hierarchy,
    geometry_restraints_manager=geometry,
    sec_str_from_pdb_file=ss_from_file,
    params=work_params.secondary_structure,
    verbose=work_params.verbose)

  # bp_p = nucleic_acids.get_basepair_plane_proxies(
  #     pdb_hierarchy,
  #     m.params.secondary_structure.nucleic_acid.base_pair,
  #     geometry)
  # st_p = nucleic_acids.get_stacking_proxies(
  #     pdb_hierarchy,
  #     m.params.secondary_structure.nucleic_acid.stacking_pair,
  #     geometry)
  # hb_b, hb_a = nucleic_acids.get_basepair_hbond_proxies(pdb_hierarchy,
  #     m.params.secondary_structure.nucleic_acid.base_pair)
  result_out = cStringIO.StringIO()
  # prefix_scope="refinement.pdb_interpretation"
  # prefix_scope=""
  prefix_scope=""
  if work_params.format == "phenix_refine":
    prefix_scope = "refinement.pdb_interpretation"
  elif work_params.format == "phenix":
    prefix_scope = "pdb_interpretation"
  ss_phil = None
  working_phil = m.as_phil_str(master_phil=sec_str_master_phil)
  phil_diff = sec_str_master_phil.fetch_diff(source=working_phil)

  if work_params.format in ["phenix", "phenix_refine"]:
    comment = "\n".join([
      "# These parameters are suitable for use in e.g. phenix.real_space_refine",
      "# or geometry_minimization. To use them in phenix.refine add ",
      "# 'refinement.' if front of pdb_interpretation."])
    if work_params.format == "phenix_refine":
      comment = "\n".join([
      "# These parameters are suitable for use in phenix.refine only.",
      "# To use them in other Phenix tools remove ",
      "# 'refinement.' if front of pdb_interpretation."])
    print >> result_out, comment
    if (prefix_scope != "") :
      print >> result_out, "%s {" % prefix_scope
    if work_params.show_all_params :
      working_phil.show(prefix="  ", out=result_out)
    else :
      phil_diff.show(prefix="  ", out=result_out)
    if (prefix_scope != "") :
      print >> result_out, "}"
  elif work_params.format == "pdb":
    print >> result_out, m.actual_sec_str.as_pdb_str()
  elif work_params.format == "phenix_bonds" :
    raise Sorry("Not yet implemented.")
  elif work_params.format in ["pymol", "refmac", "kinemage"] :
    m.show_summary(log=out)
    (hb_proxies, hb_angle_proxies, planarity_proxies,
        parallelity_proxies) = m.create_all_new_restraints(
        pdb_hierarchy=pdb_hierarchy,
        grm=geometry,
        log=out)
    if hb_proxies.size() > 0:
      if work_params.format == "pymol" :
        bonds_in_format = hb_proxies.as_pymol_dashes(
            pdb_hierarchy=pdb_hierarchy)
      elif work_params.format == "kinemage" :
        bonds_in_format = hb_proxies.as_kinemage(
            pdb_hierarchy=pdb_hierarchy)
      else :
        bonds_in_format = hb_proxies.as_refmac_restraints(
            pdb_hierarchy=pdb_hierarchy)
      print >> result_out, bonds_in_format
  result = result_out.getvalue()
  filename = "%s_ss.eff" %os.path.basename(work_params.file_name[0])
  outf = open(filename, "w")
  outf.write(result)
  outf.close()
  print >> out, result

  return os.path.abspath(filename)