-
Notifications
You must be signed in to change notification settings - Fork 230
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
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.
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.
arkane/kinetics.py
Outdated
@@ -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): |
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.
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'): |
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.
Remove spaces around =
?
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.
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. ') |
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.
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]], |
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.
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.
arkane/commonTest.py
Outdated
@@ -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) |
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.
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)])) |
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.
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") |
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 think the sum can be kept on the first line and the line break occurs right before or after the +
.
arkane/sensitivity.py
Outdated
'='*(max_label-10))) | ||
sa_f.write( | ||
'========================={0}==================================================\n\n\n'.format( | ||
'=' * (max_label - 10))) |
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.
You could consider splitting the string before \n
to put this on two lines.
arkane/statmech.py
Outdated
# 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) |
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 would prefer putting the comment on the following line instead of splitting the code.
arkane/kinetics.py
Outdated
@@ -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) |
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 would probably name it something more informative, like rxn_str
or kinetics_str
.
Thanks! |
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.""") |
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.
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.
Thanks for making all of those fixes! You can go ahead and squash, including whatever change you make regarding my new comment. |
to avoid shadowing reserved word
Also replaced assertEqual(x, True) with assertTrue(x)
@mliu49, I think this PR is ready to go |
Improved coding style in Arkane: Adhering to PEP 8 and additional minor code simplifications