I have a ReaxFF species data file that I am trying to plot via python. I am able to get the data separated but can't figure out how to maintain a time dependence. The data is formatted in a .csv like below:
Timestep No_Moles No_Specs C29H24O32N45 C C2O4N8 C2 N2 CO4N8
2800 12 6 1 2 3 2 3 1
Timestep No_Moles No_Specs C34H24O40N59 C C2O4N8 C2 N2
2900 10 5 1 2 2 1 4
Timestep No_Moles No_Specs C38H24O44N67 C N2 C2O4N8
3000 8 4 1 2 4 1
I am trying to plot a timestep dependent concentration of each species and can, for example, separate "C" and maintain its concentration dependence with the code below:
with open('species.out') as f:
lines = f.read()
rows = lines.split()
lines = lines.split('\n')
rows = np.asarray(rows)
header = []
numbers = []
arange = np.arange(len(rows))
# arrange arrays so that headers have same index as numbers
for i in arange :
numcheck = rows[i].isnumeric()
if numcheck == True :
numbers = np.append(numbers, rows[i])
if numcheck == False :
header = np.append(header, rows[i])
brange = np.arange(len(header))
temp=[]
for j in brange:
if header[j] != "#" :
temp = np.append(temp, header[j])
header = temp
crange = np.arange(len(header))
C_species= []
Time = []
for L in crange:
if header[L] == "Timestep":
Time = np.append(Time, numbers[L])
if header[L] == 'C':
C_species = np.append(C_species, numbers[L])
I just don't know how to do this for all species and have "zeros" for species that haven't been formed yet.
I have tried using pandas csv_reader and itertools islice but I can't quite figure out how to accomplish what I need to.