Skip to content

Commit 8480201

Browse files
committed
Rename and simplify species_to_dict
1 parent bc827c6 commit 8480201

1 file changed

Lines changed: 28 additions & 24 deletions

File tree

rmgpy/yaml_cantera.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def get_mech_dict_surface(spcs, rxns, solvent="solvent", solvent_data=None):
230230
names[i] += "-" + str(names.count(name))
231231

232232
result_dict = dict()
233-
result_dict["species"] = [species_to_dict(x, spcs, names=names) for x in spcs]
233+
result_dict["species"] = [species_to_dict(x) for x in spcs]
234234

235235
# separate gas and surface reactions
236236

@@ -258,7 +258,7 @@ def get_mech_dict_nonsurface(spcs, rxns, solvent="solvent", solvent_data=None):
258258
names[i] += "-" + str(names.count(name))
259259

260260
result_dict = dict()
261-
result_dict["species"] = [species_to_dict(x, spcs, names=names) for x in spcs]
261+
result_dict["species"] = [species_to_dict(x) for x in spcs]
262262

263263
reactions = []
264264
for rmg_rxn in rxns:
@@ -299,32 +299,36 @@ def reaction_to_dicts(obj, spcs):
299299
return reaction_list
300300

301301

302-
def species_to_dict(obj, spc, names=None, label="solvent"):
302+
def species_to_dict(species):
303303
"""
304-
Takes an RMG species object (obj), returns a list of dictionaries
304+
Takes an RMG species object, returns a list of dictionaries
305305
for YAML properties. Also adds in the number of surface sites
306306
('sites') to dictionary.
307307
"""
308-
309-
result_dict = dict()
310-
311-
if isinstance(obj, Species):
312-
s = obj.to_cantera(use_chemkin_identifier=True)
313-
species_data = s.input_data
314-
try:
315-
result_dict["note"] = obj.transport_data.comment
316-
except:
317-
pass
318-
if "size" in species_data:
319-
sites = species_data["size"]
320-
species_data.pop("size", None)
321-
species_data["sites"] = sites
322-
species_data.update(result_dict)
323-
return (
324-
species_data # returns composition, name, thermo, and transport, and note
325-
)
326-
else:
327-
raise Exception("Species object must be an RMG Species object")
308+
if not isinstance(species, Species):
309+
raise TypeError("species object must be an RMG Species")
310+
311+
cantera_species = species.to_cantera(use_chemkin_identifier=True)
312+
species_data = cantera_species.input_data
313+
314+
# if species.transport_data.comment exists, add it to species_data["note"]
315+
try:
316+
transport_comment = species.transport_data.comment
317+
if transport_comment:
318+
if "note" in species_data:
319+
species_data["note"] += f" Transport data: {transport_comment}"
320+
else:
321+
species_data["note"] = f"Transport data: {transport_comment}"
322+
except AttributeError:
323+
pass
324+
325+
if "size" in species_data:
326+
sites = species_data["size"]
327+
species_data.pop("size", None)
328+
species_data["sites"] = sites
329+
330+
# returns composition, name, thermo, and transport, and note
331+
return species_data
328332

329333

330334
class CanteraWriter(object):

0 commit comments

Comments
 (0)