SCM-NV / qmflows

This library tackles the construction and efficient execution of computational chemistry workflows
Other
45 stars 9 forks source link

Create a Package subclass for handling CP2K CHARMM forcefields #148

Closed BvB93 closed 4 years ago

BvB93 commented 4 years ago

Example input

>>> from qmflows import Settings, cp2k_mm, geometry
>>> from scm.plams import Molecule

>>> mol = Molecule(...)

# The charges; these will override anything specified in the .psf file
>>> charge = Settings({'param': 'charge'})
>>> charge.Cd = 0.9768
>>> charge.Se = -0.9768

# The Lennard-Jones epsilon and sigma paramters
>>> lj = Settings({'param': 'epsilon', 'sigma'})
>>> lj.unit = 'kcalmol', 'angstrom'
>>> lj['Cd Cd'] = 0.0741, 1.2340
>>> lj['Cd Se'] = 0.3639, 2.9400
>>> lj['Se Se'] = 0.1020, 4.8520

# Combine the settings
>>> s = Settings()
>>> s.periodic = 'NONE'  # This is the default
>>> s.psf = '/path/to/my/psf/file'
>>> s.prm = '/path/to/my/prm/file'
>>> s.lennard_jones = lj
>>> s.charge = charge

# Apply the geometry template
>>> s.specific.cp2k += geometry.specific.cp2k_mm

>>> job = cp2k_mm(settings=s, mol=mol)
>>> result = run(job)
BvB93 commented 4 years ago

Proposed syntax for forcefield parameters as inspired by those in Auto-FOX:

>>> from qmflows import Settings

>>> s = Settings()
>>> s.specific.cp2k.sigma = Settings({
... 'key_path': ('specific', 'cp2k', 'force_eval', 'mm', 'forcefield', 'nonbonded', 'lennard-jones')
... 'unit': 'angstrom'
... 'Cd': '3.0'
... 'Se': 2.5
... 'O': 2
... })
>>> s.specific.cp2k.epsilon = Settings({
... 'key_path': ('specific', 'cp2k', 'force_eval', 'mm', 'forcefield', 'nonbonded', 'lennard-jones')
... 'Cd': '12.0'
... 'Se': 3.5
... 'O': 8
... })

In the proposed syntax each parameter block consists of three different type of keys:

BvB93 commented 4 years ago

Open question: what would be best name for the "key_path" keyword (tentative name) as described above? Solved as of https://github.com/SCM-NV/qmflows/issues/148#issuecomment-596585344.

BvB93 commented 4 years ago

Updated the parameter syntax in https://github.com/SCM-NV/qmflows/commit/4f086061d9454f834f208913bf8bdc00356739a3: Moved "key_path" to the main key and moved the specific CP2K keys to "param". Dictionary values can now be supplied as a either scalars or sequences but cannot be freely mixed.

>>> lennard_jones = {  # Example 1
...     'param': ('epsilon', 'sigma'),
...     'unit': ('kcalmol', 'angstrom'),  # An optional key
...     'Cs': (1, 1),
...     'Cd': (2, 2),
...     'O': (3, 3),
...     'H': (4, 4)
... }

>>> lennard_jones = [  # Example 2
... {'param': 'epsilon',
...  'unit': 'kcalmol',  # An optional key
...  'Cs': 1,
...  'Cd': 2,
...  'O': 3,
...  'H': 4},
... {'param': 'sigma',
...  'unit': 'angstrom',  # An optional key
...  'Cs': 1,
...  'Cd': 2,
...  'O': 3,
...  'H': 4}
... ]

Note that both examples result in equivalent settings.

BvB93 commented 4 years ago

Introduced in https://github.com/SCM-NV/qmflows/pull/150. See https://github.com/SCM-NV/qmflows/issues/159 for further updates and new features.