Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
encyclopedia-physics-engine
Commits
d639b30e
Commit
d639b30e
authored
May 02, 2019
by
Markus Scheidgen
Browse files
Fixed bad formula search.
parent
0a9dfaa2
Changes
2
Hide whitespace changes
Inline
Side-by-side
rest-api-service/app/api_v1_0/routes.py
View file @
d639b30e
...
...
@@ -173,6 +173,7 @@ def render_es_result(result):
return
es_result
_atom_label_with_number
=
re
.
compile
(
"[A-Z][a-z]*[0-9]+"
)
@
api
.
route
(
'/materials'
,
methods
=
[
'POST'
])
@
http_auth
.
login_required
...
...
@@ -191,7 +192,12 @@ def get_materials(page, per_page):
user_elements
=
search_by
.
get
(
'element'
)
elements
=
None
if
user_formula
is
not
None
:
elements
=
reformat_user_formula
(
user_formula
)
parts
=
[
element
if
elementreformat_user_formula
(
user_formula
)
parts
=
[
part
if
_atom_label_with_number
.
match
(
part
)
else
'%s1'
%
part
for
part
in
parts
]
if
exclusive
:
match_query
[
'formula_reduced_keyword'
]
=
dict
(
query
=
""
.
join
(
sort_elements
(
elements
)))
else
:
match_query
[
'formula_reduced_terms'
]
=
dict
(
query
=
" "
.
join
(
elements
),
operator
=
'and'
)
elif
user_elements
is
not
None
:
try
:
...
...
@@ -199,7 +205,7 @@ def get_materials(page, per_page):
except
Exception
:
raise
InvalidEncRequest
(
"Could not parse given elements %s."
%
user_elements
,
400
)
if
elements
is
not
None
:
el
if
elements
is
not
None
:
if
exclusive
:
match_query
[
'atom_labels_keyword'
]
=
dict
(
query
=
""
.
join
(
sort_elements
(
elements
)))
else
:
...
...
rest-api-service/app/utils.py
View file @
d639b30e
# Copyright 2016-2018 Ioan Vancea, Markus Scheidgen
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
...
@@ -71,7 +71,7 @@ _numbers = {
def
sort_elements
(
elements
):
return
sorted
(
elements
,
key
=
lambda
element
:
_numbers
.
get
(
element
,
200
))
return
sorted
(
elements
,
key
=
lambda
element
:
_numbers
.
get
(
element
.
rstrip
(
'0123456789'
)
,
200
))
def
get_atom_number
(
symbol
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment