From 4afa968a5286717b3787cc9d2e0bc9f53153c95d Mon Sep 17 00:00:00 2001 From: Christian Rab Date: Fri, 31 Jul 2026 08:35:29 +0200 Subject: [PATCH 1/3] Fixed a syntax error in the authors list. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8b6525b..bad4bd4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ description = "A brand-new library to interact with the VAMDC infrastructure" authors = [ {name = "Carlo Maria Zwölf", email = "carlo-maria.zwolf@obspm.fr"}, {name = "Nicolas Moreau"}, - {name = "Yaye Awa Ba}, + {name = "Yaye Awa Ba"}, ] readme = "README.md" requires-python = ">=3.11" From 0b7cd2eaebc7e4d22551a12996d38b2d011caa38 Mon Sep 17 00:00:00 2001 From: Christian Rab Date: Fri, 31 Jul 2026 08:38:45 +0200 Subject: [PATCH 2/3] Properly encode request parameters in getSpeciesWithSearchCriteria. Search with ions + did not work. --- spectral/species.py | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/spectral/species.py b/spectral/species.py index 87b3159..c8f5cbe 100644 --- a/spectral/species.py +++ b/spectral/species.py @@ -3,6 +3,7 @@ import urllib.request from datetime import datetime from io import StringIO +from urllib.parse import urlencode import numpy as np from enum import Enum @@ -360,20 +361,25 @@ def getSpeciesWithSearchCriteria(text_search = None, stoichiometric_formula = No """ _, urlSpeciesEndpoint = _getEndpoints() - urlSuffix = "?" - urlSuffix = (urlSuffix+"text_search="+text_search+"&") if text_search is not None else urlSuffix - urlSuffix = (urlSuffix+"stoichiometric_formula="+stoichiometric_formula+"&") if stoichiometric_formula is not None else urlSuffix - urlSuffix = (urlSuffix+"ivo_identifier="+ivo_identifier+"&") if ivo_identifier is not None else urlSuffix - urlSuffix = (urlSuffix+"inchikey="+inchikey+"&") if inchikey is not None else urlSuffix - urlSuffix = (urlSuffix+"name="+name+"&") if name is not None else urlSuffix - urlSuffix = (urlSuffix+"structural_formula="+structural_formula+"&") if structural_formula is not None else urlSuffix + params = {} + if text_search is not None: + params["text_search"] = text_search + if stoichiometric_formula is not None: + params["stoichiometric_formula"] = stoichiometric_formula + if ivo_identifier is not None: + params["ivo_identifier"] = ivo_identifier + if inchikey is not None: + params["inchikey"] = inchikey + if name is not None: + params["name"] = name + if structural_formula is not None: + params["structural_formula"] = structural_formula if type == "molecule" or type == "atom": - urlSuffix = urlSuffix + "type="+type + "&" - + params["type"] = type # testing the difference mass_max-mass_min to be positive - maxMinDifference = mass_max-mass_min if (mass_max is not None and mass_min is not None) else 0 + maxMinDifference = mass_max - mass_min if (mass_max is not None and mass_min is not None) else 0 if maxMinDifference < 0: raise Exception("The difference (mass_max - mass_min) must be positive") @@ -382,15 +388,19 @@ def getSpeciesWithSearchCriteria(text_search = None, stoichiometric_formula = No if maxMinDifference < 0: raise Exception("The difference (charge_max - charge_min) must be positive") - urlSuffix = (urlSuffix+"mass_max="+str(mass_max)+"&") if mass_max is not None else urlSuffix - urlSuffix = (urlSuffix+"mass_min="+str(mass_min)+"&") if mass_min is not None else urlSuffix - - urlSuffix = (urlSuffix+"charge_max="+str(charge_max)+"&") if charge_max is not None else urlSuffix - urlSuffix = (urlSuffix+"charge_min="+str(charge_min)+"&") if charge_min is not None else urlSuffix + if mass_max is not None: + params["mass_max"] = str(mass_max) + if mass_min is not None: + params["mass_min"] = str(mass_min) + if charge_max is not None: + params["charge_max"] = str(charge_max) + if charge_min is not None: + params["charge_min"] = str(charge_min) - fullUrl = urlSpeciesEndpoint + urlSuffix + query_string = urlencode(params) + fullUrl = f"{urlSpeciesEndpoint}?{query_string}" if query_string else urlSpeciesEndpoint - species_df , node_df = _getChemicalInfoFromEnpoint(fullUrl) + species_df, node_df = _getChemicalInfoFromEnpoint(fullUrl) return species_df, node_df From c42d65a371c0407819170db780da4952f1bb272c Mon Sep 17 00:00:00 2001 From: Christian Rab Date: Fri, 31 Jul 2026 08:42:59 +0200 Subject: [PATCH 3/3] Return None in _getChemicalInfoFromEnpoint if nothing was found. Otherwise the routine did throw some pandas exception and was unclear what happened. --- spectral/species.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spectral/species.py b/spectral/species.py index c8f5cbe..c963ed3 100644 --- a/spectral/species.py +++ b/spectral/species.py @@ -471,10 +471,16 @@ def _getChemicalInfoFromEnpoint(specificSpeciesEndpoint): Returns: AllSpeciesDF (dataframe): a Pandas dataframe containing the chemical information obtained while resolving the URL in the specificSpeciesEndpoint variable. df_nodes (dataframe): a Pandas dataframe containing the information regarding the Nodes. + (None, None): if nothing found, is cleaner than getting some Exception from pandas when trying to create a dataframe from an empty json. """ response = urllib.request.urlopen(specificSpeciesEndpoint) data = json.loads(response.read()) + # Simply nothing found + if not data or len(data.items()) == 0: + #print("No chemical information has been found in the Species database.") + return None, None + # wrapping the results into a unique Pandas Dataframe (called AllSpeciesDF) dataFrames = [] AllSpeciesDF = None