-
Notifications
You must be signed in to change notification settings - Fork 307
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
Reorganize and refactor atomic subpackage #122
Conversation
This commit enforces the following naming conventions: element = element_symbol(argument) isotope = isotope_symbol(argument) Using `symbol` leaves it ambiguous whether it refers to an element, isotope, or ion.
The new atomic_symbols dictionary in elements.py has atomic numbers as keys and the atomic symbols as items. This results in the same functionality, but will not break if we remove neutrons from index 0.
New functions include: __is_hydrogen, __is_positron, __is_electron, __is_antiproton, __is_neutron, and __is_alpha. These functions check whether or not a particle string corresponds to any of the cases with special names. These functions are designed to make functions like atomic_symbol more readable. This is still a work in progress.
Hello @namurphy! Thanks for updating the PR.
Comment last updated on September 29, 2017 at 21:52 Hours UTC |
This fixes a bug where __extract_charge_state('H-1-') did not return ('H-1', -1).
Up until now, atomic symbols were case-insensitive (e.g., 'd' and 'D' both stand for deuterium; but 'p' means proton and 'P' means phosphorus). The problem with case-insensitivity is that it allows for sloppier and less consistent code.
Because: "coverage/coveralls — Coverage decreased (-0.01%) to 98.955%"
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.
Found some mostly minor text fixes to be done. :)
.gitignore
Outdated
Untitled* | ||
untitled* | ||
C\:* |
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.
... Wait, what? C:
?
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.
For some reason on my workstation running CentOS 6.8 I occasionally get files named C:\\nppdf32Log\\debuglog.txt
for some unbeknownst reason. Hm...maybe *debuglog*
would be a better choice, in case this has any adverse impact on Windows.
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.
Huh, that's weird.
Here's something I found out about recently that might be helpful, though: https://help.github.com/articles/ignoring-files/#create-a-global-gitignore
plasmapy/atomic/nuclear.py
Outdated
------- | ||
energy: Quantity | ||
The change in nuclear binding energy, which will be positive | ||
if the reaction releases and negative if the reaction is |
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.
...releases energy and...
plasmapy/atomic/nuclear.py
Outdated
if item == 'n': | ||
symbol = 'n' | ||
else: | ||
symbol = isotope_symbol(item) |
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'm still not sure what's worse, the weird feeling I get seeing how this has to be handled separately, or calling a neutron an isotope.
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.
Good catch. Since isotope_symbol
works with neutrons, we can shorten these four lines down to just symbol = isotope_symbol(item)
. I may change symbol
to isotope
for clarity and consistency as well.
plasmapy/atomic/atomic.py
Outdated
if __is_neutron(argument) and (mass_numb is None or mass_numb == 1): | ||
return 'n' | ||
elif argument == 0 and mass_numb == 1: | ||
return 'n' |
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.
Oh, so you did add it! One of my previous comments may have just been invalidated, then!
plasmapy/atomic/atomic.py
Outdated
else: | ||
warn("Redundant mass number information in isotope_symbol from" | ||
" inputs: (" + str(argument)+", " + str(mass_numb) + ")", | ||
UserWarning) |
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.
Excuse me, do you have a moment to talk about our typing savior the f-string?
f"Redundant mass number information in isotope_symbol from inputs: ({argument}, {mass_numb})",
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.
Oh, great idea! I think I had some bad experiences using Fortran formatting (i.e., I used Fortran formatting) and so have been reluctant to learn how to do it in Python.
plasmapy/atomic/atomic.py
Outdated
@@ -434,24 +444,25 @@ def half_life(argument, mass_numb=None): | |||
half_life_sec = Isotopes[isotope]['half_life'] | |||
except Exception: | |||
half_life_sec = None | |||
raise UserWarning("The half-life for isotope " + isotope + | |||
" is not available; returning None.") | |||
warn("The half-life for isotope " + isotope + " is not available; " |
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.
Once more, a proper place for the glory of f-strings!
|
||
Returns | ||
------- | ||
mass_number : integer | ||
An integer representing the mass number of the isotope. | ||
The total number of protons plus neutrons in a nuclide. |
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.
👌
plasmapy/atomic/atomic.py
Outdated
uses hydrogen's standard atomic weight based on terrestrial values. To | ||
get the mass of a proton, use ion_mass('p'). | ||
Calling ion_mass('H') does not return the mass of a proton but | ||
instea uses hydrogen's standard atomic weight based on terrestrial |
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.
typo, instead
plasmapy/atomic/atomic.py
Outdated
A string or integer representing an atomic number or element, or a | ||
string represnting an isotope. | ||
A string or integer representing an atomic number or element, | ||
or a string represnting an isotope. | ||
|
||
unstable_instead: boolean |
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.
Actually, how about just unstable
?
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've been going back and forth about how best to name this. The possibilities I've been wondering about are:
stable_isotopes('Fe', unstable_instead=True)
(status quo)stable_isotopes('Fe', unstable=True)
(your suggestion)stable_isotopes('Fe', invert=True)
unstable_isotopes('Fe')
(create a new function)- Not provide this functionality and let people do a list comprehension like:
[isotope for isotope in known_isotopes('H') if isotope not in stable_isotopes('H')]
Are any of these better than the others? The most readable is unstable_isotopes('Fe')
, though I'm wondering if we need to create a function for it.
plasmapy/atomic/atomic.py
Outdated
|
||
return Z | ||
|
||
|
||
def electric_charge(argument): |
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.
heck yeah!
Invert is less direct than stable. Another function is less simple.
Unstable instead seems lengthy.
…On Sep 27, 2017 19:42, "Nick Murphy" ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In plasmapy/atomic/atomic.py
<#122 (comment)>:
>
Parameters
----------
argument: integer or string
- A string or integer representing an atomic number or element, or a
- string represnting an isotope.
+ A string or integer representing an atomic number or element,
+ or a string represnting an isotope.
unstable_instead: boolean
I've been going back and forth about how best to name this. The
possibilities I've been wondering about are:
1. stable_isotopes('Fe', unstable_instead=True) (status quo)
2. stable_isotopes('Fe', unstable=True) (your suggestion)
3. stable_isotopes('Fe', invert=True)
4. unstable_isotopes('Fe') (create a new function)
5. Not provide this functionality and let people do a list
comprehension like:
[isotope for isotope in known_isotopes('H') if isotope not in stable_isotopes('H')]
Are any of these better than the others? The most readable is
unstable_isotopes('Fe'), though I'm wondering if we need to create a
function for it.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#122 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AKxDLysdUe_SgTSNNJ719zL9iiARR65hks5smokKgaJpZM4PkpW9>
.
|
I'm thinking about eventually creating a decorator that will take the arguments for these various functions and parse them into the standardized form expected later on. That will probably simplify a lot of this code. I think I may save that for a future pull request though. |
This pull request makes the following changes to the
atomic
subpackage:element_symbol
toatomic_symbol
energy_from_nuclear_reaction
tonuclear_reaction_energy
nuclear_reaction_energy
andnuclear_binding_energy
to new file callednuclear.py
atomic.py
atomic.py
atomic_symbols_list
to a dictionary calledatomic_symbols
inelements.py
warnings.warn
when there is aUserWarning
instead ofraise
atomic_symbol
andelement_name
, but continue to allow them inisotope_symbol
,isotope_mass
, andmass_number
because neutrons do count as nuclides__is_hydrogen
__is_positron
__is_electron
__is_antiproton
__is_neutron
__is_alpha