Skip to content

Commit 0419d34

Browse files
committed
partial fix to issue 2375
1 parent 105d232 commit 0419d34

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

astroquery/linelists/cdms/core.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def query_lines_async(self, min_frequency, max_frequency, *,
5252
molecule : list, string of regex if parse_name_locally=True, optional
5353
Identifiers of the molecules to search for. If this parameter
5454
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'.
5557
5658
temperature_for_intensity : float
5759
The temperature to use when computing the intensity Smu^2. Set
@@ -123,15 +125,24 @@ def query_lines_async(self, min_frequency, max_frequency, *,
123125
self._last_query_temperature = temperature_for_intensity
124126

125127
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)
126137
if parse_name_locally:
127138
self.lookup_ids = build_lookup()
128139
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:
132141
raise InvalidQueryError('No matching species found. Please '
133142
'refine your search or read the Docs '
134143
'for pointers on how to search.')
144+
payload['Molecules'] = tuple(f"{val:06d} {key}"
145+
for key, val in luts.items())[0]
135146
else:
136147
payload['Molecules'] = molecule
137148

0 commit comments

Comments
 (0)