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

Allow kwargs to be passed to force field generators (and then to SMIRNOFF ForceField) #112

Open
aclyde11 opened this issue May 7, 2020 · 5 comments
Milestone

Comments

@aclyde11
Copy link

aclyde11 commented May 7, 2020

It seems forcefield_kwargs is not being propagated sometimes. I've fixed this error below by editing

File "openmmforcefields/generators/template_generators.py", line 1112, in generate_residue_template
    system = self._smirnoff_forcefield.create_openmm_system(molecule.to_topology(), charge_from_molecules=charge_from_molecules)

to

system = self._smirnoff_forcefield.create_openmm_system(molecule.to_topology(), charge_from_molecules=charge_from_molecules, allow_nonintegral_charges = True)

as a hack-y fix.

This is the error I typically get without the fix

openmm_system_generator = SystemGenerator(forcefields=forcefields,
                                                  molecules=[self.mol],
                                                  small_molecule_forcefield=small_molecule_forcefield,
                                                  forcefield_kwargs={'allow_nonintegral_charges' : True})
2020-05-07 14:35:51,119 - openmmforcefields.generators.template_generators - INFO - Requested to generate parameters for residue <Residue 165 (UNL) of chain 1>
2020-05-07 14:35:51,130 - openmmforcefields.generators.template_generators - INFO - Generating a residue template for [H]C1=NN(c2c1c(nc(n2)N([H])[H])N3C(C(C(C(C3([H])[H])([H])[H])([H])C([H])([H])N4C(=C(N=N4)C5(C(C5([H])[H])([H])[H])[H])O[H])([H])[H])([H])[H])[H]
2020-05-07 14:35:51,235 - openforcefield.typing.engines.smirnoff.parameters - INFO - 93 angles added (0 skipped due to constraints)
2020-05-07 14:35:51,427 - openforcefield.typing.engines.smirnoff.parameters - INFO - 51 bonds added (0 skipped due to constraints)
2020-05-07 14:35:51,541 - openforcefield.typing.engines.smirnoff.parameters - INFO - 11 impropers added, each applied in a six-fold trefoil
2020-05-07 14:35:51,917 - openforcefield.typing.engines.smirnoff.parameters - INFO - 144 torsions added
Traceback (most recent call last):
  File "rlmm/tests/test_env.py", line 105, in <module>
    test_load_test_system()
  File "rlmm/tests/test_env.py", line 85, in test_load_test_system
    env.step([0.05, 0.05, 0.05])
  File "/home/aclyde11/RLMM/rlmm/environment/openmmEnv.py", line 72, in step
    self.systemloader.reload_system(gs, test,"test.pdb")
  File "/home/aclyde11/RLMM/rlmm/environment/systemloader.py", line 142, in reload_system
    self.system = openmm_system_generator.create_system(modeller.topology)
  File "/homes/aclyde11/.conda/envs/rlmm/lib/python3.6/site-packages/openmmforcefields/generators/system_generators.py", line 307, in create_system
    system = self.forcefield.createSystem(topology, **forcefield_kwargs)
  File "/homes/aclyde11/.conda/envs/rlmm/lib/python3.6/site-packages/simtk/openmm/app/forcefield.py", line 1148, in createSystem
    templateForResidue = self._matchAllResiduesToTemplates(data, topology, residueTemplates, ignoreExternalBonds)
  File "/homes/aclyde11/.conda/envs/rlmm/lib/python3.6/site-packages/simtk/openmm/app/forcefield.py", line 1352, in _matchAllResiduesToTemplates
    if generator(self, res):
  File "/homes/aclyde11/.conda/envs/rlmm/lib/python3.6/site-packages/openmmforcefields/generators/template_generators.py", line 301, in generator
    ffxml_contents = self.generate_residue_template(molecule)
  File "/homes/aclyde11/.conda/envs/rlmm/lib/python3.6/site-packages/openmmforcefields/generators/template_generators.py", line 1112, in generate_residue_template
    system = self._smirnoff_forcefield.create_openmm_system(molecule.to_topology(), charge_from_molecules=charge_from_molecules)
  File "/homes/aclyde11/.conda/envs/rlmm/lib/python3.6/site-packages/openforcefield/typing/engines/smirnoff/forcefield.py", line 1142, in create_openmm_system
    parameter_handler.postprocess_system(system, topology, **kwargs)
  File "/homes/aclyde11/.conda/envs/rlmm/lib/python3.6/site-packages/openforcefield/typing/engines/smirnoff/parameters.py", line 2786, in postprocess_system
    raise NonintegralMoleculeChargeException(msg)
openforcefield.typing.engines.smirnoff.parameters.NonintegralMoleculeChargeException: Partial charge sum (-2.169999986886978 e) for molecule '_28' (SMILES [H]C1=NN(c2c1c(nc(n2)N([H])[H])N3C(C(C(C(C3([H])[H])([H])[H])([H])C([H])([H])N4C(=C(N=N4)C5(C(C5([H])[H])([H])[H])[H])O[H])([H])[H])([H])[H])[H] does not equal formal charge sum (0). To override this error, provide the 'allow_nonintegral_charges=True' keyword to ForceField.create_openmm_system
@jchodera
Copy link
Member

jchodera commented May 8, 2020

Oh, my! I never considered providing a mechanism to pass arguments to openforcefield.typing.engines.smirnoff.ForceField. I can provide a mechanism to do so, but it will be via a different optional argument to SystemGenerator, perhaps forcefield_generator_kwargs.

Out of curiosity, why would you have non-integral charges?

@jchodera jchodera changed the title passing forcefield kwargs through to _smirnoff_forcefield.create_openmm_system Allow kwargs to be passed to force field generators (and then to SMIRNOFF ForceField) May 8, 2020
@jchodera jchodera added this to the 0.8.0 milestone May 8, 2020
@aclyde11
Copy link
Author

aclyde11 commented May 8, 2020

@jchodera why do I have non-integral charges.... ask neural networks. Not sure why that happens. My guess is something gets messed up somewhere. I knew someone would ask when I posted, but I would guess this change would be useful for something relevant as well haha

@jchodera
Copy link
Member

jchodera commented May 8, 2020

You might check out this simple idea in which you ask the ML model to predict two physical parameters (electronegativity and hardness) per atom, and then solve a simple convex optimization problem inspired by a physical charge-equilibration model to determine the (integral) charges. In our hands, this works much better than trying to get the ML model to learn the integral charge constraint!

@ijpulidos ijpulidos modified the milestones: 0.8.0, 0.11.3 Jul 7, 2023
@ijpulidos ijpulidos modified the milestones: 0.11.3, 0.11.4 Sep 23, 2023
@ijpulidos
Copy link
Collaborator

A mechanism for this has been added for the EspalomaTemplateGenerator in #293 that can be used for the other template generators, but we need to make sure the SMIRNOFFTemplateGenerator know how to handle the parameters given through this mechanism.

@mattwthompson
Copy link
Collaborator

#296 related, if I understand both accurately

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants