Skip to content

Commit b9e6c91

Browse files
committed
Handle thermo comment with newline through group name
Sometimes chemkin writes a thermo comment with a newline splitting the group name. Then extract_source_from_comments fails to get the group. This commit removes the newline and splits up the comment by spaces when extracting the groups from the comment. It also adds a test.
1 parent 33e1e95 commit b9e6c91

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

rmgpy/data/thermo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2750,7 +2750,8 @@ def extract_source_from_comments(self, species):
27502750

27512751
comment = comment.replace(' + ', ' +')
27522752
comment = comment.replace(' - ', ' -')
2753-
tokens = comment.split()
2753+
whole_comment = comment.replace('\n', '')
2754+
tokens = whole_comment.split(' ')
27542755

27552756
groups = {}
27562757
group_types = list(self.groups.keys())

test/rmgpy/data/thermoTest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,23 @@ def test_parse_thermo_comments(self):
529529
assert source["GAV"]["ring"][0][1] == -1 # the weight of benzene contribution should be -1
530530
assert source["GAV"]["group"][0][1] == 2 # weight of the group(Cs-CsCsHH) conbtribution should be 2
531531

532+
# check extract source from comment with newline through group name
533+
newline_sp = Species(smiles="[O]OC(C#N)(C)C")
534+
newline_sp.thermo = NASA()
535+
newline_sp.thermo.comment = 'Thermo group additivity estimation: group(O2s-OsCs) + group(O2s-OsH) + group(N3t-(Cs)Ct) + group(Cs-(Cds-Cds)CsCsOs) + group(Cs-CsHHH) + group(Cs-\nCsHHH) + group(Ct-N3tCs) + radical(C3COOJ)'
536+
source = self.database.extract_source_from_comments(newline_sp)
537+
assert "GAV" in source
538+
assert source['GAV']['group'][0][0].label == "O2s-OsCs"
539+
assert source['GAV']['group'][1][0].label == "O2s-OsH"
540+
assert source['GAV']['group'][2][0].label == "N3t-(Cs)Ct"
541+
assert source['GAV']['group'][3][0].label == "Cs-(Cds-Cds)CsCsOs"
542+
assert source['GAV']['group'][4][0].label == "Cs-CsHHH"
543+
assert source['GAV']['group'][5][0].label == "Ct-N3tCs"
544+
assert source["GAV"]["radical"][0][0].label == "C3COOJ"
545+
assert source["GAV"]["radical"][0][1] == 1
546+
assert all(source['GAV']['group'][x][1] == 1 for x in [0, 1, 2, 3, 5])
547+
assert source['GAV']['group'][4][1] == 2
548+
532549
def test_species_thermo_generation_hbi_library(self):
533550
"""Test thermo generation for species objects for HBI correction on library value.
534551

0 commit comments

Comments
 (0)