def species_lookuptable(cache=True): """ Get a lookuptable from chemical name + OrdinaryStructuralFormula to VAMDC id """ if not os.path.exists(Conf.cache_location): os.makedirs(Conf.cache_location) lut_path = os.path.join(Conf.cache_location, 'species_lookuptable.json') if os.path.exists(lut_path) and cache: log.info("Loading cached molecular line ID database") with open(lut_path, 'r') as fh: lutdict = json.load(fh) lookuptable = SpeciesLookuptable(lutdict) else: log.info("Loading molecular line ID database") from vamdclib import nodes as vnodes from vamdclib import request as vrequest nl = vnodes.Nodelist() nl.findnode('cdms') cdms = nl.findnode('cdms') request = vrequest.Request(node=cdms) # Retrieve all species from CDMS result = request.getspecies() molecules = result.data['Molecules'] lutdict = { "{0} {1}".format(molecules[key].ChemicalName, molecules[key].OrdinaryStructuralFormula): molecules[key].VAMDCSpeciesID for key in molecules } lookuptable = SpeciesLookuptable(lutdict) if cache: with open(lut_path, 'w') as fh: json.dump(lookuptable, fh) return lookuptable
def __init__(self, doimport=True): super(VamdcClass, self).__init__() if not doimport: # this is a hack to allow the docstrings to be produced without # importing the necessary modules return from vamdclib import nodes as vnodes from vamdclib import request as vrequest from vamdclib import results as vresults from vamdclib import specmodel self._vnodes = vnodes self._vrequest = vrequest self._vresults = vresults self._nl = vnodes.Nodelist() self._cdms = self._nl.findnode('cdms') self.specmodel = specmodel
chemical_name='SiO', energy_max=1840, energy_type='eu_k', line_lists=['SLAIM'], noHFS=True, # there seems to be a problem where HFS # for K >= 6 is included *incorrectly* show_upper_degeneracy=True) freqs = np.array(slaim['Freq-GHz']) * u.GHz aij = slaim['Log<sub>10</sub> (A<sub>ij</sub>)'] deg = slaim['Upper State Degeneracy'] EU = (np.array(slaim['E_U (K)']) * u.K * constants.k_B).to(u.erg).value ref_freq = 217.10498 * u.GHz vdiff = (np.array(-(freqs - ref_freq) / ref_freq) * constants.c).to(u.km / u.s).value nl = nodes.Nodelist() nl.findnode('cdms') cdms = nl.findnode('cdms') request = r.Request(node=cdms) # Retrieve all species from CDMS result = request.getspecies() molecules = result.data['Molecules'] sio = [ x for x in molecules.values() if (x.StoichiometricFormula) == ('OSi') and ( x.OrdinaryStructuralFormula == 'SiO') ][0] sio_inchikey = sio.InChIKey
def get_molecular_parameters(molecule_name, molecule_name_vamdc=None, tex=50, fmin=1 * u.GHz, fmax=1 * u.THz, line_lists=['SLAIM'], chem_re_flags=0, **kwargs): """ Get the molecular parameters for a molecule from the CDMS database using vamdclib Parameters ---------- molecule_name : string The string name of the molecule (normal name, like CH3OH or CH3CH2OH) molecule_name_vamdc : string or None If specified, gives this name to vamdc instead of the normal name. Needed for some molecules, like CH3CH2OH -> C2H5OH. tex : float Optional excitation temperature (basically checks if the partition function calculator works) fmin : quantity with frequency units fmax : quantity with frequency units The minimum and maximum frequency to search over line_lists : list A list of Splatalogue line list catalogs to search. Valid options include SLAIM, CDMS, JPL. Only a single catalog should be used to avoid repetition of transitions and species chem_re_flags : int An integer flag to be passed to splatalogue's chemical name matching tool Examples -------- >>> freqs, aij, deg, EU, partfunc = get_molecular_parameters(molecule_name='CH2CHCN', ... fmin=220*u.GHz, ... fmax=222*u.GHz, ... molecule_name_vamdc='C2H3CN') >>> freqs, aij, deg, EU, partfunc = get_molecular_parameters('CH3OH', ... fmin=90*u.GHz, ... fmax=100*u.GHz) """ from astroquery.vamdc import load_species_table from astroquery.splatalogue import Splatalogue from vamdclib import nodes from vamdclib import request from vamdclib import specmodel lut = load_species_table.species_lookuptable() species_id_dict = lut.find(molecule_name_vamdc or molecule_name, flags=chem_re_flags) if len(species_id_dict) == 1: species_id = list(species_id_dict.values())[0] elif len(species_id_dict) == 0: raise ValueError("No matches for {0}".format(molecule_name)) else: raise ValueError( "Too many species matched: {0}".format(species_id_dict)) # do this here, before trying to compute the partition function, because # this query could fail tbl = Splatalogue.query_lines(fmin, fmax, chemical_name=molecule_name, line_lists=line_lists, show_upper_degeneracy=True, **kwargs) nl = nodes.Nodelist() nl.findnode('cdms') cdms = nl.findnode('cdms') request = request.Request(node=cdms) query_string = "SELECT ALL WHERE VAMDCSpeciesID='%s'" % species_id request.setquery(query_string) result = request.dorequest() Q = list( specmodel.calculate_partitionfunction(result.data['States'], temperature=tex).values())[0] def partfunc(tem): Q = list( specmodel.calculate_partitionfunction(result.data['States'], temperature=tem).values())[0] return Q freqs = np.array(tbl['Freq-GHz']) * u.GHz aij = tbl['Log<sub>10</sub> (A<sub>ij</sub>)'] deg = tbl['Upper State Degeneracy'] EU = (np.array(tbl['E_U (K)']) * u.K * constants.k_B).to(u.erg).value return freqs, aij, deg, EU, partfunc