Repository navigation
Address code-review findings on the 2.x PRs #57
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,14 @@ def number_in_text(text): | |
| return float(match.group(0)) if match else None | ||
|
|
||
|
|
||
| def field_number(text): | ||
| """Number in an SDF data field: the whole value as a float (so "0" and "12" work), else the first float in the text.""" | ||
| try: | ||
| return float(str(text).strip()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: sed -n '1,160p' dbstep/ensemble.py
rg -n 'boltzmann_average|energy_of|field_number|isfinite' dbstep tests/test_review_fixes.pyRepository: patonlab/DBSTEP Length of output: 6404 Reject non-finite energy fields.
Suggested fix+import math
import re
import sys
@@
def field_number(text):
"""Number in an SDF data field: the whole value as a float (so "0" and "12" work), else the first float in the text."""
try:
- return float(str(text).strip())
+ value = float(str(text).strip())
except ValueError:
- return number_in_text(text)
+ value = number_in_text(text)
+ return value if value is None or math.isfinite(value) else None🤖 Prompt for AI Agents |
||
| except ValueError: | ||
| return number_in_text(text) | ||
|
|
||
|
|
||
| def _label(run): | ||
| return run.structure_name or run.results[0]["file"] if run.results else str(run.file) | ||
|
|
||
|
|
@@ -61,13 +69,13 @@ def energy_of(run, tag=None): | |
| key = str(tag).strip().lower() | ||
| if key not in lowered: | ||
| sys.exit(f" No <{tag}> data field for structure '{_label(run)}'. Fields present: {', '.join(properties) or 'none'}") | ||
| value = number_in_text(lowered[key]) | ||
| value = field_number(lowered[key]) | ||
| if value is None: | ||
| sys.exit(f" Data field <{tag}> of structure '{_label(run)}' is not a number: {lowered[key]!r}") | ||
| return value | ||
| for candidate in ENERGY_TAGS: | ||
| if candidate in lowered: | ||
| value = number_in_text(lowered[candidate]) | ||
| value = field_number(lowered[candidate]) | ||
| if value is not None: | ||
| return value | ||
| if "comment" in lowered: | ||
|
|
@@ -115,6 +123,7 @@ def boltzmann_average(runs, tag=None, temperature=298.15, units="kcal"): | |
| first = runs[0].results[i] | ||
| row = { | ||
| "file": first["file"], | ||
| "path": first.get("path", ""), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win Do not attribute a mixed-input summary to the first path. If a Python caller passes runs from different input files to 🤖 Prompt for AI Agents |
||
| "frame": "", | ||
| "structure": "boltzmann", | ||
| "residue": first["residue"], | ||
|
|
||
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Qualify the SDF integer-parsing claim.
The integer guard also applies to SDF fields when
field_number()falls back tonumber_in_text(). For example,field_number("E = 5 kcal")returnsNone. Say that whole-value integer fields are accepted; do not say the guard applies only to xyz comment lines.🤖 Prompt for AI Agents