def crystal_symmetry_as_sg_uc_list(crystal_symmetry): u = crystal_symmetry.unit_cell() s = crystal_symmetry.space_group_info() if (u is None): uc = ["None"]*6 else: uc = ["%.6g" % v for v in u.parameters()] sg = cns_format(space_group_info=s) if (sg is None): sg = str(s).replace(" ","") return sg, uc
def write_header(s, file=None, description=None, comment=None, space_group_info=None, n_rows=None): assert n_rows is not None if (file is not None): print >> s, "{+ file: %s +}" % str(file) if (description is not None): print >> s, "{+ description: %s +}" % str(description) if (comment is not None): print >> s, "{+ comment:" for line in comment: print >> s, line print >> s, "+}" print >> s print >> s, "{- begin block parameter definition -} define(" print >> s if (space_group_info is not None): print >> s, """\ {============================ space group ============================} {* space group *} {* use International Table conventions with subscripts substituted by parenthesis *} {===>} sg="%s"; """ % space_group_symbols.cns_format(space_group_info) print >> s, """\ {==================== derivative/MAD coordinates =====================} {+ list: for each site define: - whether the site is to be refined, fixed or ignored - derivative name (must be the same for all sites in a derivative) - chemical type (note: wavelength-dependent form factors are specified in mad_refine.inp) - coordinates (x, y, z) - B-value (b) - occupancy (q) - group name (g) +} {+ list: the optional group name (g) is a string of upto 4 characters. If a group is left blank, each site is refined individually. If a group is specified, all sites with the same group name and the same derivative name are treated as a rigid body, and their occupancies, B-values, and form factors are refined as a group. +} {+ table: rows=%d numbered cols=9 "action" "derivative name" "chemical type" "x coordinate" "y coordinate" "z coordinate" "B-value" "occupancy" "group" +} """ % n_rows
def do_dirty_work(params, fo, hl_coeffs): fo.export_as_cns_hkl(file_object=open("f_obs.hkl", "wb"), file_name="f_obs.hkl") hl_coeffs.export_as_cns_hkl(file_object=open("hl_coeffs.hkl", "wb"), file_name="hl_coeffs.hkl") cns_solve_dir = os.environ.get("CNS_SOLVE") if cns_solve_dir is None: raise RuntimeError("Environment variable CNS_SOLVE is not defined") shutil.copyfile("%s/inputs/xtal_phase/density_modify.inp" % cns_solve_dir, "tmp.inp") cns_params = {} cns_params.setdefault( "space_group", cns_format(space_group_info=params.input.space_group)) uc_params = params.input.unit_cell.parameters() cns_params["a"] = uc_params[0] cns_params["b"] = uc_params[1] cns_params["c"] = uc_params[2] cns_params["alpha"] = uc_params[3] cns_params["beta"] = uc_params[4] cns_params["gamma"] = uc_params[5] if params.d_min is None: if params.phase_extension: params.d_min = fo.d_min() else: params.d_min = hl_coeffs_start.d_min() if params.initial_d_min is None: params.initial_d_min = params.d_min assert params.initial_d_min >= params.d_min cns_params["d_min"] = params.d_min cns_params["initial_d_min"] = params.initial_d_min cns_params["phase_extend"] = str(params.phase_extension).lower() cns_params["prot_to_solv"] = params.protein_solvent_ratio cns_params["trunc_min"] = params.density_truncation.fraction_min cns_params["trunc_max"] = params.density_truncation.fraction_max cns_params["trunc_max"] = 1 cns_params["solcon"] = params.solvent_fraction if params.solvent_mask.averaging_radius.final is None: params.solvent_mask.averaging_radius.final = params.d_min if params.solvent_mask.averaging_radius.initial is None: params.solvent_mask.averaging_radius.initial \ = params.solvent_mask.averaging_radius.final + 1 cns_params[ "start_ave_radius"] = params.solvent_mask.averaging_radius.initial cns_params[ "finish_ave_radius"] = params.solvent_mask.averaging_radius.final cns_params["initial_steps"] = params.initial_steps cns_params["shrink_steps"] = params.shrink_steps cns_params["final_steps"] = params.final_steps cns_params["grid_resolution_factor"] = params.grid_resolution_factor cns_params["averaging"] = "false" cns_params["ncs_infile"] = "ncs.def" params_file = open("params.inp", "wb") params_file.write(cns_density_modify_inp_template % cns_params) params_file.close() cmd = "%s/bin/cns_transfer -def params.inp -inp tmp.inp -out density_modify.inp" % ( cns_solve_dir) print cmd result = easy_run.fully_buffered(command=cmd).raise_if_errors_or_output() cmd = "cns_solve < density_modify.inp > density_modify.out" print cmd t0 = time.time() result = easy_run.fully_buffered(command=cmd).raise_if_errors() print "CNS time: %.2f" % (time.time() - t0) result.show_stdout() import iotbx.xplor.map modified_map = iotbx.xplor.map.reader(file_name="density_modify.map") modified_map = modified_map.data[:-1, :-1, :-1] return group_args(modified_map=modified_map)
def do_dirty_work(params, fo, hl_coeffs): fo.export_as_cns_hkl( file_object=open("f_obs.hkl", "wb"), file_name="f_obs.hkl") hl_coeffs.export_as_cns_hkl( file_object=open("hl_coeffs.hkl", "wb"), file_name="hl_coeffs.hkl") cns_solve_dir = os.environ.get("CNS_SOLVE") if cns_solve_dir is None: raise RuntimeError("Environment variable CNS_SOLVE is not defined") shutil.copyfile( "%s/inputs/xtal_phase/density_modify.inp" % cns_solve_dir, "tmp.inp") cns_params = {} cns_params.setdefault("space_group", cns_format( space_group_info=params.input.space_group)) uc_params = params.input.unit_cell.parameters() cns_params["a"] = uc_params[0] cns_params["b"] = uc_params[1] cns_params["c"] = uc_params[2] cns_params["alpha"] = uc_params[3] cns_params["beta"] = uc_params[4] cns_params["gamma"] = uc_params[5] if params.d_min is None: if params.phase_extension: params.d_min = fo.d_min() else: params.d_min = hl_coeffs_start.d_min() if params.initial_d_min is None: params.initial_d_min = params.d_min assert params.initial_d_min >= params.d_min cns_params["d_min"] = params.d_min cns_params["initial_d_min"] = params.initial_d_min cns_params["phase_extend"] = str(params.phase_extension).lower() cns_params["prot_to_solv"] = params.protein_solvent_ratio cns_params["trunc_min"] = params.density_truncation.fraction_min cns_params["trunc_max"] = params.density_truncation.fraction_max cns_params["trunc_max"] = 1 cns_params["solcon"] = params.solvent_fraction if params.solvent_mask.averaging_radius.final is None: params.solvent_mask.averaging_radius.final = params.d_min if params.solvent_mask.averaging_radius.initial is None: params.solvent_mask.averaging_radius.initial \ = params.solvent_mask.averaging_radius.final + 1 cns_params["start_ave_radius"] = params.solvent_mask.averaging_radius.initial cns_params["finish_ave_radius"] = params.solvent_mask.averaging_radius.final cns_params["initial_steps"] = params.initial_steps cns_params["shrink_steps"] = params.shrink_steps cns_params["final_steps"] = params.final_steps cns_params["grid_resolution_factor"] = params.grid_resolution_factor cns_params["averaging"] = "false" cns_params["ncs_infile"] = "ncs.def" params_file = open("params.inp", "wb") params_file.write(cns_density_modify_inp_template % cns_params) params_file.close() cmd = "%s/bin/cns_transfer -def params.inp -inp tmp.inp -out density_modify.inp" %( cns_solve_dir) print cmd result = easy_run.fully_buffered(command=cmd).raise_if_errors_or_output() cmd = "cns_solve < density_modify.inp > density_modify.out" print cmd t0 = time.time() result = easy_run.fully_buffered(command=cmd).raise_if_errors() print "CNS time: %.2f" %(time.time()-t0) result.show_stdout() import iotbx.xplor.map modified_map = iotbx.xplor.map.reader(file_name="density_modify.map") modified_map = modified_map.data[:-1,:-1,:-1] return group_args(modified_map=modified_map)