Skip to content
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

better species naming for cantera models #1065

Closed
goldmanm opened this issue Jun 27, 2017 · 5 comments
Closed

better species naming for cantera models #1065

goldmanm opened this issue Jun 27, 2017 · 5 comments

Comments

@goldmanm
Copy link
Contributor

To the best of my knowledge, cantera does not have the restrictive species naming guidelines that chemkin has. When generating a cantera model, we can apply more descriptive names (like their SMILES) than would be possible with chemkin.

We currently create the cantera input file by converting from the chemkin input file with ck2cti. Getting better naming would require generating the input file directly from RMG.

@alongd, you wrote the cantera conversion for RMG, do you have thoughts on this?

@alongd
Copy link
Member

alongd commented Jun 27, 2017

I'm not familiar with the naming convention on Cantera; if it's really that flexible, this could be a nice feature.

goldmanm added a commit that referenced this issue Jun 27, 2017
Added an option to 'toCantera' methods in Species and Reaction
to allow for the name of the species/reaction to be the RMG name
instead of the chemkin name. The default behavior is still the same.

This is one step in addressing issue #1065.
@goldmanm
Copy link
Contributor Author

I wrote up this notebook which provides the species, thermo and reaction blocks to input into a cti file so analysis can be conducted in cantera with SMILES as the species names.

This is kind of a first step to getting better naming for the species in cantera modules.

goldmanm added a commit that referenced this issue Jun 30, 2017
Added an option to 'toCantera' methods in Species and Reaction
to allow for the name of the species/reaction to be the RMG name
instead of the chemkin name. The default behavior is still the same.

This is one step in addressing issue #1065.
goldmanm added a commit that referenced this issue Jun 30, 2017
Added an option to 'toCantera' methods in Species and Reaction
to allow for the name of the species/reaction to be the RMG name
instead of the chemkin name. The default behavior is still the same.

This is one step in addressing issue #1065.
@goldmanm
Copy link
Contributor Author

goldmanm commented Jul 20, 2017

I found a way to rename species from an RMG run and place them into a cantera input file.

I also commonly use this method, which renames all species based on SMILES and ensures they don't overlap. This requires the soln2cti and test_mechanism_from_solution.py which is in PR 451 in cantera. You can just put it in the same directory

def make_string_labels_independent(species):
    """
    This method reads in species labels and makes sure none of them conflict
    If a conflict occurs, the second occurance will have '-2' added
    """
    
    labels = set()
    for spec in species:
        duplicate_index = 1
        potential_label = spec.label
        while potential_label in labels:
            duplicate_index += 1
            potential_label = spec.label + '-{}'.format(duplicate_index)
        spec.label = potential_label
        labels.add(potential_label)

# use the method
species, reactions = loadChemkinFile(chemkinPath, speciesDictPath, readComments = False, useChemkinNames=False)
make_string_labels_independent(species)

#convert to cantera objects
ct_species = [spec.toCantera(useChemkinIdentifier = False) for spec in species]
# since this can return a rxn or list of reactions, this allows to make a list based on the returned type
ct_reactions = []
for rxn in reactions:
    ct_rxn = rxn.toCantera(useChemkinIdentifier = False)
    if isinstance(ct_rxn, list):
        ct_reactions.extend(ct_rxn)
    else:
        ct_reactions.append(ct_rxn)

gas = ct.Solution(thermo='IdealGas', kinetics='GasKinetics',
                  species=ct_species, reactions=ct_reactions)
# make cantera input file
new_file = soln2cti.write(gas)
# move the file to new location
os.rename(new_file, os.path.join(mainPath,'cantera_new_names.cti'))

@mjohnson541
Copy link
Contributor

should this issue be closed @goldmanm?

@JacksonBurns
Copy link
Contributor

This issue is no longer relevant - we have switched to Cantera 2.6 in #2288 and this function is gone. Closing as stale.

@JacksonBurns JacksonBurns closed this as not planned Won't fix, can't repro, duplicate, stale May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants