예제 #1
0
def exercise():
  t = henke.table("SI")
  assert t.label() == "Si"
  assert t.atomic_number() == 14
  f = t.at_angstrom(2)
  assert f.is_valid_fp()
  assert f.is_valid_fdp()
  assert f.is_valid()
  from cctbx import factor_kev_angstrom
  assert approx_equal(f.fp(), t.at_kev(factor_kev_angstrom / 2).fp())
  assert approx_equal(f.fdp(), t.at_kev(factor_kev_angstrom / 2).fdp())
  assert approx_equal(f.fp(), t.at_ev(1000 * factor_kev_angstrom / 2).fp())
  assert approx_equal(f.fdp(), t.at_ev(1000 * factor_kev_angstrom / 2).fdp())
  c = f.as_complex()
  assert c.real == f.fp()
  assert c.imag == f.fdp()
  verify(t, 10.0, -9999.00, 4.00688)
  verify(t, 29.3, 4.04139-14, 0.371742)
  verify(t, 30000.0, 14.0266-14, 0.0228459)
  n = 0
  for t in henke.table_iterator():
    n += 1
    if (n == 1):
      assert t.label() == "H"
    elif (n == 92):
      assert t.label() == "U"
    u = henke.table(t.label())
    assert u.label() == t.label()
  assert n == 92
예제 #2
0
def exercise():
    t = henke.table("SI")
    assert t.label() == "Si"
    assert t.atomic_number() == 14
    f = t.at_angstrom(2)
    assert f.is_valid_fp()
    assert f.is_valid_fdp()
    assert f.is_valid()
    from cctbx import factor_kev_angstrom
    assert approx_equal(f.fp(), t.at_kev(factor_kev_angstrom / 2).fp())
    assert approx_equal(f.fdp(), t.at_kev(factor_kev_angstrom / 2).fdp())
    assert approx_equal(f.fp(), t.at_ev(1000 * factor_kev_angstrom / 2).fp())
    assert approx_equal(f.fdp(), t.at_ev(1000 * factor_kev_angstrom / 2).fdp())
    c = f.as_complex()
    assert c.real == f.fp()
    assert c.imag == f.fdp()
    verify(t, 10.0, -9999.00, 4.00688)
    verify(t, 29.3, 4.04139 - 14, 0.371742)
    verify(t, 30000.0, 14.0266 - 14, 0.0228459)
    n = 0
    for t in henke.table_iterator():
        n += 1
        if (n == 1):
            assert t.label() == "H"
        elif (n == 92):
            assert t.label() == "U"
        u = henke.table(t.label())
        assert u.label() == t.label()
    assert n == 92
예제 #3
0
def sfgen(wavelen_A, pdb_name, algo='fft', dmin=1.5, ano_flag=True):
    """
    generate the structure factors from a pdb
    for use with LD91
    :param wavelen_A:
    :param pdb_name:
    :param algo:
    :param dmin:
    :param ano_flag:
    :return:
    """
    pdb_in = pdb.input(pdb_name)
    xray_structure = pdb_in.xray_structure_simple()
    scatts = xray_structure.scatterers()

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

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

    fcalc = xray_structure.structure_factors(d_min=dmin,
                                             algorithm=algo,
                                             anomalous_flag=ano_flag)
    return fcalc.f_calc()
예제 #4
0
    def __init__(self, resolution, pdb_text, algorithm=None, wavelength=0.9):
        from iotbx import pdb
        pdb_inp = pdb.input(source_info=None, lines=pdb_text)
        xray_structure = pdb_inp.xray_structure_simple()
        xray_structure.show_summary(prefix="Input structure ")
        #
        # take a detour to insist on calculating anomalous contribution of every atom
        scatterers = xray_structure.scatterers()
        for sc in scatterers:
            from cctbx.eltbx import sasaki, henke
            #expected_sasaki = sasaki.table(sc.element_symbol()).at_angstrom(wavelength)
            expected_henke = henke.table(
                sc.element_symbol()).at_angstrom(wavelength)
            sc.fp = expected_henke.fp()
            sc.fdp = expected_henke.fdp()

        import mmtbx.command_line.fmodel
        phil2 = mmtbx.command_line.fmodel.fmodel_from_xray_structure_master_params
        params2 = phil2.extract()
        # adjust the cutoff of the generated intensities to assure that
        # statistics will be reported to the desired high-resolution limit
        # even if the observed unit cell differs slightly from the reference.
        params2.output.type = "complex"
        params2.high_resolution = resolution
        params2.fmodel.k_sol = 0.35
        params2.fmodel.b_sol = 46.
        params2.structure_factors_accuracy.algorithm = algorithm
        self.params2 = params2
        self.xray_structure = xray_structure
예제 #5
0
    def get_amplitudes(self, at_angstrom):
        # Since we are getting amplitudes for nanoBragg, let us assure they are in P1
        symbol = self.xs.space_group().info().type().lookup_symbol()
        assert symbol == "P 1", "Must be in P1 to accept amplitudes for ExaFEL GPU interface"
        # take a detour to insist on calculating anomalous contribution of every atom
        scatterers = self.xs.scatterers()
        for sc in scatterers:
            from cctbx.eltbx import henke
            expected_henke = henke.table(
                sc.element_symbol()).at_angstrom(at_angstrom)
            sc.fp = expected_henke.fp()
            sc.fdp = expected_henke.fdp()

        import mmtbx.command_line.fmodel
        phil2 = mmtbx.command_line.fmodel.fmodel_from_xray_structure_master_params
        params2 = phil2.extract()
        params2.high_resolution = 1.6
        params2.fmodel.k_sol = 0.35
        params2.fmodel.b_sol = 46.
        params2.structure_factors_accuracy.algorithm = "fft"
        params2.output.type = "real"
        import mmtbx
        f_model = mmtbx.utils.fmodel_from_xray_structure(
            xray_structure=self.xs,
            f_obs=None,
            add_sigmas=True,
            params=params2).f_model
        #f_model.show_summary()
        return f_model
예제 #6
0
    def fcalc_from_pdb(self, resolution=None, algorithm=None, wavelength=0.9):
        ''' Generate FCalc from PDB-formatted coordinates '''

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

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

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

        # how do we do bulk solvent?
        primitive_xray_structure = xray_structure.primitive_setting()
        P1_primitive_xray_structure = primitive_xray_structure.expand_to_p1()
        fcalc = P1_primitive_xray_structure.structure_factors(
            d_min=resolution, anomalous_flag=True,
            algorithm=algorithm).f_calc()
        return fcalc.amplitudes()
예제 #7
0
def fcalc_from_pdb(resolution,
                   algorithm=None,
                   wavelength=0.9,
                   anom=True,
                   ucell=None,
                   symbol=None,
                   as_amplitudes=True):
    pdb_lines = 'HEADER TEST\nCRYST1   50.000   60.000   70.000  90.00  90.00  90.00 P 1\nATOM      1  O   HOH A   1      56.829   2.920  55.702  1.00 20.00           O\nATOM      2  O   HOH A   2      49.515  35.149  37.665  1.00 20.00           O\nATOM      3  O   HOH A   3      52.667  17.794  69.925  1.00 20.00           O\nATOM      4  O   HOH A   4      40.986  20.409  18.309  1.00 20.00           O\nATOM      5  O   HOH A   5      46.896  37.790  41.629  1.00 20.00           O\nATOM      6 SED  MSE A   6       1.000   2.000   3.000  1.00 20.00          SE\nEND\n'
    from iotbx import pdb
    pdb_inp = pdb.input(source_info=None, lines=pdb_lines)
    xray_structure = pdb_inp.xray_structure_simple()
    if ucell is not None:
        assert symbol is not None
        from cctbx.xray import structure
        from cctbx import crystal
        crystal_sym = crystal.symmetry(unit_cell=ucell,
                                       space_group_symbol=symbol)
        xray_structure = structure(scatterers=(xray_structure.scatterers()),
                                   crystal_symmetry=crystal_sym)
    scatterers = xray_structure.scatterers()
    if anom:
        from cctbx.eltbx import henke
        for sc in scatterers:
            expected_henke = henke.table(
                sc.element_symbol()).at_angstrom(wavelength)
            sc.fp = expected_henke.fp()
            sc.fdp = expected_henke.fdp()

    primitive_xray_structure = xray_structure.primitive_setting()
    P1_primitive_xray_structure = primitive_xray_structure.expand_to_p1()
    fcalc = P1_primitive_xray_structure.structure_factors(
        d_min=resolution, anomalous_flag=anom, algorithm=algorithm).f_calc()
    if as_amplitudes:
        fcalc = fcalc.amplitudes().set_observation_type_xray_amplitude()
    return fcalc
예제 #8
0
def elem_fp_fdp_at_eV(elem_symbol, energy, how="henke"):
    if how == 'sasaki':
        tbl = sasaki.table(elem_symbol)
    else:
        tbl = henke.table(elem_symbol)
    keV = energy * 1e-3
    factor = tbl.at_kev(keV)
    return factor.fp(), factor.fdp()
예제 #9
0
 def reset_wavelength(self,newvalue):
   scatterers = self.xray_structure.scatterers()
   for sc in scatterers:
     from cctbx.eltbx import sasaki, henke
     #expected_sasaki = sasaki.table(sc.element_symbol()).at_angstrom(newvalue)
     expected_henke = henke.table(sc.element_symbol()).at_angstrom(newvalue)
     sc.fp = expected_henke.fp()
     sc.fdp = expected_henke.fdp()
예제 #10
0
def Yb_fp_fdp_at_eV(energy, how="henke"):
    if how=='sasaki':
        tbl = sasaki.table("Yb")
    elif how=='henke':
        tbl = henke.table("Yb")

    keV = energy * 1e-3
    factor = tbl.at_kev(keV)
    return factor.fp(), factor.fdp()
예제 #11
0
    def __init__(self, input_file=None):
        if input_file is None:
            input_file = "fp_fdp.npz"
        self.input_file = input_file

        if input_file is not None:
            self._load()

        self.hen_tbl = henke.table("Yb")
        self.sas_tbl = sasaki.table("Yb")
예제 #12
0
def get_scattF(wavelen_A, pdblines, algo, dmin, ano_flag):
    """
    mostly borrowed from tst_nanoBragg_basic.py
    """
    pdb_in = iotbx.pdb.input(source_info=None, lines=pdblines)
    xray_structure = pdb_in.xray_structure_simple()
    scatts = xray_structure.scatterers()
    for sc in scatts:
        expected_henke = henke.table(
            sc.element_symbol()).at_angstrom(wavelen_A)
        sc.fp = expected_henke.fp()
        sc.fdp = expected_henke.fdp()

    fcalc = xray_structure.structure_factors(dmin=dmin,
                                             algorithm=algo,
                                             anomalous_flag=ano_flag)
    return fcalc.fcalc()
예제 #13
0
파일: einsle.py 프로젝트: dials/cctbx
def show_scatterers(self, fpp, wave):
    print("""Label            f"      Coordinates        Occupancy """
          "Uiso, Ustar as Uiso")
    scatterers = self.scatterers()
    types_used = {}
    for j, sc in enumerate(scatterers):
        sc.fdp = fpp[j]
        show_scatterer(sc, unit_cell=self.unit_cell())
        types_used[sc.scattering_type] = None
    print("Tabular values for %7.1f eV (%8.5f Angstrom):" %
          (12398 / wave, wave))
    from cctbx.eltbx import sasaki, henke
    for tag in types_used.keys():
        fpp_expected_sasaki = sasaki.table(tag).at_angstrom(wave).fdp()
        fpp_expected_henke = henke.table(tag).at_angstrom(wave).fdp()
        print("           %-4s" % tag, end=' ')
        print("%6.3f" % (max(fpp_expected_sasaki, fpp_expected_henke)))
예제 #14
0
def hisym_fcalc_from_pdb(resolution,pdb_text,algorithm=None,wavelength=0.9):
  from iotbx import pdb
  pdb_inp = pdb.input(source_info=None,lines = pdb_text)
  xray_structure = pdb_inp.xray_structure_simple()
  xray_structure.show_summary(prefix="Input structure ")
  #
  # take a detour to insist on calculating anomalous contribution of every atom
  scatterers = xray_structure.scatterers()
  for sc in scatterers:
    from cctbx.eltbx import sasaki, henke
    #expected_sasaki = sasaki.table(sc.element_symbol()).at_angstrom(wavelength)
    expected_henke = henke.table(sc.element_symbol()).at_angstrom(wavelength)
    sc.fp = expected_henke.fp()
    sc.fdp = expected_henke.fdp()

  fcalc = xray_structure.structure_factors(
    d_min=resolution, anomalous_flag=True, algorithm=algorithm).f_calc()
  return fcalc.amplitudes()
  def from_structure(cls,xray_structure,energy):
    CS = cls()
    wavelength = 12398.425/float(energy)
    # take a detour to insist on calculating anomalous contribution of every atom
    scatterers = xray_structure.scatterers()
    print ("from structure",energy)

    for sc in scatterers:

      from cctbx.eltbx import sasaki, henke
      #expected_sasaki = sasaki.table(sc.element_symbol()).at_angstrom(wavelength)
      expected_henke = henke.table(sc.element_symbol()).at_angstrom(wavelength)
      #print (  sc.element_symbol(), expected_henke.fp(),expected_henke.fdp())
      sc.fp = expected_henke.fp()
      sc.fdp = expected_henke.fdp()
    CS.xray_structure = xray_structure
    CS.energy = energy
    return CS
예제 #16
0
def show_scatterers(self,fpp,wave):
    print ("""Label            f"      Coordinates        Occupancy """
                 "Uiso, Ustar as Uiso")
    scatterers = self.scatterers()
    types_used = {}
    for j,sc in enumerate(scatterers):
      sc.fdp = fpp[j]
      show_scatterer(sc, unit_cell=self.unit_cell())
      types_used[sc.scattering_type]=None
    print "Tabular values for %7.1f eV (%8.5f Angstrom):"%(12398/wave,wave)
    from cctbx.eltbx import sasaki, henke
    for tag in types_used.keys():
      fpp_expected_sasaki = sasaki.table(tag).at_angstrom(
          wave).fdp()
      fpp_expected_henke = henke.table(tag).at_angstrom(
          wave).fdp()
      print "           %-4s"%tag,
      print "%6.3f" % (max(fpp_expected_sasaki,fpp_expected_henke))
예제 #17
0
def fcalc_from_pdb(resolution,algorithm=None,wavelength=0.9):
  from iotbx import pdb
  pdb_inp = pdb.input(source_info=None,lines = pdb_lines)
  xray_structure = pdb_inp.xray_structure_simple()
  #
  # take a detour to insist on calculating anomalous contribution of every atom
  scatterers = xray_structure.scatterers()
  for sc in scatterers:
    from cctbx.eltbx import sasaki, henke
    #expected_sasaki = sasaki.table(sc.element_symbol()).at_angstrom(wavelength)
    expected_henke = henke.table(sc.element_symbol()).at_angstrom(wavelength)
    sc.fp = expected_henke.fp()
    sc.fdp = expected_henke.fdp()
  # how do we do bulk solvent?
  primitive_xray_structure = xray_structure.primitive_setting()
  P1_primitive_xray_structure = primitive_xray_structure.expand_to_p1()
  fcalc = P1_primitive_xray_structure.structure_factors(
    d_min=resolution, anomalous_flag=True, algorithm=algorithm).f_calc()
  return fcalc.amplitudes()
예제 #18
0
    def fcalc_from_pdb(self, resolution, algorithm=None, override_fdp=None):
        pdb_inp = pdb.input(source_info=None, lines=_pdb_lines)
        xray_structure = pdb_inp.xray_structure_simple()
        wavelength = self.beam.get_wavelength()
        #
        # take a detour to calculate anomalous contribution of every atom
        scatterers = xray_structure.scatterers()
        for sc in scatterers:
            expected_henke = henke.table(sc.element_symbol()).at_angstrom(wavelength)
            sc.fp = expected_henke.fp()
            sc.fdp = override_fdp if override_fdp is not None else expected_henke.fdp()

        # how do we do bulk solvent?
        primitive_xray_structure = xray_structure.primitive_setting()
        P1_primitive_xray_structure = primitive_xray_structure.expand_to_p1()
        fcalc = P1_primitive_xray_structure.structure_factors(
            d_min=resolution, anomalous_flag=True, algorithm=algorithm
        ).f_calc()
        return fcalc.amplitudes()
예제 #19
0
def fmodel_from_pdb(resolution, pdb_text, algorithm=None, wavelength=0.9):
    from iotbx import pdb
    pdb_inp = pdb.input(source_info=None, lines=pdb_text)
    xray_structure = pdb_inp.xray_structure_simple()
    xray_structure.show_summary(prefix="Input structure ")
    #
    # take a detour to insist on calculating anomalous contribution of every atom
    scatterers = xray_structure.scatterers()
    for sc in scatterers:
        from cctbx.eltbx import sasaki, henke
        #expected_sasaki = sasaki.table(sc.element_symbol()).at_angstrom(wavelength)
        expected_henke = henke.table(
            sc.element_symbol()).at_angstrom(wavelength)
        sc.fp = expected_henke.fp()
        sc.fdp = expected_henke.fdp()
    primitive_xray_structure = xray_structure.primitive_setting()
    P1_primitive_xray_structure = primitive_xray_structure.expand_to_p1()
    P1_primitive_xray_structure.show_summary(prefix="P1 structure ")
    # how do we do bulk solvent?
    import mmtbx.command_line.fmodel
    phil2 = mmtbx.command_line.fmodel.fmodel_from_xray_structure_master_params
    params2 = phil2.extract()
    # adjust the cutoff of the generated intensities to assure that
    # statistics will be reported to the desired high-resolution limit
    # even if the observed unit cell differs slightly from the reference.
    params2.output.type = "complex"
    params2.high_resolution = resolution
    params2.fmodel.k_sol = 0.435  # "Babinet" optimum, used 0.35 previously
    params2.fmodel.b_sol = 46.
    params2.structure_factors_accuracy.algorithm = algorithm
    import mmtbx
    f_model_complex = mmtbx.utils.fmodel_from_xray_structure(
        xray_structure=P1_primitive_xray_structure,
        f_obs=None,
        add_sigmas=False,
        params=params2).f_model
    f_model_real = abs(f_model_complex)
    f_model_real.set_observation_type_xray_amplitude()
    f_model_real.show_summary(prefix="FMODEL ")
    return f_model_real
예제 #20
0
def get_fp_fdp(atom_type=None,wavelength=None,out=sys.stdout):
  if not atom_type or not wavelength:
    raise Sorry("Please specify either f_double_prime or " +
      "atom_type and wavelength")
  from cctbx.eltbx import sasaki
  try:
    table = sasaki.table(atom_type)
    fp_fdp = table.at_angstrom(wavelength)
  except Exception:
    return None
#
  if not fp_fdp.is_valid():
    from cctbx.eltbx import henke
    try:
      table = henke.table(atom_type)
      fp_fdp = table.at_angstrom(wavelength)
    except Exception:
      return None
    #print "Using Henke tables for scattering factors"
  if fp_fdp.is_valid():
    return fp_fdp
  else:
    return None
예제 #21
0
    def fcalc_from_pdb(self, resolution):
        from iotbx import pdb

        pdb_inp = pdb.input(source_info=None, lines=pdb_lines)
        xray_structure = pdb_inp.xray_structure_simple()
        wavelength = self.beam.get_wavelength()

        # Assuming X-ray scattering here - does not matter for the geometry. How
        # would one use electron scattering instead?
        scatterers = xray_structure.scatterers()
        for sc in scatterers:
            expected_henke = henke.table(
                sc.element_symbol()).at_angstrom(wavelength)
            sc.fp = expected_henke.fp()
            sc.fdp = expected_henke.fdp()

        primitive_xray_structure = xray_structure.primitive_setting()
        P1_primitive_xray_structure = primitive_xray_structure.expand_to_p1()
        fcalc = P1_primitive_xray_structure.structure_factors(
            d_min=resolution, anomalous_flag=True,
            algorithm="direct").f_calc()

        return fcalc.amplitudes()
예제 #22
0
    def __init__(self, resolution, pdb_text, wavelength=None, **kwargs):
        from iotbx import pdb
        self.d_min = resolution
        self.algorithm = kwargs["algorithm"]
        self.method = kwargs["sfall"]
        pdb_inp = pdb.input(source_info=None, lines=pdb_text)
        xray_structure = pdb_inp.xray_structure_simple()
        #xray_structure.show_summary(prefix="Input structure ")
        self.xray_structure = xray_structure

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

        if self.method == "f_model":
            import mmtbx.command_line.fmodel
            phil2 = mmtbx.command_line.fmodel.fmodel_from_xray_structure_master_params
            #phil2.show()
            params2 = phil2.extract()
            # adjust the cutoff of the generated intensities to assure that
            # statistics will be reported to the desired high-resolution limit
            # even if the observed unit cell differs slightly from the reference.
            params2.high_resolution = self.d_min
            params2.output.type = "complex"
            params2.fmodel.k_sol = kwargs["k_sol"]
            params2.fmodel.b_sol = kwargs["b_sol"]
            params2.structure_factors_accuracy.algorithm = kwargs["algorithm"]
            params2.structure_factors_accuracy.grid_resolution_factor = kwargs[
                "grid_resolution_factor"]
            if kwargs["k_sol"] > 0 and kwargs["b_sol"] > 0:
                params2.mask.grid_step_factor = kwargs["grid_step_factor"]
            self.params2 = params2
예제 #23
0
def examples():
  # Generate space groups (in matrix/vector form) based on spacegroup number
  # (names are *not* a pain)
  # See also: http://cctbx.sourceforge.net/current/c_plus_plus/classcctbx_1_1sgtbx_1_1space__group__symbols.html#_details
  from cctbx import sgtbx
  for s in sgtbx.space_group_info(symbol="I41/amd").group():
    print s # in "xyz" notation
    print s.r().as_rational().mathematica_form(), \
          s.t().as_rational().transpose().mathematica_form()
  print

  # now with a space group number
  space_group_info = sgtbx.space_group_info(number=123)
  space_group_info.show_summary()
  print

  # Generate conditions for allowed reflections etc
  from cctbx import crystal
  from cctbx import miller
  crystal_symmetry = crystal.symmetry(
    unit_cell=(10,10,13,90,90,90),
    space_group_info=space_group_info)
  miller_set = miller.build_set(
    crystal_symmetry=crystal_symmetry,
    anomalous_flag=False,
    d_min=4)
  # change the space group in order to get a few systematic absences
  miller_set = miller_set.customized_copy(
    space_group_info=sgtbx.space_group_info(symbol="I41/amd"))
  sys_absent_flags = miller_set.sys_absent_flags()
  for h,f in zip(sys_absent_flags.indices(), sys_absent_flags.data()):
    print h, f
  print
  # try also (from the command line): libtbx.help cctbx.miller

  # Generate point group of space group in matrix form
  point_group = miller_set.space_group().build_derived_point_group()
  point_group_info = sgtbx.space_group_info(group=point_group)
  point_group_info.show_summary()
  for s in point_group:
    print s
  print

  # Generate point-group matrices for given coordinate
  # first we have to define what we consider as special position
  special_position_settings = crystal.special_position_settings(
    crystal_symmetry=miller_set,
    min_distance_sym_equiv=0.5) # <<<<< here
  site_symmetry = special_position_settings.site_symmetry(
    site=(0,0.48,0))
  print "special position operator:", site_symmetry.special_op_simplified()
  print "distance to original site:", site_symmetry.distance_moved()
  print "point group of the special position:"
  for s in site_symmetry.matrices():
    print s
  print
  # See also: http://cci.lbl.gov/~rwgk/my_papers/iucr/au0265_reprint.pdf

  # Access database for form factors
  from cctbx.eltbx import xray_scattering
  si_form_factor = xray_scattering.it1992("Si")
  gaussians = si_form_factor.fetch()
  for stol in [0, 0.01, 0.02, 0.5]:
    print stol, gaussians.at_stol(stol)
  print

  # anomalous scattering factors: Sasaki tables
  from cctbx.eltbx import sasaki
  si_table = sasaki.table("Si")
  for wavelength in [0.5, 0.8, 0.9]:
    data = si_table.at_angstrom(wavelength)
    print wavelength, data.fp(), data.fdp()
  print

  # anomalous scattering factors: Henke tables
  from cctbx.eltbx import henke
  si_table = henke.table("Si")
  for wavelength in [0.5, 0.8, 0.9]:
    data = si_table.at_angstrom(wavelength)
    print wavelength, data.fp(), data.fdp()
  print
  print "OK"
예제 #24
0
def examples():
    # Generate space groups (in matrix/vector form) based on spacegroup number
    # (names are *not* a pain)
    # See also: http://cctbx.sourceforge.net/current/c_plus_plus/classcctbx_1_1sgtbx_1_1space__group__symbols.html#_details
    from cctbx import sgtbx
    for s in sgtbx.space_group_info(symbol="I41/amd").group():
        print(s)  # in "xyz" notation
        print(s.r().as_rational().mathematica_form(), \
              s.t().as_rational().transpose().mathematica_form())
    print()

    # now with a space group number
    space_group_info = sgtbx.space_group_info(number=123)
    space_group_info.show_summary()
    print()

    # Generate conditions for allowed reflections etc
    from cctbx import crystal
    from cctbx import miller
    crystal_symmetry = crystal.symmetry(unit_cell=(10, 10, 13, 90, 90, 90),
                                        space_group_info=space_group_info)
    miller_set = miller.build_set(crystal_symmetry=crystal_symmetry,
                                  anomalous_flag=False,
                                  d_min=4)
    # change the space group in order to get a few systematic absences
    miller_set = miller_set.customized_copy(
        space_group_info=sgtbx.space_group_info(symbol="I41/amd"))
    sys_absent_flags = miller_set.sys_absent_flags()
    for h, f in zip(sys_absent_flags.indices(), sys_absent_flags.data()):
        print(h, f)
    print()
    # try also (from the command line): libtbx.help cctbx.miller

    # Generate point group of space group in matrix form
    point_group = miller_set.space_group().build_derived_point_group()
    point_group_info = sgtbx.space_group_info(group=point_group)
    point_group_info.show_summary()
    for s in point_group:
        print(s)
    print()

    # Generate point-group matrices for given coordinate
    # first we have to define what we consider as special position
    special_position_settings = crystal.special_position_settings(
        crystal_symmetry=miller_set, min_distance_sym_equiv=0.5)  # <<<<< here
    site_symmetry = special_position_settings.site_symmetry(site=(0, 0.48, 0))
    print("special position operator:", site_symmetry.special_op_simplified())
    print("distance to original site:", site_symmetry.distance_moved())
    print("point group of the special position:")
    for s in site_symmetry.matrices():
        print(s)
    print()
    # See also: http://cci.lbl.gov/~rwgk/my_papers/iucr/au0265_reprint.pdf

    # Access database for form factors
    from cctbx.eltbx import xray_scattering
    si_form_factor = xray_scattering.it1992("Si")
    gaussians = si_form_factor.fetch()
    for stol in [0, 0.01, 0.02, 0.5]:
        print(stol, gaussians.at_stol(stol))
    print()

    # anomalous scattering factors: Sasaki tables
    from cctbx.eltbx import sasaki
    si_table = sasaki.table("Si")
    for wavelength in [0.5, 0.8, 0.9]:
        data = si_table.at_angstrom(wavelength)
        print(wavelength, data.fp(), data.fdp())
    print()

    # anomalous scattering factors: Henke tables
    from cctbx.eltbx import henke
    si_table = henke.table("Si")
    for wavelength in [0.5, 0.8, 0.9]:
        data = si_table.at_angstrom(wavelength)
        print(wavelength, data.fp(), data.fdp())
    print()
    print("OK")
예제 #25
0
  def launch(self):
    import shutil
    #check whether ACTA was set, so the cif contains all necessary information to be copied back and forth

    # Check if job folder already exists and (if needed) make the backup folders
    if os.path.exists(self.full_dir):
      self.backup = os.path.join(self.full_dir, "backup")
      i = 1
      while (os.path.exists(self.backup + "_%d"%i)):
        i = i + 1
      self.backup = self.backup + "_%d"%i
      os.mkdir(self.backup)
      try:
        files = (file for file in os.listdir(self.full_dir)
                 if os.path.isfile(os.path.join(self.full_dir, file)))
        for f in files:
          f_work = os.path.join(self.full_dir,f)
          f_dest = os.path.join(self.backup,f)
          shutil.move(f_work,f_dest)
      except:
        pass
    try:
      os.mkdir(self.full_dir)
    except:
      pass
    tries = 0
    while not os.path.exists(self.full_dir) and tries < 5:
      try:
        os.mkdir(self.full_dir)
        break
      except:
        time.sleep(0.1)
        tries += 1
        pass

    time.sleep(0.1)
    self.origin_folder = OV.FilePath()

#    if not olx.Ins('ACTA'):
#      olex.m('addins ACTA')
#      olex.m('refine')
    autogrow = olx.GetVar("settings.tonto.HAR.autogrow", None)
    if olx.xf.latt.IsGrown() == 'true':
      if olx.Alert("Please confirm",\
"""This is a grown structure. If you have created a cluster of molecules, make sure
that the structure you see on the screen obeys the crystallographic symmetry.
If this is not the case, the HAR will not work properly.
Make sure the cluster/moelcule is neutral and fully completed.

Continue?""", "YN", False) == 'N':
        return
    elif olx.xf.au.GetZprime() != '1' and autogrow == 'true':
      olex.m("kill $q")
      olx.Grow()
      olex.m("grow -w")
    elif olx.xf.au.GetZprime() < '1' and autogrow == 'false':
      if olx.Alert("Attention!",\
"""This appears to be a z' < 1 structure.
Autogrow is disabled and the structure is not grown.

This is HIGHLY unrecomendet!

Please complete the molecule in a way it forms a full chemical entity.
Benzene would need to contain one complete 6-membered ring to work,
otherwise the wavefunction can not be calculated properly!
Are you sure you want to continue with this structure?""", "YN", False) == 'N':
        return
    autorefine = olx.GetVar("settings.tonto.HAR.autorefine", None)
    if autorefine == 'true':
      olex.m("refine")
    model_file_name = os.path.join(self.full_dir, self.name) + ".cif"
    olx.Kill("$Q")
    olx.File(model_file_name)

    data_file_name = os.path.join(self.full_dir, self.name) + ".hkl"
    if not os.path.exists(data_file_name):
      from cctbx_olex_adapter import OlexCctbxAdapter
      from iotbx.shelx import hklf
      cctbx_adaptor = OlexCctbxAdapter()
      with open(data_file_name, "w") as out:
        f_sq_obs = cctbx_adaptor.reflections.f_sq_obs_filtered
        for j, h in enumerate(f_sq_obs.indices()):
          s = f_sq_obs.sigmas()[j]
          if s <= 0: f_sq_obs.sigmas()[j] = 0.01
          i = f_sq_obs.data()[j]
          if i < 0: f_sq_obs.data()[j] = 0
        f_sq_obs.export_as_shelx_hklf(out, normalise_if_format_overflow=True)
    self.save()

    args = [self.parent.exe, self.name+".cif",
            "-basis-dir", self.parent.basis_dir,
             "-shelx-f2", self.name+".hkl"]

    disp = olx.GetVar("settings.tonto.HAR.dispersion", None)
    if 'true' == disp:
      import olexex
      from cctbx.eltbx import henke
      olex_refinement_model = OV.GetRefinementModel(False)
      sfac = olex_refinement_model.get('sfac')
      fp_fdps = {}
      wavelength = olex_refinement_model['exptl']['radiation']
      if sfac is not None:
        for element, sfac_dict in sfac.iteritems():
          custom_fp_fdps.setdefault(element, sfac_dict['fpfdp'])
      asu = olex_refinement_model['aunit']
      for residue in asu['residues']:
        for atom in residue['atoms']:
          element_type = atom['type']
          if element_type not in fp_fdps:
            fpfdp = henke.table(str(element_type)).at_angstrom(wavelength).as_complex()
            fp_fdps[element_type] = (fpfdp.real, fpfdp.imag)
      disp_arg = " ".join(["%s %s %s" %(k, v[0], v[1]) for k,v in fp_fdps.iteritems()])
      args.append("-dispersion")
      args.append('%s' %disp_arg)

    for k,v in HARp_instance.options.iteritems():
      val = olx.GetVar(k, None)
      if len(v) == 2:
        if val is not None:
          args.append('-' + v[1])
          args.append(val)
      elif k == 'settings.tonto.HAR.hydrogens':
        if val == 'positions only':
          args.append("-h-adps")
          args.append("f")
        elif val == 'isotropic':
          args.append("-h-adps")
          args.append("f")
          args.append("-h-iso")
          args.append("t")
        elif val == "anisotropic":
          args.append("-h-adps")
          args.append("t")
        elif val == "not":
          args.append("-h-adps")
          args.append("f")
          args.append("-h-pos")
          args.append("f")
        pass
    clustergrow = olx.GetVar("settings.tonto.HAR.cluster-grow", None)
    if clustergrow == 'false':
      args.append("-complete-mol")
      args.append("f")

    self.result_fn = os.path.join(self.full_dir, self.name) + ".archive.cif"
    self.error_fn = os.path.join(self.full_dir, self.name) + ".err"
    self.out_fn = os.path.join(self.full_dir, self.name) + ".out"
    self.dump_fn = os.path.join(self.full_dir, "hart.exe.stackdump")
    self.analysis_fn = os.path.join(self.full_dir, "stdout.fit_analysis")
    os.environ['hart_cmd'] = '+&-'.join(args)
    os.environ['hart_file'] = self.name
    os.environ['hart_dir'] = self.full_dir
    from subprocess import Popen
    pyl = OV.getPYLPath()
    if not pyl:
      print("A problem with pyl is encountered, aborting.")
      return
    Popen([pyl,
           os.path.join(p_path, "HARt-launch.py")])
예제 #26
0
파일: fdp_plot.py 프로젝트: nksauter/LS49
    CSV = csv()

    wavelength = lambd[50]
    from iotbx import pdb
    pdb_text = open("1m2a.pdb", "r").read()
    pdb_inp = pdb.input(source_info=None, lines=pdb_text)
    xray_structure = pdb_inp.xray_structure_simple()
    xray_structure.show_summary(prefix="Input structure ")
    #
    # take a detour to insist on calculating anomalous contribution of every atom
    scatterers = xray_structure.scatterers()
    for isc, sc in enumerate(scatterers):
        from cctbx.eltbx import sasaki, henke
        #expected_sasaki = sasaki.table(sc.element_symbol()).at_angstrom(wavelength)
        expected_henke = henke.table(
            sc.element_symbol()).at_angstrom(wavelength)
        sc.fp = expected_henke.fp()
        sc.fdp = expected_henke.fdp()

        if sc.element_symbol() == "Fe":
            ife = isc
            break

    fp = flex.double()
    fdp = flex.double()
    for wave, energy in zip(lambd, energies):
        print(energy, end=' ')
        sc = scatterers[ife]
        expected_henke = henke.table(sc.element_symbol()).at_angstrom(wave)
        sc.fp = expected_henke.fp()
        sc.fdp = expected_henke.fdp()