Page 1 of 1

python module "openforcefield" for small molecule residue template generators

Posted: Fri Mar 26, 2021 1:00 am
by gudrungygli
Dear OpenMM team,

I am a first time user of openMM, trying to use the "small residue template generator", as described in section "3.6.3.1. Small molecule residue template generators" of the tutorial here: http://docs.openmm.org/latest/userguide ... generators
to be able to run simulations of an enzyme with a ThDP cofactor (https://en.wikipedia.org/wiki/Thiamine_pyrophosphate)

Unfortunately, this does not work:

Code: Select all

python ThDP_creation.py 
Traceback (most recent call last):
  File "ThDP_creation.py", line 2, in <module>
    from openforcefield.topology import Molecule
ModuleNotFoundError: No module named 'openforcefield'
Trying to install the openforcefield module fails:

Code: Select all

conda install - conda-forge openforcefield
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.

PackagesNotFoundError: The following packages are not available from current channels:

  - -
  - conda-forge
  - openforcefield

Current channels:

  - https://conda.anaconda.org/conda-forge/linux-64
  - https://conda.anaconda.org/conda-forge/noarch
  - https://repo.anaconda.com/pkgs/main/linux-64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/linux-64
  - https://repo.anaconda.com/pkgs/r/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.
I have installed all the openff packages I can find using

Code: Select all

conda search -f openf*

openff-evaluator               0.3.3    pyhd8ed1ab_0  conda-forge         
openff-evaluator               0.3.4    pyhd8ed1ab_0  conda-forge         
openff-forcefields             1.3.0    pyh44b312d_0  conda-forge         
openff-recharge                0.0.1    pyhd8ed1ab_0  conda-forge         
openff-toolkit                 0.9.0    pyh44b312d_0  conda-forge         
openff-toolkit                 0.9.0    pyhd8ed1ab_1  conda-forge         
openff-toolkit                 0.9.1    pyhd8ed1ab_1  conda-forge         
openff-toolkit-base            0.9.0    pyhd8ed1ab_1  conda-forge         
openff-toolkit-base            0.9.1    pyhd8ed1ab_1  conda-forge 
Your help solving this issue is greatly appreciated!

ThDP_creation.py:

Code: Select all

# Create an openforcefield Molecule object for benzene from SMILES
from openforcefield.topology import Molecule
molecule = Molecule.from_smiles('Cc2ncc(C[n+]1csc(CCOP(=O)(O)OP(=O)(O)O)c1C)c(N)n2')
# Create the SMIRNOFF template generator with the most up to date Open Force Field Initiative force field
from openmmforcefields.generators import SMIRNOFFTemplateGenerator
smirnoff = SMIRNOFFTemplateGenerator(molecules=molecule)
# Create an OpenMM ForceField object with AMBER ff14SB and TIP3P with compatible ions
from simtk.openmm.app import ForceField
forcefield = ForceField('amber/protein.ff14SB.xml', 'amber/tip3p_standard.xml', 'amber/tip3p_HFE_multivalent.xml')
# Register the SMIRNOFF template generator
forcefield.registerTemplateGenerator(smirnoff.generator)

Re: python module "openforcefield" for small molecule residue template generators

Posted: Fri Mar 26, 2021 9:24 am
by peastman
conda install - conda-forge openforcefield
The installation command given in the documentation is

Code: Select all

conda install -c conda-forge openmmforcefields
Notice the missing "c" and the different package name. You're telling it to install three packages called "-", "conda-forge", and "openforcefield". In fact you want to install a single package called "openmmforcefields" from the conda-forge channel.

Re: python module "openforcefield" for small molecule residue template generators

Posted: Mon Mar 29, 2021 1:04 am
by gudrungygli
Thank you, Peter, for catching the embarrassing typos!

Installation of the openmmforcefields package has now been successfull, but my python script still fails with the same error:

Code: Select all

python ThDP_creation.py 
Traceback (most recent call last):
  File "ThDP_creation.py", line 2, in <module>
    from openforcefield.topology import Molecule
ModuleNotFoundError: No module named 'openforcefield'
I cannot install a package "openforcefield":

Code: Select all

conda install -c conda-forge openforcefield
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.

PackagesNotFoundError: The following packages are not available from current channels:

  - openforcefield

Current channels:

  - https://conda.anaconda.org/conda-forge/linux-64
  - https://conda.anaconda.org/conda-forge/noarch
  - https://repo.anaconda.com/pkgs/main/linux-64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/linux-64
  - https://repo.anaconda.com/pkgs/r/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.
What package do I need to install to be able to load the required module?

Code: Select all

from openforcefield.topology import Molecule

Re: python module "openforcefield" for small molecule residue template generators

Posted: Mon Mar 29, 2021 8:09 pm
by jchodera
Apologies for the difficulties, and thanks for reporting this!

The Open Force Field Toolkit changed its namespace when it moved to conda-forge, from `openforcefield` to `openff`.
We have updated the `openmmforcefields` package README with updated instructions here:
https://github.com/openmm/openmmforcefields

However, it seems I neglected to update the OpenMM User Guide at the same time!

I'll do that now.

Let us know if the README examples don't work for you. You primarily need to change

Code: Select all

from openforcefield.topology import Molecule
to

Code: Select all

from openff.toolkit.topology import Molecule

Re: python module "openforcefield" for small molecule residue template generators

Posted: Wed Mar 31, 2021 2:23 am
by gudrungygli
Thanks for this, now the package is loading properly.

I am now trying to figure out how to properly create a forcefield object for my new molecule and store it as sdf or xml.
It appears I am using the SMIRNOFFTemplateGenerator wrong, or simply use the wrong name for the forcefield I want (amber ff14sb)?


ERRORS:

Code: Select all

python ThDP_creation.py 
Warning: Unable to load toolkit 'OpenEye Toolkit'. The Open Force Field Toolkit does not require the OpenEye Toolkits, and can use RDKit/AmberTools instead. However, if you have a valid license for the OpenEye Toolkits, consider installing them for faster performance and additional file format support: https://docs.eyesopen.com/toolkits/python/quickstart-python/linuxosx.html OpenEye offers free Toolkit licenses for academics: https://www.eyesopen.com/academic-licensing
Source amber/protein.ff14SB.xml.offxml could not be read. If this is a file, ensure that the path is correct.
If the file is present, ensure it is in a known SMIRNOFF encoding.
Valid formats are: ['XML']
Parsing failed with the following error:
not well-formed (invalid token): line 1, column 5

Traceback (most recent call last):
  File "/home/gug/anaconda3/lib/python3.8/site-packages/openmmforcefields/generators/template_generators.py", line 1005, in __init__
    self._smirnoff_forcefield = openff.toolkit.typing.engines.smirnoff.ForceField(filename)
  File "/home/gug/anaconda3/lib/python3.8/site-packages/openff/toolkit/typing/engines/smirnoff/forcefield.py", line 357, in __init__
    self.parse_sources(sources, allow_cosmetic_attributes=allow_cosmetic_attributes)
  File "/home/gug/anaconda3/lib/python3.8/site-packages/openff/toolkit/typing/engines/smirnoff/forcefield.py", line 901, in parse_sources
    smirnoff_data = self.parse_smirnoff_from_source(source)
  File "/home/gug/anaconda3/lib/python3.8/site-packages/openff/toolkit/typing/engines/smirnoff/forcefield.py", line 1135, in parse_smirnoff_from_source
    raise IOError(msg)
OSError: Source amber/protein.ff14SB.xml.offxml could not be read. If this is a file, ensure that the path is correct.
If the file is present, ensure it is in a known SMIRNOFF encoding.
Valid formats are: ['XML']
Parsing failed with the following error:
not well-formed (invalid token): line 1, column 5


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "ThDP_creation.py", line 16, in <module>
    test = SMIRNOFFTemplateGenerator(molecules=D7K, forcefield='amber/protein.ff14SB.xml')
  File "/home/gug/anaconda3/lib/python3.8/site-packages/openmmforcefields/generators/template_generators.py", line 1008, in __init__
    raise ValueError(f"Can't find specified SMIRNOFF force field ({forcefield}) in install paths")
ValueError: Can't find specified SMIRNOFF force field (amber/protein.ff14SB.xml) in install paths

ThDP_creaction.py

Code: Select all

# Create an openforcefield Molecule object for benzene from SMILES
from openff.toolkit.topology import Molecule
D7K = Molecule.from_smiles('Cc1nc(N)c(C[n+]2c(C)c(CCO[P@](O)(OP(O)(O)=O)=O)sc2)cn1')
# Create the SMIRNOFF template generator with the most up to date Open Force Field Initiative force field
from openmmforcefields.generators import SMIRNOFFTemplateGenerator
smirnoff = SMIRNOFFTemplateGenerator(molecules=D7K)
# Create an OpenMM ForceField object with AMBER ff14SB and TIP3P with compatible ions
from simtk.openmm.app import ForceField
forcefield = ForceField('amber/protein.ff14SB.xml', 'amber/tip3p_standard.xml', 'amber/tip3p_HFE_multivalent.xml')
# Register the SMIRNOFF template generator
forcefield.registerTemplateGenerator(smirnoff.generator)
# You can now parameterize an OpenMM Topology object that contains the specified molecule.
# forcefield will load the appropriate GAFF parameters when needed, and antechamber
# will be used to generate small molecule parameters on the fly.

test = SMIRNOFFTemplateGenerator(molecules=D7K, forcefield='amber/protein.ff14SB.xml')
test.add_molecules(D7K)

from simtk.openmm.app import PDBFile
pdbfile = PDBFile('MODEL_WITH_COFACTOR-processed.pdb')
system = forcefield.createSystem(pdbfile.topology)

Re: python module "openforcefield" for small molecule residue template generators

Posted: Thu Apr 01, 2021 6:13 pm
by peastman
It might be better to ask on the openmmforcefields Github repository: https://github.com/openmm/openmmforcefields.