Advertisement
shihab2196

timeseries_of_species_BASEOIL

Jan 25th, 2024
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.50 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Author: Shihab Ahmed
  4. Created on Mon Oct 23 05:15:03 2023
  5. """
  6. import pandas as pd
  7. import matplotlib.pyplot as plt
  8. import random
  9. import magnolia.speciesfile_parser as sfp
  10. import magnolia.bondfile_parser as bfp
  11.                
  12.                
  13.  
  14. base_oil = 'Squalane'
  15. cutoff   = 0.45
  16. temp     = 1600
  17.    
  18. commmon = r"C:\Users\arup2\OneDrive - University of California Merced\Desktop\LAMMPS\Base_Oil\{}\25_{}_200_O2_Soria\Production\{}".format(base_oil,base_oil,temp)
  19.  
  20. sim_dir = ['\\Sim-1','\\Sim-2','\\Sim-3']
  21. flag = True
  22. for sim in sim_dir:
  23.     directory = commmon+sim
  24.     speciesfile = directory+f'\\species_{cutoff}.out'
  25.     if cutoff==0.30:
  26.         speciesfile = directory+'\\species.out'
  27.     current = sfp.get_species_count(speciesfile).T
  28.     if flag:
  29.         summed_species = current.copy()
  30.         upper_bound_   = current.copy()
  31.         lower_bound_   = current.copy()
  32.         flag = False
  33.     else:
  34.         summed_species = summed_species.add(current,fill_value=0)
  35.         ## geting upper bound
  36.         maxx = lambda s1, s2: s1.where(s1 > s2, s2)
  37.         upper_bound_ = upper_bound_.combine(current, maxx)
  38.         ## getting lower bound
  39.         minn = lambda s1, s2: s1.where(s1 < s2, s2)
  40.         lower_bound_ = lower_bound_.combine(current, minn)
  41.  
  42.  
  43.  
  44.  
  45.  
  46. number_of_main = 25  
  47. species_cutoff = 4
  48. skipts = (temp-300)/4
  49. exclude= ['O2', 'H62C30']
  50. nsim   = len(sim_dir) # number of simulation
  51. tailps = 10
  52. nspecies = 5
  53.  
  54. species     = summed_species/nsim
  55. upper_bound = upper_bound_.copy()
  56. lower_bound = lower_bound_.copy()
  57.  
  58. species.index = species.index*0.25/1000
  59. species = species.loc[skipts:,:]
  60. species.index = species.index-skipts
  61.  
  62. last_count = species.loc[1000-tailps:,:].mean().sort_values(ascending=False)
  63. species    = species.loc[:,last_count.index]
  64. # species = species.loc[:,(species>=species_cutoff).any()]
  65. species = species.drop(exclude,axis=1)
  66. species = species.T.head(nspecies).T
  67.  
  68.  
  69. ## adjusting the index of upper_bound
  70. upper_bound.index = upper_bound_.index*0.25/1000
  71. upper_bound = upper_bound.loc[skipts:,:]
  72. upper_bound.index = upper_bound.index-skipts
  73. ## adjusting the index of lower_bound
  74. lower_bound.index = lower_bound_.index*0.25/1000
  75. lower_bound = lower_bound.loc[skipts:,:]
  76. lower_bound.index = lower_bound.index-skipts
  77.  
  78.  
  79. ## plot parameter
  80. label_fontsize  = 18
  81. tick_fontsize   = 14
  82. colors = ['b', 'g', 'r', 'c', 'm', 'y', 'k']
  83.  
  84. plt.style.use("default")
  85. fig, ax = plt.subplots(figsize=[8,6])
  86. time = species.index
  87.  
  88. for i, column in enumerate(species.columns):
  89.     label = bfp.make_molecular_formula_latex(column,sort=True)
  90.     # color = next(colors)
  91.     ax.plot(time,species[column],label=label,linewidth=0.8,
  92.              color=colors[i%len(colors)])
  93.     ax.fill_between(time, lower_bound[column], upper_bound[column],
  94.                      alpha=0.1, color=colors[i%len(colors)])
  95.    
  96. ax.legend(fontsize=tick_fontsize,loc='upper left')
  97. ax.tick_params(axis='both', labelsize=tick_fontsize)
  98. # plt.ylim(0,60)
  99. ax.set_xlim(-1,1001)
  100. ax.set_xlabel('Time (ps)',fontsize=label_fontsize)
  101. ax.set_ylabel('Number of species',fontsize=label_fontsize)
  102. title = f'This plot is generated from species file (cutoff: {cutoff})'
  103. ax.set_title(directory[directory.find('Base'):]+'\n'+title+'\n',fontsize=8)
  104. ax.grid('on')
  105. plt.savefig(r'C:\Users\arup2\OneDrive - University of California Merced\Desktop\LAMMPS\Post Processing\lammps_processing\python_outputs\species'+'\\species_speciesfile{}'.format(random.randint(0,10000000000)),dpi=500,bbox_inches='tight')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement