Skip to content

Instantly share code, notes, and snippets.

@smaret
Created June 18, 2015 21:30
Show Gist options
  • Save smaret/9901df42bfcf9001ce66 to your computer and use it in GitHub Desktop.
Save smaret/9901df42bfcf9001ce66 to your computer and use it in GitHub Desktop.
A attempt to make a query in the CDMS through the VAMDC interface
# vamdc_query.py -- Search for lines in the CDMS through VAMDC
import urllib2
import xml.etree.ElementTree as ET
species = "CO"
fmin = 109e9
fmax = 111e9
einstein = - 1
energy = -1
base_url = "http://cdms.ph1.uni-koeln.de/cdms/tap/sync?LANG=VSS2&REQUEST=doQuery&FORMAT=XSAMS&QUERY="
c = 299792458.0 #m/s
wlmin = c / fmax * 1e9 # Angstroms
wlmax = c / fmin * 1e9
# Construct the query in VSS2 format. For details, see
# http://vamdc-standards.readthedocs.org/en/latest/queryLanguage/vss2.html
vss2_query = "select * where (RadTransWavelength >= %e and RadTransWavelength >= %e" % (wlmin, wlmax)
if energy != -1:
vss2_query += "and upper.StateEnergy <= %e" % energy
if einstein != -1:
vss2_query += "and RadTransProbabilityA <= %e" % einstein
vss2_query += ")"
if species != 'All':
vss2_query += "and (MoleculeStoichiometricFormula='%s')" % species # isotologues?
vss2_query = urllib2.quote(vss2_query)
# Get the results in VAMC-XSAMS format.
tap_url = base_url + vss2_query
try:
response = urllib2.urlopen(tap_url)
except Exception, error:
raise Exception, "Could not connect to database: %s" % error
# Parse the results
# We need to get 1) a species list with their corresponding tags
# and 2) the list of lines
# How to do this?
import xml.etree.ElementTree as ET
tree = ET.parse(response)
root = tree.getroot()
response.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment