Skip to content

Guess element#2314

Merged
richardjgowers merged 15 commits intoMDAnalysis:developfrom
lilyminium:guess-element
Aug 20, 2019
Merged

Guess element#2314
richardjgowers merged 15 commits intoMDAnalysis:developfrom
lilyminium:guess-element

Conversation

@lilyminium
Copy link
Member

@lilyminium lilyminium commented Aug 5, 2019

Fixes #2313

This pull request tries a bit harder to guess atom elements from names (compared to the old way of returning the first letter).

Changes made in this Pull Request:

  • This checks atom names from left to right, chopping off letters from both ends one-by-one.
  • OXT, XO2, etc. should return O
  • also returns numbers if only numbers are given

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

@codecov
Copy link

codecov bot commented Aug 5, 2019

Codecov Report

Merging #2314 into develop will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #2314      +/-   ##
==========================================
- Coverage    89.82%   89.8%   -0.02%     
==========================================
  Files          173     173              
  Lines        21711   21722      +11     
  Branches      2846    2850       +4     
==========================================
+ Hits         19501   19508       +7     
- Misses        1615    1619       +4     
  Partials       595     595
Impacted Files Coverage Δ
package/MDAnalysis/topology/guessers.py 100% <100%> (ø) ⬆️
package/MDAnalysis/topology/tables.py 100% <100%> (ø) ⬆️
package/MDAnalysis/coordinates/TRJ.py 90.6% <0%> (-0.91%) ⬇️
package/MDAnalysis/lib/util.py 88.18% <0%> (-0.3%) ⬇️
package/MDAnalysis/lib/transformations.py 78.62% <0%> (+0.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e910a12...0718cf7. Read the comment docs.

return guess_atom_element(atomname)


SYMBOLS = re.compile(r'[0-9\*\+\-]')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you comment what this is matching? [0-9] then unlimited characters?

assert guessers.guess_atom_element('1H') == 'H'
assert guessers.guess_atom_element('2H') == 'H'

def test_guess_element_symbols(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look up how @pytest.parametrize works (grep around in our tests and find one). You should be able to write a list of [(input1, expected1), (input2, expected2), ...] which will make rattling off a lot of tests easy + expandable

Copy link
Member

@richardjgowers richardjgowers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks cool but needs a little tweaking, see comments

@richardjgowers richardjgowers self-assigned this Aug 10, 2019
('HB1', 'H'),
('OC2', 'O'),
('1he2', 'H'),
('3hg2', 'H'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to ask for more elements to be added to the table, but then obviously it will make he and hg fail. I guess there's not many people doing MD of mercury....

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! (Which I meant to say earlier). I agree that more elements would have been nice -- I originally had helium and calcium in there before realising the obvious ambiguity. As GROMOS force fields have hydrogens called HG in threonine and HE in phenylalanine, I thought element diversity could be left as a problem for a future era of simulation.

Copy link
Member

@richardjgowers richardjgowers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lilyminium , I think this improves things as much as we can do.

This is your first commit so add yourself to AUTHORS and add github handle to the top of CHANGELOG and we're good to go

@richardjgowers richardjgowers merged commit 57bc183 into MDAnalysis:develop Aug 20, 2019
@lilyminium lilyminium deleted the guess-element branch April 14, 2020 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MDAnalysis returns first letter of atom name as element

2 participants