Skip to content
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

PEP-8 renaming #1719

Merged
merged 46 commits into from
Sep 23, 2019
Merged

PEP-8 renaming #1719

merged 46 commits into from
Sep 23, 2019

Conversation

mliu49
Copy link
Contributor

@mliu49 mliu49 commented Sep 10, 2019

This PR tries to standardize naming conventions across RMG to comply with PEP-8 recommendations. This addresses the issue of inconsistent naming in RMG and allows for more easily enforceable code style guidelines.

What has been done

Almost all names in RMG (global variables and functions, class attributes and methods, function and method arguments) have been changed to use lowercase_with_underscores. Class names are still CamelCase.

In most cases, the new name is a direct conversion, e.g. isIsomorphic -> is_isomorphic. In select cases, names were changed more substantially to improve clarity, e.g. getLabeledAtom -> get_labeled_atoms and getLabeledAtoms -> get_all_labeled_atoms.

I have also created a script (scripts/rmg2to3.py) to facilitate the transition for codes dependent on RMG. It contains almost all names which have changed, except for some positional arguments. It uses regex to replace names, so there is some risk of replacing more than desired, but works for Cython and IPython notebooks as well.

Scientific variables

One challenge was renaming scientific variables, including T, P, H, S, Cp, and E. Currently this isn't completely consistent, so some discussion may be needed. In this PR, T and P have generally been left as capital letters, including cases such as T_list or P_list. H, S, and Cp are generally lowercase, since they are usually not ambiguous. E has been challenging. Currently, E0 is still capital, while e_list is lowercase.

Input, database, and yaml files

Input and database parsing functions have not been changed yet. Backward compatibility is definitely something we want to keep. However, I think it is also worth discussing when (not if) we should transition those files to yaml as well. If we think that's something we want in the near future, it might not be worth changing input and database syntax for now.

Yaml files are slightly more complicated, since they are currently directly tied to classes and their attributes. We've had a bit of offline discussion, and we think that the way forward is to have a built in conversion function which will run if we fail to parse a yaml file using the new namespace the first time. It would also write an updated file for the user.

What needs to be done

This renaming process has been more challenging than I originally anticipated, so I would like help with the remaining tasks:

  • Renaming of unit tests @amarkpayne
  • Renaming in Arkane @alongd
  • Renaming in rmgpy.tools.muq, I left this out for now since it will need to be completely refactored
  • Further discussion about scientific variables and input files
  • More testing

@mliu49
Copy link
Contributor Author

mliu49 commented Sep 11, 2019

I rebased onto py3.

@alongd
Copy link
Member

alongd commented Sep 12, 2019

I'm a bit confused re keeping backward compatibility of input files. Consider these two cases from an Arkane input file:

transitionState(
    label='TS3',
    E0=(34.1, 'kcal/mol'),
    ...
)
reaction(
    label='CH2O+H=Methoxy',
    reactants=['CH2O', 'H'],
    products=['methoxy'],
    transitionState='TS3',
)

I think we all agree that the first case can be kept backward compatible, since transitionState is mapped to the renamed function transition_state. But for the second case, transitionState is now a function argument (of reaction), and if we change arguments the input file will no longer be backward compatible.

Did I miss anything, or are there any insights for how to make these changes?

@mliu49
Copy link
Contributor Author

mliu49 commented Sep 12, 2019

That's correct, for RMG, I did not change any of the function signatures in rmgpy/rmg/input.py or the input related ones in database. In theory, we could modify the function signatures to accept kwargs and then parse them for either type of argument name.

Right now, I'm leaning towards keeping these input related functions as is, and not transitioning to new syntax with underscores. If we're keeping backward compatibility anyway, then this would not be a breaking change and could be introduced in a later minor release if we really wanted to. However, I think it might be more worthwhile to develop new yaml input and database files and have a single current -> yaml transition instead of going current -> underscores -> yaml. That way, users will only have to learn one new format.

@alongd
Copy link
Member

alongd commented Sep 14, 2019

I don't remember if we brought it up or not: did we modify all scripts under both -Py and db repos, and ipython notebooks under RMG-Py?

@mliu49
Copy link
Contributor Author

mliu49 commented Sep 14, 2019

Thanks for bringing that up! I forgot to mention it. I think I updated RMG-Py scripts, but we should double check. RMG-database scripts have not been touched. Running the conversion script on those should (in theory) be sufficient.

@rwest
Copy link
Member

rwest commented Sep 15, 2019

Agree that if a yaml change is coming for input files we should not have a second version of .py input files. Maintain current syntax, but accelerate the switch to yaml.

@alongd alongd force-pushed the py3_pep8 branch 12 times, most recently from 81a0b4b to 075182e Compare September 16, 2019 17:58
@codecov
Copy link

codecov bot commented Sep 18, 2019

Codecov Report

Merging #1719 into py3 will increase coverage by 0.02%.
The diff coverage is 65.25%.

Impacted file tree graph

@@            Coverage Diff             @@
##              py3    #1719      +/-   ##
==========================================
+ Coverage   32.62%   32.65%   +0.02%     
==========================================
  Files          87       87              
  Lines       26184    26158      -26     
  Branches     6875     6874       -1     
==========================================
- Hits         8542     8541       -1     
+ Misses      16677    16645      -32     
- Partials      965      972       +7
Impacted Files Coverage Δ
rmgpy/molecule/symmetry.py 0% <ø> (ø) ⬆️
rmgpy/rmg/pdep.py 12.21% <ø> (ø) ⬆️
rmgpy/pdep/network.py 12.62% <ø> (ø) ⬆️
rmgpy/qm/main.py 65.32% <ø> (ø) ⬆️
rmgpy/reaction.py 0% <ø> (ø) ⬆️
rmgpy/rmg/main.py 21.68% <ø> (-0.06%) ⬇️
rmgpy/data/kinetics/family.py 48.49% <ø> (ø) ⬆️
rmgpy/molecule/__init__.py 100% <ø> (ø) ⬆️
rmgpy/molecule/atomtype.py 0% <ø> (ø) ⬆️
rmgpy/tools/extractInfoFromckcsv.py 5.06% <ø> (ø) ⬆️
... and 86 more

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 28931a0...c09504d. Read the comment docs.

@alongd
Copy link
Member

alongd commented Sep 18, 2019

@mliu49, I added the Arkane stuff to rmg2to3. If it looks OK feel free to squash (there's another fixup for Arkane PEP8)

@mliu49
Copy link
Contributor Author

mliu49 commented Sep 20, 2019

I fixed some more functions which were missed during the initial pass. I plan to squash commits together and merge on Monday. Feel free to make additional comments until then.

amarkpayne and others added 26 commits September 23, 2019 13:15
To avoid shadowing the reserved keyword
Raising a NotImplementedError if called (only implemented for ReactionLibrary)
Using a syntax correction dictionary for on-the-fly conversions
Due to changes in gprof2dot API
@mliu49 mliu49 marked this pull request as ready for review September 23, 2019 18:36
@mliu49 mliu49 merged commit 5b85619 into py3 Sep 23, 2019
@mliu49 mliu49 deleted the py3_pep8 branch September 23, 2019 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants