########## Main ########### myfile = open('mol_remain.txt', 'r') res_targ = [] for line in myfile: res_targ.append([int(i) for i in line.split()]) traj_name, traj0, topology = comm.load_traj() para = comm.load_para() #res_targ, res_name = comm.select_groups(traj0) massind, chargeind = comm.load_atomic(res_targ, topology, para) bin_size = comm.bin_size dt = comm.dt nframe = comm.args.nframe - 1 xyz_pre = comm.calc_xyz_com(res_targ, traj0, topology, para) vc = [[[] for row in range(nframe - nframe / 2 + 1)] for _ in res_targ] base = [[[] for row in range(nframe - nframe / 2 + 1)] for _ in res_targ] vel_ref = [] chunk_size = 100 for chunk_index, traj in enumerate( md.iterload(traj_name, chunk=chunk_size, top='topol.pdb')): for sub_ind, frame in enumerate(traj): frame_ind = chunk_index * chunk_size + sub_ind if frame_ind == 0: continue box = frame.unitcell_lengths[0, :] xyz_com = comm.calc_xyz_com(res_targ, frame, topology, para) vel = [[] for _ in res_targ] for res_ind, xyz_res in enumerate(xyz_com): vel[res_ind] = xyz_res[:, :2] - xyz_pre[res_ind][:, :2]
#!/Users/yuzhang/anaconda3/bin/python # Filename: calc_com_OLC.py # Description: This is a python script that calculates the center of mass # coordinates of onion like carbon in an supercapacitor # system # Date: 11-22-2017 Created import calc_common as comm import mdtraj as md print('Reading input file', comm.args.filename) traj = md.load(comm.args.filename) para = comm.load_para() res_targ, res_name = comm.select_groups(traj) xyz_com = comm.calc_xyz_com(res_targ, traj, traj.topology, para) print('The center of the group:', ) for i in xyz_com: print(i) i = 0 avg = xyz_com[0][0] for i in range(1, len(xyz_com)): avg += xyz_com[i][0] print(avg / (i + 1))
fsize = 28 ########## Main ########### traj_name, traj0, topology = comm.load_traj() para = comm.load_para() res_targ, res_name = comm.select_groups(traj0) massind, chargeind = comm.load_atomic(res_targ, topology, para) direction = comm.direction bin_size = comm.bin_size bound = comm.load_bound(traj0, direction) n_all = [[[] for row in range(len(res_targ))] for row in range(4)] chunk_size = 100 for chunk_index, traj in enumerate(md.iterload(traj_name, chunk = chunk_size, top = 'topol.pdb')): for sub_ind, frame in enumerate(traj): xyz_com = comm.calc_xyz_com(res_targ, frame, topology, para) for j, item in enumerate(xyz_com): for i in range(4): n_all[i][j].append(0) for xyz in item[:, direction]: if xyz >= 1 and xyz <= 13: n_all[0][j][-1] += 1 elif xyz > 13 and xyz < 20: n_all[1][j][-1] += 1 elif xyz >= 20 and xyz<= 32: n_all[2][j][-1] += 1 else: n_all[3][j][-1] += 1 if sub_ind%10 == 9: print 'Reading chunk', chunk_index+1, 'and frame',chunk_index*chunk_size+sub_ind+1 # if chunk_index == 0:
import calc_common as comm lwidth = 4 fsize = 28 ########## Main ########### traj_name, traj0, topology = comm.load_traj() para = comm.load_para() res_targ, res_name = comm.select_groups(traj0) massind, chargeind = comm.load_atomic(res_targ, topology, para) direction = comm.direction bin_size = comm.bin_size bound = comm.load_bound(traj0, direction) last_frame = md.load_frame('last_frame.xtc', 0, top = 'topol.pdb') xyz_com = comm.calc_xyz_com(res_targ, last_frame, topology, para) res_sel = [[], []] x_t = [[], []] if comm.args.rev == False: rev = 0 else: rev = 1 bound_sel = [0, 12, 19, 31] # boundaries for slit 1 and slit 2 for i in range(2): jdg = (i+rev)%2 for j, xyz in enumerate(xyz_com[i][:, direction]): if xyz >= bound_sel[2*jdg] and xyz <= bound_sel[2*jdg+1]: res_sel[jdg].append(res_targ[i][j]) x_t[jdg].append([])