@@ -156,9 +156,19 @@ def query_lines(self, min_frequency, max_frequency, *,
156156 by the query service. This workaround is needed while JPLSpec's query
157157 tool is broken.
158158
159- use_getmolecule is an option to force the query to use get_molecule.
160- It is needed if the JPL server is completely unresponsive.
159+ use_getmolecule is an option to skip the query service entirely and
160+ retrieve full molecule catalogs via `get_molecule`. It is needed when
161+ the JPL query server is unresponsive. Frequency and strength limits
162+ are not applied in this mode.
161163 """
164+ if use_getmolecule :
165+ if get_query_payload :
166+ return [('Mol' , tuple (self ._resolve_molecules (molecule , flags = flags ,
167+ parse_name_locally = parse_name_locally )))]
168+ mols = self ._resolve_molecules (molecule , flags = flags ,
169+ parse_name_locally = parse_name_locally )
170+ return self ._build_table_from_get_molecule (mols )
171+
162172 response = self .query_lines_async (min_frequency = min_frequency ,
163173 max_frequency = max_frequency ,
164174 min_strength = min_strength ,
@@ -171,13 +181,44 @@ def query_lines(self, min_frequency, max_frequency, *,
171181 if get_query_payload :
172182 return response
173183 else :
174- return self ._parse_result (response , fallback_to_getmolecule = fallback_to_getmolecule ,
175- use_getmolecule = use_getmolecule )
184+ return self ._parse_result (response , fallback_to_getmolecule = fallback_to_getmolecule )
176185
177186 query_lines .__doc__ = process_asyncs .async_to_sync_docstr (query_lines_async .__doc__ )
178187
179- def _parse_result (self , response , * , verbose = False , fallback_to_getmolecule = False ,
180- use_getmolecule = True ):
188+ def _resolve_molecules (self , molecule , * , flags = 0 , parse_name_locally = False ):
189+ """Return a list of molecule identifiers to feed to get_molecule."""
190+ if molecule is None or molecule == 'All' :
191+ raise InvalidQueryError ("use_getmolecule requires an explicit molecule "
192+ "or regex; 'All' is not supported." )
193+ if parse_name_locally :
194+ self .lookup_ids = build_lookup ()
195+ mols = list (self .lookup_ids .find (molecule , flags ).values ())
196+ if len (mols ) == 0 :
197+ raise InvalidQueryError ('No matching species found.' )
198+ return mols
199+ if isinstance (molecule , (list , tuple )):
200+ return list (molecule )
201+ return [molecule ]
202+
203+ def _build_table_from_get_molecule (self , mols ):
204+ """Fetch full catalog tables for each molecule and combine them."""
205+ self .lookup_ids = build_lookup ()
206+ tbs = [self .get_molecule (mol ) for mol in mols ]
207+ if len (tbs ) > 1 :
208+ for tb , mol in zip (tbs , mols ):
209+ tb ['Name' ] = self .lookup_ids .find (str (mol ), flags = 0 )
210+ for key in list (tb .meta .keys ()):
211+ tb .meta [f'{ mol } _{ key } ' ] = tb .meta .pop (key )
212+ tb = table .vstack (tbs )
213+ tb .meta ['molecule_list' ] = list (mols )
214+ return tb
215+ else :
216+ tb = tbs [0 ]
217+ tb .meta ['molecule_id' ] = mols [0 ]
218+ tb .meta ['molecule_name' ] = self .lookup_ids .find (str (mols [0 ]), flags = 0 )
219+ return tb
220+
221+ def _parse_result (self , response , * , verbose = False , fallback_to_getmolecule = False ):
181222 """
182223 Parse a response into an `~astropy.table.Table`
183224
@@ -208,28 +249,11 @@ def _parse_result(self, response, *, verbose=False, fallback_to_getmolecule=Fals
208249 QN": Quantum numbers for the lower state.
209250 """
210251
211- if 'Zero lines were found' in response .text or use_getmolecule :
252+ if 'Zero lines were found' in response .text :
212253 if fallback_to_getmolecule :
213- self .lookup_ids = build_lookup ()
214254 payload = parse_qs (response .request .body )
215- tbs = [self .get_molecule (mol ) for mol in payload ['Mol' ]]
216- if len (tbs ) > 1 :
217- mols = []
218- for tb , mol in zip (tbs , payload ['Mol' ]):
219- tb ['Name' ] = self .lookup_ids .find (mol , flags = 0 )
220- for key in list (tb .meta .keys ()):
221- tb .meta [f'{ mol } _{ key } ' ] = tb .meta .pop (key )
222- mols .append (mol )
223- tb = table .vstack (tbs )
224- tb .meta ['molecule_list' ] = mols
225- else :
226- tb = tbs [0 ]
227- tb .meta ['molecule_id' ] = payload ['Mol' ][0 ]
228- tb .meta ['molecule_name' ] = self .lookup_ids .find (payload ['Mol' ][0 ], flags = 0 )
229-
230- return tb
231- else :
232- raise EmptyResponseError (f"Response was empty; message was '{ response .text } '." )
255+ return self ._build_table_from_get_molecule (payload ['Mol' ])
256+ raise EmptyResponseError (f"Response was empty; message was '{ response .text } '." )
233257
234258 # data starts at 0 since regex was applied
235259 # Warning for a result with more than 1000 lines:
0 commit comments