def __init__(self, miller_array, n_residues=None, n_bases=None, asu_contents=None, prot_frac = 1.0, nuc_frac= 0.0): """ Maximum likelihood anisotropic wilson scaling""" #Checking input if (n_residues is None): if (n_bases is None): assert asu_contents is not None assert (type(asu_contents) == type({}) ) if asu_contents is None: assert ( (n_residues is not None) or (n_bases is not None) ) assert (prot_frac+nuc_frac<=1.0) assert ( miller_array.is_real_array() ) self.info = miller_array.info() if ( miller_array.is_xray_intensity_array() ): miller_array = miller_array.f_sq_as_f() work_array = miller_array.resolution_filter( d_max=1.0/math.sqrt( scaling.get_d_star_sq_low_limit() ), d_min=1.0/math.sqrt( scaling.get_d_star_sq_high_limit() )) work_array = work_array.select(work_array.data()>0) self.d_star_sq = work_array.d_star_sq().data() self.scat_info = None if asu_contents is None: self.scat_info= scattering_information( n_residues=n_residues, n_bases = n_bases) else: self.scat_info = scattering_information( asu_contents = asu_contents, fraction_protein = prot_frac, fraction_nucleic = nuc_frac) self.scat_info.scat_data(self.d_star_sq) self.b_cart = None if (work_array.size() > 0 ): self.hkl = work_array.indices() self.f_obs = work_array.data() self.unit_cell = uctbx.unit_cell( miller_array.unit_cell().parameters() ) ## Make sure sigma's are used when available if (work_array.sigmas() is not None): self.sigma_f_obs = work_array.sigmas() else: self.sigma_f_obs = flex.double(self.f_obs.size(),0.0) if (flex.min( self.sigma_f_obs ) < 0): self.sigma_f_obs = self.sigma_f_obs*0.0 ## multiplicities self.epsilon = work_array.epsilons().data().as_double() ## Determine Wilson parameters self.gamma_prot = self.scat_info.gamma_tot self.sigma_prot_sq = self.scat_info.sigma_tot_sq ## centric flags self.centric = flex.bool(work_array.centric_flags().data()) ## Symmetry stuff self.sg = work_array.space_group() self.adp_constraints = self.sg.adp_constraints() self.dim_u = self.adp_constraints.n_independent_params() ## Setup number of parameters assert self.dim_u <= 6 ## Optimisation stuff self.x = flex.double(self.dim_u+1, 0.0) ## B-values and scale factor! exception_handling_params = scitbx.lbfgs.exception_handling_parameters( ignore_line_search_failed_step_at_lower_bound = False, ignore_line_search_failed_step_at_upper_bound = False, ignore_line_search_failed_maxfev = False) term_parameters = scitbx.lbfgs.termination_parameters( max_iterations = 50) minimizer = scitbx.lbfgs.run(target_evaluator=self, termination_params=term_parameters, exception_handling_params=exception_handling_params) ## Done refining Vrwgk = math.pow(self.unit_cell.volume(),2.0/3.0) self.p_scale = self.x[0] self.u_star = self.unpack() self.u_star = list( flex.double(self.u_star) / Vrwgk ) self.b_cart = adptbx.u_as_b(adptbx.u_star_as_u_cart(self.unit_cell, self.u_star)) self.u_cif = adptbx.u_star_as_u_cif(self.unit_cell, self.u_star) #get eigenvalues of B-cart eigen = eigensystem.real_symmetric( self.b_cart ) self.eigen_values = eigen.values() self.eigen_vectors = eigen.vectors() self.work_array = work_array # i need this for further analyses self.analyze_aniso_correction() # FIXME see 3ihm:IOBS4,SIGIOBS4 if (self.eigen_values[0] != 0) : self.anirat = (abs(self.eigen_values[0] - self.eigen_values[2]) / self.eigen_values[0]) else : self.anirat = None del self.x del self.f_obs del self.sigma_f_obs del self.epsilon del self.gamma_prot del self.sigma_prot_sq del self.centric del self.hkl del self.d_star_sq del self.adp_constraints
def __init__(self, miller_array, n_residues=None, n_bases=None, asu_contents=None, prot_frac=1.0, nuc_frac=0.0): """ Maximum likelihood anisotropic wilson scaling""" #Checking input if (n_residues is None): if (n_bases is None): assert asu_contents is not None assert (type(asu_contents) == type({})) if asu_contents is None: assert ((n_residues is not None) or (n_bases is not None)) assert (prot_frac + nuc_frac <= 1.0) assert (miller_array.is_real_array()) self.info = miller_array.info() if (miller_array.is_xray_intensity_array()): miller_array = miller_array.f_sq_as_f() work_array = miller_array.resolution_filter( d_max=1.0 / math.sqrt(scaling.get_d_star_sq_low_limit()), d_min=1.0 / math.sqrt(scaling.get_d_star_sq_high_limit())) work_array = work_array.select(work_array.data() > 0) self.d_star_sq = work_array.d_star_sq().data() self.scat_info = None if asu_contents is None: self.scat_info = scattering_information(n_residues=n_residues, n_bases=n_bases) else: self.scat_info = scattering_information(asu_contents=asu_contents, fraction_protein=prot_frac, fraction_nucleic=nuc_frac) self.scat_info.scat_data(self.d_star_sq) self.b_cart = None if (work_array.size() > 0): self.hkl = work_array.indices() self.f_obs = work_array.data() self.unit_cell = uctbx.unit_cell( miller_array.unit_cell().parameters()) ## Make sure sigma's are used when available if (work_array.sigmas() is not None): self.sigma_f_obs = work_array.sigmas() else: self.sigma_f_obs = flex.double(self.f_obs.size(), 0.0) if (flex.min(self.sigma_f_obs) < 0): self.sigma_f_obs = self.sigma_f_obs * 0.0 ## multiplicities self.epsilon = work_array.epsilons().data().as_double() ## Determine Wilson parameters self.gamma_prot = self.scat_info.gamma_tot self.sigma_prot_sq = self.scat_info.sigma_tot_sq ## centric flags self.centric = flex.bool(work_array.centric_flags().data()) ## Symmetry stuff self.sg = work_array.space_group() self.adp_constraints = self.sg.adp_constraints() self.dim_u = self.adp_constraints.n_independent_params() ## Setup number of parameters assert self.dim_u <= 6 ## Optimisation stuff self.x = flex.double(self.dim_u + 1, 0.0) ## B-values and scale factor! exception_handling_params = scitbx.lbfgs.exception_handling_parameters( ignore_line_search_failed_step_at_lower_bound=False, ignore_line_search_failed_step_at_upper_bound=False, ignore_line_search_failed_maxfev=False) term_parameters = scitbx.lbfgs.termination_parameters( max_iterations=50) minimizer = scitbx.lbfgs.run( target_evaluator=self, termination_params=term_parameters, exception_handling_params=exception_handling_params) ## Done refining Vrwgk = math.pow(self.unit_cell.volume(), 2.0 / 3.0) self.p_scale = self.x[0] self.u_star = self.unpack() self.u_star = list(flex.double(self.u_star) / Vrwgk) self.b_cart = adptbx.u_as_b( adptbx.u_star_as_u_cart(self.unit_cell, self.u_star)) self.u_cif = adptbx.u_star_as_u_cif(self.unit_cell, self.u_star) #get eigenvalues of B-cart eigen = eigensystem.real_symmetric(self.b_cart) self.eigen_values = eigen.values() self.eigen_vectors = eigen.vectors() self.work_array = work_array # i need this for further analyses self.analyze_aniso_correction() # FIXME see 3ihm:IOBS4,SIGIOBS4 if (self.eigen_values[0] != 0): self.anirat = ( abs(self.eigen_values[0] - self.eigen_values[2]) / self.eigen_values[0]) else: self.anirat = None del self.x del self.f_obs del self.sigma_f_obs del self.epsilon del self.gamma_prot del self.sigma_prot_sq del self.centric del self.hkl del self.d_star_sq del self.adp_constraints
def __init__(self, miller_array, n_residues=None, n_bases=None, asu_contents=None, prot_frac = 1.0, nuc_frac= 0.0, include_array_info=True): self.p_scale, self.b_wilson = None, None ## Checking input combinations if (n_residues is None): if (n_bases is None): assert asu_contents is not None assert (type(asu_contents) == type({}) ) if asu_contents is None: assert ( (n_residues is not None) or (n_bases is not None) ) assert (prot_frac+nuc_frac<=1.0) if ( miller_array.is_xray_intensity_array() ): miller_array = miller_array.f_sq_as_f() assert ( miller_array.is_real_array() ) self.info = None if (include_array_info) : ## Save the information of the file name etc self.info = miller_array.info() work_array = miller_array.resolution_filter( d_max=1.0/math.sqrt( scaling.get_d_star_sq_low_limit() ), d_min=1.0/math.sqrt( scaling.get_d_star_sq_high_limit() )) if work_array.data().size() > 0: work_array = work_array.select(work_array.data() > 0) self.d_star_sq = work_array.d_star_sq().data() self.scat_info = None if asu_contents is None: self.scat_info = scattering_information( n_residues=n_residues, n_bases = n_bases, fraction_protein = prot_frac, fraction_nucleic = nuc_frac) else: self.scat_info = scattering_information( asu_contents = asu_contents, fraction_protein = prot_frac, fraction_nucleic = nuc_frac) if (work_array.size() > 0 ): ## Compute the terms self.scat_info.scat_data(self.d_star_sq) self.f_obs = work_array.data() ## Make sure sigma's are used when available if (work_array.sigmas() is not None): self.sigma_f_obs = work_array.sigmas() else: self.sigma_f_obs = flex.double(self.f_obs.size(),0.0) if (flex.min( self.sigma_f_obs ) < 0): self.sigma_f_obs = self.sigma_f_obs*0.0 ## multiplicities and d_star_sq self.epsilon = work_array.epsilons().data().as_double() ## centric flags self.centric = flex.bool(work_array.centric_flags().data()) ## Wilson parameters come from scattering_information class self.gamma_prot = self.scat_info.gamma_tot self.sigma_prot_sq = self.scat_info.sigma_tot_sq ## Optimisation stuff self.x = flex.double(2,0.0) self.x[0]=0.0 self.x[1]=50.0 self.f=0 term_parameters = scitbx.lbfgs.termination_parameters( max_iterations = 1e6 ) # just for safety minimizer = scitbx.lbfgs.run(target_evaluator=self, termination_params=term_parameters) self.p_scale = self.x[0] self.b_wilson = self.x[1] ## this we do not need anymore del self.x del self.f_obs del self.sigma_f_obs del self.epsilon del self.gamma_prot del self.sigma_prot_sq del self.d_star_sq del self.centric
def __init__(self, miller_array, n_residues=None, n_bases=None, asu_contents=None, prot_frac=1.0, nuc_frac=0.0, include_array_info=True): self.p_scale, self.b_wilson = None, None ## Checking input combinations if (n_residues is None): if (n_bases is None): assert asu_contents is not None assert (type(asu_contents) == type({})) if asu_contents is None: assert ((n_residues is not None) or (n_bases is not None)) assert (prot_frac + nuc_frac <= 1.0) if (miller_array.is_xray_intensity_array()): miller_array = miller_array.f_sq_as_f() assert (miller_array.is_real_array()) self.info = None if (include_array_info): ## Save the information of the file name etc self.info = miller_array.info() work_array = miller_array.resolution_filter( d_max=1.0 / math.sqrt(scaling.get_d_star_sq_low_limit()), d_min=1.0 / math.sqrt(scaling.get_d_star_sq_high_limit())) if work_array.data().size() > 0: work_array = work_array.select(work_array.data() > 0) self.d_star_sq = work_array.d_star_sq().data() self.scat_info = None if asu_contents is None: self.scat_info = scattering_information( n_residues=n_residues, n_bases=n_bases, fraction_protein=prot_frac, fraction_nucleic=nuc_frac) else: self.scat_info = scattering_information( asu_contents=asu_contents, fraction_protein=prot_frac, fraction_nucleic=nuc_frac) if (work_array.size() > 0): ## Compute the terms self.scat_info.scat_data(self.d_star_sq) self.f_obs = work_array.data() ## Make sure sigma's are used when available if (work_array.sigmas() is not None): self.sigma_f_obs = work_array.sigmas() else: self.sigma_f_obs = flex.double(self.f_obs.size(), 0.0) if (flex.min(self.sigma_f_obs) < 0): self.sigma_f_obs = self.sigma_f_obs * 0.0 ## multiplicities and d_star_sq self.epsilon = work_array.epsilons().data().as_double() ## centric flags self.centric = flex.bool(work_array.centric_flags().data()) ## Wilson parameters come from scattering_information class self.gamma_prot = self.scat_info.gamma_tot self.sigma_prot_sq = self.scat_info.sigma_tot_sq ## Optimisation stuff self.x = flex.double(2, 0.0) self.x[0] = 0.0 self.x[1] = 50.0 self.f = 0 term_parameters = scitbx.lbfgs.termination_parameters( max_iterations=1e6) # just for safety minimizer = scitbx.lbfgs.run( target_evaluator=self, termination_params=term_parameters) self.p_scale = self.x[0] self.b_wilson = self.x[1] ## this we do not need anymore del self.x del self.f_obs del self.sigma_f_obs del self.epsilon del self.gamma_prot del self.sigma_prot_sq del self.d_star_sq del self.centric