MolSSI / QCEngine

Quantum chemistry program executor and IO standardizer (QCSchema).
https://molssi.github.io/QCEngine/
BSD 3-Clause "New" or "Revised" License
162 stars 78 forks source link

2D torsion scan #439

Open xiki-tempula opened 6 months ago

xiki-tempula commented 6 months ago

Describe the bug I tried to run 2D torsion scan but failed.

To Reproduce

import numpy as np
from openff.toolkit import Molecule, ForceField
import qcengine
from qcelemental.models.procedures import TorsionDriveInput, TDKeywords, QCInputSpecification, OptimizationSpecification

# load the molecule
lig = Molecule.from_file('lig_ejm_55.sdf')
# load the combined bespokefit force field
ff = ForceField('combined.offxml')

# now make the scan job
torsion_task = TorsionDriveInput(
    keywords=TDKeywords(
        dihedrals=[(4, 10, 16, 12), (4, 7, 15, 11)],
        grid_spacing=[15,15]
    ),
    initial_molecule=[
        lig.to_qcschema()
    ],
    input_specification=QCInputSpecification(
        model={'method': 'combined.offxml', 'basis': 'smirnoff'},
    ),
    optimization_spec=OptimizationSpecification(
        procedure='geometric',
        keywords={
            'program': 'openmm',
            'coordsys': 'dlc',
            'enforce': 0.1,
            'reset': True,
            'qccnv': True,
            'epsilon': 0.0
        }
    )
)

result = qcengine.compute_procedure(torsion_task, 'torsiondrive', raise_error=True)
with open('combined_2D_scan.json', 'w') as output:
    output.write(result.json())

Expected behavior It runs.

Additional context I got the error

Traceback (most recent call last):
  File "/Users/zwu/mambaforge/envs/danny/lib/python3.11/site-packages/IPython/core/interactiveshell.py", line 3550, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-3991d0bf5926>", line 1, in <module>
    runfile('/Users/zwu/Desktop/Torsion/openff/run_torsion_drive.py', wdir='/Users/zwu/Desktop/Torsion/openff')
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/zwu/Desktop/Torsion/openff/run_torsion_drive.py", line 41, in <module>
    result = qcengine.compute_procedure(torsion_task, 'torsiondrive', raise_error=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/zwu/mambaforge/envs/danny/lib/python3.11/site-packages/qcengine/compute.py", line 179, in compute_procedure
    output_data = executor.compute(input_data, config)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/zwu/mambaforge/envs/danny/lib/python3.11/site-packages/qcengine/procedures/torsiondrive.py", line 138, in compute
    output_data = self._compute(input_model, config)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/zwu/mambaforge/envs/danny/lib/python3.11/site-packages/qcengine/procedures/torsiondrive.py", line 70, in _compute
    grid_point_results = self._spawn_optimizations(next_jobs=next_jobs, input_model=input_model, config=config)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/zwu/mambaforge/envs/danny/lib/python3.11/site-packages/qcengine/procedures/torsiondrive.py", line 228, in _spawn_optimizations
    grid_point_results = {
                         ^
  File "/Users/zwu/mambaforge/envs/danny/lib/python3.11/site-packages/qcengine/procedures/torsiondrive.py", line 229, in <dictcomp>
    grid_point: [self._spawn_optimization(grid_point, job, input_model, config) for job in jobs]
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/zwu/mambaforge/envs/danny/lib/python3.11/site-packages/qcengine/procedures/torsiondrive.py", line 229, in <listcomp>
    grid_point: [self._spawn_optimization(grid_point, job, input_model, config) for job in jobs]
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/zwu/mambaforge/envs/danny/lib/python3.11/site-packages/qcengine/procedures/torsiondrive.py", line 189, in _spawn_optimization
    "set": [
           ^
  File "/Users/zwu/mambaforge/envs/danny/lib/python3.11/site-packages/qcengine/procedures/torsiondrive.py", line 193, in <listcomp>
    "value": int(angle),
             ^^^^^^^^^^
ValueError: invalid literal for int() with base 10: '15,180'

I think one should change https://github.com/MolSSI/QCEngine/blob/master/qcengine/procedures/torsiondrive.py#L184 to angles = grid_point.split(',') lig_ejm_55.sdf.zip