-
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
Improper atom order incorrect in LAMMPS data writer for harmonic impropers? #899
Comments
I can't really remember how I came to that conclusion in an old PR |
@ahy3nz thanks for hopping in here. I guess we need to make some simple test cases to throw through |
Unless someone beats me to the punch, I'm going to create a test case with formic acid. Its a small and simple molecule. I'll make up a fake improper if I have to and I'll create two XMLs; one with a harmonic improper and one with an amber-style improper. Then we can look at the |
Impropers are a complete and utter mess. Everybody does it a little differently, everybody adds their own quirks, nobody can agree on the right ordering. I can go on but we're all familiar with the idea. I don't trust anything short of running an MM single-point energy and isolating just the improper contribution to the overall potential energy. Absolutely tedious but I don't think there's any shortcuts to be had here. LAMMPS and GROMACS make it feasible enough to decompose potential energy contributions (with some file parsing), and I'm assuming Cassandra does as well. CHARMM might, Amber probably does, but OpenMM doesn't. In fact, OenMM's grouping of propers and impropers has probably led to some confusion in Foyer - are there impropers here? I don't know. ParmEd will probably find some, and plausibly be correct about them, but it's hard to verify them without understanding the source of the data (which I do not). |
Agreed, but we're stuck with them 👎 . Here is a gist with an XML file that has an amber-style improper and a python script for formic acid. Please don't take it too seriously. Its a bit of a frankenstein file, but will work for this purpose. Am I being dumb or can we even specify harmonic impropers with
Update: For formic acid and with amber-style impropers import foyer
import mbuild
import parmed
mol = mbuild.load("C(=O)O", smiles=True)
ff = foyer.Forcefield("improper_amber.xml")
mol_ff = ff.apply(mol)
mol_ff.save("test.gro", overwrite=True)
mol_ff.save("test.top", overwrite=True)
impropers = [d for d in mol_ff.dihedrals if d.improper]
print(impropers[0].atom3.idx) # this atom is index 0, the central atom.
# Just to double check that loaded parmed from file gives the same
# result as using foyer -> parmed
mol_loaded = parmed.load_file("test.top", xyz="test.gro")
impropers = [d for d in mol_loaded.dihedrals if d.improper]
print(impropers[0].atom3.idx) # this atom is index 0, the central atom. So for amber-style impropers, The open question is then for harmonic impropers. The parmed docs say central atom first. I'll update when I learn more. |
This comment has been minimized.
This comment has been minimized.
Just to add more options for thinking about this... |
First, apologies if anyone is confused by this thread. I have removed a few earlier comments because I felt that they were unnecessarily complicating the matter. Harmonic impropers: I am going to compare manually computed energies with LAMMPS and GROMACS.
Next, if we trust the parmed docs, we know the central atom should be first. Then, we can calculate the energy of the improper. We can also flip the first and third atom and re-compute the energy. Next, we can compute the energies of the original and flipped topologies with Finally, we can compute the improper energy in LAMMPS, which clearly defines central atom first. Summary: gromacs_files.tar.gz Here are the results from the manual calculation:
From GROMACS with this topology:
the energy is: For the flipped topology:
the energy is: The energy from lammps is:
|
@ahy3nz I agree with most of the observations in your comment. However, I disagree with:
As far as I can tell, the CHARMM-style (harmonic) impropers are stored central-atom-first. I make this statement based upon reading/writing GROMACS files, the documentation, and a comparison of the computed energies between by-hand, LAMMPS, and GROMACS. |
Similar test case as above but for Amber improper dihedrals. I don't get agreement in improper energies between gromacs and lammps unless I flip the 1st and 3rd atom of the improper in gromacs ( |
I updated the above example. There is now a |
Sounds like the lammpswriter probably needs to update the ordering then. In hindsight, I'm really curious what I had seen 3 years ago that made me incorrectly think the parmed convention was central-atom-third. |
@ahy3nz I'm pretty convinced for the harmonic impropers. I'm still struggling to figure out the amber-style impropers. GROMACS energies match with by-hand calculations (shout out to @rmatsum836) if you use central-atom-first. But the question still remains, does amber specify central-atom-third. And I lean towards yes on that. The main reason is this: for amber-style impropers, you should be able to use the same functional form as proper dihedrals, but just drop in the central atom as the third atom. If you do that in |
@lilyminium is correct. ParmEd correctly maintains the order of Amber impropers (central-atom third) so we should be able to keep the atom order from ParmEd dihedrals when writing out to LAMMPS. |
I think this foyer test might be fishy then. The central atom is well-defined but the resultant parmed improper puts that central atom as the 3rd element in the pmd.improper object? |
Thanks for bringing this to my attention. This is why I opened up the thread rather than just dropping in a fix immediately. I'll let you know what I find. |
@ahy3nz I took a look at the test. I agree--central atom definitely ends up third in the What is interesting is that the central atom ( |
It appears the atom ordering switching happens when foyer creates the openmm system, BEFORE any conversion-to-parmed happens. Specifically, when creating the customtorsionforce object via the customtorsionforcegenerator, there is some interesting improper-matching logic implemented in openmm. Consequently, the order of the atoms in the improper changes depending on the presence of wildcards. At the very least, I think this atom-ordering-improper issue stems in how openmm creates the customtorsionforces, and our writers try to be consistent with those, but this improper-with-wildcards is an interesting situation. Maybe the a test similar to |
I may be misinterpreting the code, but it looks like for |
That's what I had gathered from the code, central-atom changes if there are wildcards. I don't know why, and I don't know how that logic was determined. If this openmm logic is the "right" way to treat these customtorsionforce elements in an XML, then this might mean one of two things?
|
We need to resolve this issue (only a year later). This is a pretty important one to anyone using these systems. I'm marking this as high priority, and bringing it up at the next developers meeting. |
Bug summary
It appears that the atom ordering for harmonic impropers is incorrect in the LAMMPS data writer. Here is the code that writes the impropers. Note that the atoms are written so that the atom1.idx is written in the third position.
However, LAMMPS specifies that the central atom should be first see docs here, and
parmed
stores the central atom first see docs here.Am I missing something, or are we reordering these atoms when we should not be.
The text was updated successfully, but these errors were encountered: