Пример #1
0
def call_read_xyz_box(dcdfile,current_frame,total_atoms,return_numpy): 

    # declare variables:    

    dcdfile,strlength = string_to_ctypes_string(dcdfile) 

    current_frame = int_to_ctypes_int(current_frame)

    total_atoms = int_to_ctypes_int(total_atoms) 

    #box = (c_double*3)()
    box = np.ctypeslib.as_ctypes(np.zeros(3,dtype=np.float64)) 
    
    #xyz = ((c_float*total_atoms.value)*3)() 

    xyz = np.ctypeslib.as_ctypes(np.zeros(total_atoms.value*3,dtype=np.float32)) 

    #current_frame = c_int(current_frame) 

    dcd_lib.call_dcd_traj(dcdfile,byref(strlength),byref(total_atoms),byref(current_frame),box,xyz) 

    if ( return_numpy ): 

        xyz = np.ctypeslib.as_array(xyz).reshape((total_atoms.value,3)) 

        box = np.ctypeslib.as_array(box)
        
        return xyz,box 
    
    else: 

        return xyz,box 
Пример #2
0
def loadtxt(txtfile, num_lines, num_cols, skiprows, return_numpy):

    txtfile, strlength = string_to_ctypes_string(txtfile)

    num_selected = num_lines - skiprows

    loaded_data = np.ctypeslib.as_ctypes(
        np.zeros(num_selected * num_cols, dtype=np.float64))

    num_lines = int_to_ctypes_int(num_lines)

    num_cols = int_to_ctypes_int(num_cols)

    skiprows = int_to_ctypes_int(skiprows)

    txt_lib.load_txt(txtfile, byref(strlength), byref(num_lines),
                     byref(num_cols), byref(skiprows), loaded_data)

    if (return_numpy):

        return np.ctypeslib.as_array(loaded_data).reshape(
            (num_cols.value, num_lines.value - skiprows.value)).T

    else:

        return loaded_data
Пример #3
0
def call_read_xyz_xyz_box(xyzfile,
                          current_frame,
                          total_atoms,
                          read_box=True,
                          return_numpy=True):

    # declare variables:

    xyzfile, strlength = string_to_ctypes_string(xyzfile)

    total_atoms = int_to_ctypes_int(total_atoms)

    current_frame = int_to_ctypes_int(current_frame)

    # xyz = ((c_float*total_atoms.value)*3)()

    xyz = np.ctypeslib.as_ctypes(
        np.zeros(total_atoms.value * 3, dtype=np.float64))

    # current_frame = c_int(current_frame)

    # if the box is read from the xyz
    if (read_box):

        box = np.ctypeslib.as_ctypes(np.zeros(3, dtype=np.float64))

        xyz_lib.call_read_xyz_with_box(xyzfile, byref(strlength),
                                       byref(current_frame),
                                       byref(total_atoms), box, xyz)

        # if the xyz, box has to be returned as numpy data type
        if (return_numpy):

            xyz = np.ctypeslib.as_array(xyz).reshape((total_atoms.value, 3))

            box = np.ctypeslib.as_array(box)

            # return numpy array format of xyz,box
            return xyz, box

        else:

            # return ctypes format of xyz,box
            return xyz, box

    # if the box is not read from the xyz
    else:

        xyz_lib.call_read_xyz_no_box(xyzfile, byref(strlength),
                                     byref(current_frame), byref(total_atoms),
                                     xyz)
        # if the xyz has to be returned as numpy data type
        if (return_numpy):

            return np.ctypeslib.as_array(xyz).reshape((total_atoms.value, 3))

        else:

            return xyz
Пример #4
0
def call_read_dcd_xyz_box_in_chunk(dcdfile, start_at, num_configs, total_atoms,
                                   return_numpy):

    # declare variables:

    dcdfile, strlength = string_to_ctypes_string(dcdfile)

    num_configs = int_to_ctypes_int(num_configs)

    start_at = int_to_ctypes_int(start_at)

    total_atoms = int_to_ctypes_int(total_atoms)

    # box = ((c_double*3)*num_configs)()
    box = np.ctypeslib.as_ctypes(
        np.zeros(3 * num_configs.value, dtype=np.float64))

    # xyz = (((c_float*total_atoms.value)*3)*num_configs.value)()
    xyz = np.ctypeslib.as_ctypes(
        np.zeros(3 * num_configs.value * total_atoms.value, dtype=np.float32))

    dcd_lib.call_dcd_traj_chunk(dcdfile, byref(strlength), byref(start_at),
                                byref(num_configs), byref(total_atoms), box,
                                xyz)

    if (return_numpy):

        xyz = np.ctypeslib.as_array(xyz).reshape(
            (num_configs.value, total_atoms.value, 3))

        box = np.ctypeslib.as_array(box).reshape((num_configs.value, 3))

        return xyz, box

    else:

        # convert to double precision
        xyz = np.ctypeslib.as_ctypes(
            np.ctypeslib.as_array(xyz).astype(np.float64))

        return xyz, box
Пример #5
0
def compute_static_sf(file_lst, R_ranges, Q_ranges, num_bins_q):

    corrected = True

    num_bins_q = int_to_ctypes_int(num_bins_q)

    ssf_or_pair = "structure_factor"

    r_or_Q, pair_correl_or_ssf = compute_pair_correl_from_hist_file(
        file_lst, ssf_or_pair, corrected, R_ranges, Q_ranges)

    return r_or_Q[0], pair_correl_or_ssf[0]
Пример #6
0
def compute_q_tetra(total_atoms, xyz, box):

    sorted_q_indx = np.ctypeslib.as_ctypes(
        np.zeros(total_atoms, dtype=np.int32))

    q_tetra = np.ctypeslib.as_ctypes(np.zeros(total_atoms, dtype=np.float64))

    total_atoms = int_to_ctypes_int(total_atoms)

    maxnb = c_int(35)

    nnb = c_int(4)

    cutoff_sqr = c_double(5.8 * 5.8)

    bt_lib.call_label_high_q_low_q(byref(total_atoms),
                                   byref(maxnb), byref(nnb), xyz, box,
                                   byref(cutoff_sqr), sorted_q_indx, q_tetra)

    return np.ctypeslib.as_array(sorted_q_indx), q_tetra
Пример #7
0
def compute_Bhatia_Thornton_ssf(file_lst, R_ranges, Q_ranges, num_bins_q,
                                x_H_frac, x_L_frac):

    corrected = True

    ssf_or_pair = "structure_factor"

    x_H_frac = c_double(x_H_frac)

    x_L_frac = c_double(x_L_frac)

    SNN = np.ctypeslib.as_ctypes(np.zeros(num_bins_q, dtype=np.float64))

    SCC = np.ctypeslib.as_ctypes(np.zeros(num_bins_q, dtype=np.float64))

    SNC = np.ctypeslib.as_ctypes(np.zeros(num_bins_q, dtype=np.float64))

    theta = np.ctypeslib.as_ctypes(np.zeros(num_bins_q, dtype=np.float64))

    SA = np.ctypeslib.as_ctypes(np.zeros(num_bins_q, dtype=np.float64))

    num_bins_q = int_to_ctypes_int(num_bins_q)

    S0_fs_lst, r_or_Q, pair_correl_or_ssf = compute_pair_correl_from_hist_file(
        file_lst, ssf_or_pair, corrected, R_ranges, Q_ranges, num_bins_q)
    SHH, SLL, SHL = pair_correl_or_ssf

    SHH = np.ctypeslib.as_ctypes(SHH)

    SLL = np.ctypeslib.as_ctypes(SLL)

    SHL = np.ctypeslib.as_ctypes(SHL)

    ssf_lib.call_Bhatia_Thornton(byref(num_bins_q), byref(x_H_frac),
                                 byref(x_L_frac), SHH, SLL, SHL, SNN, SCC, SNC,
                                 theta, SA)

    return (np.ctypeslib.as_array(r_or_Q[0]), np.ctypeslib.as_array(SNN),
            np.ctypeslib.as_array(SCC), np.ctypeslib.as_array(SNC),
            np.ctypeslib.as_array(theta), np.ctypeslib.as_array(SA))
Пример #8
0
def compute_pair_correl_ssf(keyword, corrected, partial, same_species, N1N2,
                            x_spec_1_2, N, R_ranges, Q_ranges, num_bins_q,
                            num_bins_gr, rho, r_mid, gr):

    corrected = c_bool(corrected)

    partial = c_bool(partial)

    same_species = c_bool(same_species)

    N1N2 = double_to_ctypes_double(N1N2)

    x_spec_1_2 = double_to_ctypes_double(x_spec_1_2)

    N = double_to_ctypes_double(N)

    R_size = int_to_ctypes_int(R_ranges.size)

    R_ranges = np_to_ctypes_array(R_ranges.astype(np.float64))

    Q_ranges = np_to_ctypes_array(Q_ranges.astype(np.float64))

    num_bins_q = int_to_ctypes_int(num_bins_q)

    num_bins_gr = int_to_ctypes_int(num_bins_gr)

    rho = double_to_ctypes_double(rho)

    r_mid = np_to_ctypes_array(r_mid)

    gr = np_to_ctypes_array(gr)

    if (keyword == "pair_correl"):

        r2hr = np.ctypeslib.as_ctypes(
            np.zeros(num_bins_gr.value, dtype=np.float64))

        ssf_lib.call_hr_fs_correct(byref(corrected), byref(partial),
                                   byref(same_species), byref(N1N2),
                                   byref(x_spec_1_2), byref(N),
                                   byref(R_size), R_ranges, Q_ranges,
                                   byref(num_bins_q), byref(num_bins_gr),
                                   byref(rho), r_mid, gr, r2hr)

        return np.ctypeslib.as_array(r_mid), np.ctypeslib.as_array(r2hr)

    elif (keyword == "structure_factor"):

        SQ = np.ctypeslib.as_ctypes(
            np.zeros(num_bins_q.value, dtype=np.float64))

        Q_mid = np.ctypeslib.as_ctypes(
            np.zeros(num_bins_q.value, dtype=np.float64))

        S0_fs = c_double()

        ssf_lib.call_ssf_fs_correct(byref(corrected), byref(partial),
                                    byref(same_species), byref(x_spec_1_2),
                                    byref(N), byref(R_size), R_ranges,
                                    Q_ranges, byref(num_bins_q),
                                    byref(num_bins_gr), byref(rho), r_mid, gr,
                                    byref(S0_fs), Q_mid, SQ)

        return S0_fs.value, np.ctypeslib.as_array(
            Q_mid), np.ctypeslib.as_array(SQ)