sys.exit(2) frame_end = int(sys.argv[3]) if (len(sys.argv) == 5): frame_stride = 1 else: frame_stride = int(sys.argv[4]) if frame_stride <= 0: print('The frame stride is invalid') sys.exit(2) frame_num = frame_end - frame_begin + 1 if frame_num < 1: print('The number of frames is invalid.') sys.exit(2) dcd = DcdFile(sys.argv[1]) dcd.open_to_read() if (len(sys.argv) == 5): dcd_out = DcdFile(sys.argv[4]) else: dcd_out = DcdFile(sys.argv[5]) dcd_out.open_to_write() # header dcd.read_header() header = dcd.get_header() ##header.istart = header.nstep_save * (frame_begin - 1) #header.istart = header.istart + header.nstep_save * frame_begin ##header.nset = int(frame_num / frame_stride) #header.nset = int((frame_end-frame_begin)/frame_stride) + 1 #header.nstep = header.nstep_save * (frame_num - 1)
else: print("Error: resid {:d} should not be there".format(i)) sys.exit(2) for cM in cMs: filename_dcd = 'cM{:s}.fit{:s}.dcd'.format(cM,name) filename_dx = 'cM{:s}.fit{:s}.dx'.format(cM,name) nMg = 0 c = PdbFile('../make_ninfo/16SCD.cM{:s}.cg.ion.pdb'.format(cM),'r').read_all_and_close()[0] for r in c.residues: if r.atoms[0].name.strip() == 'MG': nMg += 1 dcd = DcdFile(filename_dcd) dcd.open_to_read() dcd.read_header() data = [] mm = minmax() ''' Create target volume ''' mm_target = minmax() c = PdbFile('./16SCD.cg.pdb','r').read_all_and_close()[0] for i in range(c.num_atom()): if i+1 in serials: mm_target.update(c.get_atom(i).xyz.get_as_list()) #print('Target volume:')
f_rst.write('n_replica_all: %i\n' % (Nrep, )) for i, label in enumerate(replica_labels): f_rst.write('rep2lab: %5i %5i\n' % (i + 1, label)) #### Step f_rst.write('# step\n') f_rst.write('istep_sim: 1\n') f_rst.write('istep: %i\n' % (step, )) #### coordinates of each replicas for irep in range(1, Nrep + 1): f_rst.write('# xyz_mp_rep\n') f_rst.write('grep: %i\n' % (irep, )) dcd = DcdFile(file_path + '_%04i.dcd' % (irep, )) dcd.open_to_read() header = dcd.read_header() while dcd.has_more_data(): data = dcd.read_onestep() if len(data) != nmp: print(('Error len(data) != nmp in replica %i. len(data)=%i' % (irep, len(data)))) sys.exit(2) f_rst.write('nmp_all: %i\n' % (nmp, )) for imp in range(nmp): f_rst.write('%f %f %f\n' % (data[imp][0], data[imp][1], data[imp][2])) f_rst.write('# velo_mp\n')
''' import sys from cafysis.file_io.dcd import DcdFile from copy import copy if __name__ == '__main__': if len(sys.argv) < 4: print('Usage: % SCRIPT [DCD1] [DCD2] ([DCD3] ...) [output DCD]') sys.exit(2) # Number of input DCD files num_dcd = len(sys.argv) - 2 # New DCD file f_out = DcdFile(sys.argv[-1]) f_out.open_to_write() # Count the total frame number num_frame = 1 for i in range(1, num_dcd): f_in = DcdFile(sys.argv[i]) f_in.open_to_read() f_in.read_header() num_frame += f_in.get_header().nset f_in.close() # Get the total step number from final DCD file f_in = DcdFile(sys.argv[num_dcd]) f_in.open_to_read() f_in.read_header()
''' Created on 2013/08/20 @author: Naoto Hori ''' import sys from cafysis.file_io.dcd import DcdFile from cafysis.file_io.ts import TsFile if len(sys.argv) != 4: print('Usage: % SCRIPT [input DCD] [ts file] [output DCD]') sys.exit(2) # Open DCD and read the header dcd_filename = sys.argv[1] dcd = DcdFile(dcd_filename) dcd.open_to_read() dcd.read_header() header = dcd.get_header() #header.istart = header.nstep_save * (frame_begin - 1) #header.istart = header.istart + header.nstep_save * frame_begin #header.nset = int(frame_num / frame_stride) #header.nset = int((frame_end-frame_begin)/frame_stride) + 1 #header.nstep = header.nstep_save * (frame_num - 1) #header.nstep_save = header.nstep_save * frame_stride # Open DCD and read the header dcd_out = DcdFile(sys.argv[-1]) dcd_out.open_to_write() dcd_out.set_header(header)
def dcd_fit(filename_dcd, filename_dcd_out, natom_total, serials, filename_rmsd): f_out = open(filename_rmsd, 'w') # Coord1 pdb = PdbFile('16SCD.cg.pdb') pdb.open_to_read() ref_chains = pdb.read_all() pdb.close() #num_atom = 0 #for chain in ref_chains : # for residue in chain.residues : # num_atom += len(residue.atoms) ref = zeros((natom_total, 3), dtype=float64, order='C') i = 0 for chain in ref_chains: for residue in chain.residues: for atom in residue.atoms: (ref[i][0], ref[i][1], ref[i][2]) = atom.xyz.get_as_tuple() i += 1 mask = [] for i in range(natom_total): # the serial ID starts from 1, thus i+1 is the serial ID if i + 1 in serials: mask.append(1) else: mask.append(0) dcd = DcdFile(filename_dcd) dcd.open_to_read() dcd.read_header() out_dcd = DcdFile(filename_dcd_out) out_dcd.open_to_write() out_dcd.set_header(dcd.get_header()) out_dcd.write_header() #dcd.show_header() k = 0 while dcd.has_more_data(): k += 1 coords_dcd = dcd.read_onestep_np() rmsd = superimpose(ref.T, coords_dcd.T, mask) f_out.write('{:8d} {:6.2f}\n'.format(k, rmsd)) out_dcd.write_onestep(coords_dcd) dcd.close() out_dcd.close()
@author: Naoto Hori ''' import sys import math from cafysis.file_io.dcd import DcdFile from cafysis.file_io.drid import DridFile, DridHeader import cafysis.lib_f2py.py_drid as py_drid import numpy as np if len(sys.argv) not in (4,5): print('Usage: % SCRIPT [input DCD] [mask file] [output DRID]') print(' or : % SCRIPT [input DCD] [mask file] [# solute in DCD] [output DRID]') sys.exit(2) dcd = DcdFile(sys.argv[1]) dcd.open_to_read() dcd.read_header() mask = [] for l in open(sys.argv[2]): lsp = l.strip().split() a = [] for x in lsp: a.append( float(x) ) mask.append( a ) if len(sys.argv) == 5: flg_solute = True nsolute = int(sys.argv[3]) if len(mask) != nsolute or len(mask[0]) != nsolute:
#i = 0 #for chain in ref_chains : # for residue in chain.residues: # for atom in residue.atoms : # (ref[0][i], ref[1][i], ref[2][i]) = atom.xyz.get_as_tuple() # i += 1 # #ref_idx = [] #pre_idx = [] # all to all #for i in range(num_atom) : # ref_idx.append(i + 1) # pre_idx.append(i + 1) dcd = DcdFile(filename_dcd) dcd.open_to_read() dcd.read_header() bf = zeros((num_atom, 3), dtype=float64) bf_2 = zeros((num_atom, 3), dtype=float64) k = 0 while dcd.has_more_data(): k += 1 data = array(dcd.read_onestep()) bf += data bf_2 += data**2 dcd.close()
if args.frame_stride <= 0: print('Error: Frame stride must be > 0') sys.exit(2) # Read the reference PDB pdb = PdbFile(args.pdb) pdb.open_to_read() chains = pdb.read_all() pdb.close() # Output PDB movie = PdbFile(args.out) movie.open_to_write() # Open DCD and read the header dcd = DcdFile(args.dcd) dcd.open_to_read() dcd.read_header() num_dcd_frames = dcd.count_frame() if args.frame_end == -1: frame_end = num_dcd_frames - 1 elif args.frame_end > num_dcd_frames - 1: print('Warning: There are only %i frames found in the dcd while you specified --to %i' % (num_dcd_frames, args.frame_end)) print(' Output only %i frames.' % (num_dcd_frames)) frame_end = num_dcd_frames - 1 else: frame_end = args.frame_end
pdb.close() num_atom = 0 for chain in ref_chains : num_atom += chain.num_atom() ref = zeros((3, num_atom), dtype=float64, order='F') i = 0 for chain in ref_chains : for residue in chain.residues: for atom in residue.atoms : (ref[0][i], ref[1][i], ref[2][i]) = atom.xyz.get_as_tuple() i += 1 dcd = DcdFile(filename_dcd) dcd.open_to_read() dcd.read_header() out_dcd = DcdFile(filename_out_dcd) out_dcd.open_to_write() out_dcd.set_header(dcd.get_header()) out_dcd.write_header() k = 0 while dcd.has_more_data() : k += 1 data = dcd.read_onestep_np() rmsd = superimpose(ref, data.T) print(k, rmsd)
#!/usr/bin/env python ''' @author: Naoto Hori ''' import sys from cafysis.file_io.dcd import DcdFile if (len(sys.argv) != 2): print('Usage: % SCRIPT [filename]') sys.exit(2) dcd = DcdFile(sys.argv[1]) dcd.open_to_read() dcd.read_header() dcd.show_header() dcd.close()
print('The frame stride is invalid') sys.exit(2) frame_num = frame_end - frame_begin + 1 if frame_num < 1 : print('The number of frames is invalid.') sys.exit(2) # Output PDB f_out = open(sys.argv[-1],'w') # Open DCD and read the header dcd_filename = sys.argv[1] dcd = DcdFile(dcd_filename) dcd.open_to_read() dcd.read_header() def error_no_data() : print('The number of frames is invalid.') print('Header information:') dcd.show_header() sys.exit(2) # skip dcd.skip(frame_begin) #dcd.skip(frame_begin - 1) ## 2013/10/26 i_org = frame_begin # read and write
help='first particle ID') parser.add_argument( '--PosCor', dest='flg_poscor', default=False, action='store_true', help='Consider only the length which has positive correlation') parser.add_argument('dcd', help='target DCD file') parser.add_argument('out', help='output file') args = parser.parse_args() ################################################################################ dcd = DcdFile(args.dcd) dcd.open_to_read() dcd.read_header() nmp = dcd.get_header().nmp_real unit_len_sq = 0.0 n_unit_len_sq = 0 sum_cos_theta = [0.0] * (nmp - 1) num_n = [0] * (nmp - 1) dcd.skip(args.frame_skip) first = True while dcd.has_more_data(): data = dcd.read_onestep_np()
print(' # #') print(' #polar com1 #') print(' # : : : #') print(' # #') print(' #rg mol #') print(' # : : : #') print(' # #') print(' #dt_hb name r theta1 theta2 phi phi1 phi2#') print(' ##########################################') sys.exit(2) JUDGE_CONTACT = 1.2 JUDGE_CONTACT_2 = JUDGE_CONTACT**2.0 DISPLAY_PROCEDURE_DCD_STEP = 0 dcd = DcdFile(sys.argv[1]) dcd.open_to_read() dcd.read_header() nmp = dcd.get_header().nmp_real f_cmd = open(sys.argv[2], 'r') # Read command file cmds = [] defs = {} ninfo_files = {} frameskip = 1 display = 0 out_time = 0 for line in f_cmd: if line.find('#') != -1:
pdb.open_to_read() chains = pdb.read_all() pdb.close() header = DcdHeader() header.nset = 1 header.istart = 1 header.nstep_save = 1 header.nstep = 1 header.nunit_real = len(chains) header.delta = 0.0 header.title = [' ' * 80, ' ' * 80] header.tempk = 0.0 header.lunit2mp = [] imp = 0 xyzs = [] for c in chains: for r in c.residues: for a in r.atoms: imp += 1 xyzs.append([a.xyz.x, a.xyz.y, a.xyz.z]) header.lunit2mp.append(imp) header.nmp_real = imp dcd = DcdFile(sys.argv[-1]) dcd.open_to_write() dcd.set_header(header) dcd.write_header() dcd.write_onestep(xyzs) dcd.close()
from cafysis.file_io.ts import TsFile if __name__ == '__main__': if len(sys.argv) < 5: print('Usage: % SCRIPT [name] [Dir 1] [Dir 2] ([Dir 3] ...) [output dir]') sys.exit(2) name = sys.argv[1] dirs = sys.argv[2:-1] dir_out = sys.argv[-1] # Prepare output files out_ts = TsFile( '%s/%s.ts' % (dir_out, name) ) out_ts.open_to_write() out_dcd = DcdFile( '%s/%s.dcd' % (dir_out, name) ) out_dcd.open_to_write() nstep_total_ts = 0 nstep_total_dcd = 0 for (i_dir, d) in enumerate(dirs): in_ts = TsFile( '%s/%s.ts' % (d, name) ) in_ts.open_to_read() in_ts.read_header() in_dcd = DcdFile( '%s/%s.dcd' % (d, name) ) in_dcd.open_to_read() in_dcd.read_header() # For the first directory if i_dir == 0:
f_out.write('\n\n') # Member of cluster f_out.write('### Members of cluster\n') for i in range(1,ncls+1): f_out.write('#cluster %i\n' % (i,)) for iframe, f in enumerate(fcls): if f == i: f_out.write("%i %i\n" % (iframe, iframe*nskip)) f_out.write('\n\n') f_out.close() ############################# Center dcd_ref = DcdFile(dcd_ref_filepath) dcd_ref.open_to_read() dcd_ref.read_header() data_ref = dcd_ref.read_onestep_np() dcd_ref.close() dcd = DcdFile(dcd_filepath) dcd.open_to_read() dcd.read_header() nmp = dcd._header.nmp_real cls_centroids = [] for icls in range(ncls): cls_centroids.append( np.zeros((nmp,3)) ) k = 0
dir_in = sys.argv[1] name = sys.argv[2] id_end = int(sys.argv[3]) dir_out = sys.argv[-1] #Open input files in_ts_files = [] in_dcd_files = [] for id_rep in range(1, id_end + 1): ts = TsFile('%s/%s_%04i.ts' % (dir_in, name, id_rep)) ts.open_to_read() #ts.read_header() ## Commented out since the header will be read later in_ts_files.append(ts) dcd = DcdFile('%s/%s_%04i.dcd' % (dir_in, name, id_rep)) dcd.open_to_read() #dcd.read_header() ## Commented out since the header will be read later in_dcd_files.append(dcd) id_finish = 0 while id_finish < id_end: id_begin_now = id_finish + 1 id_end_now = id_finish + NUM_OUTFILE_OPEN if id_end_now > id_end: id_end_now = id_end id_finish = id_end_now # Prepare output files list_id_out = list(range(id_begin_now, id_end_now + 1))
help='log scale time') parser.add_argument('--maxint', dest='max_interval', action='store', type=int, help='maximum frame interval') parser.add_argument('dcd', help='target DCD file') parser.add_argument('out', help='output file') args = parser.parse_args() ################################################################################ n_frame = count(args.dcd) # e.g. 501 (i=0, 1, 2,..., 500) dcd = DcdFile(args.dcd) dcd.open_to_read() dcd.read_header() f_out = open(args.out, 'w') sum_rmsd = [0.0] * (n_frame - args.skip + 1) count_rmsd = [0.0] * (n_frame - args.skip + 1) iframe_max = n_frame - 1 # 500 (= 501 - 1) for iframe_ref in range(args.skip, iframe_max): # iframe_ref = 5, 6, ...., 499 dcd.rewind() dcd.skip(iframe_ref)
print('Usage: % SCRIPT [input DCD] [ts file] [reference PDB] [output movie]') sys.exit(2) # Read the reference PDB pdb = PdbFile(sys.argv[-2]) pdb.open_to_read() chains = pdb.read_all() pdb.close() # Output PDB pdb = PdbFile(sys.argv[-1]) pdb.open_to_write() # Open DCD and read the header dcd_filename = sys.argv[1] dcd = DcdFile(dcd_filename) dcd.open_to_read() dcd.read_header() # Open TS and read the header ts = TsFile(sys.argv[2]) ts.open_to_read() ts.read_header() # read and write imodel = 0 i_org = 0 while dcd.has_more_data(): if not ts.has_more_data(): print('Not enough data in .ts file (1)') sys.exit(2)
def count_frame(path): dcd = DcdFile(path) dcd.open_to_read() dcd.read_header() icount = 0 while dcd.has_more_data(): try: dcd.skip(1) icount += 1 except EOFError: icount += 1 print( 'There is another frame at the end, that is not written completely.' ) break except: break dcd.close() return icount
def dcd_concatenate(filepaths): n_frames = [] # To return the number of frames # Number of input DCD files num_dcd = len(filepaths) - 1 # New DCD file f_out = DcdFile(filepaths[-1]) f_out.open_to_write() # Count the total frame number num_frame = 1 for i in range(0, num_dcd - 1): f_in = DcdFile(filepaths[i]) f_in.open_to_read() f_in.read_header() num_frame += f_in.get_header().nset - 1 f_in.close() # Get the total step number from final DCD file f_in = DcdFile(filepaths[num_dcd - 1]) f_in.open_to_read() f_in.read_header() num_frame += f_in.get_header().nset - 1 num_step = f_in.get_header().nstep f_in.close() f_in = DcdFile(filepaths[0]) f_in.open_to_read() f_in.read_header() header = copy(f_in.get_header()) header.nset = num_frame header.nstep = num_step f_out.set_header(header) f_out.write_header() #print filepaths[0], f_in.get_header().nset n_frames.append(f_in.get_header().nset) while f_in.has_more_data(): f_out.write_onestep(f_in.read_onestep()) f_in.close() for i in range(1, num_dcd): f_in = DcdFile(filepaths[i]) f_in.open_to_read() f_in.read_header() f_in.skip_onestep() # skip the first step #print filepaths[i], f_in.get_header().nset - 1 n_frames.append(f_in.get_header().nset - 1) while f_in.has_more_data(): f_out.write_onestep(f_in.read_onestep()) f_in.close() f_out.close() return n_frames
if len(sys.argv) != 9: print('Usage: SCRIPT [input DCD] [input PDB] [ID domain begin] [ID domain end] [ID for fit begin] [ID for fit end] [Box size] [output DCD]') sys.exit(2) ID_DOM_INI = int(sys.argv[3]) - 1 # 重心を求める際に必要 ID_DOM_END = int(sys.argv[4]) - 1 ID_DOM_INI_FIT = int(sys.argv[5]) - 1 # 重心を求める際に必要 ID_DOM_END_FIT = int(sys.argv[6]) - 1 BOXSIZE = float(sys.argv[7]) BOXMAX = 0.5 * BOXSIZE BOXMIN = -0.5 * BOXSIZE ### Files dcd = DcdFile(sys.argv[1]) dcd.open_to_read() pdb = PdbFile(sys.argv[2]) pdb.open_to_read() dcd_out = DcdFile(sys.argv[-1]) dcd_out.open_to_write() ### Read the reference pdb ref_chains = pdb.read_all() num_atom = 0 for chain in ref_chains : num_atom += chain.num_atom()
for chain in ref_chains : for residue in chain.residues: for atom in residue.atoms : #(ref[0][i], ref[1][i], ref[2][i]) = atom.xyz.get_as_tuple() (ref[i][0], ref[i][1], ref[i][2]) = atom.xyz.get_as_tuple() i += 1 # 1 - 77 and 270 - 950 mask = [] for i in range(NATOM_TOTAL): if i in (309-1, 477-1, 519-1): mask.append(1) else: mask.append(0) dcd = DcdFile('dcd/cM0.0300.dcd') dcd.open_to_read() dcd.read_header() out_dcd = DcdFile('cM0.0300.fit665.dcd') out_dcd.open_to_write() out_dcd.set_header(dcd.get_header()) out_dcd.write_header() #dcd.show_header() k = 0 while dcd.has_more_data() : k += 1 coords_dcd = dcd.read_onestep_np() rmsd = superimpose(ref.T, coords_dcd.T, mask)
prefix = sys.argv[-1] f_out = open('%s.Pr' % (prefix,), 'w') f_out.write('#') f_out.write('%6s' % sys.argv) f_out.write('\n') f_out.flush() nbin = max_r * 10 bin_edges = [x*0.1 for x in range(nbin+1)] bin_edges_sq = [(x*0.1)**2 for x in range(nbin+1)] f_out_traj = open('%s.Pr_traj' % (prefix,), 'wb') dcd = DcdFile(sys.argv[1]) dcd.open_to_read() dcd.read_header() hist_all = [0] * nbin icount = 0 fmt = '%iI' % (nbin,) while dcd.has_more_data() : data = dcd.read_onestep_npF() hist = py_dcd_r2_histogram.dcd_r2_histogram(data[:,:nmp], bin_edges_sq) hist_all += hist icount += 1
name = sys.argv[2] id_end = int(sys.argv[3]) dir_out = sys.argv[-1] #Open input files in_ts_files = [] in_dcd_files = [] for id_rep in range(1, id_end + 1): idx = id_rep - 1 ts = TsFile('%s/%s_%04i.ts' % (dir_in, name, id_rep)) ts.open_to_read() ts.read_header() in_ts_files.append(ts) dcd = DcdFile('%s/%s_%04i.dcd' % (dir_in, name, id_rep)) dcd.open_to_read() dcd.read_header() in_dcd_files.append(dcd) # Loop for output label for id_lab in range(1, id_end + 1): #Prepare output files tsout = TsFile('%s/%s_%04i.ts' % (dir_out, name, id_lab)) tsout.open_to_write() dcdout = DcdFile('%s/%s_%04i.dcd' % (dir_out, name, id_lab)) dcdout.open_to_write() #Rewind for id_rep in range(1, id_end + 1):
#!/usr/bin/env python ''' Created on 2016/08/05 @author: Naoto Hori ''' import sys import math from cafysis.file_io.dcd import DcdFile if len(sys.argv) != 5: print(' Usage: % SCRIPT [input DCD] [ID1] [ID2] [output PDB] ') sys.exit(2) dcd = DcdFile(sys.argv[1]) id1 = int(sys.argv[2]) - 1 id2 = int(sys.argv[3]) - 1 dcd.open_to_read() dcd.read_header() f_out = open(sys.argv[-1], 'w') #nframe = 0 while dcd.has_more_data(): data = dcd.read_onestep() #nframe += 1 d = math.sqrt((data[id1][0] - data[id2][0])**2 + (data[id1][1] - data[id2][1])**2 + (data[id1][2] - data[id2][2])**2) f_out.write('%.2f\n' % d) dcd.close()
sys.exit(2) dir_in = sys.argv[1] name = sys.argv[2] id_end = int(sys.argv[3]) dir_out = sys.argv[-1] out_ts_files = [] out_dcd_files = [] #Prepare output files for id_rep in range(1, id_end + 1): ts = TsFile('%s/%s_%04i.ts' % (dir_out, name, id_rep)) ts.open_to_write() out_ts_files.append(ts) dcd = DcdFile('%s/%s_%04i.dcd' % (dir_out, name, id_rep)) dcd.open_to_write() out_dcd_files.append(dcd) in_ts_files = [] in_dcd_files = [] #Open input files for id_rep in range(1, id_end + 1): idx = id_rep - 1 ts = TsFile('%s/%s_%04i.ts' % (dir_in, name, id_rep)) ts.open_to_read() ts.read_header() in_ts_files.append(ts) out_ts_files[idx].copy_header(ts)
#!/usr/bin/env python import sys import scipy.cluster import numpy as np from CalcRMSD import calcrmsd from cafysis.file_io.dcd import DcdFile if len(sys.argv) != 4: print('Usage: % SCRIPT [input DCD] [#frame to skip] [output prefix]') sys.exit(2) nskip = int(sys.argv[2]) prefix = sys.argv[-1] dcd = DcdFile(sys.argv[1]) dcd.open_to_read() dcd.read_header() dist_array = [] while dcd.has_more_data(): ref = dcd.read_onestep_np() dcd.set_mark() if dcd.has_more_data(): while dcd.has_more_data(): data = dcd.read_onestep_np() dist_array.append(calcrmsd(ref.T, data.T)) dcd.go_mark() else:
# Calculate number of steps from file sieze crdsize = os.path.getsize(filepath_crd) num_step = crdsize / 8 / 3 / (nmp + 1) crd = CoordFile(filepath_crd, nmp) crd.open_to_read() header = DcdHeader() header.nset = num_step header.istart = 1 header.nstep_save = 1 header.nstep = 0 header.nunit_real = 0 header.delta = 0.05 header.title = ('', '') header.tempk = 0.0 header.lunit2mp = [] header.nmp_real = nmp dcd = DcdFile(filepath_dcd) dcd.open_to_write() dcd.set_header(header) dcd.write_header() while crd.has_more_data(): dcd.write_onestep(crd.read_onestep()) dcd.close() crd.close()