-
Notifications
You must be signed in to change notification settings - Fork 81
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
Updates to energy minimization routines #1061
Conversation
…straints, with various checking/parsing of input
for more information, see https://pre-commit.ci
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1061 +/- ##
==========================================
- Coverage 90.69% 90.69% -0.01%
==========================================
Files 57 57
Lines 5397 5500 +103
==========================================
+ Hits 4895 4988 +93
- Misses 502 512 +10 ☔ View full report in Codecov by Sentry. |
I put together two notebooks demonstrating the usage (these will eventually be merged into the main tutorials). https://github.com/chrisiacovella/mbuild_energy_minimization |
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.
Looking good, such an exciting feature!
fixing typo Co-authored-by: CalCraven <54594941+CalCraven@users.noreply.github.com>
fixing typo Co-authored-by: CalCraven <54594941+CalCraven@users.noreply.github.com>
fix more typos in comments Co-authored-by: CalCraven <54594941+CalCraven@users.noreply.github.com>
…e tests of errors
for more information, see https://pre-commit.ci
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.
Looks good, only a few comments to shorten the codes. The logic looks fine, the sanity checks can be a bit disruptive of the flow (may be have those as a helper method?).
mbuild/compound.py
Outdated
if len(fixed_compounds) == 2: | ||
# At this point in the code, we only want to see if the second element in the list | ||
# is a Compound. If it is a Compound we don't need to santize the input. | ||
# If it is not a Compound, (e.g., if the list passed is of the form [Compound, [True, true,True]], |
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.
# If it is not a Compound, (e.g., if the list passed is of the form [Compound, [True, true,True]], | |
# If it is not a Compound, (e.g., if the list passed is of the form [Compound, [bool, bool, bool]], |
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.
LGTM! A few minor suggestions I'm seconding from @daico007.
An individual Compound or list of Compounds that will have their | ||
position fixed during energy minimization. Note, positions are fixed | ||
using a restraining potential and thus may change slightly. | ||
Position fixing will apply to all Particles (i.e., atoms) that exist |
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.
Are we capitalizing or not capitalizing the word particle
? I would maybe suggest no, since we really do want people to understand that these are really Compounds.
mbuild/compound.py
Outdated
if id(p1) == id(particle): | ||
pid = index | ||
if all_true == True: | ||
ob_constraints.AddAtomConstraint(pid) |
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 this get's fixed by the suggest made hy @daico007 in line 2486 to 2498.
… additional tests.
for more information, see https://pre-commit.ci
I think I got all the comments and suggestions incorporated. |
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.
Only one final bit and everything LGTM!
mbuild/compound.py
Outdated
elif dims[0] == True: | ||
ob_constraints.AddAtomXConstraint(pid) | ||
elif dims[1] == True: | ||
ob_constraints.AddAtomYConstraint(pid) | ||
elif dims[2] == True: | ||
ob_constraints.AddAtomZConstraint(pid) |
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.
elif dims[0] == True: | |
ob_constraints.AddAtomXConstraint(pid) | |
elif dims[1] == True: | |
ob_constraints.AddAtomYConstraint(pid) | |
elif dims[2] == True: | |
ob_constraints.AddAtomZConstraint(pid) | |
else: | |
if dims[0] == True: | |
ob_constraints.AddAtomXConstraint(pid) | |
if dims[1] == True: | |
ob_constraints.AddAtomYConstraint(pid) | |
if dims[2] == True: | |
ob_constraints.AddAtomZConstraint(pid) |
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.
Unless they are mutually exclusive, I think they should belong to individual if
block
PR Summary:
A few extensions to the existing energy minimization functions for compounds. In particular, changes were made to support additional OpenBabel features.
General operations:
1- After energy minimization, shift the Compound to the original COM; this behavior can be toggled with the shift_com variable. Default behavior will be to shift to the original COM. For example, toggle the shift off via:
dodecane = Alkane(n=12) dodecane.energy_minimize(steps=1000,shift_com=False)
2- Rather than retaining the COM position, the user can specify an "anchor" within the Compound. After energy minimization, the Compound is shifted such that the position (or COM as the case may be) of the anchor is unchanged. Example usage:
dodecane = Alkane(n=12) anchor_point = dodecane.labels['chain'].labels['CH3'][0] dodecane.energy_minimize(steps=10000,shift_com=False, anchor=anchor_point)
OpenBabel specific:
1- Energy minimization call will accept a list of Compounds whose positions will be fixed during energy minimization. Note, positions are not truly fixed, but have a strong harmonic energy term associated between the particle and its original position. This can apply to a Compound at any level, as the code will loop over all successors to fix any particle in the Compound. Example usage:
dodecane = Alkane(n=12) point0 = dodecane.labels['chain'].labels['CH3'][0] dodecane.energy_minimize(steps=1000,shift_com=False, fixed_compounds=point0)
Note, can also specify which directions to fix:
dodecane = Alkane(n=12) point0 = dodecane.labels['chain'].labels['CH3'][0] point1 = dodecane.labels['chain'].labels['monomer'][0] fixed = [ [ point0, (True, True, True)], [ point1, (False, False, True)] ] dodecane.energy_minimize(steps=1000,shift_com=False, fixed_compounds=fixed)
2- Distance constraints...a list of Compound pairs and the constrained distance. This must be between Compounds that represent atoms; cannot be between Compounds which contain other Compounds or multiple particles. The code will check to ensure only are applying to Compounds without children. Example usage:
dodecane = Alkane(n=12) point0 = dodecane.labels['chain'].labels['CH3'][0].labels['C'][0] point1 = dodecane.labels['chain'].labels['CH3'][1].labels['C'][0] dodecane.energy_minimize(steps=10000,shift_com=False, distance_constraints=[ [(point0, point1), 0.5 ]])
3- Will accept a list of Compounds to ignore during energy minimization. These Compounds will not have any parameters assigned during energy minimization from the force field, and will have their positions "fixed" (as described above). Note, interactions for ignore particles can be set by a user, e.g., via a distance constraint. This can apply to a Compound at any level, as the code will loop over all successors to fix any particle in the Compound. Example usage:
dodecane = Alkane(n=12) helium = mb.Compound(pos=dodecane.labels['chain'].labels['monomer'][5].pos+[0.0,0.0,0.05], name='He', element='He') dodecane.add(helium) dodecane.energy_minimize(shift_com=False, ignore_compounds=helium)
Can combine ignore_compounds with distance constraints, to, e.g., allow the COM of several atoms to be tied to the position of an associated coarse-grained bead.
PR Checklist