-
Notifications
You must be signed in to change notification settings - Fork 663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
modified guess_atom_element for more accurate guess #4168
Changes from 14 commits
921616b
e358dcb
da13425
80c8eb2
1ce5387
76d6bec
aa7f457
878b496
35abfaa
3454ceb
7b5285a
ed4bbb4
d1d4f54
075f2dc
f77c6f5
5fe84ab
9d30a1e
575e6eb
19511fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,9 +202,14 @@ def guess_atom_element(atomname): | |
try: | ||
return tables.atomelements[atomname.upper()] | ||
except KeyError: | ||
# strip symbols and numbers | ||
# strip symbols | ||
no_symbols = re.sub(SYMBOLS, '', atomname) | ||
name = re.sub(NUMBERS, '', no_symbols).upper() | ||
|
||
# split name by numbers | ||
no_numbers = re.split(NUMBERS, no_symbols) | ||
no_numbers = list(filter(None, no_numbers)) #remove '' | ||
# if no_numbers is not empty, use the first element of no_numbers | ||
name = list(filter(None, no_numbers))[0].upper() if no_numbers else '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apologies if I'm missing something obvious, but do you need to apply filter again here? You've already removed the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I think I made a mistake while modifying the code... |
||
|
||
# just in case | ||
if name in tables.atomelements: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,9 @@ def test_guess_atom_element_1H(self): | |
('zn', 'ZN'), | ||
('Ca2+', 'CA'), | ||
('CA', 'C'), | ||
('N0A', 'N'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One more nit sorry could you test Na+ -> Na? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just added two tests for Na+ and Cu2+ |
||
('C0U', 'C'), | ||
('C0S', 'C') | ||
)) | ||
def test_guess_element_from_name(self, name, element): | ||
assert guessers.guess_atom_element(name) == element | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a space, I am assuming?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not let me know, other than that looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed a space... Thank you!