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

OpenMMSolutionGen().get_input_set(...) ValueError #16

Open
xperrylinn opened this issue Mar 25, 2023 · 3 comments
Open

OpenMMSolutionGen().get_input_set(...) ValueError #16

xperrylinn opened this issue Mar 25, 2023 · 3 comments
Assignees

Comments

@xperrylinn
Copy link
Collaborator

xperrylinn commented Mar 25, 2023

Hey @orionarcher,

I'm running the code below and where I get a ValueError from within OpenFF stating there aren't any registered toolkits can provide the capability "assign_partial_charges":

>>> from pymatgen.io.openmm.schema import InputMoleculeSpec
>>> from pymatgen.io.openmm.generators import OpenMMSolutionGen
>>> 
>>> water_input_mol_spec = InputMoleculeSpec(name="water", smile="O", count=1)
>>> 
>>> input_set = OpenMMSolutionGen().get_input_set(input_mol_dicts=[water_input_mol_spec])
/Users/xperrylinn/miniconda3/envs/atomate2-openmm/bin/wrapped_progs/antechamber: Fatal Error!
Cannot properly run "/Users/xperrylinn/miniconda3/envs/atomate2-openmm/bin/sqm -O -i sqm.in -o sqm.out".
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/xperrylinn/miniconda3/envs/atomate2-openmm/lib/python3.8/site-packages/pymatgen/io/openmm/generators.py", line 196, in get_input_set
    openff_mol.assign_partial_charges(self.default_charge_method)
  File "/Users/xperrylinn/miniconda3/envs/atomate2-openmm/lib/python3.8/site-packages/openff/toolkit/topology/molecule.py", line 2503, in assign_partial_charges
    toolkit_registry.call(
  File "/Users/xperrylinn/miniconda3/envs/atomate2-openmm/lib/python3.8/site-packages/openff/toolkit/utils/toolkit_registry.py", line 370, in call
    raise ValueError(msg)
ValueError: No registered toolkits can provide the capability "assign_partial_charges" for args "()" and kwargs "{'molecule': Molecule with name '' and SMILES '[H][O][H]', 'partial_charge_method': 'am1bcc', 'use_conformers': None, 'strict_n_conformers': False, 'normalize_partial_charges': True, '_cls': <class 'openff.toolkit.topology.molecule.Molecule'>}"
Available toolkits are: [ToolkitWrapper around The RDKit version 2022.09.5, ToolkitWrapper around AmberTools version 22.0, ToolkitWrapper around Built-in Toolkit version None]
 ToolkitWrapper around The RDKit version 2022.09.5 <class 'openff.toolkit.utils.exceptions.ChargeMethodUnavailableError'> : partial_charge_method 'am1bcc' is not available from RDKitToolkitWrapper. Available charge methods are ['mmff94', 'gasteiger'] 
 ToolkitWrapper around AmberTools version 22.0 <class 'subprocess.CalledProcessError'> : Command '['antechamber', '-i', 'molecule.sdf', '-fi', 'sdf', '-o', 'charged.mol2', '-fo', 'mol2', '-pf', 'yes', '-dr', 'n', '-c', 'bcc', '-nc', '0.0']' returned non-zero exit status 1.
 ToolkitWrapper around Built-in Toolkit version None <class 'openff.toolkit.utils.exceptions.ChargeMethodUnavailableError'> : Partial charge method "am1bcc"" is not supported by the Built-in toolkit. Available charge methods are ['zeros', 'formal_charge']

I poked through the files referenced in the traceback and it seems like I need to have one of the supporting dependencies installed for one of the toolkit wrappers, so I conda installed rdkit. I then realized the OpenMMSolutionGen.default_charge_method default parameter is not compatible with all possible tool toolkit wrappers. I updated the instantiation to look like OpenMMSolutionGen(default_charge_method="mmff94") and this seems to have unsnagged this bit. Is this expected?

Following that snag, I'm now snagging on this:

Traceback (most recent call last):
  File "/Users/xperrylinn/miniconda3/envs/atomate2-openmm/lib/python3.8/site-packages/jobflow/managers/local.py", line 98, in _run_job
    response = job.run(store=store)
  File "/Users/xperrylinn/miniconda3/envs/atomate2-openmm/lib/python3.8/site-packages/jobflow/core/job.py", line 544, in run
    response = function(*self.function_args, **self.function_kwargs)
  File "/Users/xperrylinn/Documents/Academics/MSSE/spring_2023/Capstone/atomate2-openmm/src/atomate2/openmm/jobs/core.py", line 63, in make
    input_set = OpenMMSolutionGen(default_charge_method="mmff94").get_input_set(
  File "/Users/xperrylinn/miniconda3/envs/atomate2-openmm/lib/python3.8/site-packages/pymatgen/io/openmm/generators.py", line 222, in get_input_set
    coordinates = get_coordinates(
  File "/Users/xperrylinn/miniconda3/envs/atomate2-openmm/lib/python3.8/site-packages/pymatgen/io/openmm/utils.py", line 202, in get_coordinates
    pw = PackmolBoxGen(seed=random_seed).get_input_set(
  File "/Users/xperrylinn/miniconda3/envs/atomate2-openmm/lib/python3.8/site-packages/pymatgen/io/packmol.py", line 225, in get_input_set
    return PackmolSet(
TypeError: Can't instantiate abstract class PackmolSet with abstract methods from_directory

How can I understand what's happening here?

@orionarcher
Copy link
Owner

I am quite confused by this. PackmolSet is not an abstract class nor is it being instantiated with from_directory.

Are you getting the tests to pass locally or are they currently failing?

I ran the same code and ran into two errors, though not the one you described. First, the density argument was missing in get_input_set and second the box was too small, I believe it has to be around 15 Angstrom to be large enough to be instantiated by OpenMM. I made these modifications and it started working for me

    from pymatgen.io.openmm.schema import InputMoleculeSpec
    from pymatgen.io.openmm.generators import OpenMMSolutionGen

    water_input_mol_spec = InputMoleculeSpec(name="water", smile="O", count=100)

    input_set = OpenMMSolutionGen().get_input_set(input_mol_dicts=[water_input_mol_spec], density=0.2)

@xperrylinn
Copy link
Collaborator Author

xperrylinn commented Mar 26, 2023

The tests are failing for me. I created a new Python 3.8 conda environment dedicated for the pymatgen-io-openmm repo and after working through installing the required dependencies, I ran the tests and they are failing: 28 failed, 28 passed, 24 warnings, 2 errors in 25.02s. I've sampled some of the failures below. I've attached my conda environment YAML export (as a .txt file because GitHub doesn't allow you to upload YAML). This feels like an issue related to setup.
environment.txt

E       TypeError: get_disconnected_fragments() got an unexpected keyword argument 'return_index_map'
E       TypeError: Can't instantiate abstract class PackmolSet with abstract methods from_directory
E       ValueError: No registered toolkits can provide the capability "assign_partial_charges" for args "()" and kwargs "{'molecule': Molecule with name '' and SMILES '[H][O][H]', 'partial_charge_method': 'am1bcc', 'use_conformers': None, 'strict_n_conformers': False, 'normalize_partial_charges': True, '_cls': <class 'openff.toolkit.topology.molecule.Molecule'>}"
E       Available toolkits are: [ToolkitWrapper around The RDKit version 2022.09.5, ToolkitWrapper around AmberTools version 22.0, ToolkitWrapper around Built-in Toolkit version None]
E        ToolkitWrapper around The RDKit version 2022.09.5 <class 'openff.toolkit.utils.exceptions.ChargeMethodUnavailableError'> : partial_charge_method 'am1bcc' is not available from RDKitToolkitWrapper. Available charge methods are ['gasteiger', 'mmff94'] 
E        ToolkitWrapper around AmberTools version 22.0 <class 'subprocess.CalledProcessError'> : Command '['antechamber', '-i', 'molecule.sdf', '-fi', 'sdf', '-o', 'charged.mol2', '-fo', 'mol2', '-pf', 'yes', '-dr', 'n', '-c', 'bcc', '-nc', '0.0']' returned non-zero exit status 1.
E        ToolkitWrapper around Built-in Toolkit version None <class 'openff.toolkit.utils.exceptions.ChargeMethodUnavailableError'> : Partial charge method "am1bcc"" is not supported by the Built-in toolkit. Available charge methods are ['zeros', 'formal_charge']

@xperrylinn
Copy link
Collaborator Author

@orionarcher, steps for creating the Python 3.9 environment that is failing at running pytest:

  1. conda create -n pymatgen-io-openmm python=3.9
  2. conda activate pymatgen-io-openmm
  3. pip install pymatgen
  4. conda install -c conda-forge openmm parmed numpy pytest openbabel rdkit pydantic openff-toolkit packmol openmmforcefields
  5. conda install -c conda-forge MDAnalysis
  6. pytest .

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

No branches or pull requests

2 participants