Example #1
0
    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

# query everything for sio
query_string = "SELECT ALL WHERE VAMDCSpeciesID='%s'" % sio.VAMDCSpeciesID
request.setquery(query_string)
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