Advertisement
shihab2196

BO_Evolution_Heatmap_Molecule_B

Jan 15th, 2024
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.33 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Wed Jun 14 13:18:47 2023
  4.  
  5. @author: Shihab
  6. """
  7. import magnolia.bondfile_parser as bfp
  8. import matplotlib.pyplot as plt
  9. import sys
  10. import magnolia.needless_essential as ne
  11. import pandas as pd
  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\D\D_300_O2\Production\1200K\Sim-1'
  17. filename  = '\\bonds.reaxc'
  18. bondfile  = directory+filename
  19.  
  20. atomsymbols = ['H','C','O']
  21. atominfo = bfp.get_neighbours(bondfile,bo=True)
  22. #%%--
  23. neighbours, atomtypes, bondorders = atominfo
  24. steps = list(neighbours.keys())
  25. bondlist = []
  26.  
  27. firststepneigh = neighbours[steps[0]]
  28. # 1 H
  29. # 2 C
  30. # 3 O
  31. bonds = {}
  32. ethyl_oxy=[]
  33. for parent,children in firststepneigh.items():    
  34.     if atomtypes[parent] == 3:
  35.         # C=O bond
  36.         if atomtypes[parent]==3 and len(children)==1 and atomtypes[children[0]]==2:
  37.             child = children[0]
  38.             key = 'C=O'
  39.             if key not in bonds.keys():
  40.                 bonds[key] = [(parent,child)]
  41.             else:
  42.                 bonds[key].append((parent,child))
  43.                
  44.         # O-H bonds
  45.         for child in children:
  46.             if atomtypes[child]==1:
  47.                 key = 'O-H'
  48.                 if key not in bonds.keys():
  49.                     bonds[key] = [(parent,child)]
  50.                 else:
  51.                     bonds[key].append((parent,child))
  52.            
  53.         # C-C Bonds    
  54.         if len(children)==1:
  55.             key = 'C-C'
  56.             child1 = children[0]
  57.             for ch in firststepneigh[child]:
  58.                 if atomtypes[ch]==2:
  59.                     bond = (child1,ch)
  60.                     if key not in bonds.keys():
  61.                         bonds[key] = [bond]
  62.                     else:
  63.                         bonds[key].append(bond)
  64.        
  65.         # C-O Bonds
  66.         if len(children)==2 and atomtypes[children[0]]==2 and atomtypes[children[1]]==2:
  67.             for child in children:
  68.                 bond      = (parent,child)
  69.                 schildren = firststepneigh[child]
  70.                 sctypes   = [atomtypes[x] for x in schildren]
  71.                
  72.                 # C-O-lower
  73.                 if sctypes.count(3) == 1:
  74.                     ethyl_oxy.append(child)
  75.                     key  = 'C-O-lower'
  76.                     if key not in bonds.keys():
  77.                         bonds[key] = [bond]
  78.                     else:
  79.                         bonds[key].append(bond)
  80.                
  81.                 # C-O-upper
  82.                 elif sctypes.count(3) == 2:
  83.                     key  = 'C-O-upper'
  84.                     if key not in bonds.keys():
  85.                         bonds[key] = [bond]
  86.                     else:
  87.                         bonds[key].append(bond)
  88.                 #
  89.                 else:
  90.                     print('Dumb')
  91.         # O=O Bonds
  92.         if len(children)==1 and atomtypes[children[0]]==3:
  93.             key = 'O=O'
  94.             bond = (parent,children[0])
  95.             if key not in bonds.keys():
  96.                 bonds[key] = [bond]
  97.             else:
  98.                 bonds[key].append(bond)
  99.                
  100.  
  101. key  = 'Ethyl-Oxygen Bond'
  102. keyy = 'H Absorption'
  103. species = 'H5C2'
  104. bonds[key]  = []
  105. bonds[keyy] = []
  106. oxygens = []
  107.  
  108. # Ethyl-Oxygen Bond
  109. for step,neigh in neighbours.items():
  110.     for parent, children in neigh.items():
  111.         if parent in ethyl_oxy:
  112.             for child in children:
  113.                 bond = (parent,child)
  114.                 if child>2600 and bond not in bonds[key]:
  115.                     bonds[key].append(bond)
  116.                
  117.                 ############################
  118.                 schildren = neigh[child]
  119.                 for schield in schildren:
  120.                     if atomtypes[schield] == 3 and schield not in oxygens:
  121.                         oxygens.append(schield)
  122.                 ############################
  123. # H Absorptionby Oxygen
  124. print(len(oxygens))
  125. for step,neigh in neighbours.items():
  126.     for parent, children in neigh.items():
  127.         if parent in oxygens:
  128.             for child in children:
  129.                 bond = (parent,child)
  130.                 if atomtypes[child]==1 and bond not in bonds[keyy]:
  131.                     bonds[keyy].append(bond)
  132. print(len(bonds[keyy]))
  133. #%%-
  134. bond_type = ['O-H','C-O-lower','C-O-upper','C-C','C=O','O=O','Ethyl-Oxygen Bond','H Absorption']
  135. marker = ['s','^','x','o','>','*']    
  136. cutoff = {'O-H':1, 'C=O':1.5, 'C-C':1.4, 'C-O-upper':2, 'C-O-lower':1,'Ethyl-Oxygen Bond':1,'H Absorption':1}
  137. tol    = {'O-H':0.9, 'C=O':0.9, 'C-C':0.9, 'C-O-upper':0.35, 'C-O-lower':0.9,'Ethyl-Oxygen Bond':0.7,'H Absorption':0.7}
  138. color    = {'O-H':'b', 'C=O':'k', 'C-C':'c', 'C-O-upper':'m', 'C-O-lower':'r','Ethyl-Oxygen Bond':'g','H Absorption':'k'}
  139. marker   = {'O-H':'s', 'C=O':'^', 'C-C':'x', 'C-O-upper':'o', 'C-O-lower':'>','Ethyl-Oxygen Bond':'o','H Absorption':'x'}
  140. label   = {'O-H':'Bond-1', 'C=O':'Bond-5', 'C-C':'Bond-2', 'C-O-upper':'Bond-3', 'C-O-lower':'Bond-4','Ethyl-Oxygen Bond':'Ethyl-Oxygen Bonds','H Absorption':'H Absorption'}
  141.  
  142. plot_keys = ['O-H','C-C','C-O-upper','C-O-lower']
  143. n_plot = len(plot_keys)
  144. skipts = (1200-300)/4
  145. tick_fontsize  = 11
  146. label_fontsize = 15
  147. vmin   = 0
  148. vmax   = 2
  149.  
  150. fig, ax = plt.subplots(1,len(plot_keys)+1,figsize=(9, 4),
  151.                        gridspec_kw={'width_ratios': [1, 1, 1, 1, 0.1]})
  152. subtitle = ["O–H bond","C–C bond","C–O bond","C–O bond"]
  153. for i,key in enumerate(plot_keys):
  154.     b = bonds[key]
  155.     title = '{} {}\nMolecule D\n'.format(label[key],key)
  156.     savedir = r'C:\Users\arup2\OneDrive - University of California Merced\Desktop\LAMMPS\Post Processing\lammps_processing\python_outputs\BO_Evolution'
  157.     steps = np.array(list(bondorders.keys()))
  158.     timestep = 0.25
  159.     df = bfp.bondorder_evolution(bondorders, b, ts=timestep,
  160.                                  skipts=skipts,plot='no')
  161.    
  162.     if i<n_plot-1:
  163.         hm = sns.heatmap(df,cmap='jet',xticklabels=2000,
  164.                          ax=ax[i],vmin=0.0,vmax=2.0,cbar=False)
  165.     else:
  166.         cbar_ticks = np.arange(vmin,vmax+1,step=1,dtype=int)
  167.         cbar_kws = {'ticks': cbar_ticks}
  168.         sns.heatmap(df,cmap='jet',cbar_kws=cbar_kws,
  169.                     xticklabels=2000,ax=ax[i],vmin=vmin,vmax=vmax,
  170.                     cbar_ax=ax[-1])
  171.         ax[-1].set_ylabel("Bond order", fontsize=label_fontsize)
  172.    
  173.     xticklabels = [int(float(x.get_text())) for x in ax[i].get_xticklabels()]
  174.     ax[i].set_xticklabels(xticklabels,rotation=90,fontsize=tick_fontsize)
  175.     yticks = [1]+list(range(10,51,10))
  176.     ax[i].set_yticks(yticks)
  177.     ax[i].tick_params(bottom=True, left=True, right=False, top=False)
  178.     if i==0: ax[i].set_yticklabels(yticks,rotation=0,fontsize=tick_fontsize)
  179.     ax[i].set_title('{}A: {}'.format(i+1,subtitle[i]),
  180.                     fontsize=label_fontsize-1)
  181.  
  182. fig.text(0.5, -0.04, 'Time (ps)', ha='center', va='center',
  183.          fontsize=label_fontsize)
  184. fig.text(0.08,0.5, 'Molecule Index', ha='center', va='center',rotation=90,
  185.          fontsize=label_fontsize)
  186.  
  187.  
  188. title = directory[directory.find('ABCDE'):]
  189. fig.suptitle(title, y=1.04, fontsize=12)
  190. 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')
  191.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement