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

Improved coding style in Arkane #1596

Merged
merged 28 commits into from
May 13, 2019
Merged

Improved coding style in Arkane #1596

merged 28 commits into from
May 13, 2019

Conversation

alongd
Copy link
Member

@alongd alongd commented May 9, 2019

Improved coding style in Arkane: Adhering to PEP 8 and additional minor code simplifications

@alongd alongd requested a review from mliu49 May 9, 2019 19:39
@alongd alongd self-assigned this May 9, 2019
@codecov
Copy link

codecov bot commented May 9, 2019

Codecov Report

Merging #1596 into master will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1596      +/-   ##
=========================================
+ Coverage   41.58%   41.6%   +0.01%     
=========================================
  Files         176     176              
  Lines       29147   29147              
  Branches     5995    5995              
=========================================
+ Hits        12122   12127       +5     
+ Misses      16187   16183       -4     
+ Partials      838     837       -1
Impacted Files Coverage Δ
rmgpy/data/kinetics/family.py 52.97% <0%> (+0.23%) ⬆️

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 fe57caa...0982f57. Read the comment docs.

Copy link
Contributor

@mliu49 mliu49 left a comment

Choose a reason for hiding this comment

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

Thanks for this PR! Since the entire PR is code style changes, I made a lot of picky style comments. Since they mostly come down to personal preference, don't feel obligated to change all of them.

@@ -609,7 +609,7 @@ def draw(self, reaction, format, path=None):
for c in column:
top0 = wellRects[c][1]
bottom0 = top + wellRects[c][3]
if (top >= top0 and top <= bottom0) or (top <= top0 and top0 <= bottom):
if (bottom0 >= top >= top0) or (bottom >= top <= top0):
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to order these as one would normally for math expressions, i.e. top0 <= top <= bottom0 or top <= top0 <= bottom?

arkane/input.py Outdated
kineticsEstimator = 'rate rules',
):
def database(thermoLibraries = None, transportLibraries = None, reactionLibraries = None, frequenciesLibraries = None,
kineticsFamilies = 'default', kineticsDepositories = 'default', kineticsEstimator = 'rate rules'):
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove spaces around =?

Copy link
Member Author

Choose a reason for hiding this comment

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

That was done in a different commit

arkane/common.py Outdated
logging.warning('the species corresponding to ' + str(os.path.basename(path))
+ ' is different in energy from the lowest energy conformer by '
+ "%0.2f" % Vdiff + ' kJ/mol. This can cause significant errors in your computed '
'rate constants. ')
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you update this to use str.format()?

arkane/common.py Outdated
'Ds': [[281, 281.16451]], 'Rg': [[280, 280.16514]], 'Cn': [[285, 285.17712]], 'Nh': [[284, 284.17873]],
'Fl': [[289, 289.19042]], 'Mc': [[288, 288.19274]], 'Lv': [[293, 293.20449]], 'Ts': [[292, 292.20746]],
'Og': [[294, 294.21392]]}
'He': [[3, 3.0160293201, 0.00000134], [4, 4.00260325414, 0.99999866]],
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional style preference: For long lists/dictionaries, I like putting the first entry on the next line:

mass_by_symbol = {
    'H': [],
    'He': [],
}

Random thought, but it seems like this should be located in rmgpy.molecule.element. No need to move it now though.

@@ -173,7 +176,8 @@ def testPressureList(self):
"""
Test the pressure list.
"""
self.assertEqual(numpy.array_equal(self.PlistValue, numpy.array([0.01, 0.1, 1, 3, 10, 100, 1000])), True, msg=None)
self.assertEqual(numpy.array_equal(self.PlistValue, numpy.array([0.01, 0.1, 1, 3, 10, 100, 1000])), True,
msg=None)
Copy link
Contributor

Choose a reason for hiding this comment

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

You could just get rid of the msg argument.

arkane/output.py Outdated
@@ -137,27 +140,29 @@ def visit_Dict(self, node):
return result
else:
# Keep elements on one line
result = '{{{0}}}'.format(', '.join(['{0}: {1}'.format(self.visit(key), self.visit(value)) for key, value in zip(node.keys, node.values)]))
result = '{{{0}}}'.format(', '.join(
['{0}: {1}'.format(self.visit(key), self.visit(value)) for key, value in zip(node.keys, node.values)]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps

result = '{{{0}}}'.format(', '.join(['{0}: {1}'.format(self.visit(key), self.visit(value))
                                     for key, value in zip(node.keys, node.values)]))

arkane/pdep.py Outdated
transitionState.conformer.E0 = (sum([spec.conformer.E0.value_si for spec in reaction.reactants]) + reaction.kinetics.Ea.value_si,"J/mol")
transitionState.conformer.E0 = (sum([spec.conformer.E0.value_si
for spec in reaction.reactants]) + reaction.kinetics.Ea.value_si,
"J/mol")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the sum can be kept on the first line and the line break occurs right before or after the +.

'='*(max_label-10)))
sa_f.write(
'========================={0}==================================================\n\n\n'.format(
'=' * (max_label - 10)))
Copy link
Contributor

Choose a reason for hiding this comment

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

You could consider splitting the string before \n to put this on two lines.

# Note: If your model chemistry does not include spin orbit coupling, you should add the corrections
# to the energies here
if modelChemistry.startswith(
'cbs-qb3'): # only check start of string to allow different bond corrections (see below)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer putting the comment on the following line instead of splitting the code.

@@ -284,8 +284,8 @@ def save(self, outputFile):
f.write('# krev (TST+T) = {0} \n\n'.format(kineticsrev))

# Reaction path degeneracy is INCLUDED in the kinetics itself!
string = 'kinetics(label={0!r}, kinetics={1!r})'.format(reaction.label, reaction.kinetics)
f.write('{0}\n\n'.format(prettify(string)))
_string = 'kinetics(label={0!r}, kinetics={1!r})'.format(reaction.label, reaction.kinetics)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would probably name it something more informative, like rxn_str or kinetics_str.

@alongd
Copy link
Member Author

alongd commented May 10, 2019

Thanks!
I squashed the fixups for _string and simplifying the chained comparison (x <= y <= z). Everything else is still in fixup commits

arkane/main.py Outdated
parser.add_argument('file', metavar='FILE', type=str, nargs=1,
help='a file describing the job to execute')
parser = argparse.ArgumentParser(description="""Arkane is a Python toolkit for computing chemical reaction
rates and other properties used in detailed kinetics models using various methodologies and theories.""")
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, my previous comment wasn't very clear. I was referring to the opening quotes """ only. I think the line breaks in the text are likely intentional and should be preserved, since they transfer directly to the output in terminal.

@mliu49
Copy link
Contributor

mliu49 commented May 13, 2019

Thanks for making all of those fixes! You can go ahead and squash, including whatever change you make regarding my new comment.

@alongd
Copy link
Member Author

alongd commented May 13, 2019

@mliu49, I think this PR is ready to go

@mliu49 mliu49 merged commit baed747 into master May 13, 2019
@mliu49 mliu49 deleted the arkane_style branch May 13, 2019 21:14
@mliu49 mliu49 mentioned this pull request May 15, 2019
5 tasks
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.

2 participants