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()
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
Example #3
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())
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
Example #5
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
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
Example #7
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
Example #8
0
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
Example #9
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
def build_scattering_library(atom_types, q_array, radii, radius_scale,
                             Explicit_H, S_factor):
    scat_lib = intensity.scattering_library(q_array)
    ener_lib = server.ener_lib()
    for at in atom_types:
        element = ener_lib.lib_atom[at].element
        if (element is ''):
            element = 'C'
            print "Warning: unexpected atom found, and C element is used"
        val = xray_scattering.it1992(element, True).fetch()
        a = val.array_of_a()
        b = val.array_of_b()
        c = val.c()
        sf_result = scattering_factor(a, b, c, q_array)
        # getting displaced solvent volumn
        if (radii.__contains__(at)):
            r = radii[at] * radius_scale
            v = math.pi * 4.0 / 3.0 * r**3.0
        else:
            v = 16.44
        dummy_sf = dummy_factor(v, q_array)

        if (not Explicit_H):
            if (S_factor.__contains__(at)):
                scale = S_factor[at]
                sf_result *= (scale[0] *
                              flex.exp(-scale[1] * q_array * q_array))
                dummy_sf *= (flex.exp(-1.25 * q_array * q_array))

        scat_lib.load_scattering_info(at, sf_result, dummy_sf)
    return scat_lib
def calc_abs_Io(atom_types, at_collection, S_factor, Explicit_H=False):
    ener_lib = server.ener_lib()
    abs_Io = 0.0
    for at in at_collection:
        element = ener_lib.lib_atom[at].element
        if (element is ''):
            element = 'C'
            print "Warning: unexpected atom found, and C element is used"
        val = xray_scattering.it1992(element, True).fetch()
        a = val.array_of_a()
        c = val.c()
        this_sf0 = c
        for aa in a:
            this_sf0 += aa
        if (not Explicit_H):
            if (S_factor.__contains__(at)):
                scale = S_factor[at]
                this_sf0 = this_sf0 * scale[0]
        sel = flex.bool(atom_types == at)
        isel = sel.iselection()
        n_at = isel.size()
        #    print at, this_sf0
        abs_Io = abs_Io + n_at * this_sf0
    abs_Io = abs_Io**2.0
    return abs_Io
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())
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"
Example #14
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"
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())
Example #16
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)
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)
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)
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)
Example #20
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.
  #
  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)
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
Example #22
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 = {}
Example #23
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)
Example #24
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)
Example #25
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
Example #26
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
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
Example #28
0
 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)
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())
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
  69 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
  59 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) == 86)
    # 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) == 86)
Example #31
0
def morph_models (params, out=None, debug=False) :
  assert len(params.morph.pdb_file) > 1
  assert (len(params.morph.frames) == (len(params.morph.pdb_file) - 1))
  if (out is None) : out = sys.stdout
  from mmtbx.monomer_library import pdb_interpretation, server
  from iotbx import file_reader
  pdb_hierarchies = []
  for pdb_file in params.morph.pdb_file :
    pdb_in = file_reader.any_file(pdb_file, force_type="pdb")
    pdb_in.check_file_type("pdb")
    hierarchy = pdb_in.file_object.hierarchy
    pdb_hierarchies.append(hierarchy)
  new_pdb = homogenize_structures(
    pdb_hierarchies=pdb_hierarchies,
    delete_waters=params.morph.delete_waters,
    debug=debug)
  mon_lib_srv = server.server()
  ener_lib = server.ener_lib()
  for cif_file in params.morph.cif_file :
    print "Loading CIF file %s" % cif_file
    cif_object = server.read_cif(file_name=cif_file)
    mon_lib_serv.process_cif_object(cif_object=cif_object, file_name=cif_file)
    ener_lib.process_cif_object(cif_object=cif_object, file_name=cif_file)
  if (params.morph.minimization.interpolate_dihedrals) :
    params.pdb_interpretation.peptide_link.discard_psi_phi = False
  processed_pdb_file = pdb_interpretation.process(
    mon_lib_srv=mon_lib_srv,
    ener_lib=ener_lib,
    params=params.pdb_interpretation,
    pdb_inp=new_pdb[0],
    substitute_non_crystallographic_unit_cell_if_necessary=True)
  all_chain_proxies = processed_pdb_file.all_chain_proxies
  static_coords = [ all_chain_proxies.pdb_hierarchy.atoms().extract_xyz() ]
  for pdb_inp in new_pdb[1:] :
    sites = pdb_inp.atoms().extract_xyz()
    static_coords.append(sites)
  if (params.morph.fitting.align_atoms is not None) :
    print >> out, "Superposing on initial structure..."
    selection_cache = all_chain_proxies.pdb_hierarchy.atom_selection_cache()
    selection = selection_cache.selection(params.morph.fitting.align_atoms)
    if (selection.count(True) == 0) :
      raise Sorry("No atoms in alignment selection!")
    i_ref = params.morph.fitting.reference_structure
    sites_fixed = static_coords[i_ref]
    j = 0
    while (j < len(static_coords)) :
      if (j != i_ref) :
        sites_moving = static_coords[j]
        assert (len(sites_moving) == len(sites_fixed) > 0)
        if (params.morph.fitting.sieve_fit) :
          from scitbx.math import superpose
          lsq_fit = superpose.sieve_fit(
            sites_fixed=sites_fixed,
            sites_moving=sites_moving,
            selection=selection)
          sites_moving_new = lsq_fit.r.elems * sites_moving + lsq_fit.t.elems
        else :
          sites_moving_new = fit_sites(
            sites_fixed=sites_fixed,
            sites_moving=sites_moving,
            selection=selection)
        assert (sites_moving_new.size() == sites_moving.size())
        static_coords[j] = sites_moving_new
      j += 1
  print >> out, "Ready to morph"
  morphs = []
  restraints_manager = processed_pdb_file.geometry_restraints_manager()
  for i in range(len(params.morph.pdb_file) - 1) :
    morph = adiabatic_mapping(
      pdb_hierarchy=all_chain_proxies.pdb_hierarchy,
      restraints_manager=restraints_manager,
      start_coords = static_coords[i],
      end_coords = static_coords[i+1],
      params = params.morph.minimization,
      nsteps = params.morph.frames[i],
      out=out)
    morphs.append(morph)
  serial = 1
  if (params.morph.output_directory is not None) :
    output_base = os.path.join(params.morph.output_directory,
      params.morph.output_prefix)
  else :
    output_base = params.morph.output_prefix
  for i, morph in enumerate(morphs) :
    serial = morph.write_pdb_files(
      output_base=output_base,
      serial=serial,
      serial_format=params.morph.serial_format,
      pause=params.morph.pause,
      pause_at_end=(i == (len(morphs) - 1)),
      log=out)
  f = open("%s.pml" % output_base, "w")
  for i in range(1, serial) :
    format_base = "%s_%s" % (output_base, params.morph.serial_format)
    print >> f, "load %s.pdb, morph" % (format_base % i)
  f.close()
  print >> out, "PyMOL script is %s.pml" % output_base
Example #32
0
        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)
    t5 = time.time()
Example #33
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)
Example #34
0
    def __init__(self,
                 pdb_file,
                 q_array=None,
                 rho=0.334,
                 drho=0.03,
                 max_L=15,
                 max_i=13,
                 implicit_hydrogens=True):
        if (q_array is not None):
            q_values = q_array
        else:
            q_values = flex.double(range(51)) / 100.0
        # read in pdb file
        pdbi = pdb.hierarchy.input(file_name=pdb_file)
        atoms = pdbi.hierarchy.atoms()
        # predefine some arrays we will need
        atom_types = flex.std_string()
        dummy_atom_types = flex.std_string()
        radius = flex.double()
        b_values = flex.double()
        occs = flex.double()
        xyz = flex.vec3_double()
        # keep track of the atom types we have encountered
        dummy_at_collection = []
        for atom in atoms:
            b_values.append(atom.b)
            occs.append(atom.occ)
            xyz.append(atom.xyz)

        self.natom = xyz.size()

        dummy_ats = sas_library.read_dummy_type(file_name=pdb_file)
        for at in dummy_ats:
            if at not in dummy_at_collection:
                dummy_at_collection.append(at)

        # Hydrogen controls whether H is treated explicitly or implicitly
        #Hydrogen = True
        Hydrogen = not implicit_hydrogens

        radius_dict = {}
        ener_lib = server.ener_lib()
        for dummy in dummy_at_collection:
            if (Hydrogen):
                radius_dict[dummy] = ener_lib.lib_atom[dummy].vdw_radius
            else:
                radius_dict[dummy] = ener_lib.lib_atom[dummy].vdwh_radius
            if (radius_dict[dummy] is None):
                radius_dict[dummy] = ener_lib.lib_atom[dummy].vdw_radius
        if (radius_dict[dummy] is None):
            print "********************* WARNING WARNING  *************************"
            print "Did not find atom type: ", dummy, "default value 1.58 A was used"
            print "****************************************************************"
            radius_dict[dummy] = 1.58

        for at in dummy_ats:
            dummy_atom_types.append(at)
            radius.append(radius_dict[at])

        Scaling_factors = sas_library.load_scaling_factor()

        #------------------
        #
        B_factor_on = False
        f_step = 0.8
        q_step = 0.01
        solvent_radius_scale = 0.91
        protein_radius_scale = 1.2
        delta = 3.0
        #------------------

        scat_lib_dummy = sas_library.build_scattering_library(
            dummy_at_collection, q_values, radius_dict, solvent_radius_scale,
            Hydrogen, Scaling_factors)

        model = intensity.model(xyz, radius * protein_radius_scale, b_values,
                                occs, dummy_ats, scat_lib_dummy, B_factor_on)

        max_z_eps = 0.02
        max_z = model.get_max_radius() * (q_values[-1] + max_z_eps)
        self.engine = intensity.she_engine(model, scat_lib_dummy, max_i, max_L,
                                           f_step, q_step, max_z, delta, rho,
                                           drho)
        self.engine.update_solvent_params(rho, drho)
  def add_species(self,pdb_input=None,n_copies=1,form_factor_table='WK1995'):
    if (n_copies <= 0):
      raise Sorry('n_copies has to be greater than or equal to 1')

    # construct entry
    s = species()
    s.n_copies = n_copies
    s.pdb_input = pdb_input

    # find center and radius of sphere enclosing molecule
    atoms = s.pdb_input.atoms()
    x = flex.double(len(atoms))
    y = flex.double(len(atoms))
    z = flex.double(len(atoms))
    for i in xrange(len(atoms)):
      x[i] = atoms[i].xyz[0]
      y[i] = atoms[i].xyz[1]
      z[i] = atoms[i].xyz[2]
    x_stats = basic_statistics(x)
    y_stats = basic_statistics(y)
    z_stats = basic_statistics(z)
    r = flex.double( ( (x_stats.max - x_stats.min)/2.0,
                       (y_stats.max - y_stats.min)/2.0,
                       (z_stats.max - z_stats.min)/2.0 ) )
    center = (x_stats.mean,y_stats.mean,z_stats.mean)
    s.radius = r.norm()

    # center model at origin
    center = flex.double(center)
    s.xyz = flex.vec3_double(len(atoms))
    for i in xrange(len(atoms)):
      s.xyz[i] = tuple(flex.double(atoms[i].xyz) - center)

    # determine scattering types
    mon_lib_srv = server.server()
    ener_lib = server.ener_lib()
    interpreted_pdb = pdb_interpretation.process\
                        (mon_lib_srv=mon_lib_srv,ener_lib=ener_lib,
                         pdb_inp=s.pdb_input)
    s.scattering_types = interpreted_pdb.all_chain_proxies.\
                         scattering_type_registry.symbols
    s.scattering_type_registry = scattering_type_registry()
    for f in s.scattering_types:
      s.scattering_type_registry.process(f)
    s.scattering_type_registry.assign_from_table(form_factor_table)
    s.n_electrons = s.scattering_type_registry.\
                    sum_of_scattering_factors_at_diffraction_angle_0()

    # apply solvent model
    if (self.use_solvent):
      sm = solvent_model()
      sm.interpreted_pdb = interpreted_pdb
      sm.xyz = s.xyz
      sm.fudge_factor = 0.6
      s.scattering_type_registry = sm.add_bulk_solvent(s.scattering_type_registry)
      s.scattering_types = sm.scattering_types
      sm.boundary_layer_scale = 0.6
      s.boundary_layer_scaling_factors = sm.add_boundary_layer_solvent\
                                         (s.scattering_type_registry)
    else:
      s.boundary_layer_scaling_factors = flex.double(len(s.xyz),0.0)

    # finalize entry
    self.species.append(s)
Example #36
0
def run(args):
  master_phil = get_master_phil()
  import iotbx.utils
  input_objects = iotbx.utils.process_command_line_inputs(
    args=args,
    master_phil=master_phil,
      input_types=("pdb",))
  work_phil = master_phil.fetch(sources=input_objects["phil"])
  work_params = work_phil.extract()
  file_name = work_params.mp_geo.pdb
  out_file = None
  if work_params.mp_geo.out_file != None:
    out_file = work_params.mp_geo.out_file
  do_bonds_and_angles = work_params.mp_geo.bonds_and_angles
  do_kinemage = work_params.mp_geo.kinemage
  do_rna_backbone = work_params.mp_geo.rna_backbone
  outliers_only = work_params.mp_geo.outliers_only
  use_cdl = work_params.mp_geo.cdl
  log = StringIO()
  basename = os.path.basename(file_name)
  if do_bonds_and_angles:
    out = file(out_file, 'w')
  elif do_kinemage:
    out = file(out_file, 'a')
  elif do_rna_backbone:
    if out_file == None:
      import sys
      out = sys.stdout
    else:
      out = file(out_file, 'w')
  restraints_loading_flags = {}
  restraints_loading_flags["use_neutron_distances"]=False
  from mmtbx.validation import utils
  params = pdb_interpretation.master_params.extract()
  params.restraints_library.cdl = use_cdl
  params.clash_guard.nonbonded_distance_threshold = None
  processed_pdb_file = pdb_interpretation.process(
    params                   = params,
    mon_lib_srv              = server.server(),
    ener_lib                 = server.ener_lib(),
    file_name                = file_name,
    strict_conflict_handling = True,
    restraints_loading_flags = restraints_loading_flags,
    force_symmetry           = True,
    substitute_non_crystallographic_unit_cell_if_necessary=True,
    log                      = log)
  grm = processed_pdb_file.geometry_restraints_manager()
  use_segids = utils.use_segids_in_place_of_chainids(
                 hierarchy=processed_pdb_file.all_chain_proxies.pdb_hierarchy)
  if do_bonds_and_angles or do_kinemage:
    rc = get_bond_and_angle_outliers(
           pdb_hierarchy=processed_pdb_file.all_chain_proxies.pdb_hierarchy,
           xray_structure=processed_pdb_file.xray_structure(),
           geometry_restraints_manager=grm,
           use_segids=use_segids,
           outliers_only=outliers_only)
    #get chain types
    chain_types = {}
    for chain in processed_pdb_file.all_chain_proxies.\
                   pdb_hierarchy.models()[0].chains() :
      if use_segids:
        chain_id = utils.get_segid_as_chainid(chain=chain)
      else:
        chain_id = chain.id
      main_conf = chain.conformers()[0]
      if chain_types.get(chain_id) not in ["NA", "PROTEIN"]:
        if (main_conf.is_na()) :
          chain_types[chain_id] = "NA"
        elif (main_conf.is_protein()):
          chain_types[chain_id] = "PROTEIN"
        else:
          chain_types[chain_id] = "UNK"
    outliers = []
    #bonds
    for result in rc.bonds.results:
      atom_info = result.atoms_info[0]
      # label:chain:number:ins:alt:type:measure:value:sigmas:class
      atoms_str = get_atoms_str(atoms_info=result.atoms_info)
      altloc = get_altloc(atoms_info=result.atoms_info)
      chain_id = atom_info.chain_id
      outliers.append( [chain_id,
                        atom_info.resseq,
                        atom_info.icode,
                        altloc,
                        atom_info.resname,
                        atoms_str,
                        result.model,
                        result.score,
                        chain_types[atom_info.chain_id]] )
    #angles
    for result in rc.angles.results:
      atom_info = result.atoms_info[0]
      # label:chain:number:ins:alt:type:measure:value:sigmas:class
      atoms_str = get_atoms_str(atoms_info=result.atoms_info)
      altloc = get_altloc(atoms_info=result.atoms_info)
      chain_id = atom_info.chain_id
      outliers.append( [chain_id,
                        atom_info.resseq,
                        atom_info.icode,
                        altloc,
                        atom_info.resname,
                        atoms_str,
                        result.model,
                        result.score,
                        chain_types[atom_info.chain_id]] )

    if do_bonds_and_angles:
      for outlier in outliers:
        print >> out, "%s:%2s:%s:%s:%s:%s:%s:%.3f:%.3f:%s" % (
          basename, outlier[0], outlier[1], outlier[2], outlier[3],
          outlier[4], outlier[5], outlier[6], outlier[7], outlier[8])
    elif do_kinemage:
      print >> out, rc.bonds.kinemage_header
      for result in rc.bonds.results:
        print >> out, result.as_kinemage()
      print >> out, rc.angles.kinemage_header
      for result in rc.angles.results:
        print >> out, result.as_kinemage()
    out.close()
  elif do_rna_backbone:
    from mmtbx.validation import utils
    rna_bb = utils.get_rna_backbone_dihedrals(processed_pdb_file)
    print >> out, rna_bb
    if out_file is not None:
      out.close()
Example #37
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 "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"
Example #38
0
def run(args):
    """
  I suggest adding here:
  cctbx_project/mmtbx/validation/regression/tst_mp_geo.py
  test cases with just .pdb, without arguments, etc.
  """
    master_phil = get_master_phil()
    import iotbx.phil
    input_objects = iotbx.phil.process_command_line_with_files(
        args=args, master_phil=master_phil, pdb_file_def="mp_geo.pdb")
    work_params = input_objects.work.extract()
    assert len(work_params.mp_geo.pdb) == 1, "Need a model file to run"
    file_name = work_params.mp_geo.pdb[0]
    out_file = None
    if work_params.mp_geo.out_file != None:
        out_file = work_params.mp_geo.out_file
    do_bonds_and_angles = work_params.mp_geo.bonds_and_angles
    do_kinemage = work_params.mp_geo.kinemage
    do_rna_backbone = work_params.mp_geo.rna_backbone
    outliers_only = work_params.mp_geo.outliers_only
    use_cdl = work_params.mp_geo.cdl
    log = StringIO()
    basename = os.path.basename(file_name)
    if out_file == None:
        import sys
        out = sys.stdout
    else:
        if do_bonds_and_angles:
            out = file(out_file, 'w')
        elif do_kinemage:
            out = file(out_file, 'a')
        elif do_rna_backbone:
            out = file(out_file, 'w')
    restraints_loading_flags = {}
    restraints_loading_flags["use_neutron_distances"] = False
    from mmtbx.validation import utils
    params = pdb_interpretation.master_params.extract()
    params.restraints_library.cdl = use_cdl
    params.clash_guard.nonbonded_distance_threshold = None
    processed_pdb_file = pdb_interpretation.process(
        params=params,
        mon_lib_srv=server.server(),
        ener_lib=server.ener_lib(),
        file_name=file_name,
        strict_conflict_handling=True,
        restraints_loading_flags=restraints_loading_flags,
        force_symmetry=True,
        substitute_non_crystallographic_unit_cell_if_necessary=True,
        log=log)
    grm = processed_pdb_file.geometry_restraints_manager()
    use_segids = utils.use_segids_in_place_of_chainids(
        hierarchy=processed_pdb_file.all_chain_proxies.pdb_hierarchy)
    if do_bonds_and_angles or do_kinemage:
        rc = get_bond_and_angle_outliers(
            pdb_hierarchy=processed_pdb_file.all_chain_proxies.pdb_hierarchy,
            xray_structure=processed_pdb_file.xray_structure(),
            geometry_restraints_manager=grm,
            use_segids=use_segids,
            outliers_only=outliers_only)
        #get chain types
        chain_types = {}
        for chain in processed_pdb_file.all_chain_proxies.\
                       pdb_hierarchy.models()[0].chains():
            if use_segids:
                chain_id = utils.get_segid_as_chainid(chain=chain)
            else:
                chain_id = chain.id
            main_conf = chain.conformers()[0]
            if chain_types.get(chain_id) not in ["NA", "PROTEIN"]:
                if (main_conf.is_na()):
                    chain_types[chain_id] = "NA"
                elif (main_conf.is_protein()):
                    chain_types[chain_id] = "PROTEIN"
                else:
                    chain_types[chain_id] = "UNK"
        outliers = []
        #bonds
        #for result in rc.bonds.results:
        for result in sorted(
                rc.bonds.results,
                key=lambda x:
            (x.atoms_info[0].resseq, get_altloc(atoms_info=x.atoms_info),
             get_atoms_str(atoms_info=x.atoms_info))):
            atom_info = result.atoms_info[0]
            # label:chain:number:ins:alt:type:measure:value:sigmas:class
            atoms_str = get_atoms_str(atoms_info=result.atoms_info)
            altloc = get_altloc(atoms_info=result.atoms_info)
            chain_id = atom_info.chain_id
            outliers.append([
                chain_id, atom_info.resseq, atom_info.icode, altloc,
                atom_info.resname, atoms_str, result.model, result.score,
                chain_types[atom_info.chain_id]
            ])
        #angles
        #for result in rc.angles.results:
        for result in sorted(
                rc.angles.results,
                key=lambda x:
            (x.atoms_info[0].resseq, get_altloc(atoms_info=x.atoms_info),
             get_atoms_str(atoms_info=x.atoms_info))):
            atom_info = result.atoms_info[0]
            # label:chain:number:ins:alt:type:measure:value:sigmas:class
            atoms_str = get_atoms_str(atoms_info=result.atoms_info)
            altloc = get_altloc(atoms_info=result.atoms_info)
            chain_id = atom_info.chain_id
            outliers.append([
                chain_id, atom_info.resseq, atom_info.icode, altloc,
                atom_info.resname, atoms_str, result.model, result.score,
                chain_types[atom_info.chain_id]
            ])

        if do_bonds_and_angles:
            for outlier in outliers:
                print >> out, "%s:%2s:%s:%s:%s:%s:%s:%.3f:%.3f:%s" % (
                    basename, outlier[0], outlier[1], outlier[2], outlier[3],
                    outlier[4], outlier[5], outlier[6], outlier[7], outlier[8])
        elif do_kinemage:
            print >> out, rc.bonds.kinemage_header
            for result in rc.bonds.results:
                print >> out, result.as_kinemage()
            print >> out, rc.angles.kinemage_header
            for result in rc.angles.results:
                print >> out, result.as_kinemage()
        out.close()
    elif do_rna_backbone:
        from mmtbx.validation import utils
        rna_bb = utils.get_rna_backbone_dihedrals(processed_pdb_file)
        print >> out, rna_bb
        if out_file is not None:
            out.close()
Example #39
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
Example #40
0
    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()
  #
  # XXX FIXME!!! Ramachandran selections does not work properly with insertion
Example #41
0
def run(args):
  global f
  f = os.path.join(os.path.split(sys.path[0])[0],"she.txt")
  with open(f,"w") as tempf:
    tempf.truncate()
  
  #check if we have experimental data
  t1=time.time()
  exp_data = None
  q_values = None
  var = None


  with open(f,"a") as tempf:
    params = get_input( args, master_params, "sas_I", banner, print_help,tempf)
  
  
  if (params is None):
    exit()

  if params.sas_I.experimental_data is not None:
    exp_data = saxs_read_write.read_standard_ascii_qis(params.sas_I.experimental_data)
    #exp_data.s = flex.sqrt( exp_data.i )
    if params.sas_I.data_reduct:
      qmax = exp_data.q[-1]
      bandwidth = 0.5/(params.sas_I.n_step-1.0)
      exp_data=reduce_raw_data( exp_data, qmax, bandwidth,outfile=f )
    q_values = exp_data.q
    var = flex.pow(exp_data.s,2.0)

  if q_values is None:
    q_values = params.sas_I.q_start +  \
              (params.sas_I.q_stop-params.sas_I.q_start
              )*flex.double( range(params.sas_I.n_step) )/(
                params.sas_I.n_step-1)
  # read in pdb file
  pdbi = pdb.hierarchy.input(file_name=params.sas_I.structure)
  #atoms = pdbi.hierarchy.atoms()
  atoms = pdbi.hierarchy.models()[0].atoms()
  # predefine some arrays we will need
  dummy_atom_types = flex.std_string()
  radius= flex.double()
  b_values = flex.double()
  occs = flex.double()
  xyz = flex.vec3_double()
  # keep track of the atom types we have encountered
  dummy_at_collection = []
  for atom in atoms:
   #if(not atom.hetero):   #### temporarily added
    b_values.append( atom.b )
    occs.append( atom.occ )
    xyz.append( atom.xyz )

  # Hydrogen controls whether H is treated explicitly or implicitly
  Hydrogen = not params.sas_I.internals.implicit_hydrogens

### Using Zernike Expansion to Calculate Intensity ###
  if(params.sas_I.method == 'zernike'):
    znk_nmax=params.sas_I.znk_nmax
    absolute_Io = znk_model.calc_abs_Io( atoms, Hydrogen)
    if( absolute_Io == 0.0): ## in case pdb hierarchy parse did not work out correctly
      absolute_Io = sas_library.calc_abs_Io_from_pdb( params.sas_I.structure, Hydrogen )
    if(Hydrogen):
      density = znk_model.get_density( atoms ) ## Get number of electrons as density
    else:
      density = znk_model.get_density( atoms ) + 1  ## add one H-atom to each heavy atom as a correction
    znk_engine = znk_model.xyz2znk(xyz,absolute_Io,znk_nmax, density=density)
    calc_i, calc_i_vac, calc_i_sol, calc_i_layer=znk_engine.calc_intensity(q_values)
    if(params.sas_I.experimental_data is not None):
      if params.sas_I.internals.solvent_scale:
        znk_engine.optimize_solvent(exp_data)
        calc_i = znk_engine.best_i_calc
      else:  #quick scaling
        scale, offset = linear_fit( calc_i, exp_data.i, exp_data.s )
        calc_i = calc_i*scale + offset

      CHI2 = flex.mean(flex.pow((calc_i-exp_data.i)/exp_data.s,2.0))
      CHI=math.sqrt(CHI2)
      with open(f,"a") as log:
        print >>log, "fitting to experimental curve, chi = %5.4e"%CHI

      print  "fitting to experimental curve, chi = %5.4e"%CHI
     
      write_debye_data(q_values, calc_i, params.sas_I.output+".fit")
      write_json(params.sas_I.output+"data.json", q_values, calc_i, y2=exp_data.i)
    else: ## scaled to the absolute I(0)
      write_she_data(q_values, calc_i, calc_i_vac, calc_i_layer, calc_i_sol, params.sas_I.output)
      write_json(params.sas_I.output+"data.json", q_values, calc_i)

    with open(f,"a") as log:
      print >>log,  znk_engine.summary()
      print >>log, "Done! total time used: %5.4e (seconds)"%(time.time()-t1)   

    print   znk_engine.summary()
    print  "Done! total time used: %5.4e (seconds)"%(time.time()-t1) 
    return
### End of Zernike Model ###


  dummy_ats= sas_library.read_dummy_type(file_name=params.sas_I.structure)
  for at in dummy_ats:
    if at not in dummy_at_collection:
      dummy_at_collection.append( at )


  radius_dict={}
  ener_lib=server.ener_lib()
  for dummy in dummy_at_collection:
    if(Hydrogen):
      radius_dict[dummy]=ener_lib.lib_atom[dummy].vdw_radius
    else:
      if ener_lib.lib_atom[dummy].vdwh_radius is not None:
        radius_dict[dummy]=ener_lib.lib_atom[dummy].vdwh_radius
      else:
        radius_dict[dummy]=ener_lib.lib_atom[dummy].vdw_radius

    if(radius_dict[dummy] is None):
      with open(f,"a") as log:
        print >> log, "****************** WARNING WARNING  *******************"
        print >> log, "Did not find atom type: ", dummy, "default value 1.58 A was used"
        print >> log, "*******************************************************"

      print  "****************** WARNING WARNING  *******************"
      print  "Did not find atom type: ", dummy, "default value 1.58 A was used"
      print  "*******************************************************"
      radius_dict[dummy]=1.58

  for at in dummy_ats:
    dummy_atom_types.append( at)
    radius.append(radius_dict[at])

  Scaling_factors=sas_library.load_scaling_factor()


  #------------------
  #
  B_factor_on=params.sas_I.internals.use_adp
  max_i = params.sas_I.internals.max_i
  max_L = params.sas_I.internals.max_L
  f_step= params.sas_I.internals.f_step
  q_step= params.sas_I.internals.integration_q_step
  solvent_radius_scale=params.sas_I.internals.solvent_radius_scale
  protein_radius_scale=params.sas_I.internals.protein_radius_scale
  rho=params.sas_I.internals.rho
  drho=params.sas_I.internals.drho
  delta=params.sas_I.internals.delta
  #------------------
  scat_lib_dummy =  sas_library.build_scattering_library( dummy_at_collection,
                                              q_values,
                                              radius_dict,
                                              solvent_radius_scale,
                                              Hydrogen,
                                              Scaling_factors)

  new_indx =flex.int()
  new_coord = flex.vec3_double()

  model=intensity.model(xyz,
                        radius*protein_radius_scale,
                        b_values,
                        occs,
                        dummy_ats,
                        scat_lib_dummy,
                        B_factor_on)
  t2=time.time()



  if(params.sas_I.method == 'she'):
    max_z_eps=0.02
    max_z=model.get_max_radius()*(q_values[-1]+max_z_eps) + max_z_eps
    engine = intensity.she_engine( model, scat_lib_dummy,max_i,max_L,f_step, q_step,max_z, delta,rho,drho )
    engine.update_solvent_params(rho,drho)
    i = engine.I()
    a = engine.get_IA()
    b = engine.get_IB()
    c = engine.get_IC()

    attri = engine.Area_Volume()
    with open(f,"a") as log:
      print >> log, "Inner surface Area of the Envelop is (A^2.0): ", attri[0];
      print >> log, "Inner Volume of the Envelop is       (A^3.0): ", attri[1];
      print >> log, "Volume of the Envelop shell is       (A^3.0): ", attri[2];
    
    print  "Inner surface Area of the Envelop is (A^2.0): ", attri[0];
    print  "Inner Volume of the Envelop is       (A^3.0): ", attri[1];
    print  "Volume of the Envelop shell is       (A^3.0): ", attri[2];
    if params.sas_I.output is not None:
       write_she_data( q_values, i,a,b,c, params.sas_I.output )
       write_json(params.sas_I.output+"data.json", q_values, i)


    if params.sas_I.pdblist is not None:
      pdblist=params.sas_I.pdblist
      if(os.path.isfile(pdblist)):
        list= open(pdblist,'r')
        for line in list:
          filename=line.split('\n')[0]
          pdbi = pdb.hierarchy.input(file_name=filename)
          t21 = time.time()
          atoms = pdbi.hierarchy.atoms()
          new_coord.clear()
          new_indx.clear()
          i=0
          for atom in atoms:
            new_coord.append( atom.xyz )
            new_indx.append(i)
            i=i+1

          engine.update_coord(new_coord,new_indx)
          i = engine.I()
          a = engine.get_IA()
          b = engine.get_IB()
          c = engine.get_IC()
          attri = engine.Area_Volume()
          with open(f,"a") as log:
            print >> log, "Inner surface Area of the Envelop is (A^2.0): ", attri[0]
            print >> log, "Inner Volume of the Envelop is       (A^3.0): ", attri[1]
            print >> log, "Volume of the Envelop shell is       (A^3.0): ", attri[2]

          print  "Inner surface Area of the Envelop is (A^2.0): ", attri[0]
          print  "Inner Volume of the Envelop is       (A^3.0): ", attri[1]
          print  "Volume of the Envelop shell is       (A^3.0): ", attri[2]
          write_she_data( q_values, i,a,b,c, filename+'.int' )
          with open(f,"a") as log:
            print >> log, '\nfininshed pdb ', filename, 'at: ',time.ctime(t21),'\n'
          print  '\nfininshed pdb ', filename, 'at: ',time.ctime(t21),'\n'

  #  attri = engine.Area_Volume2()
  #  print "Inner surface Area of the Envelop is (A^2.0): ", attri[0];

  elif(params.sas_I.method == 'debye'):
    engine = intensity.debye_engine (model, scat_lib_dummy)
    i = engine.I()
    if params.sas_I.output is not None:
       write_debye_data(q_values, i, params.sas_I.output)
       write_json(params.sas_I.output+"data.json", q_values, i)

  if(params.sas_I.experimental_data is not None):
    if params.sas_I.internals.solvent_scale:
      # more thorough scaling
      solvent_optim = solvent_parameter_optimisation(she_object=engine,
                                                     observed_data=exp_data )

      scale, offset, drho, a = solvent_optim.get_scales()
      i = solvent_optim.get_scaled_data()
    else:
      #quick scaling
      scale, offset = linear_fit( i, exp_data.i, exp_data.s )
      i = scale*i+offset

    with open(f,"a") as log:
      print >>log,  "Scaled calculated data against experimental data"
      print >>log, "Scale factor : %5.4e"%scale
      print >>log,"Offset       : %5.4e"%offset
  
    print   "Scaled calculated data against experimental data"
    print  "Scale factor : %5.4e"%scale
    print "Offset       : %5.4e"%offset

    if  params.sas_I.internals.solvent_scale:
      with open(f,"a") as log:
        print >> log, "  Solvent average R ra   : ", a
        print >> log, "  Solvation Contrast drho: ", drho
      
      print  "  Solvent average R ra   : ", a
      print  "  Solvation Contrast drho: ", drho
    print
    write_debye_data(q_values, i, params.sas_I.output+".fit")
    write_json(params.sas_I.output+"data.json", q_values, i, y2=exp_data.i)
    CHI2 = flex.mean(flex.pow((i-exp_data.i)/exp_data.s,2.0))
    CHI=math.sqrt(CHI2)
    with open(f,"a") as log:
      print >>log, "fitting to experimental curve, chi = %5.4e"%CHI
    print  "fitting to experimental curve, chi = %5.4e"%CHI

  t3=time.time()
  
  with open(f,"a") as log:
    print >> log, "Done! total time used: %5.4e (seconds)"%(t3-t1)
    print >>log, 'start running at:                ',time.ctime(t1)
    print >>log, 'finished PDB file processing at: ',time.ctime(t2)
    print >>log, 'got all desired I(q) at :        ',time.ctime(t3)

  print  "Done! total time used: %5.4e (seconds)"%(t3-t1)
  print  'start running at:                ',time.ctime(t1)
  print  'finished PDB file processing at: ',time.ctime(t2)
  print  'got all desired I(q) at :        ',time.ctime(t3)
  with open(f,"a") as log:
    log.write("__END__")
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
Example #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")
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)