def __init__(self, flipping_iterator, f_obs, **kwds): self.flipping_iterator = flipping_iterator adopt_optional_init_args(self, kwds) assert (self.min_delta_guessing_iterations < self.max_delta_guessing_iterations) self.attempts = [] self.normalisations = None self.f_calc_solutions = [] self.had_phase_transition = False self.max_attempts_exceeded = False # prepare f_obs f_obs = f_obs.eliminate_sys_absent()\ .as_non_anomalous_array() \ .merge_equivalents().array() # setup state machine self.state = self.starting = self._starting(f_obs) self.guessing_delta = { "sigma": self._guessing_delta_with_map_sigma, "c_tot_over_c_flip": self._guessing_delta_with_c_tot_over_c_flip, }[self.delta_guessing_method]() self.solving = self._solving() self.polishing = self._polishing() self.evaluating = self._evaluating(f_obs) self.finished = self._finished()
def __init__(self, f_in_p1, **kwds): isinstance(f_in_p1, miller.array) assert f_in_p1.space_group().type().hall_symbol() == ' P 1' self.f_in_p1 = f_in_p1 adopt_optional_init_args(self, kwds) self.search_parameters = maptbx.peak_search_parameters( peak_search_level=3, interpolate=True, min_distance_sym_equiv=0.25, ) self.space_group = sgtbx.space_group('P 1', t_den=sg_t_den) self.origin = None self.symmetry_pool = [] self.find_centring_translations() if self.space_group.order_z() > 1: f_in_centered = self.f_in_p1.customized_copy( space_group_info=sgtbx.space_group_info(group=self.space_group) ).eliminate_sys_absent().merge_equivalents().array() self.cb_op_to_primitive = \ f_in_centered.change_of_basis_op_to_primitive_setting() self.f_in_p1 = f_in_centered.change_basis(self.cb_op_to_primitive) self.space_group = self.f_in_p1.space_group() else: self.cb_op_to_primitive = sgtbx.change_of_basis_op() self.f_in_p1 = self.f_in_p1.generate_bijvoet_mates() self.find_space_group() self.space_group = sgtbx.space_group(self.space_group.type().hall_symbol(), t_den=sgtbx.sg_t_den) self.space_group_info = sgtbx.space_group_info(group=self.space_group)
def __init__(self, f_in_p1, **kwds): isinstance(f_in_p1, miller.array) assert f_in_p1.space_group().type().hall_symbol() == ' P 1' self.f_in_p1 = f_in_p1 adopt_optional_init_args(self, kwds) self.search_parameters = maptbx.peak_search_parameters( peak_search_level=3, interpolate=True, min_distance_sym_equiv=0.25, ) self.space_group = sgtbx.space_group('P 1', t_den=sg_t_den) self.origin = None self.symmetry_pool = [] self.find_centring_translations() if self.space_group.order_z() > 1: f_in_centered = self.f_in_p1.customized_copy( space_group_info=sgtbx.space_group_info(group=self.space_group) ).eliminate_sys_absent().merge_equivalents().array() self.cb_op_to_primitive = \ f_in_centered.change_of_basis_op_to_primitive_setting() self.f_in_p1 = f_in_centered.change_basis(self.cb_op_to_primitive) self.space_group = self.f_in_p1.space_group() else: self.cb_op_to_primitive = sgtbx.change_of_basis_op() self.f_in_p1 = self.f_in_p1.generate_bijvoet_mates() self.find_space_group() self.space_group = sgtbx.space_group( self.space_group.type().hall_symbol(), t_den=sgtbx.sg_t_den) self.space_group_info = sgtbx.space_group_info(group=self.space_group)
def __init__( self, target, prediction_parameterisation, constraints_manager=None, log=None, tracking=None, max_iterations=20, **kwds ): AdaptLstbx.__init__( self, target, prediction_parameterisation, constraints_manager, log=log, tracking=tracking, max_iterations=max_iterations, ) # add an attribute to the journal self.history.add_column("reduced_chi_squared") # flex.double() # adopt any overrides of the defaults above libtbx.adopt_optional_init_args(self, kwds)
def __init__(self, structure, **kwds): from cctbx.eltbx import covalent_radii self.structure = structure libtbx.adopt_optional_init_args(self, kwds) max_r = 0 for st in structure.scattering_type_registry( ).type_index_pairs_as_dict(): r = 0 if self.radii: r = self.radii.get(st, 0) if r == 0: r = covalent_radii.table(st).radius() if r > max_r: max_r = r self.structure = structure self.buffer_thickness = 2 * max_r + self.covalent_bond_tolerance asu_mappings = structure.asu_mappings( buffer_thickness=self.buffer_thickness) self._pair_asu_table = crystal.pair_asu_table(asu_mappings) self._pair_asu_table_needs_updating = False if self.radii is None: self.radii = {} self._pair_asu_table.add_covalent_pairs( structure.scattering_types(), conformer_indices=self.conformer_indices, sym_excl_indices=self.sym_excl_indices, tolerance=self.covalent_bond_tolerance, radii=self.radii) self.pair_sym_table = self.pair_asu_table.extract_pair_sym_table()
def __init__(self, target, prediction_parameterisation, log=None, verbosity=0, track_step=False, track_gradient=False, track_parameter_correlation=False, track_out_of_sample_rmsd=False, max_iterations=20, **kwds): AdaptLstbx.__init__( self, target, prediction_parameterisation, log=log, verbosity=verbosity, track_step=track_step, track_gradient=track_gradient, track_parameter_correlation=track_parameter_correlation, track_out_of_sample_rmsd=track_out_of_sample_rmsd, max_iterations=max_iterations) # add an attribute to the journal self.history.add_column("reduced_chi_squared") #flex.double() # adopt any overrides of the defaults above libtbx.adopt_optional_init_args(self, kwds)
def __init__(self, structure, **kwds): from cctbx.eltbx import covalent_radii self.structure = structure libtbx.adopt_optional_init_args(self, kwds) max_r = 0 for st in structure.scattering_type_registry().type_index_pairs_as_dict(): r = 0 if self.radii: r = self.radii.get(st, 0) if r == 0: r = covalent_radii.table(st).radius() if r > max_r: max_r = r self.structure = structure self.buffer_thickness = 2*max_r + self.covalent_bond_tolerance asu_mappings = structure.asu_mappings( buffer_thickness=self.buffer_thickness) self._pair_asu_table = crystal.pair_asu_table(asu_mappings) self._pair_asu_table_needs_updating = False if self.radii is None: self.radii = {} self._pair_asu_table.add_covalent_pairs( structure.scattering_types(), conformer_indices=self.conformer_indices, sym_excl_indices=self.sym_excl_indices, tolerance=self.covalent_bond_tolerance, radii=self.radii ) self.pair_sym_table = self.pair_asu_table.extract_pair_sym_table()
def __init__( self, target, prediction_parameterisation, log=None, verbosity=0, track_step=False, track_gradient=False, track_parameter_correlation=False, track_out_of_sample_rmsd=False, max_iterations=20, **kwds ): AdaptLstbx.__init__( self, target, prediction_parameterisation, log=log, verbosity=verbosity, track_step=track_step, track_gradient=track_gradient, track_parameter_correlation=track_parameter_correlation, track_out_of_sample_rmsd=track_out_of_sample_rmsd, max_iterations=max_iterations, ) # add an attribute to the journal self.history.add_column("reduced_chi_squared") # flex.double() # adopt any overrides of the defaults above libtbx.adopt_optional_init_args(self, kwds)
def __init__(self, non_linear_ls, **kwds): """ """ libtbx.adopt_optional_init_args(self, kwds) if self.track_all: self.track_step = self.track_gradient = True self.non_linear_ls = journaled_non_linear_ls(non_linear_ls, self, self.track_gradient, self.track_step) self.do()
def __init__(self, unit_cell, light_position, **kwds): super(widget, self).__init__(QGLFormat(QGL.SampleBuffers),) adopt_optional_init_args(self, kwds) self.unit_cell = unit_cell self.light_position = light_position self.set_extent(self.from_here, self.to_there) self.orthogonaliser = gltbx.util.matrix( unit_cell.orthogonalization_matrix()) self.orbiting = None self.dolly = None self.mouse_position = None
def __init__(self, normalised, **kwds): super(polynomial_fit, self).__init__(n_parameters=3, normalised=normalised) libtbx.adopt_optional_init_args(self, kwds) self.t = t = flex.double_range(self.n_data)/self.n_data noise = self.noise*flex.double([ (-1)**i for i in xrange(self.n_data) ]) self.yo = 2.*t**2.*(1-t) + noise self.one = flex.double(self.n_data, 1) self.t2 = t**2 self.t3 = t**3 self.restart()
def __init__(self, normalised, **kwds): super(klass, self).__init__(n_parameters=3, normalised=normalised) libtbx.adopt_optional_init_args(self, kwds) self.t = t = flex.double_range(self.n_data) / self.n_data noise = self.noise * flex.double([(-1)**i for i in xrange(self.n_data)]) self.yo = 2. * t**2. * (1 - t) + noise self.one = flex.double(self.n_data, 1) self.t2 = t**2 self.t3 = t**3 self.restart()
def __init__(self, observations, reparametrisation, **kwds): super(klass, self).__init__(reparametrisation.n_independents) self.observations = observations self.reparametrisation = reparametrisation adopt_optional_init_args(self, kwds) if self.f_mask is not None: assert self.f_mask.size() == observations.fo_sq.size() self.one_h_linearisation = direct.f_calc_modulus_squared( self.xray_structure) if self.weighting_scheme == "default": self.weighting_scheme = self.default_weighting_scheme() self.origin_fixing_restraint = self.origin_fixing_restraints_type( self.xray_structure.space_group()) self.taken_step = None self.restraints_normalisation_factor = None
def __init__(self, observations, reparametrisation, **kwds): super(crystallographic_ls, self).__init__(reparametrisation.n_independents) self.observations = observations self.reparametrisation = reparametrisation adopt_optional_init_args(self, kwds) if self.f_mask is not None: assert self.f_mask.size() == observations.fo_sq.size() self.one_h_linearisation = direct.f_calc_modulus_squared( self.xray_structure) if self.weighting_scheme == "default": self.weighting_scheme = self.default_weighting_scheme() self.origin_fixing_restraint = self.origin_fixing_restraints_type( self.xray_structure.space_group()) self.taken_step = None self.restraints_normalisation_factor = None
def __init__(self, space_group_info, **kwds): libtbx.adopt_optional_init_args(self, kwds) self.space_group_info = space_group_info self.structure = random_structure.xray_structure( space_group_info, elements=self.elements, volume_per_atom=20., min_distance=1.5, general_positions_only=True, use_u_aniso=False, u_iso=adptbx.b_as_u(10), ) self.structure.set_inelastic_form_factors(1.54, "sasaki") self.scale_factor = 0.05 + 10 * flex.random_double() fc = self.structure.structure_factors(anomalous_flag=True, d_min=self.d_min, algorithm="direct").f_calc() fo = fc.as_amplitude_array() fo.set_observation_type_xray_amplitude() if self.use_students_t_errors: nu = random.uniform(1, 10) normal_g = variate(normal_distribution()) gamma_g = variate(gamma_distribution(0.5 * nu, 2)) errors = normal_g(fc.size()) / flex.sqrt(2 * gamma_g(fc.size())) else: # use gaussian errors g = variate(normal_distribution()) errors = g(fc.size()) fo2 = fo.as_intensity_array() self.fo2 = fo2.customized_copy( data=(fo2.data() + errors) * self.scale_factor, sigmas=flex.double(fc.size(), 1), ) self.fc = fc xs_i = self.structure.inverse_hand() self.fc_i = xs_i.structure_factors(anomalous_flag=True, d_min=self.d_min, algorithm="direct").f_calc() fo2_twin = self.fc.customized_copy( data=self.fc.data() + self.fc_i.data()).as_intensity_array() self.fo2_twin = fo2_twin.customized_copy( data=(errors + fo2_twin.data()) * self.scale_factor, sigmas=self.fo2.sigmas())
def __init__(self, space_group_info, **kwds): libtbx.adopt_optional_init_args(self, kwds) self.space_group_info = space_group_info self.structure = random_structure.xray_structure( space_group_info, elements=self.elements, volume_per_atom=20., min_distance=1.5, general_positions_only=True, use_u_aniso=False, u_iso=adptbx.b_as_u(10), ) self.structure.set_inelastic_form_factors(1.54, "sasaki") self.scale_factor = 0.05 + 10 * flex.random_double() fc = self.structure.structure_factors( anomalous_flag=True, d_min=self.d_min, algorithm="direct").f_calc() fo = fc.as_amplitude_array() fo.set_observation_type_xray_amplitude() if self.use_students_t_errors: nu = random.uniform(1, 10) normal_g = variate(normal_distribution()) gamma_g = variate(gamma_distribution(0.5*nu, 2)) errors = normal_g(fc.size())/flex.sqrt(2*gamma_g(fc.size())) else: # use gaussian errors g = variate(normal_distribution()) errors = g(fc.size()) fo2 = fo.as_intensity_array() self.fo2 = fo2.customized_copy( data=(fo2.data()+errors)*self.scale_factor, sigmas=flex.double(fc.size(), 1), ) self.fc = fc xs_i = self.structure.inverse_hand() self.fc_i = xs_i.structure_factors( anomalous_flag=True, d_min=self.d_min, algorithm="direct").f_calc() fo2_twin = self.fc.customized_copy( data=self.fc.data()+self.fc_i.data()).as_intensity_array() self.fo2_twin = fo2_twin.customized_copy( data=(errors + fo2_twin.data()) * self.scale_factor, sigmas=self.fo2.sigmas())
def __init__(self, **kwds): adopt_optional_init_args(self, kwds) self.values = flex.double() self.raw_values = flex.double() self.differences = flex.double()
def __init__(self, **kwds): adopt_optional_init_args(self, kwds)