def show_literature_fits(label, n_terms, null_fit, n_points, e_other=None): for lib in [ xray_scattering.wk1995, xray_scattering.it1992, xray_scattering.two_gaussian_agarwal_isaacs, xray_scattering.two_gaussian_agarwal_1978, xray_scattering.one_gaussian_agarwal_1978 ]: if (lib == xray_scattering.wk1995): try: lib_gaussian = xray_scattering.wk1995(label, True).fetch() lib_source = "WK1995" except Exception: lib_gaussian = None elif (lib == xray_scattering.it1992): try: lib_gaussian = xray_scattering.it1992(label, True).fetch() lib_source = "IT1992" except Exception: lib_gaussian = None elif (lib.table.has_key(label)): lib_gaussian = lib.table[label] lib_source = lib.source_short else: lib_gaussian = None if (lib_gaussian is not None): gaussian_fit = scitbx.math.gaussian.fit( null_fit.table_x()[:n_points], null_fit.table_y()[:n_points], null_fit.table_sigmas()[:n_points], lib_gaussian) e = flex.max(gaussian_fit.significant_relative_errors()) show_fit_summary(lib_source, label, gaussian_fit, e, e_other, lib_gaussian.n_terms())
def show_literature_fits(label, n_terms, null_fit, n_points, e_other=None): for lib in [xray_scattering.wk1995, xray_scattering.it1992, xray_scattering.two_gaussian_agarwal_isaacs, xray_scattering.two_gaussian_agarwal_1978, xray_scattering.one_gaussian_agarwal_1978]: if (lib == xray_scattering.wk1995): try: lib_gaussian = xray_scattering.wk1995(label, True).fetch() lib_source = "WK1995" except Exception: lib_gaussian = None elif (lib == xray_scattering.it1992): try: lib_gaussian = xray_scattering.it1992(label, True).fetch() lib_source = "IT1992" except Exception: lib_gaussian = None elif (lib.table.has_key(label)): lib_gaussian = lib.table[label] lib_source = lib.source_short else: lib_gaussian = None if (lib_gaussian is not None): gaussian_fit = scitbx.math.gaussian.fit( null_fit.table_x()[:n_points], null_fit.table_y()[:n_points], null_fit.table_sigmas()[:n_points], lib_gaussian) e = flex.max(gaussian_fit.significant_relative_errors()) show_fit_summary(lib_source, label, gaussian_fit, e, e_other, lib_gaussian.n_terms())
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 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 exercise_it1992(): e = xray_scattering.it1992("c1") assert e.table() == "IT1992" assert e.label() == "C" g = e.fetch() assert g.n_terms() == 4 assert g.n_parameters() == 9 assert approx_equal(g.array_of_a(), (2.31000, 1.02000, 1.58860, 0.865000)) assert approx_equal(g.array_of_b(), (20.8439, 10.2075, 0.568700, 51.6512)) assert approx_equal(g.c(), 0.215600) assert approx_equal(g.at_stol_sq(0), 5.99919997156) assert approx_equal(g.at_stol_sq(1. / 9), 2.26575563201) assert approx_equal(g.at_stol(1. / 9), 4.93537567523) assert approx_equal(g.at_d_star_sq(1. / 9), 4.04815863088) e = xray_scattering.it1992("yb2+", True) assert e.label() == "Yb2+" g = e.fetch() assert approx_equal(g.array_of_a()[0], 28.1209) assert approx_equal(g.array_of_b()[3], 20.3900) assert approx_equal(g.c(), 3.70983) e = xray_scattering.it1992(" yB3+") assert e.label() == "Yb3+" g = e.fetch() assert approx_equal(g.array_of_a()[0], 27.8917) n = 0 for e in xray_scattering.it1992_iterator(): n += 1 if (n == 213): assert e.label() == "Cf" else: assert e.label() != "Cf" d = xray_scattering.it1992(e.label(), True) assert d.label() == e.label() assert n == 213 i = xray_scattering.it1992_iterator() j = iter(i) assert i is j
def exercise_it1992(): e = xray_scattering.it1992("c1") assert e.table() == "IT1992" assert e.label() == "C" g = e.fetch() assert g.n_terms() == 4 assert g.n_parameters() == 9 assert approx_equal(g.array_of_a(), (2.31000, 1.02000, 1.58860, 0.865000)) assert approx_equal(g.array_of_b(), (20.8439, 10.2075, 0.568700, 51.6512)) assert approx_equal(g.c(), 0.215600) assert approx_equal(g.at_stol_sq(0), 5.99919997156) assert approx_equal(g.at_stol_sq(1./9), 2.26575563201) assert approx_equal(g.at_stol(1./9), 4.93537567523) assert approx_equal(g.at_d_star_sq(1./9), 4.04815863088) e = xray_scattering.it1992("yb2+", True) assert e.label() == "Yb2+" g = e.fetch() assert approx_equal(g.array_of_a()[0], 28.1209) assert approx_equal(g.array_of_b()[3], 20.3900) assert approx_equal(g.c(), 3.70983) e = xray_scattering.it1992(" yB3+") assert e.label() == "Yb3+" g = e.fetch() assert approx_equal(g.array_of_a()[0], 27.8917) n = 0 for e in xray_scattering.it1992_iterator(): n += 1 if (n == 213): assert e.label() == "Cf" else: assert e.label() != "Cf" d = xray_scattering.it1992(e.label(), True) assert d.label() == e.label() assert n == 213 i = xray_scattering.it1992_iterator() j = iter(i) assert i is j
def run(args): assert len(args) == 0 sds_it = xray_scattering.it1992("H").fetch() sds_wk = xray_scattering.wk1995("H").fetch() sds_ng = xray_scattering.n_gaussian_table_entry("H", 6).gaussian() iso_it = xray_scattering.it1992("Hiso").fetch() iso_wk = xray_scattering.wk1995("Hiso").fetch() iso_ng = xray_scattering.n_gaussian_table_entry("Hiso", 6).gaussian() print("@with g0") print('@ s0 legend "SDS ITC Tab 6.1.1.2"') for i, lbl in enumerate( ["SDS IT", "SDS WK", "SDS NG", "ISO IT", "ISO WK", "ISO NG"]): print('@ s%d legend "%s"' % (i + 1, lbl)) print("@ s0 symbol 1") print("@ s0 line linestyle 0") for x, y in itc_tab_6112: print(x, y) print("&") n_samples = 1000 for g in [sds_it, sds_wk, sds_ng, iso_it, iso_wk, iso_ng]: for i_stol in range(n_samples + 1): stol = 6 * i_stol / n_samples print(stol, g.at_stol(stol)) print("&")
def run(args): assert len(args) == 0 sds_it = xray_scattering.it1992("H").fetch() sds_wk = xray_scattering.wk1995("H").fetch() sds_ng = xray_scattering.n_gaussian_table_entry("H", 6).gaussian() iso_it = xray_scattering.it1992("Hiso").fetch() iso_wk = xray_scattering.wk1995("Hiso").fetch() iso_ng = xray_scattering.n_gaussian_table_entry("Hiso", 6).gaussian() print "@with g0" print '@ s0 legend "SDS ITC Tab 6.1.1.2"' for i,lbl in enumerate(["SDS IT", "SDS WK", "SDS NG", "ISO IT", "ISO WK", "ISO NG"]): print '@ s%d legend "%s"' % (i+1, lbl) print "@ s0 symbol 1" print "@ s0 line linestyle 0" for x,y in itc_tab_6112: print x, y print "&" n_samples = 1000 for g in [sds_it, sds_wk, sds_ng, iso_it, iso_wk, iso_ng]: for i_stol in xrange(n_samples+1): stol = 6 * i_stol / n_samples print stol, g.at_stol(stol) print "&"
def ensure_common_symbols(): lbl_it = [] for e in xray_scattering.it1992_iterator(): lbl_it.append(e.label()) lbl_it.sort() lbl_wk = [] for e in xray_scattering.wk1995_iterator(): lbl_wk.append(e.label()) lbl_wk.sort() assert lbl_wk == lbl_it lbl_ng = [] for i_entry in xrange(xray_scattering.n_gaussian_table_size()): lbl_ng.append(xray_scattering.n_gaussian_table_entry(i_entry, 6).label()) lbl_ng.sort() assert lbl_ng == lbl_it # for label in xray_scattering.standard_labels_list(): it = xray_scattering.it1992(label, True).fetch() wk = xray_scattering.wk1995(label, True).fetch() ng = xray_scattering.n_gaussian_table_entry(label, 0, 0).gaussian() assert approx_equal(wk.at_stol(0)/it.at_stol(0), 1, 5.e-3)
def ensure_common_symbols(): lbl_it = [] for e in xray_scattering.it1992_iterator(): lbl_it.append(e.label()) lbl_it.sort() lbl_wk = [] for e in xray_scattering.wk1995_iterator(): lbl_wk.append(e.label()) lbl_wk.sort() assert lbl_wk == lbl_it lbl_ng = [] for i_entry in range(xray_scattering.n_gaussian_table_size()): lbl_ng.append( xray_scattering.n_gaussian_table_entry(i_entry, 6).label()) lbl_ng.sort() assert lbl_ng == lbl_it # for label in xray_scattering.standard_labels_list(): it = xray_scattering.it1992(label, True).fetch() wk = xray_scattering.wk1995(label, True).fetch() ng = xray_scattering.n_gaussian_table_entry(label, 0, 0).gaussian() assert approx_equal(wk.at_stol(0) / it.at_stol(0), 1, 5.e-3)
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")
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"