-
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
Support for AMBER proper and improper dihedrals in write_lammpsdata #896
Support for AMBER proper and improper dihedrals in write_lammpsdata #896
Conversation
…HARMM forcefields.
…ckwards compatibility.
Codecov Report
@@ Coverage Diff @@
## master #896 +/- ##
==========================================
+ Coverage 89.45% 89.68% +0.22%
==========================================
Files 63 63
Lines 8130 8163 +33
==========================================
+ Hits 7273 7321 +48
+ Misses 857 842 -15
Continue to review full report at Codecov.
|
…nto lammpsdata_improper
for more information, see https://pre-commit.ci
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.
Thanks for this much needed addition! Would it also be useful to add tests that check the ordering of atoms in the Dihedral
section of the lammps data file?
I've been doing a comparison similar to #899 for amber style impropers in gromacs and LAMMPS. I don't reach agreement between the two engines unless I swap the order of atom 1 and atom 3, which makes me think that the ordering of amber improper atoms from pmd to gromacs may be incorrect. |
@rwsmith7531 Would you also mind explaining the conversion from the functional form from Gromacs periodic to Lammps periodic? |
Please see the discussion #899. For Amber Impropers, I believe we want to maintain that the central atom is 3rd. Therefore, the central atom should be third when writing out the Amber Impropers to Lammps. |
@rmatsum836 ParmEd does indeed have central-atom third for Amber impropers, but LAMMPS does not take central-atom third in the LAMMPS data file for improper style cvff. Refer to the LAMMPS documentation on improper style cvff here: https://lammps.sandia.gov/doc/improper_cvff.html |
@rmatsum836 The Gromacs periodic style is converted to LAMMPS cvff improper style. The force constant and periodicity are kept the same (just adjusted for different units), while d (in the cvff style) is determined from the dihedral phase. The absolute value of the dihedral phase is only allowed to be 0 (corresponding to d = 1) or 180 (corresponding to d = -1). |
@rwsmith7531 please take a look at the discussion that was mentioned by @rmatsum836. The fact that LAMMPS specifies central-atom first does not matter in this case. If I'm understanding everything correctly, AMBER impropers need to be specified central atom third no matter what. We did some energy tests, and I also looked at how we write impropers with our MAFFA tools. I know I was the one who pointed you in the wrong direction on this...so apologies. |
So far, I was able to analyze the AMBER impropers and dihedrals. They look correct for the CVFF improper types, according to the LAMMPS website LAMMPS_CVFF_impropers. Note: the CVFF improper types seem to take the central atom 1st from my read. |
@rwsmith7531, yes, I would still sort them. Like I do here in the MCF file. |
for more information, see https://pre-commit.ci
…nto lammpsdata_improper
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.
Overall this looks like it works well!! Good work!
I ran your test cases and checked the impropers by hand for both CHARMM and AMBER:
- If CHARMM they appear to write with the center atom in position 1.
- If AMBER they appear to write with the center atom in position 3.
I approve this after my question is addressed for the weighting factor not being 0 or 1 for the CHARMM case.
if zero_dihedral_weighting_factor: | ||
weight = 0.0 | ||
else: | ||
weight = 1.0 / len(dihedral.type) |
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 may have missed it, but should we make a test case that covers when this is not 1 or just set it to 1 if it will never be not 1.?
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 anything, we should verify that the assert listed in the tests validate that the weighting factor is being applied like we expect.
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.
@bc118 This PR only really covers support for AMBER force fields, and will maintain the prior (incorrect) determination of the weighting factor for CHARMM force fields because they are not AMBER. The addition of zero_dihedral_weighting_factor
ensures that the LAMMPS data writer can handle AMBER proper dihedrals correctly. As this is written, the weighting factor can take values other than 1 in the case of multi-term dihedrals when zero_dihedral_weighting_factor = False
.
I intend to follow the suggestion from @justinGilmer by including assertions that the weighting factor is zero when zero_dihedral_weighting_factor = True
and the weighting factor is 1 for a single-term dihedral when zero_dihedral_weighting_factor = False
(choosing the dihedral such that this behavior should not change when the code is eventually updated to determine CHARMM dihedral weighting factors correctly).
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 first assertion was already there and I just added the other one.
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.
Some small addition to our tests to make sure that the weighting factors are being set to the values we expect. And then it should be good! Thanks @rwsmith7531 !
if zero_dihedral_weighting_factor: | ||
weight = 0.0 | ||
else: | ||
weight = 1.0 / len(dihedral.type) |
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 anything, we should verify that the assert listed in the tests validate that the weighting factor is being applied like we expect.
found_angles = True | ||
elif "Dihedral Coeffs" in line: | ||
assert "# charmm" in line | ||
assert "#k, n, phi, weight" in out_lammps[i + 1] |
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.
For at least the two conditions for the weighting factor we added, can you add in a test that verifies that the weighting factor is being set to zero?
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 assertion that the weighting factor is zero when zero_dihedral_weighting_factor = True
was already in test_amber
. I just added an assertion that the weighting factor is 1.0 in test_save_charmm
, where zero_dihedral_weighting_factor
is left at the default, which is False
.
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 I’m misunderstanding, if the writhing factor is only 1 or 0, do we need to use the list length? Or do we just set to 1 or 0?
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.
@bc118 When zero_dihedral_weighting_factor = False
, the weighting factor is 1.0/(number of terms in the dihedral), which can be 1.0, 0.5, 0.3333, etc.
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.
Should we add a test where it is 1/2, like in a cyclic ring? I’m ok with not doing it if else is.
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.
When the method of determining the weighting factor for CHARMM dihedrals is fixed in a future PR, it should include such a test, but the current method has nothing to do with correcting for rings (which is the actual intended purpose of the weighting factor). Any test made now in which it is 0.5 would probably break when that fix is eventually made.
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.
Ok. Thanks for clarifying. I’m approving then
…edral." This reverts commit 03156bf.
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.
My only comments were clarified and it looks good now.
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.
My comments/suggestions have been resolved. Thanks for this @rwsmith7531 and all who have reviewed this PR!
…#896) This PR allows AMBER-style improper dihedrals to be written to LAMMPS data file. When CHARMM-style dihedrals are used in a non-CHARMM force field, such as in AMBER force fields, the dihedral 1-4 weighting parameter is automatically set to zero for all dihedrals. A new optional input argument was added to write_lammpsdata to designate when the CHARMM dihedral style is used in a non-CHARMM force field. * Add support for AMBER-style improper torsions. * Apply zero 1-4 weighting parameter in CHARMM-style dihedrals in non-CHARMM forcefields. * Make dihedral weighting parameters not default to zero, to restore backwards compatibility. * Add/improve unit tests and fix bugs found by them. * Update syntax to maintain code style consistency. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Correct mistake in merge conflict correction. * Move imports to tops of functions in unit tests. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Sort non-central atoms in improper dihedral by atom type. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix bug in atom type sorting. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Write central-atom third for AMBER-style impropers. * Add comments explaining multiple reorderings of atoms in improper dihedrals. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Rename borrowed_charmm flag and add additional comment. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove atom sorting in improper dihedrals. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Check for the correct dihedral weighting factor in CHARMM dihedral. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Revert "Check for the correct dihedral weighting factor in CHARMM dihedral." This reverts commit 03156bfd2962aeb9e5c8e8bda70c0f1cc91fccbd. * Add a unit test for the weighting parameter of a CHARMM dihedral. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Use get_boundingbox instead of boundingbox. Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
PR Summary:
This PR allows AMBER-style improper dihedrals to be written to LAMMPS data file. When CHARMM-style dihedrals are used in a non-CHARMM force field, such as in AMBER force fields, the dihedral 1-4 weighting parameter is automatically set to zero for all dihedrals. A new optional input argument was added to
write_lammpsdata
to designate when the CHARMM dihedral style is used in a non-CHARMM force field.Closes #866
PR Checklist