@@ -52,6 +52,8 @@ def query_lines_async(self, min_frequency, max_frequency, *,
52
52
molecule : list, string of regex if parse_name_locally=True, optional
53
53
Identifiers of the molecules to search for. If this parameter
54
54
is not provided the search will match any species. Default is 'All'.
55
+ Note that if the molecule name contains parentheses, they must be
56
+ escaped. For exmaple, 'H2C(CN)2' must be specified as 'H2C\(CN\)2'.
55
57
56
58
temperature_for_intensity : float
57
59
The temperature to use when computing the intensity Smu^2. Set
@@ -123,15 +125,24 @@ def query_lines_async(self, min_frequency, max_frequency, *,
123
125
self ._last_query_temperature = temperature_for_intensity
124
126
125
127
if molecule is not None :
128
+
129
+ # escape parentheses in molecule names if needed
130
+ # (assumes _no_ escapes done; if you give 'XY\(ZG)', i.e.,
131
+ # escape one and not the other, this won't work)
132
+ if re .search ("[()]" , molecule ):
133
+ if len (re .findall (r'\(' , molecule )) != len (re .findall (r'(' , molecule )):
134
+ molecule = re .sub (r'(' , r'\(' , molecule )
135
+ if len (re .findall (r'\)' , molecule )) != len (re .findall (r')' , molecule ))
136
+ molecule = re .sub (r')' , r'\)' , molecule )
126
137
if parse_name_locally :
127
138
self .lookup_ids = build_lookup ()
128
139
luts = self .lookup_ids .find (molecule , flags )
129
- payload ['Molecules' ] = tuple (f"{ val :06d} { key } "
130
- for key , val in luts .items ())[0 ]
131
- if len (molecule ) == 0 :
140
+ if len (luts ) == 0 :
132
141
raise InvalidQueryError ('No matching species found. Please '
133
142
'refine your search or read the Docs '
134
143
'for pointers on how to search.' )
144
+ payload ['Molecules' ] = tuple (f"{ val :06d} { key } "
145
+ for key , val in luts .items ())[0 ]
135
146
else :
136
147
payload ['Molecules' ] = molecule
137
148
0 commit comments