def _init_phasing_algorithms(self): if not self._phasing_algorithms_dirty: self._log("Phasing algorithms already initialised.","DEBUG") return i = 0 for alg_conf in self._phasing_algorithms_configs: alg = dict(alg_conf) if alg_conf["number_of_iterations"] is None: if len(self._phasing_algorithms_configs) == 1: alg["number_of_iterations"] = self._number_of_iterations else: self._log("Number of iterations can not be None if many phasing algorithms are specified. Please report this error.","ERROR") return # constraints constraints = spimage.SpNoConstraints if "constraints" in alg: if "enforce_positivity" in alg["constraints"] and "enforce_real" in alg["constraints"]: constraints |= spimage.SpPositiveRealObject elif "enforce_real" in alg["constraints"]: constraints |= spimage.SpRealObject elif "enforce_positivity" in alg["constraints"]: constraints |= spimage.SpPositiveComplexObject if "enforce_centrosymmetry" in alg["constraints"]: constraints |= spimage.SpCentrosymmetricObject # phasing algorithm if alg["type"] in ["raar","hio","diffmap"]: alg["beta"] = spimage.sp_smap_alloc(1) spimage.sp_smap_insert(alg["beta"], i,alg["beta_init"]) spimage.sp_smap_insert(alg["beta"], i+alg["number_of_iterations"], alg["beta_final"]) if alg["type"] == "raar": alg["spimage_phasing"] = spimage.sp_phasing_raar_alloc(alg["beta"], constraints) elif alg["type"] == "hio": alg["spimage_phasing"] = spimage.sp_phasing_hio_alloc(alg["beta"], constraints) elif alg["type"] == "diffmap": alg["spimage_phasing"] = spimage.sp_phasing_diffmap_alloc(alg["beta"], alg["gamma1"], alg["gamma2"], constraints) elif alg["type"] == "er": alg["spimage_phasing"] = spimage.sp_phasing_er_alloc(constraints) else: self._log("Phasing algorithm %s not implemented. Please report this error!" % type,"ERROR") return i += alg["number_of_iterations"] self._phasing_algorithms.append(alg) self._phasing_algorithms_dirty = False self._log("Phasing algorithm initialised.","DEBUG")
def _init_phasing_algorithms(self): if not self._phasing_algorithms_dirty: self._log("Phasing algorithms already initialised.","DEBUG") return i = 0 for alg_conf in self._phasing_algorithms_configs: alg = dict(alg_conf) if alg_conf["number_of_iterations"] is None: if len(self._phasing_algorithms_configs) == 1: alg["number_of_iterations"] = self._number_of_iterations else: self._log("Number of iterations can not be None if many phasing algorithms are specified. Please report this error.","ERROR") return # constraints constraints = spimage.SpNoConstraints if "constraints" in alg: if "enforce_positivity" in alg["constraints"] and "enforce_real" in alg["constraints"]: constraints |= spimage.SpPositiveRealObject elif "enforce_real" in alg["constraints"]: constraints |= spimage.SpRealObject elif "enforce_positivity" in alg["constraints"]: constraints |= spimage.SpPositiveComplexObject if "enforce_centrosymmetry" in alg["constraints"]: constraints |= spimage.SpCentrosymmetricObject # phasing algorithm if alg["type"] in ["raar","hio","diffmap"]: alg["beta"] = spimage.sp_smap_alloc(1) spimage.sp_smap_insert(alg["beta"], i,alg["beta_init"]) spimage.sp_smap_insert(alg["beta"], i+alg["number_of_iterations"], alg["beta_final"]) if alg["type"] == "raar": alg["spimage_phasing"] = spimage.sp_phasing_raar_alloc(alg["beta"], constraints) elif alg["type"] == "hio": alg["spimage_phasing"] = spimage.sp_phasing_hio_alloc(alg["beta"], constraints) elif alg["type"] == "diffmap": alg["spimage_phasing"] = spimage.sp_phasing_diff_map_alloc(alg["beta"], alg["gamma1"], alg["gamma2"], constraints) elif alg["type"] == "er": alg["spimage_phasing"] = spimage.sp_phasing_er_alloc(constraints) else: self._log("Phasing algorithm %s not implemented. Please report this error!" % type,"ERROR") return i += alg["number_of_iterations"] self._phasing_algorithms.append(alg) self._phasing_algorithms_dirty = False self._log("Phasing algorithm initialised.","DEBUG")
def algorithm_raar(beta, real=False, positive=False): """Create a RAAR algorithm object""" beta_sp = smap(beta) constraints = get_constraints(real, positive) algorithm = _spimage.sp_phasing_raar_alloc(beta_sp, constraints) return algorithm