-
Notifications
You must be signed in to change notification settings - Fork 1
Flux diagram #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NellyMitnik
wants to merge
5
commits into
main
Choose a base branch
from
Flux_Diagram
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+9,652
−0
Open
Flux diagram #10
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f799f9f
First version of flux diagram with Cantera
NellyMitnik 092f277
Added Readme file
NellyMitnik c6c3948
Rename Insructions.md to README.md
calvinp0 e5e5df0
Fixed grammar in README.md 2
NellyMitnik 258b7d8
Update README.md
NellyMitnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| <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> | ||
| <br><br> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| 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() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be enough: |
||
|
|
||
| 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() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 modelThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider: