def try_den_weight_torsion(self, grid_pair): #backup_k_rep = self.params.tardy.\ # prolsq_repulsion_function_changes.k_rep local_seed = int(self.random_seed+grid_pair[1]) flex.set_random_seed(value=local_seed) random.seed(local_seed) self.fmodels.fmodel_xray().xray_structure.replace_scatterers( self.save_scatterers_local.deep_copy()) self.fmodels.update_xray_structure( xray_structure = self.fmodels.fmodel_xray().xray_structure, update_f_calc = True) utils.assert_xray_structures_equal( x1 = self.fmodels.fmodel_xray().xray_structure, x2 = self.model.xray_structure) gamma_local = grid_pair[0] weight_local = grid_pair[1] self.model.restraints_manager.geometry.\ den_manager.gamma = gamma_local self.model.restraints_manager.geometry.\ den_manager.weight = weight_local cycle = 0 self.model.restraints_manager.geometry.\ den_manager.current_cycle = cycle+1 num_den_cycles = self.model.restraints_manager.geometry.\ den_manager.num_cycles if self.params.den.optimize and \ self.nproc != Auto and \ self.nproc > 1: local_log = sys.stdout elif self.params.den.optimize and \ self.nproc == 1: if self.verbose: local_log = self.log else: local_log = StringIO() else: local_log = self.log print >> self.log, " ...trying gamma %.1f, weight %.1f" % ( gamma_local, weight_local) while cycle < num_den_cycles: #if self.model.restraints_manager.geometry.\ # generic_restraints_manager.den_manager.current_cycle == \ # self.model.restraints_manager.geometry.\ # generic_restraints_manager.den_manager.torsion_mid_point+1: # self.params.tardy.\ # prolsq_repulsion_function_changes.k_rep = 1.0 print >> local_log, "DEN cycle %d" % (cycle+1) #print >> local_log, "Random seed: %d" % flex.get_random_seed() r_free = self.fmodels.fmodel_xray().r_free() print >> local_log, "rfree at start of SA cycle: %.4f" % r_free print >> local_log, "k_rep = %.2f" % \ self.params.tardy.\ prolsq_repulsion_function_changes.k_rep tardy.run( fmodels=self.fmodels, model=self.model, target_weights=self.target_weights, params=self.params.tardy, log=local_log, format_for_phenix_refine=True, call_back_after_step=False) if self.params.den.bulk_solvent_and_scale: self.bulk_solvent_and_scale(log=local_log) self.fmodels.fmodel_xray().xray_structure = self.model.xray_structure if self.params.den.refine_adp: self.adp_refinement(log=local_log) self.model.restraints_manager.geometry.update_dihedral_ncs_restraints( sites_cart=self.model.xray_structure.sites_cart(), pdb_hierarchy=self.model.pdb_hierarchy(sync_with_xray_structure=True), log=local_log) cycle += 1 self.model.restraints_manager.geometry.\ den_manager.current_cycle += 1 r_free = self.fmodels.fmodel_xray().r_free() print >> local_log, "rfree at end of SA cycle: %f" % r_free r_free = self.fmodels.fmodel_xray().r_free() step_xray_structure = self.fmodels.fmodel_xray().\ xray_structure.deep_copy_scatterers().scatterers() step_eq_distances = self.model.restraints_manager.geometry.\ den_manager.get_current_eq_distances() return (gamma_local, weight_local, r_free, step_xray_structure, step_eq_distances)
def try_den_weight_torsion(self, grid_pair): #backup_k_rep = self.params.tardy.\ # prolsq_repulsion_function_changes.k_rep local_seed = int(self.random_seed+grid_pair[1]) flex.set_random_seed(value=local_seed) random.seed(local_seed) self.fmodels.fmodel_xray().xray_structure.replace_scatterers( self.save_scatterers_local.deep_copy()) self.fmodels.update_xray_structure( xray_structure = self.fmodels.fmodel_xray().xray_structure, update_f_calc = True) utils.assert_xray_structures_equal( x1 = self.fmodels.fmodel_xray().xray_structure, x2 = self.model.get_xray_structure()) gamma_local = grid_pair[0] weight_local = grid_pair[1] self.model.restraints_manager.geometry.\ den_manager.gamma = gamma_local self.model.restraints_manager.geometry.\ den_manager.weight = weight_local cycle = 0 self.model.restraints_manager.geometry.\ den_manager.current_cycle = cycle+1 num_den_cycles = self.model.restraints_manager.geometry.\ den_manager.num_cycles if self.params.den.optimize and \ self.nproc != Auto and \ self.nproc > 1: local_log = sys.stdout elif self.params.den.optimize and \ self.nproc == 1: if self.verbose: local_log = self.log else: local_log = StringIO() else: local_log = self.log print >> self.log, " ...trying gamma %.1f, weight %.1f" % ( gamma_local, weight_local) while cycle < num_den_cycles: #if self.model.restraints_manager.geometry.\ # generic_restraints_manager.den_manager.current_cycle == \ # self.model.restraints_manager.geometry.\ # generic_restraints_manager.den_manager.torsion_mid_point+1: # self.params.tardy.\ # prolsq_repulsion_function_changes.k_rep = 1.0 print >> local_log, "DEN cycle %d" % (cycle+1) #print >> local_log, "Random seed: %d" % flex.get_random_seed() r_free = self.fmodels.fmodel_xray().r_free() print >> local_log, "rfree at start of SA cycle: %.4f" % r_free print >> local_log, "k_rep = %.2f" % \ self.params.tardy.\ prolsq_repulsion_function_changes.k_rep tardy.run( fmodels=self.fmodels, model=self.model, target_weights=self.target_weights, params=self.params.tardy, log=local_log, format_for_phenix_refine=True, call_back_after_step=False) if self.params.den.bulk_solvent_and_scale: self.bulk_solvent_and_scale(log=local_log) self.fmodels.fmodel_xray().xray_structure = self.model.get_xray_structure() if self.params.den.refine_adp: self.adp_refinement(log=local_log) self.model.torsion_ncs_restraints_update(log=local_log) cycle += 1 self.model.restraints_manager.geometry.\ den_manager.current_cycle += 1 r_free = self.fmodels.fmodel_xray().r_free() print >> local_log, "rfree at end of SA cycle: %f" % r_free r_free = self.fmodels.fmodel_xray().r_free() step_xray_structure = self.fmodels.fmodel_xray().\ xray_structure.deep_copy_scatterers().scatterers() step_eq_distances = self.model.restraints_manager.geometry.\ den_manager.get_current_eq_distances() return (gamma_local, weight_local, r_free, step_xray_structure, step_eq_distances)