def extractMolecule(file_path,atom_no=0): if isMd(file_path): with open(file_path,'r') as file: df_cords=io.readFileMd(file,config.start_frame_no,frame_no_pos=config.frame_no_pos) else: df_cords=io.readFile(file_path) io.writeFile('ring_track_frame.tmp.xyz',df_cords) subprocess.run(['babel','ring_track_frame.tmp.xyz','ring_track_frame.tmp.mol']) G=io.readFile('ring_track_frame.tmp.mol',info='graph') subprocess.run(['rm','ring_track_frame.tmp.xyz','ring_track_frame.tmp.mol']) cc_list=list(nx.connected_component_subgraphs(G)) print(f'number of molecules found is {len(cc_list)}') for cc in cc_list: if atom_no in list(cc.nodes): return sorted(list(cc.nodes))
def stretchBond(infile_path, outfile_path='', atom0=0, atom1=1, moiety=list(range(56, 90)), trans=0.1): df = io.readFile(infile_path) atom0_vec = df.iloc[atom0, :] atom1_vec = df.iloc[atom1, :] vec = np.zeros((3, )) vec[0] = atom1_vec['x'] - atom0_vec['x'] vec[1] = atom1_vec['y'] - atom0_vec['y'] vec[2] = atom1_vec['z'] - atom0_vec['z'] mag = np.linalg.norm(vec) uvec = vec / mag trans_vec = trans * uvec cords = df.loc[:, ['x', 'y', 'z']].values cords[moiety] = cords[moiety] + trans_vec new_df = df.copy() new_df.loc[:, ['x', 'y', 'z']] = cords io.writeFile(outfile_path, new_df) validate(infile_path, outfile_path, atom0=atom0, atom1=atom1, moiety=moiety)
def fixAtoms(file_path, atoms_list): df = io.readFile(file_path, file_type='opt') print(df.head()) io.writeFile(file_path, df, file_type='opt', info='fix_atoms', atoms_list=atoms_list)
def init(): init_struct_file_path = os.path.join(config.proj_dir_abs_path, config.init_job_dir_name, config.init_job_dir_name + '.xyz') print(f'optimizing intial structure file: {init_struct_file_path}') df = io.readFile(init_struct_file_path) job.runJob(config.init_job_dir_name, config.init_job_dir_name, steps=list(range(3, 10)))
def validate(infile_path, outfile_path, atom0=0, atom1=1, moiety=list(range(56, 90))): prev_df = io.readFile(infile_path) print(prev_df) atom0_row = prev_df.iloc[atom0, :][['x', 'y', 'z']] atom1_row = prev_df.iloc[atom1, :][['x', 'y', 'z']] prev_dist=np.sqrt((atom0_row['x']-atom1_row['x'])**2 + \ (atom0_row['y']-atom1_row['y'])**2 + \ (atom0_row['z']-atom1_row['z'])**2) nxt_df = io.readFile(outfile_path) atom0_row = nxt_df.iloc[atom0, :][['x', 'y', 'z']] atom1_row = nxt_df.iloc[atom1, :][['x', 'y', 'z']] nxt_dist=np.sqrt((atom0_row['x']-atom1_row['x'])**2 + \ (atom0_row['y']-atom1_row['y'])**2 + \ (atom0_row['z']-atom1_row['z'])**2) print('strech along {} , {}'.format(atom0, atom1)) print('moiety:' + str(moiety)) print('prev_dist: {} nxt_dist:{} difference:{}'.format( prev_dist, nxt_dist, nxt_dist - prev_dist))
args_dict={'input_file_path':input_file_path,'output_dir_path':output_dir_path,'d_theta':d_theta,'ref_atom1_no':ref_atom1_no,'ref_atom2_no':ref_atom2_no,'atom_no_list':atom_no_list} return args_dict def getAxis(agrs_dict,cords_df): axis=[0,0,0] ref_atom1_no=args_dict['ref_atom1_no'] ref_atom2_no=args_dict['ref_atom2_no'] ref_atom1_cords=cords_df[cords_df['atom_no']==ref_atom1_no][['x','y','z']].values[0] ref_atom2_cords=cords_df[cords_df['atom_no']==ref_atom2_no][['x','y','z']].values[0] axis[0]=ref_atom2_cords[0]-ref_atom1_cords[0] axis[1]=ref_atom2_cords[1]-ref_atom1_cords[1] axis[2]=ref_atom2_cords[2]-ref_atom1_cords[2] return axis args_dict=get_sys_agrs() output_file_name=args_dict['input_file_path'].split('/')[-1].split('.')[0] output_file_md=open(os.path.join(args_dict['output_dir_path'],output_file_name+f'_md.xyz'),'w') initial_cords_df=io.readFile(args_dict['input_file_path']) ref_atom1_no=args_dict['ref_atom1_no'] ref_atom1_cords=initial_cords_df[initial_cords_df['atom_no']==ref_atom1_no][['x','y','z']].values[0] shifted_initial_cords_df=rotation.shiftOrigin(initial_cords_df,ref_atom1_cords) axis=getAxis(args_dict,initial_cords_df) for key,value in args_dict.items(): print(f'{key} = {value}') print(initial_cords_df.head()) print(f'rotation axis = {axis}') for curr_frame_no,theta in enumerate(tqdm(range(0,360,args_dict['d_theta']))): final_cords_df=rotation.rotateAlongAxis(shifted_initial_cords_df,axis,math.radians(theta),args_dict['atom_no_list']) io.writeFile(os.path.join(args_dict['output_dir_path'],output_file_name+f'_{theta}.xyz'),final_cords_df) io.writeFileMd(output_file_md,final_cords_df,curr_frame_no,frame_no_pos=2)