mosdef-hub / foyer

A package for atom-typing as well as applying and disseminating forcefields
https://foyer.mosdef.org
MIT License
117 stars 76 forks source link

foyer.general_forcefield.Forcefield apply method results in improper parameter definition for lj epsilon #479

Closed CalCraven closed 2 years ago

CalCraven commented 2 years ago

Bug summary

I was trying to create a gmso ethane molecule from an mbuild object and the oplsaa general_forcefield. When trying to use the gmso lammpswriter to write out my system, I get an error message about a missing parameter epsilon in the lennard jones potential expression class. Looking into this a little more deeply, the gmso object that is being created from applying the general_forcefield.Forcefield is resulting in an ep and a sigma parameter. However, if we use the more standardized method of the forcefield.Forcefield to write out a parmed object and bring that into gmso, the nonbonded parameters are epsilon and sigma, which is what the lammpwriter is looking for. I can figure out a way to overwrite the parameter symbol and name in the gmso topology before writing to lammps, but it might be useful to be consistent in our naming conventions for these gmso objects in order to reduce other bugs that might pop up from this behavior.

Code to reproduce the behavior

>>>import mbuild as mb #Be sure to have the lammpswriter PR installed
>>>import foyer
>>>import gmso
>>>mb.__version__, foyer.__version__, gmso.__version__
>>>ethane = mb.load('CC', smiles=True)
>>>from foyer.general_forcefield import Forcefield
>>>oplsaa = Forcefield(name='oplsaa', strict=False)
>>>gmso_ethane = oplsaa.apply(ethane, assert_improper_params=False)
>>>gmso_ethane.save('ethane.lammps')

Output

KeyError                                  Traceback (most recent call last)
<ipython-input-4-8b2fca1f8802> in <module>
----> 1 gmso_ethane.save('ethane.lammps')
      2 gmso_ethane2 = gmso.Topology()
      3 gmso_ethane2.load('ethane.lammps')

~/Dropbox/Mac/Documents/Vanderbilt/Research/gmso/gmso/core/topology.py in save(self, filename, overwrite, **kwargs)
   1056 
   1057         saver = SaversRegistry.get_callable(filename.suffix)
-> 1058         saver(self, filename, **kwargs)
   1059 
   1060     def __repr__(self):

~/Dropbox/Mac/Documents/Vanderbilt/Research/gmso/gmso/formats/lammpsdata.py in write_lammpsdata(topology, filename, atom_style)
    187                     "{}\t{:.5f}\t{:.5f}\n".format(
    188                         idx + 1,
--> 189                         param.parameters["epsilon"]
    190                         .in_units(u.Unit("kcal/mol"))
    191                         .value,

KeyError: 'epsilon'


**Software versions**

- Which version of Foyer are you using? (`python -c "import foyer; print(foyer.version)"`)
0.10.0
- Which version of Python (`python --version`)?
3.7
- Which operating system?
- MacOS Catalina 10.15.7
CalCraven commented 2 years ago

Here is what it looks like when I convert the expression directly from Foyer: image

Here is what it looks like when I convert the expression through Parmed: image