Commit d9ee730b authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Use by atom number order to elements in atom_labels.

parent 10b06c29
......@@ -31,7 +31,7 @@ from ..decorators import json
from ..decorators.paginate import paginate_queryparams, paginate
from ..dmss import diagram_data_types
from ..errors import InvalidEncRequest
from ..utils import generate_auth_token, verify_auth_token, flag_to_gitlab, reformat_user_formula, hill_decomposition
from ..utils import generate_auth_token, verify_auth_token, flag_to_gitlab, reformat_user_formula, hill_decomposition, sort_elements
LOGGER = logging.getLogger(__name__)
......@@ -173,7 +173,7 @@ def get_materials(page, per_page):
if elements is not None:
if exclusive:
match_query['atom_labels_keyword'] = dict(query="".join(elements))
match_query['atom_labels_keyword'] = dict(query="".join(sort_elements(elements)))
else:
match_query['atom_labels'] = dict(query=" ".join(elements), operator='and')
......
......@@ -65,9 +65,15 @@ _numbers = {
'Th': 90, 'Pa': 91, 'U': 92, 'Np': 93, 'Pu': 94,
'Am': 95, 'Cm': 96, 'Bk': 97, 'Cf': 98, 'Es': 99,
'Fm': 100, 'Md': 101, 'No': 102, 'Lr': 103,
'Rf': 104, 'Db': 105, 'Sg': 106, 'Bh': 107, 'Hs': 108,
'Mt': 109, 'Ds': 110, 'Rg': 111, 'Cn': 112, 'Nh': 103
}
def sort_elements(elements):
return sorted(elements, key=lambda element: _numbers.get('element', 200))
def get_atom_number(symbol):
"""Given an element symbol, return the atomic number (number of protons).
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment