""" 
The main purpose of this script is to demonstrate the use of the CASSIS database API.

Author: M. Boiziot
Date: 10/16/20
Version: 2
Licence: CeCILL-C
Tested on: CASSIS 6.5
"""

# The import
from eu.omp.irap.cassis.database.access import AccessDataBase


# Init the connection with the currently configured database.
connection = AccessDataBase.getDataBaseConnection()


# Get all the species in the database
mols = connection.getAllMoleculeDescriptionDB()

""" 
This return a list of SimpleMoleculeDescriptionDB.
For each of them you can get their tag, name, source using:
    getSpeciesId()
    getName()
    getSource()
"""
for mol in mols:
    id = mol.getSpeciesId()
    source = mol.getSource()
    name = mol.getName()
    print(id, source, name)


# In case you know the tag of a species and only want one, like here for 28503 (CO, v=0).
mol = connection.getSimpleMolecule("28503")
id = mol.getSpeciesId()
source = mol.getSource()
name = mol.getName()
print (id, source, name)



"""
After that, you can get the lines for this species:
    - getLineDescriptionDB(mol) : give you all the lines for the species.

    - getLineDescriptionDB(mol, freqMinMhz, freqMaxMhz) : give you all the line 
for the species between the given frequency min and max (in MHz)
    
    - getLineDescriptionDB(mol, freqMinMhz, freqMaxMhz, eupMin, eupMax, aijMin, 
aijMax): give you all the line for the species between the given frequency, eup 
and aij.
"""

# Get all the lines for CO, v=0:
lines = connection.getLineDescriptionDB(mol)


"""
This return a list of LineDescriptionDB.
For each of them you can get their tag, frequency, quandtic numbers, error,
 aint, elow, igu, gamma self, eup:
    .getSpeciesId()
    .getFrequency()
    .getQuandticNumbers()
    .getError()
    .getAint()
    .getElow()
    .getIgu()
    .getGammaSelf()
    .getEup()
"""
for line in lines:
    tag = line.getSpeciesId()
    freq = line.getFrequency()
    qn = line.getQuanticNumbers()
    error = line.getError()
    aint = line.getAint()
    elow = line.getElow()
    igu = line.getIgu()
    gs = line.getGammaSelf()
    eup = line.getEup()
    print (freq, igu, eup) # only print freq, igu, eup here.


