-
Notifications
You must be signed in to change notification settings - Fork 1
Hack in bonded interactions #236
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
Draft
clpetix
wants to merge
14
commits into
main
Choose a base branch
from
feature/bonds
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
047da30
Filter neighbor list.
clpetix b1ba252
Make bonds a private variable of the initializer.
clpetix 6e2694e
Change neighborlist method to calculate from a full neighborlist.
clpetix 1e9b4c9
Simplify RDF calculations, including with bond exclusions
mphoward 7fbecd5
Histogram and normalize RDFs manually
mphoward ccfff2d
Set number of rdf origins.
clpetix f8bd8cc
Merge branch 'main' into feature/bonds
mphoward 3d326dc
Filter bond exclusions using Cantor pairing function.
clpetix fad8cd0
Merge branch 'main' of https://github.com/mphowardlab/relentless into…
clpetix 3a0ca1b
Merge branch 'main' into feature/bonds
clpetix 09b3ebd
Merge branch 'main' into feature/bonds
clpetix 1d19b93
Add bond potentials and exclusions.
clpetix d05147b
Fix error in naming.
clpetix 0a9ad40
Add angle exclusions.
clpetix 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,8 @@ def _call_v3(self, sim): | |
| # parse masses by type | ||
| snap = sim["engine"]["_hoomd"].state.get_snapshot() | ||
| sim.masses = self._get_masses_from_snapshot(sim, snap) | ||
| sim[self]["_bonds"] = self._get_bonds_from_snapshot(sim, snap) | ||
| sim[self]["_angles"] = self._get_angles_from_snapshot(sim, snap) | ||
| self._assert_dimension_safe(sim, snap) | ||
| # create the potentials, defer attaching until later | ||
| neighbor_list = hoomd.md.nlist.Tree(buffer=sim.potentials.pair.neighbor_buffer) | ||
|
||
|
|
@@ -152,6 +154,12 @@ def _get_masses_from_snapshot(self, sim, snap): | |
| masses.update(masses_) | ||
| return masses | ||
|
|
||
| def _get_bonds_from_snapshot(self, sim, snap): | ||
| return snap.bonds.group | ||
|
|
||
| def _get_angles_from_snapshot(self, sim, snap): | ||
| return snap.angles.group | ||
|
|
||
| def _assert_dimension_safe(self, sim, snap): | ||
| if sim.dimension == 3: | ||
| dim_safe = True | ||
|
|
@@ -987,6 +995,8 @@ def _pre_run_v3(self, sim, sim_op): | |
| system=sim["engine"]["_hoomd"].state, | ||
| rdf_params=self._get_rdf_params(sim), | ||
| constraints=self._get_constrained_quantities(sim, sim_op), | ||
| bonds=sim[sim.initializer]["_bonds"], | ||
| angles=sim[sim.initializer]["_angles"], | ||
| ) | ||
| sim[self]["_hoomd_thermo_callback"] = hoomd.write.CustomWriter( | ||
| trigger=self.every, | ||
|
|
@@ -1178,6 +1188,8 @@ def __init__( | |
| system, | ||
| rdf_params=None, | ||
| constraints=None, | ||
| bonds=None, | ||
| angles=None, | ||
| ): | ||
| if dimension not in (2, 3): | ||
| raise ValueError("Only 2 or 3 dimensions supported") | ||
|
|
@@ -1188,6 +1200,8 @@ def __init__( | |
| self.system = system | ||
| self.rdf_params = rdf_params | ||
| self.constraints = constraints if constraints is not None else {} | ||
| self.bonds = bonds | ||
| self.angles = angles | ||
|
|
||
| # this method handles all the initialization | ||
| self.reset() | ||
|
|
@@ -1282,6 +1296,40 @@ def act(self, timestep): | |
| ), | ||
| ).toNeighborList() | ||
|
|
||
| # filter bonds from the neighbor list if they are present | ||
| # bond exclusions apply regardless of order, so | ||
| # consider both (i,j) and (j,i) permutations | ||
| if snap.bonds is not None and len(neighbors[:]) > 0: | ||
| bonds = numpy.vstack( | ||
| [self.bonds, numpy.flip(self.bonds, axis=1)], | ||
| ) | ||
| # list intersect using Cantor Pairing Function (pi): | ||
| # https://en.wikipedia.org/wiki/Pairing_function | ||
| pi_bond = (bonds[:, 0] + bonds[:, 1]) * ( | ||
| bonds[:, 0] + bonds[:, 1] + 1 | ||
| ) / 2 + bonds[:, 1] | ||
| pi_neighbor = (neighbors[:, 0] + neighbors[:, 1]) * ( | ||
| neighbors[:, 0] + neighbors[:, 1] + 1 | ||
| ) / 2 + neighbors[:, 1] | ||
| bond_exclusion_filter = ~numpy.isin(pi_neighbor, pi_bond) | ||
|
|
||
| neighbors.filter(bond_exclusion_filter) | ||
|
|
||
| if snap.angles is not None and len(neighbors[:]) > 0: | ||
| angles = numpy.vstack( | ||
| [self.angles, numpy.flip(self.angles, axis=1)], | ||
| ) | ||
| # list intersect using Cantor Pairing Function (pi): | ||
| # https://en.wikipedia.org/wiki/Pairing_function | ||
| pi_angle = (angles[:, 0] + angles[:, 2]) * ( | ||
| angles[:, 0] + angles[:, 2] + 1 | ||
| ) / 2 + angles[:, 2] | ||
| pi_neighbor = (neighbors[:, 0] + neighbors[:, 1]) * ( | ||
| neighbors[:, 0] + neighbors[:, 1] + 1 | ||
| ) / 2 + neighbors[:, 1] | ||
| angle_exclusion_filter = ~numpy.isin(pi_neighbor, pi_angle) | ||
|
|
||
| neighbors.filter(angle_exclusion_filter) | ||
| for i in self.types: | ||
| for j in self.types: | ||
| filter_ij = numpy.logical_and( | ||
|
|
@@ -1294,6 +1342,7 @@ def act(self, timestep): | |
| range=(0, self.rdf_params["stop"]), | ||
| ) | ||
| self._rdf_counts[i, j] += counts | ||
|
|
||
| self.num_samples += 1 | ||
| if compute_rdf: | ||
| self.num_rdf_samples += 1 | ||
|
|
||
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.
One thing we do still want to do is make sure we can specify the neighbor list exclusions, and then only do the exclusions in the thermo if they are active. I think we talked about adding that as an argument / property of the
PairPotentialTabulator, like theneighbor_buffer, and then we would set it here by setting theexclusionsoption.