Advertisement
shihab2196

species_plot_speciesfile

Dec 10th, 2023 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.13 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 = 'PAO4'
  15. cutoff   = 0.3
  16.    
  17. commmon = r"C:\Users\arup2\OneDrive - University of California Merced\Desktop\LAMMPS\Base_Oil\{}\25_{}_200_O2_Soria\Production\1600".format(base_oil,base_oil)
  18.  
  19. sim_dir = ['\\Sim-1','\\Sim-2','\\Sim-3']
  20. flag = True
  21. for sim in sim_dir:
  22.     directory = commmon+sim
  23.     speciesfile = directory+f'\\species_{cutoff}.out'
  24.     if cutoff==0.30:
  25.         speciesfile = directory+'\\species.out'
  26.     current = sfp.get_species_count(speciesfile).T
  27.     if flag:
  28.         summed_species = current.copy()
  29.         upper_bound_   = current.copy()
  30.         lower_bound_   = current.copy()
  31.         flag = False
  32.     else:
  33.         summed_species = summed_species.add(current,fill_value=0)
  34.         ## geting upper bound
  35.         maxx = lambda s1, s2: s1.where(s1 > s2, s2)
  36.         upper_bound_ = upper_bound_.combine(current, maxx)
  37.         ## getting lower bound
  38.         minn = lambda s1, s2: s1.where(s1 < s2, s2)
  39.         lower_bound_ = lower_bound_.combine(current, minn)
  40.  
  41.  
  42.  
  43.  
  44.  
  45. number_of_main = 25  
  46. species_cutoff = 4
  47. skipts = (1600-300)/4
  48. exclude= ['O2', 'H62C30']
  49. nsim   = len(sim_dir) # number of simulation
  50.  
  51. species     = summed_species/nsim
  52. upper_bound = upper_bound_.copy()
  53. lower_bound = lower_bound_.copy()
  54.  
  55. last_count = species.iloc[-1,:].sort_values(ascending=False)
  56. species    = species.loc[:,last_count.index]
  57. species = species.loc[:,(species>=species_cutoff).any()]
  58. species = species.drop(exclude,axis=1)
  59. species.index = species.index*0.25/1000
  60. species = species.loc[skipts:,:]
  61. species.index = species.index-skipts
  62.  
  63. ## adjusting the index of upper_bound
  64. upper_bound.index = upper_bound_.index*0.25/1000
  65. upper_bound = upper_bound.loc[skipts:,:]
  66. upper_bound.index = upper_bound.index-skipts
  67. ## adjusting the index of lower_bound
  68. lower_bound.index = lower_bound_.index*0.25/1000
  69. lower_bound = lower_bound.loc[skipts:,:]
  70. lower_bound.index = lower_bound.index-skipts
  71.  
  72.  
  73. time = species.index
  74.  
  75. colors = iter(['b', 'g', 'r', 'c', 'm', 'y', 'k'])
  76. plt.style.use("classic")
  77. plt.figure(figsize=(6.4, 4.8))
  78.  
  79. for column in species.columns:
  80.     label = bfp.make_molecular_formula_latex(column,sort=True)
  81.     # color = next(colors)
  82.     plt.plot(time,species[column],label=label,linewidth=0.8)
  83.     plt.fill_between(time, lower_bound[column], upper_bound[column],
  84.                      alpha=0.1)
  85.    
  86. plt.legend(fontsize=15,loc='upper left')
  87. plt.ylim(0,60)
  88. plt.xlabel('Time (ps)',fontsize=15)
  89. plt.ylabel('Number of molecules',fontsize=15)
  90. title = f'This plot is generated from species file (cutoff: {cutoff})'
  91. plt.title(directory[directory.find('Base'):]+'\n'+title+'\n',fontsize=8)
  92. plt.grid('on')
  93. 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=400,bbox_inches='tight')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement