Advertisement
shihab2196

total_species

Dec 10th, 2023 (edited)
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.46 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Author: Shihab Ahmed
  4. Created on Fri Dec  8 13:29:43 2023
  5. """
  6. import numpy as np
  7. import pandas as pd
  8. import matplotlib.pyplot as plt
  9. import random
  10.  
  11. def get_species_count(speciesfile):
  12.     with open(speciesfile,'r') as sf:
  13.         species = {}
  14.         for line in sf:
  15.             if "Timestep" in line:
  16.                 headers       = line.strip().split()[1:] # not taking '#'
  17.                 species_name  = headers[3:] # skip Timestep, No_moles, No_Specs
  18.             else:
  19.                 values        = [int(x) for x in line.strip().split()]
  20.                 timestep      = values[0]
  21.                 species_count = values[3:]
  22.                 species[timestep]={}
  23.                 for key,value in zip(species_name,species_count):
  24.                     if key in species:
  25.                         species[timestep][key]+=value
  26.                     else:
  27.                         species[timestep][key] = value
  28.    
  29.     df = pd.DataFrame(species).fillna(0)
  30.     df.index.name = 'Timestep'
  31.     return df
  32.  
  33.                
  34. base_oil = 'PAO4'
  35. data = {}
  36. for cutoff in np.array(range(30,76,5))/100:
  37.     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)
  38.     sim_dir = ['\\Sim-1','\\Sim-2','\\Sim-3']
  39.     flag = True
  40.     for sim in sim_dir:
  41.         directory = commmon+sim
  42.         speciesfile = directory+f'\\species_{cutoff}.out'
  43.         if cutoff==0.30:
  44.             speciesfile = directory+'\\species.out'
  45.         current = get_species_count(speciesfile).T
  46.         if flag:
  47.             summed_species = current.copy()
  48.             flag = False
  49.         else:
  50.             summed_species = summed_species.add(current,fill_value=0)
  51.     exclude= ['O2', 'H62C30']
  52.     nsim   = len(sim_dir) # number of simulation
  53.     species = (summed_species/nsim).drop(exclude,axis=1)
  54.     plt.style.use("classic")
  55.     plt.figure(figsize=(6.4, 4.8))
  56.     total_molecule = species.sum(axis=1)
  57.     last_value = total_molecule.iloc[-1:].mean()
  58.     data[cutoff]=last_value
  59.    
  60. plt.plot(data.keys(),data.values(),marker='s',c='r')
  61. plt.xlim(0.29)
  62. plt.xlabel('Bond order cutoff')
  63. plt.ylabel('Total number of reaction products')
  64. 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