Repository

ParmEd/ParmEd

Parameter/topology editor and molecular simulator
245 120 30 596

Error writing out prmtop file from OpenMM system

I am trying to write out a prmtop file from an OpenMM system. However, we are getting an error when we try to save the file. Here is an example of the code:

import parmed as pmd
import openmm
import os

forcefield = openmm.app.ForceField('amber14-all.xml','amber14/tip3pfb.xml')
pdb = openmm.app.PDBFile(receptor_path)
modeller = openmm.app.Modeller(pdb.topology, pdb.positions)
modeller.addSolvent(forcefield, padding=0.9*openmm.unit.nanometers, positiveIon='Na+', negativeIon='Cl-',
                    ionicStrength=0.1*openmm.unit.molar) 
solvated_system = forcefield.createSystem(modeller.topology)
structure = pmd.openmm.load_topology( modeller.topology, solvated_system, modeller.positions)
structure.save(os.path.join(outPath,'complex_solvated_system.prmtop'), overwrite=True)
structure.save(os.path.join(outPath,'complex_solvated_system.inpcrd'), overwrite=True)

However, we get an error on the line that saves the .prmtop file.

Traceback (most recent call last):
  File "/lustre/scratch/code/generate_prmtop.py", line 165, in <module>
    structure.save(os.path.join(outPath,'complex_solvated_system.prmtop'), overwrite=True)
  File "/fslhome/anaconda3/envs/openmm/lib/python3.9/site-packages/parmed/structure.py", line 1507, in save
    s = amber.AmberParm.from_structure(self)
  File "/fslhome/anaconda3/envs/openmm/lib/python3.9/site-packages/parmed/amber/_amberparm.py", line 349, in from_structure
    inst.remake_parm()
  File "/fslhome/anaconda3/envs/openmm/lib/python3.9/site-packages/parmed/amber/_amberparm.py", line 676, in remake_parm
    self._xfer_bond_info()
  File "/fslhome/anaconda3/envs/openmm/lib/python3.9/site-packages/parmed/amber/_amberparm.py", line 1580, in _xfer_bond_info
    bond.type.used = True
AttributeError: 'NoneType' object has no attribute 'used'

We don't get this error when trying to save the same system without solvent, so it may have something to do with the solvent. Any ideas how to fix this? Thanks for the help!

2 Comments

  1. You're using a rigid water model and adopt the default behavior for constraints which is to adopt rigid water (3-constraint waters). By default, ForceField does not add bond parameters to the system when constraining those degrees of freedom. As a result, ParmEd cannot assign that bond type (it remains None) and the (admittedly obscure) error appears.

    Fortunately, forcefield.createSystem supports a flexibleConstraints keyword that will force OpenMM to add constrained parameters to the system. So this issue should be resolved by changing

    solvated_system = forcefield.createSystem(modeller.topology)

    to

    solvated_system = forcefield.createSystem(modeller.topology, flexibleConstraints=True)

    in your code snippet.