Skip to content

Commit

Permalink
fixed "sites" v. "size" problem, yaml_writer now works for catalysis …
Browse files Browse the repository at this point in the history
…and gas phase. Time for pull request?
  • Loading branch information
Nora-Khalil committed Jul 13, 2022
1 parent e09705b commit 6574356
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 36 deletions.
42 changes: 8 additions & 34 deletions rmgpy/cantera.py
Expand Up @@ -18,8 +18,7 @@
from rmgpy.chemkin import get_species_identifier

def write_cantera(spcs, rxns, surface_site_density=None, solvent=None, solvent_data=None, path="chem.yml"):
# result_dict = get_mech_dict(spcs, rxns, solvent=solvent, solvent_data=solvent_data)


# intro to file will change depending on the presence of surface species
is_surface = False
for spc in spcs:
Expand Down Expand Up @@ -120,25 +119,16 @@ def write_surface_species(spcs,rxns, surface_site_density):
#Dr. West, why can't i just write the above lines as:
#surface_species = [spc for spc in spcs if spc.contains_surface_site()]
#gas_species = [spc for spc in spcs if not spc.contains_surface_site()]

#VERY INTERESTING: for some reason, the sample catalysis yaml that i was looking at split up the species (surface v. gas), but when I do that, I get an error in cantera

sorted_surface_species = sorted(surface_species, key=lambda surface_species: surface_species.index)
surface_species_to_write = [get_species_identifier(surface_species) for surface_species in sorted_surface_species]

sorted_gas_species = sorted(gas_species, key=lambda gas_species: gas_species.index)
gas_species_to_write = [get_species_identifier(gas_species) for gas_species in sorted_gas_species]
#using this now instead because the separated species gave me errors?


sorted_species = sorted(spcs, key=lambda spcs: spcs.index)
species_to_write = [get_species_identifier(spec) for spec in sorted_species]

# coverage_dependencies = {}
# for rxn in rxns:
# coverage_dependence = getattr(rxn.kinetics, 'coverage_dependence', {})
# if coverage_dependence:
# coverage_dependencies.update(coverage_dependence)



#gas part
Expand Down Expand Up @@ -237,7 +227,6 @@ def get_mech_dict_nonsurface(spcs, rxns, solvent='solvent', solvent_data=None):
if names.count(name) > 1:
names[i] += "-"+str(names.count(name))

# for spc in spcs:
result_dict = dict()
result_dict["species"]= [obj_to_dict(x, spcs, names=names) for x in spcs]

Expand All @@ -256,7 +245,6 @@ def reaction_to_dicts(obj, spcs):
length 1, but a MultiArrhenius or MultiPDepArrhenius will be longer.
"""

#try:
reaction_list = []
if isinstance(obj.kinetics, MultiArrhenius) or isinstance(obj.kinetics, MultiPDepArrhenius):
list_of_cantera_reactions = obj.to_cantera(use_chemkin_identifier=True)
Expand All @@ -268,28 +256,10 @@ def reaction_to_dicts(obj, spcs):
efficiencies = getattr(obj.kinetics, 'efficiencies', {})
if efficiencies:
reaction_data["efficiencies"] = {spcs[i].to_chemkin(): float(val) for i, val in enumerate(obj.kinetics.get_effective_collider_efficiencies(spcs)) if val != 1}
# if isinstance(obj.kinetics, StickingCoefficient):
# reaction_data.pop('equation', None)
# reaction_data['equation'] = str(obj)
reaction_list.append(reaction_data)

# for reaction in list_of_cantera_reactions:
# reaction_data = reaction.input_data
# efficiencies = getattr(obj.kinetics, 'efficiencies', {})
# if efficiencies:
# reaction_data["efficiencies"] = {spcs[i].to_chemkin(): float(val) for i, val in enumerate(obj.kinetics.get_effective_collider_efficiencies(spcs)) if val != 1}

# reaction_list.append(reaction_data)

# if isinstance[obj.kinetics, StickingCoefficient]:
# print(str(obj))

return reaction_list
# except:
# print('passing')
# print(type(obj.kinetics))
# print(str(obj))
# return []



def obj_to_dict(obj, spcs, names=None, label="solvent"):
Expand All @@ -303,6 +273,10 @@ def obj_to_dict(obj, spcs, names=None, label="solvent"):
result_dict['note'] = obj.transport_data.comment
except:
pass
if 'size' in species_data:
sites = species_data['size']
species_data.pop('size', None)
species_data['sites'] = sites
species_data.update(result_dict)
return species_data #returns composition, name, thermo, and transport, and note

Expand Down
12 changes: 10 additions & 2 deletions rmgpy/species.py
Expand Up @@ -434,9 +434,17 @@ def to_cantera(self, use_chemkin_identifier=False):
else:
element_dict[symbol] += 1
if use_chemkin_identifier:
ct_species = ct.Species(self.to_chemkin(), element_dict)
label = self.to_chemkin()
else:
ct_species = ct.Species(self.label, element_dict)
label = self.label

if self.contains_surface_site() and element_dict['X'] > 1:
# for multidentate adsorbates, 'size' is the same as 'sites'? for some reason, cantera won't take the input 'size,' so will need to use 'sites'
ct_species = ct.Species(label, element_dict, size=element_dict['X'])
#hopefully this will be fixed soon, so that ct.Species can take a 'sites' parameter or that cantera can read input files with 'size' specified
else:
ct_species = ct.Species(label, element_dict)

if self.thermo:
try:
ct_species.thermo = self.thermo.to_cantera()
Expand Down

0 comments on commit 6574356

Please sign in to comment.