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
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
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
def get_lines_columns(txtfile): txtfile,strlength = string_to_ctypes_string(txtfile) num_lines = c_int() num_columns = c_int() txt_lib.get_txt_lines_columns(txtfile,byref(strlength),byref(num_lines),byref(num_columns)) return num_lines.value, num_columns.value
def call_read_dcd_header(dcdfile): # declare c types varibles: dcdfile,strlength = string_to_ctypes_string(dcdfile) total_atoms = c_int() total_frames = c_int() dcd_lib.call_dcd_header(dcdfile,byref(strlength),byref(total_atoms),byref(total_frames)) return total_frames.value, total_atoms.value
def calc_ql_cluster(style, total_atoms, box, xyz, maxnb, nnb, l, ql_cutoff, cluster_cutoff, n_bonds): style_key, strlength = string_to_ctypes_string(style) total_atoms = c_int(total_atoms) maxnb = c_int(maxnb) nnb = c_int(nnb) l = c_int(l) ql_cutoff_sqr = c_double(ql_cutoff * ql_cutoff) cluster_cutoff = c_double(cluster_cutoff) n_bonds = c_int(n_bonds) nxtl = c_int() lcl = c_int() HMC_lib.call_calc_ql_cluster(style_key, byref(strlength), byref(total_atoms), box, xyz, byref(maxnb), byref(nnb), byref(l), byref(ql_cutoff_sqr), byref(cluster_cutoff), byref(n_bonds), byref(nxtl), byref(lcl)) return nxtl.value, lcl.value
def call_read_xyz_header(xyzfile): if (not IO.check_file.status_is_ok(xyzfile)): sys.exit("Errors in reading file: %s; The file " "does not exist or is empty " % xyzfile) xyzfile, strlength = string_to_ctypes_string(xyzfile) total_atoms = c_int() total_frames = c_int() xyz_lib.call_read_xyz_header(xyzfile, byref(strlength), byref(total_atoms), byref(total_frames)) return total_atoms.value, total_frames.value
def get_lines_columns(txtfile): if (not IO.check_file.status_is_ok(txtfile)): sys.exit("Errors in reading file: %s; The file " "does not exist or is empty " % txtfile) txtfile, strlength = string_to_ctypes_string(txtfile) num_lines = c_int() num_columns = c_int() txt_lib.get_txt_lines_columns(txtfile, byref(strlength), byref(num_lines), byref(num_columns)) return num_lines.value, num_columns.value
def call_read_dcd_header(dcdfile): if (not IO.check_file.status_is_ok(dcdfile)): sys.exit("Errors in reading file: %s; The file " "does not exist or is empty " % dcdfile) # declare c types varibles: dcdfile, strlength = string_to_ctypes_string(dcdfile) total_atoms = c_int() total_frames = c_int() dcd_lib.call_dcd_header(dcdfile, byref(strlength), byref(total_atoms), byref(total_frames)) return total_atoms.value, total_frames.value
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
def call_CHILL(keyword, sph_const, Plm_const, total_atoms, l, xyz, box, maxnb, nnb, cutoff_sqr): CHILL_keyword, strlength = string_to_ctypes_string(keyword) cij = np.ctypeslib.as_ctypes(np.zeros(nnb*total_atoms, dtype=np.float64)) cij_hist = np.ctypeslib.as_ctypes(np.zeros(20, dtype=np.float64)) chill_ID_list = np.ctypeslib.as_ctypes(np.zeros(total_atoms, dtype=np.int32)) cutoff_sqr = c_double(cutoff_sqr) l = c_int(l) total_atoms = c_int(total_atoms) maxnb = c_int(maxnb) nnb = c_int(nnb) num_ice = c_int() CHILL_lib.call_CHILL(sph_const, Plm_const, CHILL_keyword, byref(strlength), byref(total_atoms), byref(maxnb), byref(nnb), byref(l), byref(cutoff_sqr), box, xyz, cij, cij_hist, chill_ID_list, byref(num_ice)) return np.ctypeslib.as_array(cij_hist), np.ctypeslib.as_array(chill_ID_list)