From bbe0d26f810647863c61ac5ea03cc2f055861b58 Mon Sep 17 00:00:00 2001 From: Lily Wang Date: Thu, 7 Nov 2019 01:59:44 +1100 Subject: [PATCH] guess zinc properly --- package/CHANGELOG | 1 + package/MDAnalysis/topology/guessers.py | 7 ++++++- testsuite/MDAnalysisTests/topology/test_guessers.py | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/package/CHANGELOG b/package/CHANGELOG index 12b67be1c2a..3a732996c23 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -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 diff --git a/package/MDAnalysis/topology/guessers.py b/package/MDAnalysis/topology/guessers.py index cd61f61a0c5..495b8406273 100644 --- a/package/MDAnalysis/topology/guessers.py +++ b/package/MDAnalysis/topology/guessers.py @@ -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 diff --git a/testsuite/MDAnalysisTests/topology/test_guessers.py b/testsuite/MDAnalysisTests/topology/test_guessers.py index cf7c69e8c1e..8b5e4fe08bc 100644 --- a/testsuite/MDAnalysisTests/topology/test_guessers.py +++ b/testsuite/MDAnalysisTests/topology/test_guessers.py @@ -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