Advertisement
shihab2196

bond_order_heatmaps_molecule_B_righ_left

Dec 29th, 2023 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.94 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Author: Shihab Ahmed
  4. Created on Thu Dec 28 05:02:35 2023
  5. """
  6.  
  7. import magnolia.bondfile_parser as bfp
  8. import networkx as nx
  9. import sys
  10. import matplotlib.pyplot as plt
  11. import magnolia.molecular_analysis as man
  12. import numpy as np
  13. import seaborn as sns
  14. import random
  15.  
  16. directory = r'C:\Users\arup2\OneDrive - University of California Merced\Desktop\LAMMPS\Antioxidants\ABCDE\B\B_300_O2\Production\1250\Sim-1'
  17. filename  = 'bonds.reaxc'
  18. bondfilepath = directory+'\\'+filename
  19.  
  20. cutoff = 0.50
  21. bonddata = bfp.parsebondfile(bondfilepath,cutoff=cutoff, mtypes=True,bo=True)
  22. #%%
  23. neighbors = bonddata['neighbours']
  24. atypes    = bonddata['atypes']
  25. mtypes    = bonddata['mtypes']
  26. bondorders= bonddata['bondorders']
  27. asyms = 'HCO'
  28.  
  29. bondlist = ['left_ring_O-H', 'right_ring_O-H','left_chain_O-H','right_chain_O-H',
  30.             'left_ring_O-C','right_ring_O-C','left_chain_O-C','right_chain_O-C',]
  31. bonds = {}
  32. for key in bondlist:
  33.     bonds[key] = []
  34.  
  35. number_intial_molecules = 50
  36. length = {}
  37. draw_one = True
  38. for m in range(1,number_intial_molecules+1):
  39.     g = {}
  40.     for parent, children in neighbors[0].items():
  41.         if mtypes[parent]==m:
  42.             g[parent]=children.copy()
  43.     G = nx.Graph(g)
  44.     center = nx.center(G)
  45.     oxygen = [o for o in G.nodes if atypes[o]==3]
  46.    
  47.     left, right = sorted(center)
  48.    
  49.     for ox in oxygen:
  50.         dist = nx.dijkstra_path_length(G, source=ox, target=left)
  51.         length[ox]=dist
  52.    
  53.  
  54. oxy_selection = {}
  55. oxy_type_list = ['right_ring_O','left_ring_O','right_chain_O','left_chain_O']
  56. for ox in oxy_type_list:
  57.     oxy_selection[ox]=[]
  58.    
  59. for key, value in length.items():
  60.     if value == 2:
  61.         oxy_selection['left_ring_O'].append(key)
  62.     elif value == 3:
  63.         oxy_selection['right_ring_O'].append(key)
  64.     elif value == 6:
  65.         oxy_selection['left_chain_O'].append(key)
  66.     elif value == 7:
  67.         oxy_selection['right_chain_O'].append(key)
  68.  
  69.  
  70. node_to_remove = [node for node in G.nodes if atypes[node]==1]
  71. G.remove_nodes_from(node_to_remove)
  72. c = []
  73. for node in G.nodes:
  74.     if node in oxy_selection['left_ring_O']:
  75.         c.append('r')
  76.     elif node in oxy_selection['right_ring_O']:
  77.         c.append('pink')
  78.     elif node in oxy_selection['left_chain_O']:
  79.         c.append('green')
  80.     elif node in oxy_selection['right_chain_O']:
  81.         c.append('lightgreen')
  82.     else:
  83.         c.append('tab:blue')
  84.  
  85.    
  86. nx.draw_spring(G,node_color=c,with_labels=False)
  87. draw_one=False  
  88.    
  89. for parent, children in neighbors[0].items():
  90.     for ox in oxy_type_list:
  91.         if parent in oxy_selection[ox]:
  92.             for child in children:
  93.                 if atypes[child]==1:
  94.                     bonds[ox+'-H'].append((parent,child))
  95.                 elif atypes[child]==2:
  96.                     bonds[ox+'-C'].append((parent,child))
  97. #%%
  98. skipts = 0#(1150-300)/4
  99. vmin   = 0
  100. vmax   = 2
  101. tick_fontsize  = 8.5
  102. label_fontsize = 14
  103.  
  104. count = 1
  105. n_plot = len(bonds)
  106. fig, ax = plt.subplots(1,n_plot+1,figsize=(1.25*n_plot, 4),
  107.                        gridspec_kw={'width_ratios': [1]*n_plot+[0.1]})
  108. j = 0
  109. for i,key in enumerate(bonds):
  110.     b = bonds[key]
  111.     timestep = 0.25
  112.     df = bfp.bondorder_evolution(bondorders, b, ts=timestep,
  113.                                  skipts=skipts,plot='no')
  114.    
  115.     if j<n_plot-1:
  116.         hm = sns.heatmap(df,cmap='jet',xticklabels=2000,
  117.                          ax=ax[j],vmin=vmin,vmax=vmax,cbar=False)
  118.     else:
  119.         cbar_ticks = np.arange(vmin,vmax+1,step=1,dtype=int)
  120.         cbar_kws = {'ticks': cbar_ticks}
  121.         sns.heatmap(df,cmap='jet',cbar_kws=cbar_kws,
  122.                     xticklabels=2000,ax=ax[j],vmin=vmin,vmax=vmax,
  123.                     cbar_ax=ax[-1])
  124.         ax[-1].set_ylabel("Bond order", fontsize=label_fontsize)
  125.    
  126.     xticklabels = [int(float(x.get_text())) for x in ax[j].get_xticklabels()]
  127.     ax[j].set_xticklabels(xticklabels,rotation=90,fontsize=tick_fontsize)
  128.     yticks = [1]+list(range(10,51,10))
  129.     ax[j].set_yticks(yticks)
  130.     ax[j].tick_params(bottom=True, left=True, right=False, top=False)
  131.     if j==0: ax[j].set_yticklabels(yticks,rotation=0,fontsize=tick_fontsize)
  132.    
  133.     ## title
  134.     if 'left_' in key:
  135.         title = '{}B\n{}'.format(count,key.replace('_',' '))
  136.     else:
  137.         title = '{}B\'\n{}'.format(count,key.replace('_',' '))
  138.         count+=1
  139.        
  140.     ax[j].set_title(title,fontsize=tick_fontsize)
  141.     j+=1
  142.  
  143.  
  144. fig.text(0.5, -0.02,'Time (ps)',ha='center',va='center',fontsize=label_fontsize)
  145. fig.text(0.08,0.5, 'Molecule Index', ha='center', va='center',rotation=90,
  146.          fontsize=label_fontsize)
  147.  
  148. title = directory[directory.find('ABCDE'):]+"Molecule B_{}\n".format(cutoff)
  149. fig.suptitle(title, y=1.04, fontsize=tick_fontsize)
  150. plt.savefig(r'C:\Users\arup2\OneDrive - University of California Merced\Desktop\LAMMPS\Post Processing\lammps_processing\python_outputs\BO_Evolution\bo_evolution_'+str(random.randint(100000, 999999)),dpi=500,bbox_inches='tight')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement