Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Flux diagram/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Flux diagram
This script simulates your Shock Tube system through different time intervals and creates flux diagrams with species molecule images.

- Clone these scripts to a new folder: `Flux diagram` <br><br>
- In the Cantera environment in terminal, install `conda install -c conda-forge pdf2image` <br><br>
- Copy from your RMG run the Cantera output `chem_annotated.cti` and paste it in the folder, (the given file is for running a test, so you can just rename it). <br><br>
- Same with the species dictionary `species_dictionary.txt`, (the given file is for running a test, so you can just rename it).<br><br>
- In the first code block in `cte_replace_labels_to_smiles v2.ipynb` change the 4 paths to your files' location. <br><br>
- Change the initial operating conditions of your Shock Tube system in the first code block in `cte_replace_labels_to_smiles v2.ipynb`.<br><br>
- Put attention to your system's elements. Cantera lables them as one thing and Smiles as another thing, you should consider that in the code itself.<br><br>
For instance, Argon's label in `cti` file is `Ar`, but in Smiles its label is `[Ar]`. For elements, you should consider Cantera's notation. Two cases are considered in the script: `Ar` and `Ne`.<br><br>
- Run the script `cte_replace_labels_to_smiles v2.ipynb` under Cantera environmemt.

## Output:<br>
Ignition delay time plot in the folder:<br><br>
![Idt](idt_plot.png)<br><br>

11 folder for 11 different times intervals:
0.5tau, 0.6tau...tau, 1.1tau,...1.5tau<br>
In each folder you will find a `png` file which contains the flux diagram specified in theat time. <br><br>
For example:<br><br>
![rxn_diagram_tau](ReactionPathDiagram.png)<br><br>
Binary file added Flux diagram/ReactionPathDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions Flux diagram/background_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import argparse
import os
import yaml

from rmgpy.chemkin import load_species_dictionary
from rmgpy.molecule.draw import MoleculeDrawer

def parse_command_line_arguments(command_line_args=None):
"""
Parse command-line arguments.

Args:
command_line_args: The command line arguments.

Returns:
The parsed command-line arguments by key words.
"""

parser = argparse.ArgumentParser(description='desc')
parser.add_argument('file', metavar='FILE', type=str, nargs=1,
help='a file describing the job to execute')

args = parser.parse_args(command_line_args)
args.file = args.file[0]

return args


def dict_species(path_species_dict):
"""
This fucn creates an output.yml file of cantera_labels as keys
and smiles as values.
After that, it creates a folder of images of the species of pdf format (high resolution)
The name of the images are {smiles}.pdf
"""
#######output.yml#######
dir_name=os.path.dirname(path_species_dict)
species_dict=load_species_dictionary(path_species_dict)
#generate_resonance_structures=False)
dict_label_smiles={species.label: species.molecule[0].to_smiles() for species in species_dict.values()}

path_output_yml=os.path.join(dir_name,"output.yml")
yaml_str = yaml.dump(data=dict_label_smiles)
with open(path_output_yml, 'w') as f:
f.write(yaml_str)

#######species images#######
if not os.path.exists(os.path.join(os.path.abspath(''),"images")): #check whether images folder exists
images_path=os.path.join(os.path.abspath(''),'images')
os.mkdir(images_path)
os.chdir(images_path)

else: #images folder exists
if "images" not in os.getcwd(): #can be Flux diagram folder or species_dictionary.txt file inside Flux folder -> check the 2 options
if "species_dictionary" in os.getcwd():
os.chdir(os.path.join(os.chdir("../"),"images"))
else:
os.chdir(os.path.join(os.getcwd(),"images"))
else:
pass #we are probably in the right filder of images

print("the images path: ",os.path.abspath(''))

for specie in species_dict.values():
molecule=specie.molecule[0]
smiles=molecule.to_smiles()
if smiles != "[Ne]" and smiles != "[Ar]": #avoid parenthesis for elements - keep convention with Cantera
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[He] will probably need a similar treatment if it's present in a model

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider:

    for smiles in species_output_dict.values():
        if smiles in ['[Ne]', '[He]', '[Ar]']:
            convert_pdf_2_png(smiles[1:3], os.path.join(flux_diagram_folder_path, 'images', f'{smiles[1:3]}.pdf'))
        else:
            convert_pdf_2_png(smiles, os.path.join(flux_diagram_folder_path, 'images', f'{smiles}.pdf'))

MoleculeDrawer().draw(molecule, file_format='pdf', target=f'{smiles}.pdf')
else:
if smiles=="[Ne]":
MoleculeDrawer().draw(molecule, file_format='pdf', target='Ne.pdf')
else:
MoleculeDrawer().draw(molecule, file_format='pdf', target='Ar.pdf')


def main():
"""
The main ARC executable function
"""
args = parse_command_line_arguments()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like args is not being used

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be enough:

    args = parse_command_line_arguments()
    dict_species(args.file)


if "images" in os.getcwd():
os.chdir("../") #go back one folder back in current working dir path

path=os.path.normpath(os.getcwd() )
path_species_dict = os.path.join(path,'species_dictionary.txt')

dict_species(path_species_dict)

if __name__ == '__main__':
main()
Loading