def debye_waller_factors(self, miller_index=None, miller_indices=None, u_iso=None, b_iso=None, u_cart=None, b_cart=None, u_cif=None, u_star=None, exp_arg_limit=50, truncate_exp_arg=False): assert [miller_index, miller_indices].count(None) == 1 assert [u_iso, b_iso, u_cart, b_cart, u_cif, u_star].count(None) == 5 from cctbx import adptbx h = miller_index if (h is None): h = miller_indices if (u_iso is not None): b_iso = adptbx.u_as_b(u_iso) if (b_iso is not None): return adptbx.debye_waller_factor_b_iso( self.stol_sq(h), b_iso, exp_arg_limit, truncate_exp_arg) if (b_cart is not None): u_cart = adptbx.b_as_u(b_cart) if (u_cart is not None): u_star = adptbx.u_cart_as_u_star(self, u_cart) if (u_cif is not None): u_star = adptbx.u_cif_as_u_star(self, u_cif) assert u_star is not None return adptbx.debye_waller_factor_u_star( h, u_star, exp_arg_limit, truncate_exp_arg)
def lex_scatterer(self, args, scatterer_index): name = args[0] n = int(args[1]) n_vars = len(args) - 2 if n_vars == 5 or (not self.strictly_shelxl and n_vars == 6): values, behaviours = self.decode_variables(args[2:7], u_iso_idx=n_vars - 1) u = values[4] isotropic = True elif n_vars == 10: unit_cell = self.builder.crystal_symmetry.unit_cell() values, behaviours = self.decode_variables( args[2:-3] + (args[-1], args[-2], args[-3]), u_iso_idx=None) u = adptbx.u_cif_as_u_star(unit_cell, values[-6:]) isotropic = False else: raise shelx_error("wrong number of parameters for scatterer", self.line) site = values[0:3] occ = values[3] scattering_type = eltbx.xray_scattering.get_standard_label( self.label_for_sfac[n], # works thank to (a) above exact=True) scatterer = xray.scatterer(label=name, site=site, occupancy=occ, u=u, scattering_type=scattering_type) if (not isotropic or not isinstance(behaviours[-1], tuple) or behaviours[-1][0] != constant_times_u_eq): self.scatterer_to_bind_u_eq_to = (scatterer, scatterer_index) return scatterer, behaviours
def run(): symmetry = crystal.symmetry(unit_cell=(10.67, 10.67, 4.68, 90, 90, 120), space_group_symbol="P 3") special_position_settings = crystal.special_position_settings( crystal_symmetry=symmetry, min_distance_sym_equiv=0.5) site = (0, 0, 0.236) u_cif = ((0.17, 0.17, 0.19, 0.09, 0, 0)) site_symmetry = special_position_settings.site_symmetry(site) print "Input Ucif:", u_cif u_star = adptbx.u_cif_as_u_star(symmetry.unit_cell(), u_cif) if (not site_symmetry.is_compatible_u_star(u_star)): print "Warning: ADP tensor is incompatible with site symmetry." u_star = site_symmetry.average_u_star(u_star) u_cif = adptbx.u_star_as_u_cif(symmetry.unit_cell(), u_star) print "Averaged Ucif:", u_cif u_cart = adptbx.u_star_as_u_cart(symmetry.unit_cell(), u_star) eigenvalues = adptbx.eigenvalues(u_cart) if (not adptbx.is_positive_definite(eigenvalues)): print "ADP tensor is not positive definite." print "Eigenvectors and values:" eigensystem = adptbx.eigensystem(u_cart) for i in xrange(3): print " v=(%.5f %.5f %.5f) " % eigensystem.vectors(i), print "lambda=%.4f" % (eigensystem.values()[i], )
def run(): symmetry = crystal.symmetry( unit_cell=(10.67, 10.67, 4.68, 90, 90, 120), space_group_symbol="P 3") special_position_settings = crystal.special_position_settings( crystal_symmetry=symmetry, min_distance_sym_equiv=0.5) site = (0, 0, 0.236) u_cif = ((0.17, 0.17, 0.19, 0.09, 0, 0)) site_symmetry = special_position_settings.site_symmetry(site) print "Input Ucif:", u_cif u_star = adptbx.u_cif_as_u_star(symmetry.unit_cell(), u_cif) if (not site_symmetry.is_compatible_u_star(u_star)): print "Warning: ADP tensor is incompatible with site symmetry." u_star = site_symmetry.average_u_star(u_star) u_cif = adptbx.u_star_as_u_cif(symmetry.unit_cell(), u_star) print "Averaged Ucif:", u_cif u_cart = adptbx.u_star_as_u_cart(symmetry.unit_cell(), u_star) eigenvalues = adptbx.eigenvalues(u_cart) if (not adptbx.is_positive_definite(eigenvalues)): print "ADP tensor is not positive definite." print "Eigenvectors and values:" eigensystem = adptbx.eigensystem(u_cart) for i in xrange(3): print " v=(%.5f %.5f %.5f) " % eigensystem.vectors(i), print "lambda=%.4f" % (eigensystem.values()[i],)
def lex_scatterer(self, args, scatterer_index): name = args[0] n = int(args[1]) n_vars = len(args) - 2 if n_vars == 5 or (not self.strictly_shelxl and n_vars == 6): values, behaviours = self.decode_variables( args[2:7], u_iso_idx=n_vars-1) u = values[4] isotropic = True elif n_vars == 10: unit_cell = self.builder.crystal_symmetry.unit_cell() values, behaviours = self.decode_variables( args[2:-3] + (args[-1], args[-2], args[-3]), u_iso_idx=None) u = adptbx.u_cif_as_u_star(unit_cell, values[-6:]) isotropic = False else: raise shelx_error("wrong number of parameters for scatterer", self.line) site = values[0:3] occ = values[3] scattering_type = eltbx.xray_scattering.get_standard_label( self.label_for_sfac[n], # works thank to (a) above exact=True) scatterer = xray.scatterer( label = name, site = site, occupancy = occ, u = u, scattering_type = scattering_type) if (not isotropic or not isinstance(behaviours[-1], tuple) or behaviours[-1][0] != constant_times_u_eq): self.scatterer_to_bind_u_eq_to = (scatterer, scatterer_index) return scatterer, behaviours
def u_cif_as_u_star(self, u_cif): return adptbx.u_cif_as_u_star(self.crystal_symmetry.unit_cell(), u_cif)
class crystal_structure_builder(crystal_symmetry_builder): def __init__(self, cif_block): # XXX To do: interpret _atom_site_refinement_flags crystal_symmetry_builder.__init__(self, cif_block, strict=True) atom_sites_frac = [ as_double_or_none_if_all_question_marks( _, column_name='_atom_site_fract_%s' % axis) for _ in [ cif_block.get('_atom_site_fract_%s' % axis) for axis in ('x', 'y', 'z') ] ] if atom_sites_frac.count(None) == 3: atom_sites_cart = [ as_double_or_none_if_all_question_marks( _, column_name='_atom_site_Cartn_%s' % axis) for _ in [ cif_block.get('_atom_site_Cartn_%s' % axis) for axis in ('x', 'y', 'z') ] ] if atom_sites_cart.count(None) != 0: raise CifBuilderError("No atomic coordinates could be found") atom_sites_cart = flex.vec3_double(*atom_sites_cart) # XXX do we need to take account of _atom_sites_Cartn_tran_matrix_ ? atom_sites_frac = self.crystal_symmetry.unit_cell().fractionalize( atom_sites_cart) else: if atom_sites_frac.count(None) != 0: raise CifBuilderError("No atomic coordinates could be found") atom_sites_frac = flex.vec3_double(*atom_sites_frac) labels = cif_block.get('_atom_site_label') type_symbol = cif_block.get('_atom_site_type_symbol') U_iso_or_equiv = flex_double_else_none( cif_block.get('_atom_site_U_iso_or_equiv', cif_block.get('_atom_site_U_equiv_geom_mean'))) if U_iso_or_equiv is None: B_iso_or_equiv = flex_double_else_none( cif_block.get('_atom_site_B_iso_or_equiv', cif_block.get('_atom_site_B_equiv_geom_mean'))) adp_type = cif_block.get('_atom_site_adp_type') occupancy = flex_double_else_none( cif_block.get('_atom_site_occupancy')) scatterers = flex.xray_scatterer() atom_site_aniso_label = flex_std_string_else_none( cif_block.get('_atom_site_aniso_label')) if atom_site_aniso_label is not None: atom_site_aniso_label = atom_site_aniso_label adps = [ cif_block.get('_atom_site_aniso_U_%i' % i) for i in (11, 22, 33, 12, 13, 23) ] have_Bs = False if adps.count(None) > 0: adps = [ cif_block.get('_atom_site_aniso_B_%i' % i) for i in (11, 22, 33, 12, 13, 23) ] have_Bs = True if adps.count(None) == 6: adps = None elif adps.count(None) > 0: CifBuilderError("Some ADP items are missing") else: sel = None for adp in adps: f = (adp == "?") if (sel is None): sel = f else: sel &= f sel = ~sel atom_site_aniso_label = atom_site_aniso_label.select(sel) try: adps = [flex.double(adp.select(sel)) for adp in adps] except ValueError, e: raise CifBuilderError("Error interpreting ADPs: " + str(e)) adps = flex.sym_mat3_double(*adps) for i in range(len(atom_sites_frac)): kwds = {} if labels is not None: kwds.setdefault('label', str(labels[i])) if type_symbol is not None: kwds.setdefault('scattering_type', str(type_symbol[i])) if (atom_site_aniso_label is not None and adps is not None and labels is not None and labels[i] in atom_site_aniso_label): adp = adps[flex.first_index(atom_site_aniso_label, labels[i])] if have_Bs: adp = adptbx.b_as_u(adp) kwds.setdefault( 'u', adptbx.u_cif_as_u_star(self.crystal_symmetry.unit_cell(), adp)) elif U_iso_or_equiv is not None: kwds.setdefault('u', float_from_string(U_iso_or_equiv[i])) elif B_iso_or_equiv is not None: kwds.setdefault('b', float_from_string(B_iso_or_equiv[i])) if occupancy is not None: kwds.setdefault('occupancy', float_from_string(occupancy[i])) scatterers.append(xray.scatterer(**kwds)) scatterers.set_sites(atom_sites_frac) special_position_settings = crystal.special_position_settings( crystal_symmetry=self.crystal_symmetry, min_distance_sym_equiv=0.0001) self.structure = xray.structure( special_position_settings=special_position_settings, scatterers=scatterers)