Ejemplo n.º 1
0
def calc_model_full(func_no_const, lattice_num, layer=0.1, const=0.0, ddens=1, peakmax=5):
    """
    :param func_no_const:   function that sets the surface implicitly
    :param lattice_num:     points in one side of mesh
    :param layer:           layer width, fraction of lattice parameter
    :param const:           const for function
    :param peakmax:         max number in hkl
    :param show:            to show or not to show triangulation
    :return:
    """
    def func(x, y, z):
        return func_no_const(x, y, z, const)

    qsvec, lenqs = generate_qvecs_lenqs_deprecated(peakmax)

    cube = cube_lattice(lattice_num, func)

    factor_struct = factor_calc_structural(qsvec, cube)
    factor_mol = factor_calc_molecular(qsvec, layer, ddens)

    amplitude = factor_struct * factor_mol
    intensity = amplitude**2

    multiplicity = factor_calc_multiplicity_intens(qsvec)
    intensity *= multiplicity

    lorentz = lenqs * lenqs
    intensity *= lorentz

    return qsvec, intensity
Ejemplo n.º 2
0
def task_surface():
    try:
        mkdir(addr)
    except:
        pass

    #parameter space generation
    qsvec, lenqs = generate_qvecs_lenqs_deprecated(peakmax=peakmax)
    const_s = np.linspace(bounds_const[0], bounds_const[-1], pnum_const)
    layer_s = np.linspace(bounds_const[0], bounds_const[-1], pnum_layer)

    #experimental data correction
    lenqs_exp_grand, intens_exp_grand = read_exp_data(scat_exp_file, intens_exp_file)

    peaks_indices = find_peaks_ind_in_smooth_profile(intens_exp_grand, cond='>')
    lenqs_exp = lenqs_exp_grand[peaks_indices]
    intens_exp = intens_exp_grand[peaks_indices]

    lattice_parameter = get_lattice_parameter(lenqs_exp_abs=lenqs_exp, peaks_file=peaks_file)

    lenqs_exp /= lattice_parameter
    lenqs_exp_grand /= lattice_parameter

    lenqs_exp = peaks_file_to_lenqs(peaks_file)

    exp_ind_in_model = find_exp_indices(lenqs_exp_short=lenqs_exp, lenqs_model=lenqs, corr_file=peaks_file) #corrction of model
    intens_exp = insert_exp_peaks(intensity_exp=intens_exp, indices_exp=exp_ind_in_model, lenqs_model=lenqs)

    #for model correction
    ind_forbid = []
    peak_max = exp_ind_in_model[-1]
    if qsvec_forbid is not None:
        ind_forbid = find_indices(qsvec_forbid, lenqs)
        print("ind forbid: "+str(ind_forbid))

    #for output xaxis
    ind_exp = np.nonzero(intens_exp)[0]
    xaxis = [round(lenqs[ind_exp[0]])-1, round(lenqs[ind_exp[-1]])+1]

    #init
    err_map = np.zeros((pnum_const, pnum_layer))
    lenqs = qsvec_to_lenqs(qsvec)

    #brute_force
    for num_const, val_const in enumerate(const_s):
        func_p = lambda x, y, z: double_diamond(x, y, z, const=val_const)
        cube_p = cube_lattice(lattice_num, func_p)
        func_n = lambda x, y, z: -double_diamond(x, y, z, const=-val_const)
        cube_n = cube_lattice(lattice_num, func_n)

        factor_struct = factor_calc_structural(qsvec, cube_p*cube_n)
        for num_layer, val_layer in enumerate(layer_s):
            temp_intens_exp = deepcopy(intens_exp)
            qsvec_new, intens_mod = calc_model_set_fstruct(factor_struct, val_layer, ddens=1., peakmax=peakmax)

            assert (qsvec_new == qsvec).prod(), "Something went wrong with qsvec's "
            err = calculate_error(lenqs, intens_mod, lenqs, temp_intens_exp, norm='area')

            err_map[num_const, num_layer] = err
            if err<errtr:
                assert (temp_intens_exp/max(temp_intens_exp)).all() == (intens_exp/max(intens_exp)).all(),"intens was changed during err calc"
                name_cur = "p1(%1.2f) p2(%1.2f) " % (val_const, val_layer)
                output(name=name_cur,pic_path=addr, lenqs=lenqs, intens_exp=temp_intens_exp, intens_mod=intens_mod,
                   error=err, lenqs_exp_grand=lenqs_exp_grand, intens_exp_grand=intens_exp_grand, xaxis=xaxis)

    np.save(addr+'/'+model_name+"results.npy", err_map)
    parameters = np.array([const_s, layer_s])
    np.save(addr+'/'+model_name+"params.npy", parameters)