Skip to content

Commit

Permalink
guess zinc properly
Browse files Browse the repository at this point in the history
  • Loading branch information
lilyminium authored and richardjgowers committed Nov 7, 2019
1 parent 971248a commit bbe0d26
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Fixes
* Chainreader and continuous option work correctly when readers work for more
than one format (Issue #2353)
* PDBQTParser now gives icode TopologyAttrs (Issue #2361)
* Guess atom element with uppercase name

Enhancements
* Uniforms exception handling between Python 2.7 and Python 3: raised exceptions
Expand Down
7 changes: 6 additions & 1 deletion package/MDAnalysis/topology/guessers.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,16 @@ def guess_atom_element(atomname):
if atomname == '':
return ''
try:
return tables.atomelements[atomname]
return tables.atomelements[atomname.upper()]
except KeyError:
# strip symbols and numbers
no_symbols = re.sub(SYMBOLS, '', atomname)
name = re.sub(NUMBERS, '', no_symbols).upper()

# just in case
if name in tables.atomelements:
return tables.atomelements[name]

while name:
if name in tables.elements:
return name
Expand Down
4 changes: 3 additions & 1 deletion testsuite/MDAnalysisTests/topology/test_guessers.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ def test_guess_atom_element_1H(self):
('3hg2', 'H'),
('OH-', 'O'),
('HO', 'H'),
('he', 'H')
('he', 'H'),
('zn', 'ZN'),
('Ca2+', 'CA'),
))
def test_guess_element_from_name(self, name, element):
assert guessers.guess_atom_element(name) == element
Expand Down

0 comments on commit bbe0d26

Please sign in to comment.