Exemplo n.º 1
0
def test_Molecule():
    m = pyfant.Molecule()

    sol = pyfant.SetOfLines()
    sol.append_line(2000., .25, 10.5, "P")
    sol.append_line(1000., .25, 10.5, "Q1")

    m.sol = [sol]

    assert m.llzero == 1000.
    assert m.llfin == 2000.
    assert m.num_lines == 2

    sol = pyfant.SetOfLines()
    sol.append_line(3000., .125, 13.5, "R21")

    m.sol.append(sol)

    assert len(m) == 2
    assert m.num_lines == 3

    assert all(m.lmbdam == [2000., 1000., 3000.])
    assert all(m.sj == [.25, .25, .125])
    assert all(m.jj == [10.5, 10.5, 13.5])
    assert all(m.branch == ["P", "Q1", "R21"])

    m.qqv
    m.ggv
    m.bbv
    m.ddv

    m.cut(500, 1500)

    assert m.num_lines == 1
Exemplo n.º 2
0
def test_FileMolecules(tmpdir):
    os.chdir(str(tmpdir))
    m = pyfant.Molecule()
    sol = pyfant.SetOfLines()
    sol.append_line(2000., .25, 10.5, "P")
    sol.append_line(1000., .25, 10.5, "Q1")
    m.sol = [sol]
    sol = pyfant.SetOfLines()
    sol.append_line(3000., .125, 13.5, "R21")
    m.sol.append(sol)

    f = pyfant.FileMolecules()
    f.molecules = [m]

    assert f.llzero == 1000.
    assert f.llfin == 3000.
    assert f.num_lines == 3
    assert f.num_sols == 2

    f.lmbdam
    f.sj
    f.jj
    f.branch
    f.qqv
    f.ggv
    f.bbv
    f.ddv
    f.fe
    f.do
    f.mm
    f.am
    f.ua
    f.ub
    f.te
    f.cro
    f.s

    f.cut(500, 1500)

    assert f.num_lines == 1
    assert f.num_sols == 1

    m.symbols = ["We", "Ur"]

    assert m.formula == "WeUr"

    f.save_as("qq")
Exemplo n.º 3
0
    def append_line(self, line, gf_pfant, branch):
        """Use to append line to object"""
        sol_key = (line.vl, line.v2l)

        if sol_key not in self:
            qgbd = self.qgbd_calculator(self.molconsts, line.v2l)
            self[sol_key] = pyfant.SetOfLines(line.vl, line.v2l,
                                          qgbd["qv"], qgbd["gv"], qgbd["bv"], qgbd["dv"], 1.)

        self[sol_key].append_line(line.lambda_, gf_pfant, line.J2l, branch)
Exemplo n.º 4
0
def test_SetOfLines():
    sol = pyfant.SetOfLines()
    sol.append_line(2000., .25, 10.5, "P")
    sol.append_line(1000., .25, 10.5, "Q1")

    assert sol.llzero == 1000.
    assert sol.llfin == 2000.
    assert sol.num_lines == 2
    assert len(sol) == 2

    assert sol.lmbdam[0] == 2000.

    sol.sort()

    assert sol.lmbdam[0] == 1000.

    sol.cut(500, 1500)

    assert sol.llzero == 1000.
    assert sol.llfin == 1000.
    assert sol.num_lines == 1
    assert len(sol) == 1

    sol.sort()
Exemplo n.º 5
0
def hitran_to_sols(molconsts, lines, qgbd_calculator):
    """
    Converts HITRAN molecular lines data to PFANT "sets of lines"

    Args:
        molconsts: a dict-like object combining field values from tables 'molecule', 'state',
                    'pfantmol', and 'system' from a FileMolDB database
        lines: item from rom hapi.LOCAL_TABLE_CACHE (a dictionary)
        qgbd_calculator: callable that can calculate "qv", "gv", "bv", "dv",
                         e.g., calc_qbdg_tio_like()

    Returns: (a list of ftpyfant.SetOfLines objects, a MolConversionLog object)
    """
    def append_error(msg):
        log.errors.append("#{}{} line: {}".format(i + 1,
                                                  a99.ordinal_suffix(i + 1),
                                                  str(msg)))

    # C     BAND (v',v'')=(VL,V2L)
    # C     WN: vacuum wavenumber   WL : air wavelength
    # C     J2L: lower state angular momentum number
    # C     iso: isotope/ 26: 12C16O, 36: 13C16O, 27: 12C17O, 28: 12C18O
    # C     ramo: branch, for P: ID=1, for R: ID=2
    # C     name: file name/ coisovLv2L
    # C     HL: Honl-London factor
    # C     FR: oscillator strength

    header = lines["header"]
    data = lines["data"]

    S = molconsts.get_S2l()
    DELTAK = molconsts.get_deltak()
    formula = molconsts["formula"]

    n = header["number_of_rows"]
    log = MolConversionLog(n)
    sols = OrderedDict()  # one item per (vl, v2l) pair

    try:
        f_class = _CLASS_DICT[formula]
    except KeyError:
        log.errors.append(
            "Cannot determine Table 3 'class' (Rothman et al. 2005) for formula '{}'"
            .format(formula))
        log.flag_ok = False

    try:
        f_group = _GROUP_DICT[formula]
    except KeyError:
        log.errors.append(
            "Cannot determine Table 4 'group' (Rothman et al. 2005) for formula '{}'"
            .format(formula))
        log.flag_ok = False

    if not log.flag_ok:
        return [], log

    for i in range(n):

        try:
            nu = data["nu"][i]
            wl = avv.vacuum_to_air(1e8 / nu)
            Br, J2l = f_group(data["local_lower_quanta"][i])
            # TODO assuming singlet!!!
            Jl = ph.singlet.quanta_to_branch(Br, J2l)
            V = f_class(data["global_upper_quanta"][i])
            V_ = f_class(data["global_lower_quanta"][i])
            A = data["a"][i]

            # A seguir normalizacion de factor de Honl-london (HLN)
            Normaliza = 1 / ((2.0 * J2l + 1) * (2.0 * S + 1) * (2.0 - DELTAK))

            # A seguir teremos a forca de oscilador
            # mas q sera normalizada segundo o programa da Beatriz
            gf = Normaliza * 1.499 * (2 * Jl + 1) * A / (nu**2)

            J2l_pfant = int(
                J2l
            )  # ojo, estamos colocando J2L-0.5! TODO ask BLB: we write J2l or J2l-.5? (20171114 I think this is wrong, molecules.dat has decimal values)
        except Exception as e:
            log.errors.append("#{}{} line: {}".format(
                i + 1, a99.ordinal_suffix(i + 1), a99.str_exc(e)))
            continue

        sol_key = (V, V_)  # (v', v'') transition (v_sup, v_inf)
        if sol_key not in sols:
            qgbd = qgbd_calculator(molconsts, sol_key[1])
            qqv = qgbd["qv"]
            ggv = qgbd["gv"]
            bbv = qgbd["bv"]
            ddv = qgbd["dv"]

            sols[sol_key] = pyfant.SetOfLines(V, V_, qqv, ggv, bbv, ddv, 1.)
        sol = sols[sol_key]
        sol.append_line(wl, gf, J2l_pfant, Br)

    return (list(sols.values()), log)