openmm / openmmforcefields

CHARMM and AMBER forcefields for OpenMM (with small molecule support)
http://openmm.org
Other
254 stars 80 forks source link

"No template found for residue..." Error #297

Closed jaketanderson closed 1 year ago

jaketanderson commented 1 year ago

Hi, I'm trying to use openmmforcefields to simulate a mixture of (GAFF-parameterized) TMAO and tip3p waters. I've tried following the steps on the README but I cannot get rid of "ValueError: No template found for residue 11 (TMA)" errors. I've tried keeping the TMAO residue as UNL (the default using openbabel), I've tried creating the openff molecule from an SDF file, and I've ensured that the CONECT information is in all my PDB files before using Packmol to create the mixture PDB. I'm at a loss here and would really appreciate some guidance!

Simulation:

from openmm.app import *
from openmm import *
from openmm.unit import *
from sys import stdout

from openff.toolkit.topology import Molecule
molecule = Molecule.from_pdb_and_smiles("../setup/TMAO.pdb", "C[N+](C)(C)[O-]")

from openmmforcefields.generators import GAFFTemplateGenerator
gaff = GAFFTemplateGenerator(molecules=molecule)

forcefield = ForceField('amber/tip3pfb_standard.xml', 'amber/tip3pfb_HFE_multivalent.xml')
forcefield.registerTemplateGenerator(gaff.generator)
gaff.generate_residue_template(molecule)

pdb = PDBFile('../setup/mixture.pdb')
sys = forcefield.createSystem(pdb.topology)

Preparation:

packmol.input

#
# A mixture of water and TMAO
#

tolerance 2.0

filetype pdb

output mixture.pdb
connect yes

structure water.pdb 
  number 10
  inside box 0. 0. 0. 80. 80. 80. 
end structure

structure TMAO.pdb
  number 1
  inside box 0. 0. 0. 80. 80. 80. 
end structure

water.pdb

COMPND    HOH
AUTHOR    GENERATED BY OPEN BABEL 3.1.0
HETATM    1  O   HOH     1       0.994   0.071   0.066  1.00  0.00           O  
HETATM    2  H1  HOH     1       1.962   0.040   0.101  1.00  0.00           H  
HETATM    3  H2  HOH     1       0.716  -0.550   0.756  1.00  0.00           H  
CONECT    1    2    3                                                 
CONECT    2    1                                                      
CONECT    3    1                                                      
MASTER        0    0    0    0    0    0    0    0    3    0    3    0
END

TMAO.pdb

HEADER
REMARK  99                                                                      
REMARK  99 MOE v2020.09 (Chemical Computing Group ULC) Wed Aug 16 14:01:14 2023 
HETATM    1  C   TMA     0       2.778  -0.080  -0.540  1.00  0.00           C
HETATM    2  N   TMA     0       1.459   0.049   0.265  1.00  0.00           N1+
HETATM    3  C   TMA     0       1.461   1.584   0.218  1.00  0.00           C
HETATM    4  C   TMA     0       0.261  -0.082  -0.710  1.00  0.00           C
HETATM    5  O   TMA     0       1.452  -1.201   0.397  1.00  0.00           O1-
HETATM    6  H1  TMA     0       3.017   0.719  -1.229  1.00  0.00           H
HETATM    7  H2  TMA     0       2.869  -0.972  -1.153  1.00  0.00           H
HETATM    8  H3  TMA     0       3.635  -0.120   0.118  1.00  0.00           H
HETATM    9  H1  TMA     0       2.274   2.020   0.783  1.00  0.00           H
HETATM   10  H2  TMA     0       0.579   2.018   0.671  1.00  0.00           H
HETATM   11  H3  TMA     0       1.525   2.045  -0.761  1.00  0.00           H
HETATM   12  H1  TMA     0       0.119   0.713  -1.429  1.00  0.00           H
HETATM   13  H2  TMA     0      -0.678  -0.116  -0.174  1.00  0.00           H
HETATM   14  H3  TMA     0       0.250  -0.978  -1.325  1.00  0.00           H
CONECT    1    2    6    7    8
CONECT    2    1    3    4    5
CONECT    3    2    9   10   11
CONECT    4    2   12   13   14
CONECT    5    2
CONECT    6    1
CONECT    7    1
CONECT    8    1
CONECT    9    3
CONECT   10    3
CONECT   11    3
CONECT   12    4
CONECT   13    4
CONECT   14    4
END

mixture.pdb

HEADER 
TITLE     Built with Packmol                                             
REMARK   Packmol generated pdb file 
REMARK   Home-Page: http://m3g.iqm.unicamp.br/packmol
REMARK
HETATM    1  O   HOH A   1      36.818  20.864  52.708  1.00  0.00           O  
HETATM    2  H1  HOH A   1      36.688  19.906  52.638  1.00  0.00           H  
HETATM    3  H2  HOH A   1      37.212  21.108  51.857  1.00  0.00           H  
HETATM    4  O   HOH A   2      52.649  14.294  57.800  1.00  0.00           O  
HETATM    5  H1  HOH A   2      52.523  15.224  58.042  1.00  0.00           H  
HETATM    6  H2  HOH A   2      53.310  13.977  58.434  1.00  0.00           H  
HETATM    7  O   HOH A   3      37.844  40.550  69.267  1.00  0.00           O  
HETATM    8  H1  HOH A   3      37.368  41.347  69.545  1.00  0.00           H  
HETATM    9  H2  HOH A   3      37.569  40.424  68.347  1.00  0.00           H  
HETATM   10  O   HOH A   4      56.705  24.553  15.266  1.00  0.00           O  
HETATM   11  H1  HOH A   4      55.943  24.455  15.856  1.00  0.00           H  
HETATM   12  H2  HOH A   4      56.659  23.771  14.695  1.00  0.00           H  
HETATM   13  O   HOH A   5      63.606  66.016  41.551  1.00  0.00           O  
HETATM   14  H1  HOH A   5      62.881  66.292  40.970  1.00  0.00           H  
HETATM   15  H2  HOH A   5      63.463  66.527  42.362  1.00  0.00           H  
HETATM   16  O   HOH A   6      40.477  44.772  30.262  1.00  0.00           O  
HETATM   17  H1  HOH A   6      40.646  43.856  29.995  1.00  0.00           H  
HETATM   18  H2  HOH A   6      41.346  45.099  30.537  1.00  0.00           H  
HETATM   19  O   HOH A   7      41.809  54.797   8.137  1.00  0.00           O  
HETATM   20  H1  HOH A   7      42.722  54.475   8.151  1.00  0.00           H  
HETATM   21  H2  HOH A   7      41.805  55.457   7.427  1.00  0.00           H  
HETATM   22  O   HOH A   8      60.341  67.903  22.677  1.00  0.00           O  
HETATM   23  H1  HOH A   8      59.998  67.030  22.922  1.00  0.00           H  
HETATM   24  H2  HOH A   8      61.231  67.719  22.343  1.00  0.00           H  
HETATM   25  O   HOH A   9      52.652  63.762  26.810  1.00  0.00           O  
HETATM   26  H1  HOH A   9      52.362  62.842  26.905  1.00  0.00           H  
HETATM   27  H2  HOH A   9      52.753  63.877  25.853  1.00  0.00           H  
HETATM   28  O   HOH A  10      41.346  16.006  16.906  1.00  0.00           O  
HETATM   29  H1  HOH A  10      42.065  16.436  16.418  1.00  0.00           H  
HETATM   30  H2  HOH A  10      40.582  16.581  16.748  1.00  0.00           H  
HETATM   31  C   TMA B   1       0.815   2.645  77.501  1.00  0.00           C  
HETATM   32  N   TMA B   1       2.307   2.451  77.878  1.00  0.00           N1+
HETATM   33  C   TMA B   1       2.071   1.077  78.521  1.00  0.00           C  
HETATM   34  C   TMA B   1       3.061   1.866  76.657  1.00  0.00           C  
HETATM   35  O   TMA B   1       2.538   3.604  77.433  1.00  0.00           O1-
HETATM   36  H1  TMA B   1       0.227   1.752  77.336  1.00  0.00           H  
HETATM   37  H2  TMA B   1       0.629   3.234  76.608  1.00  0.00           H  
HETATM   38  H3  TMA B   1       0.280   3.168  78.282  1.00  0.00           H  
HETATM   39  H1  TMA B   1       1.475   1.132  79.422  1.00  0.00           H  
HETATM   40  H2  TMA B   1       2.988   0.608  78.855  1.00  0.00           H  
HETATM   41  H3  TMA B   1       1.583   0.326  77.910  1.00  0.00           H  
HETATM   42  H1  TMA B   1       2.812   0.857  76.359  1.00  0.00           H  
HETATM   43  H2  TMA B   1       4.127   1.825  76.838  1.00  0.00           H  
HETATM   44  H3  TMA B   1       2.968   2.428  75.732  1.00  0.00           H  
CONECT    1    2    3
CONECT    2    1
CONECT    3    1
CONECT    4    5    6
CONECT    5    4
CONECT    6    4
CONECT    7    8    9
CONECT    8    7
CONECT    9    7
CONECT   10   11   12
CONECT   11   10
CONECT   12   10
CONECT   13   14   15
CONECT   14   13
CONECT   15   13
CONECT   16   17   18
CONECT   17   16
CONECT   18   16
CONECT   19   20   21
CONECT   20   19
CONECT   21   19
CONECT   22   23   24
CONECT   23   22
CONECT   24   22
CONECT   25   26   27
CONECT   26   25
CONECT   27   25
CONECT   28   29   30
CONECT   29   28
CONECT   30   28
CONECT   31   32   36   37   38
CONECT   32   31   33   34   35
CONECT   33   32   39   40   41
CONECT   34   32   42   43   44
CONECT   35   32
CONECT   36   31
CONECT   37   31
CONECT   38   31
CONECT   39   33
CONECT   40   33
CONECT   41   33
CONECT   42   34
CONECT   43   34
CONECT   44   34
END
mattwthompson commented 1 year ago

Does the order here matter?


forcefield.registerTemplateGenerator(gaff.generator)
gaff.generate_residue_template(molecule)
jaketanderson commented 1 year ago

Does the order here matter?

forcefield.registerTemplateGenerator(gaff.generator)
gaff.generate_residue_template(molecule)

Unfortunately swapping these two lines does not fix the issue. The README example for GAFF actually does not use the first line at all, but I added it to see if it works as a fix. It does not seem to.

mattwthompson commented 1 year ago

You probably don't need the PDB file for system generation at all; you can create the (OpenMM)` topology just with OpenFF objects, and then later on set the positions on the context.

This code runs without error, I figure it can be extended to run a simulation. I forget if the system needs residue information or the topology, in which case that might still need to be set.


In [3]: from openmm.app import ForceField
   ...: from openff.toolkit import Molecule, Topology
   ...:
   ...: molecule = Molecule.from_smiles("C[N+](C)(C)[O-]")
   ...: water = Molecule.from_smiles("O")
   ...:
   ...: from openmmforcefields.generators import GAFFTemplateGenerator
   ...:
   ...: gaff = GAFFTemplateGenerator(molecules=molecule)
   ...:
   ...: forcefield = ForceField(
   ...:     "amber/tip3pfb_standard.xml", "amber/tip3pfb_HFE_multivalent.xml"
   ...: )
   ...: forcefield.registerTemplateGenerator(gaff.generator)
   ...: gaff.generate_residue_template(molecule)
   ...:
   ...: topology = Topology.from_molecules([water, water, molecule])  # add more waters as you wish
   ...: sys = forcefield.createSystem(topology.to_openmm())
jaketanderson commented 1 year ago

Thanks very much @mattwthompson! I've got it up and running with your suggestion of making the topology in OpenFF and combining it with the PDB's positions.