def run_refine(rsr_simple_refiner, xray_structure, scorer, log, weight): weight_best = None try: refined = individual_sites.refinery(refiner=rsr_simple_refiner, xray_structure=xray_structure, start_trial_weight_value=1.0, rms_bonds_limit=0.02, rms_angles_limit=2.0) scorer.update(sites_cart=refined.sites_cart_result) weight_best = refined.weight_final # except KeyboardInterrupt: raise except Exception: if (log): print >> log, "A trial failed: keep going..." return weight_best
def run_refine(rsr_simple_refiner, xray_structure, scorer, log, weight): weight_best = None try: refined = individual_sites.refinery( refiner = rsr_simple_refiner, xray_structure = xray_structure, start_trial_weight_value = 1.0, rms_bonds_limit = 0.02, rms_angles_limit = 2.0) scorer.update(sites_cart=refined.sites_cart_result) weight_best = refined.weight_final # except KeyboardInterrupt: raise except Exception: if(log): print >> log, "A trial failed: keep going..." return weight_best
def exercise(): # Exercise "simple" target pi = get_pdb_inputs(pdb_str=pdb_str_1) selection = flex.bool(pi.xrs.scatterers().size(), True) for d_min in [1, 2, 3]: print("d_min:", d_min) f_calc = pi.xrs.structure_factors(d_min=d_min).f_calc() fft_map = f_calc.fft_map(resolution_factor=0.25) fft_map.apply_sigma_scaling() target_map = fft_map.real_map_unpadded() rsr_simple_refiner = individual_sites.simple( target_map=target_map, selection=selection, real_space_gradients_delta=d_min / 4, max_iterations=150, geometry_restraints_manager=pi.grm.geometry) for shake_size in [ 1, ]: print(" shake_size:", shake_size) for p in [(0.01, 1.0), (0.03, 3.0), (0.1, 10.0)]: print(" target:", p) w_opt = flex.double() for start_value in [0.001, 0.01, 0.1, 0, 1, 10, 100, 1000]: xrs_poor = pi.xrs.deep_copy_scatterers() random.seed(0) flex.set_random_seed(0) xrs_poor.shake_sites_in_place(mean_distance=shake_size) # refined = individual_sites.refinery( refiner=rsr_simple_refiner, xray_structure=xrs_poor, start_trial_weight_value=start_value, rms_bonds_limit=p[0], rms_angles_limit=p[1]) w_opt.append(refined.weight_final) dist = flex.mean( flex.sqrt((pi.xrs.sites_cart() - refined.sites_cart_result).dot())) print( " w_start,w_final,b,a,dist: %9.4f %9.4f %6.3f %6.3f %6.3f" % (start_value, refined.weight_final, refined.rms_bonds_final, refined.rms_angles_final, dist)) assert refined.rms_bonds_final <= p[0] assert refined.rms_angles_final <= p[1]
def exercise(): # Exercise "simple" target pi = get_pdb_inputs(pdb_str=pdb_str_1) selection = flex.bool(pi.xrs.scatterers().size(), True) for d_min in [1, 2, 3]: print "d_min:", d_min f_calc = pi.xrs.structure_factors(d_min = d_min).f_calc() fft_map = f_calc.fft_map(resolution_factor=0.25) fft_map.apply_sigma_scaling() target_map = fft_map.real_map_unpadded() rsr_simple_refiner = individual_sites.simple( target_map = target_map, selection = selection, real_space_gradients_delta = d_min/4, max_iterations = 150, geometry_restraints_manager = pi.grm.geometry) for shake_size in [1,]: print " shake_size:", shake_size for p in [(0.01, 1.0), (0.03, 3.0), (0.1, 10.0)]: print " target:", p w_opt = flex.double() for start_value in [0.001, 0.01, 0.1, 0, 1, 10, 100, 1000]: xrs_poor = pi.xrs.deep_copy_scatterers() random.seed(0) flex.set_random_seed(0) xrs_poor.shake_sites_in_place(mean_distance = shake_size) # refined = individual_sites.refinery( refiner = rsr_simple_refiner, xray_structure = xrs_poor, start_trial_weight_value = start_value, rms_bonds_limit = p[0], rms_angles_limit = p[1]) w_opt.append(refined.weight_final) dist = flex.mean(flex.sqrt((pi.xrs.sites_cart() - refined.sites_cart_result).dot())) print " w_start,w_final,b,a,dist: %9.4f %9.4f %6.3f %6.3f %6.3f"%( start_value, refined.weight_final, refined.rms_bonds_final, refined.rms_angles_final, dist) assert refined.rms_bonds_final <= p[0] assert refined.rms_angles_final <= p[1]
def exercise(d_min=5, random_seed=1111111): inp = get_pdb_inputs(pdb_str=pdb_str) xrs_good = inp.xrs.deep_copy_scatterers() target_map = get_tmo(inp=inp, d_min=d_min) inp.ph.write_pdb_file(file_name="start.pdb") show(prefix="GOOD", pdb_hierarchy=inp.ph, tm=target_map, xrs=xrs_good, grm=inp.grm.geometry) # sites_cart_reference = [] selections_reference = [] pdb_hierarchy_reference = inp.ph.deep_copy() pdb_hierarchy_reference.reset_i_seq_if_necessary() for model in inp.ph.models(): for chain in model.chains(): for residue in chain.residues(): sites_cart_reference.append(residue.atoms().extract_xyz()) selections_reference.append(residue.atoms().extract_i_seq()) # sites_cart_reference_for_chi_only = [] selections_reference_for_chi_only = [] for model in inp.ph.models(): for chain in model.chains(): for residue in chain.residues(): s1 = flex.vec3_double() s2 = flex.size_t() for atom in residue.atoms(): if (not atom.name.strip().upper() in ["O"]): s1.append(atom.xyz) s2.append(atom.i_seq) sites_cart_reference_for_chi_only.append(s1) selections_reference_for_chi_only.append(s2) # xrs_poor = shake_sites(xrs=xrs_good.deep_copy_scatterers(), random=False, shift=2.0, grm=inp.grm) inp.ph.adopt_xray_structure(xrs_poor) inp.ph.write_pdb_file(file_name="poor.pdb") # for use_reference_torsion in [ "no", "yes_add_once", "yes_add_per_residue", "yes_manual" ]: es = inp.grm.energies_sites( sites_cart=xrs_good.sites_cart()) # it's essential to update grm inp.ph.adopt_xray_structure(xrs_poor) random.seed(random_seed) flex.set_random_seed(random_seed) print "*" * 79 print "use_reference_torsion:", use_reference_torsion print "*" * 79 show(prefix="START", pdb_hierarchy=inp.ph, tm=target_map, xrs=xrs_poor, grm=inp.grm.geometry) # if (use_reference_torsion == "yes_add_per_residue"): inp.grm.geometry.remove_chi_torsion_restraints_in_place() for sites_cart, selection in zip(sites_cart_reference, selections_reference): inp.grm.geometry.add_chi_torsion_restraints_in_place( pdb_hierarchy=pdb_hierarchy_reference, sites_cart=sites_cart, selection=selection, chi_angles_only=True, sigma=1) if (use_reference_torsion == "yes_add_once"): inp.grm.geometry.remove_chi_torsion_restraints_in_place() inp.grm.geometry.add_chi_torsion_restraints_in_place( pdb_hierarchy=pdb_hierarchy_reference, sites_cart=xrs_good.sites_cart(), chi_angles_only=True, sigma=1) if (use_reference_torsion == "yes_manual"): inp.grm.geometry.remove_chi_torsion_restraints_in_place() for sites_cart, selection in zip( sites_cart_reference_for_chi_only, selections_reference_for_chi_only): inp.grm.geometry.add_chi_torsion_restraints_in_place( pdb_hierarchy=pdb_hierarchy_reference, sites_cart=sites_cart, selection=selection, chi_angles_only=True, sigma=1) # tmp = xrs_poor.deep_copy_scatterers() rsr_simple_refiner = individual_sites.simple( target_map=target_map.data, selection=flex.bool(tmp.scatterers().size(), True), real_space_gradients_delta=d_min / 4, max_iterations=500, geometry_restraints_manager=inp.grm.geometry) refined = individual_sites.refinery(refiner=rsr_simple_refiner, optimize_weight=True, xray_structure=tmp, start_trial_weight_value=50, rms_bonds_limit=0.02, rms_angles_limit=2.0) assert refined.sites_cart_result is not None tmp = tmp.replace_sites_cart(refined.sites_cart_result) inp.ph.adopt_xray_structure(tmp) show(prefix="FINAL", pdb_hierarchy=inp.ph, tm=target_map, xrs=tmp, grm=inp.grm.geometry) inp.ph.write_pdb_file(file_name="final_%s.pdb" % str(use_reference_torsion))
def exercise(d_min=5, random_seed=1111111): inp = get_pdb_inputs(pdb_str=pdb_str) xrs_good = inp.xrs.deep_copy_scatterers() target_map = get_tmo(inp=inp, d_min = d_min) inp.ph.write_pdb_file(file_name="start.pdb") show(prefix="GOOD", pdb_hierarchy = inp.ph, tm=target_map, xrs=xrs_good, grm=inp.grm.geometry) # sites_cart_reference = [] selections_reference = [] pdb_hierarchy_reference = inp.ph.deep_copy() pdb_hierarchy_reference.reset_i_seq_if_necessary() for model in inp.ph.models(): for chain in model.chains(): for residue in chain.residues(): sites_cart_reference.append(residue.atoms().extract_xyz()) selections_reference.append(residue.atoms().extract_i_seq()) # sites_cart_reference_for_chi_only = [] selections_reference_for_chi_only = [] for model in inp.ph.models(): for chain in model.chains(): for residue in chain.residues(): s1 = flex.vec3_double() s2 = flex.size_t() for atom in residue.atoms(): if(not atom.name.strip().upper() in ["O"]): s1.append(atom.xyz) s2.append(atom.i_seq) sites_cart_reference_for_chi_only.append(s1) selections_reference_for_chi_only.append(s2) # xrs_poor = shake_sites(xrs=xrs_good.deep_copy_scatterers(), random=False, shift=2.0, grm=inp.grm) inp.ph.adopt_xray_structure(xrs_poor) inp.ph.write_pdb_file(file_name="poor.pdb") # for use_reference_torsion in ["no", "yes_add_once", "yes_add_per_residue", "yes_manual"]: es = inp.grm.energies_sites(sites_cart = xrs_good.sites_cart()) # it's essential to update grm inp.ph.adopt_xray_structure(xrs_poor) random.seed(random_seed) flex.set_random_seed(random_seed) print "*"*79 print "use_reference_torsion:", use_reference_torsion print "*"*79 show(prefix="START",pdb_hierarchy = inp.ph, tm=target_map, xrs=xrs_poor, grm=inp.grm.geometry) # if(use_reference_torsion == "yes_add_per_residue"): inp.grm.geometry.remove_chi_torsion_restraints_in_place() for sites_cart, selection in zip(sites_cart_reference, selections_reference): inp.grm.geometry.add_chi_torsion_restraints_in_place( pdb_hierarchy = pdb_hierarchy_reference, sites_cart = sites_cart, selection = selection, chi_angles_only = True, sigma = 1) if(use_reference_torsion == "yes_add_once"): inp.grm.geometry.remove_chi_torsion_restraints_in_place() inp.grm.geometry.add_chi_torsion_restraints_in_place( pdb_hierarchy = pdb_hierarchy_reference, sites_cart = xrs_good.sites_cart(), chi_angles_only = True, sigma = 1) if(use_reference_torsion == "yes_manual"): inp.grm.geometry.remove_chi_torsion_restraints_in_place() for sites_cart, selection in zip(sites_cart_reference_for_chi_only, selections_reference_for_chi_only): inp.grm.geometry.add_chi_torsion_restraints_in_place( pdb_hierarchy = pdb_hierarchy_reference, sites_cart = sites_cart, selection = selection, chi_angles_only = True, sigma = 1) # tmp = xrs_poor.deep_copy_scatterers() rsr_simple_refiner = individual_sites.simple( target_map = target_map.data, selection = flex.bool(tmp.scatterers().size(), True), real_space_gradients_delta = d_min/4, max_iterations = 500, geometry_restraints_manager = inp.grm.geometry) refined = individual_sites.refinery( refiner = rsr_simple_refiner, optimize_weight = True, xray_structure = tmp, start_trial_weight_value = 50, rms_bonds_limit = 0.02, rms_angles_limit = 2.0) assert refined.sites_cart_result is not None tmp = tmp.replace_sites_cart(refined.sites_cart_result) inp.ph.adopt_xray_structure(tmp) show(prefix="FINAL",pdb_hierarchy = inp.ph, tm=target_map, xrs=tmp, grm=inp.grm.geometry) inp.ph.write_pdb_file(file_name="final_%s.pdb"%str(use_reference_torsion))