-
Notifications
You must be signed in to change notification settings - Fork 2
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
fix xml2xyz function #92
Conversation
Merge pull request #85 from jcwang587/dev
merge update of dependencies
WalkthroughThis update involves enhancements and modifications across several components of the project. Key changes include the correction of a typo in a URL, introduction of new functions for energy profiles, updates to function imports reflecting module renamings, and the addition of a new parameter in an existing function to handle free energy data more flexibly. Changes
Recent Review DetailsConfiguration used: CodeRabbit UI Files selected for processing (6)
Files skipped from review due to trivial changes (1)
Additional Context UsedLanguageTool (17)
Ruff (35)
Additional comments not posted (4)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Actionable comments posted: 1
def fes_1d(hillspot_path, hills_count, cv_range, resolution=100): | ||
""" | ||
Calculate the 1D free energy profile from a HILLSPOT file. | ||
|
||
Parameters | ||
---------- | ||
hillspot_path : str | ||
The path of the HILLSPOT file | ||
hills_count : int | ||
The number of hills to be read | ||
cv_range : list | ||
The range of the collective variable | ||
resolution : int (optional) | ||
The resolution of the free energy profile | ||
""" | ||
assert isinstance(cv_range, list) and len(cv_range) == 2, "cv_range must be a list of length 2" | ||
|
||
f = open(hillspot_path, "r") | ||
|
||
data = [] | ||
h = [] | ||
w = [] | ||
hills_in = 0 | ||
for line in f.readlines(): | ||
line = line.split() | ||
x = [] | ||
if len(line) > 2: | ||
for i in range(len(line) - 2): | ||
x.append(float(line[i])) | ||
data.append(x) | ||
h.append(float(line[-2])) | ||
w.append(float(line[-1])) | ||
hills_in += 1 | ||
if hills_in > hills_count: | ||
break | ||
f.close() | ||
|
||
step = (cv_range[1] - cv_range[0]) / resolution | ||
cv = cv_range[0] | ||
|
||
data_list = [] | ||
|
||
for i in range(1, resolution): | ||
en = 0.0 | ||
cv = cv + step | ||
for j in range(len(data)): | ||
cv0 = data[j][0] | ||
en_ = gauss_pot_1d(cv, cv0, h[j], w[j]) | ||
en += en_ | ||
data_list.append({"cv": cv, "potential_energy": en}) | ||
|
||
df = pd.DataFrame(data_list) | ||
|
||
return df | ||
|
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.
The functions for calculating 1D, 2D, and 3D free energy profiles are well-implemented and documented. Consider adding error handling for file operations and validating input parameters to enhance robustness.
+ try:
+ f = open(hillspot_path, "r")
+ except IOError as e:
+ print(f"Error opening file: {e}")
+ return
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
def fes_1d(hillspot_path, hills_count, cv_range, resolution=100): | |
""" | |
Calculate the 1D free energy profile from a HILLSPOT file. | |
Parameters | |
---------- | |
hillspot_path : str | |
The path of the HILLSPOT file | |
hills_count : int | |
The number of hills to be read | |
cv_range : list | |
The range of the collective variable | |
resolution : int (optional) | |
The resolution of the free energy profile | |
""" | |
assert isinstance(cv_range, list) and len(cv_range) == 2, "cv_range must be a list of length 2" | |
f = open(hillspot_path, "r") | |
data = [] | |
h = [] | |
w = [] | |
hills_in = 0 | |
for line in f.readlines(): | |
line = line.split() | |
x = [] | |
if len(line) > 2: | |
for i in range(len(line) - 2): | |
x.append(float(line[i])) | |
data.append(x) | |
h.append(float(line[-2])) | |
w.append(float(line[-1])) | |
hills_in += 1 | |
if hills_in > hills_count: | |
break | |
f.close() | |
step = (cv_range[1] - cv_range[0]) / resolution | |
cv = cv_range[0] | |
data_list = [] | |
for i in range(1, resolution): | |
en = 0.0 | |
cv = cv + step | |
for j in range(len(data)): | |
cv0 = data[j][0] | |
en_ = gauss_pot_1d(cv, cv0, h[j], w[j]) | |
en += en_ | |
data_list.append({"cv": cv, "potential_energy": en}) | |
df = pd.DataFrame(data_list) | |
return df | |
def fes_1d(hillspot_path, hills_count, cv_range, resolution=100): | |
""" | |
Calculate the 1D free energy profile from a HILLSPOT file. | |
Parameters | |
---------- | |
hillspot_path : str | |
The path of the HILLSPOT file | |
hills_count : int | |
The number of hills to be read | |
cv_range : list | |
The range of the collective variable | |
resolution : int (optional) | |
The resolution of the free energy profile | |
""" | |
assert isinstance(cv_range, list) and len(cv_range) == 2, "cv_range must be a list of length 2" | |
try: | |
f = open(hillspot_path, "r") | |
except IOError as e: | |
print(f"Error opening file: {e}") | |
return | |
data = [] | |
h = [] | |
w = [] | |
hills_in = 0 | |
for line in f.readlines(): | |
line = line.split() | |
x = [] | |
if len(line) > 2: | |
for i in range(len(line) - 2): | |
x.append(float(line[i])) | |
data.append(x) | |
h.append(float(line[-2])) | |
w.append(float(line[-1])) | |
hills_in += 1 | |
if hills_in > hills_count: | |
break | |
f.close() | |
step = (cv_range[1] - cv_range[0]) / resolution | |
cv = cv_range[0] | |
data_list = [] | |
for i in range(1, resolution): | |
en = 0.0 | |
cv = cv + step | |
for j in range(len(data)): | |
cv0 = data[j][0] | |
en_ = gauss_pot_1d(cv, cv0, h[j], w[j]) | |
en += en_ | |
data_list.append({"cv": cv, "potential_energy": en}) | |
df = pd.DataFrame(data_list) | |
return df |
Summary by CodeRabbit
Documentation
New Features
Enhancements
xml2xyz
conversion function.Version Update