-
Notifications
You must be signed in to change notification settings - Fork 10
Add RDF generation #25
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| import hoomd | ||
| import time | ||
| from cmeutils.sampling import is_equilibrated | ||
| import csv | ||
|
Contributor
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. Need csv? |
||
|
|
||
| def initialize_snapshot_rand_walk(num_pol, num_mon, density, bond_length=1.0, seed=1234): | ||
| ''' | ||
|
|
@@ -225,3 +226,48 @@ def simulation_energy_end(A,r,r_cut,num_pol,num_mon,density,energy_idx=-1): | |
| else: | ||
| return False | ||
|
|
||
| def generate_rdf( | ||
| start_idx = -1, | ||
| end_idx = None, | ||
| bins=300, | ||
| r_max=3.0, | ||
| r_min=0.0, | ||
| gsd_file_name="trajectory.gsd", | ||
| output_file_name="rdf.txt" | ||
| ): | ||
| ''' | ||
| Generate a radial distribution function for the provided GSD file and save | ||
| the data to the provided output file. | ||
|
|
||
| ---------- | ||
| Parameters | ||
| ---------- | ||
| start_idx : int, default -1 | ||
| Which frame to use for the start of the RDF average. Supplying None or 0 | ||
| will use the first frame. Supports negative indices. | ||
| end_idx : int, default None | ||
| Which frame to use for the last frame of the RDF average. Supplying None | ||
| will use the last frame. Supports negative indices. | ||
| bins : int, default 300 | ||
| How many bins to use for the histogram | ||
| r_max : float, default 3.0 | ||
| Maximum interparticle distance to include in the calculation. If this | ||
| value is greater than half the box length, then that will be used | ||
| instead. | ||
| r_min : float, default 0.0 | ||
| Minimum interparticle distance to include in the calculation. | ||
| gsd_file_name : str, default 'trajectory.gsd' | ||
| The file to read the trajectory data used for calculating the RDF. | ||
| output_file_name : str, default 'rdf.txt' | ||
| The file to output the RDF data into. | ||
| ''' | ||
| rdf = freud.density.RDF(bins=bins, r_max=r_max, r_min=r_min) | ||
| traj = gsd.hoomd.open(gsd_file_name, 'r') | ||
| for frame in traj[start_idx:end_idx]: | ||
| rdf.compute(system=frame, reset=False) | ||
|
|
||
| np.savetxt( | ||
| fname=output_file_name, | ||
| X=np.column_stack((rdf.bin_centers, rdf.rdf)), | ||
| header="r rdf" | ||
| ) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Overall looks good, but two small nitpicks: I don't think we want to calculate average RDFs in this case, just the last frame, and reading from a GSD that has been written out adds some complexity relative to calculating RDFs as the simulation proceeds (which could be used in our stop criteria)