Skip to content
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

Changing ff causes error in apply_forcefield method #154

Open
marjanalbooyeh opened this issue Jul 23, 2024 · 0 comments
Open

Changing ff causes error in apply_forcefield method #154

marjanalbooyeh opened this issue Jul 23, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@marjanalbooyeh
Copy link
Collaborator

Bug description:

When building a molecule and initializing the system, if we call the apply_forcefield() function with a forcefield and then call it again with a different forcefield, this error pops up:

"Forcefield is not provided. Valid forcefield must be provided either during Molecule initialization or when calling the "
"`apply_forcefield` method of the System class."

Here's the code to replicate the error:

from flowermd.base import Molecule, Pack
from flowermd.library import OPLS_AA, GAFF

mol = Molecule(num_mols=1, smiles="CCC")
system = Pack(molecules=mol, density=0.5, packing_expand_factor=5)
system.apply_forcefield(r_cut=2.5, force_field=OPLS_AA(), auto_scale=True, scale_charges=True)

system.apply_forcefield(r_cut=2.5, force_field=GAFF(), auto_scale=True, scale_charges=True)

Potential cause:
This error is coming from the _validate_forcefield(). When a forcefield is specified for the first time, that forcefield will be added to self._gmso_forcefields_dict in the system class. If we try to rerun the apply_forcefield() with a different forcefield, there will be a mistmatch between that dictionary and the new forcefield. That will cause the exception to raise. We originally put that check so that users stick to the same forcefield during initialization. This would make sense when the apply_forcefield() function did parameterize the system correctly.
However, for a case where the apply_forcefield() didn't work the first time (due to some missing parameter in opls ff) and user wants to try a different ff like GAFF, that's where this becomes an issue. This is the scenario that Lauren @lestes1118 tried and got this error.

My first suggestion is to re-evaluate the _validate_forcefield() function and make sure the checks are still valid, specially since we changed the apply_forcefield() interface a few times before finalizing it.

@marjanalbooyeh marjanalbooyeh added the bug Something isn't working label Jul 23, 2024
@marjanalbooyeh marjanalbooyeh self-assigned this Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant