ppqm 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. ppqm-0.1.0/LICENSE +21 -0
  2. ppqm-0.1.0/PKG-INFO +115 -0
  3. ppqm-0.1.0/env/bin/activate_this.py +59 -0
  4. ppqm-0.1.0/ppqm/__init__.py +7 -0
  5. ppqm-0.1.0/ppqm/calculator.py +110 -0
  6. ppqm-0.1.0/ppqm/chembridge.py +1211 -0
  7. ppqm-0.1.0/ppqm/constants.py +25 -0
  8. ppqm-0.1.0/ppqm/gamess.py +790 -0
  9. ppqm-0.1.0/ppqm/gaussian.py +373 -0
  10. ppqm-0.1.0/ppqm/jupyter.py +60 -0
  11. ppqm-0.1.0/ppqm/mndo.py +510 -0
  12. ppqm-0.1.0/ppqm/mopac.py +475 -0
  13. ppqm-0.1.0/ppqm/orca.py +523 -0
  14. ppqm-0.1.0/ppqm/tasks.py +100 -0
  15. ppqm-0.1.0/ppqm/units.py +17 -0
  16. ppqm-0.1.0/ppqm/utils/__init__.py +2 -0
  17. ppqm-0.1.0/ppqm/utils/env.py +0 -0
  18. ppqm-0.1.0/ppqm/utils/files.py +117 -0
  19. ppqm-0.1.0/ppqm/utils/functools.py +125 -0
  20. ppqm-0.1.0/ppqm/utils/linesio.py +185 -0
  21. ppqm-0.1.0/ppqm/utils/shell.py +198 -0
  22. ppqm-0.1.0/ppqm/version.py +1 -0
  23. ppqm-0.1.0/ppqm/xtb.py +862 -0
  24. ppqm-0.1.0/ppqm.egg-info/PKG-INFO +115 -0
  25. ppqm-0.1.0/ppqm.egg-info/SOURCES.txt +39 -0
  26. ppqm-0.1.0/ppqm.egg-info/dependency_links.txt +1 -0
  27. ppqm-0.1.0/ppqm.egg-info/requires.txt +22 -0
  28. ppqm-0.1.0/ppqm.egg-info/top_level.txt +7 -0
  29. ppqm-0.1.0/pyproject.toml +88 -0
  30. ppqm-0.1.0/readme.md +81 -0
  31. ppqm-0.1.0/setup.cfg +4 -0
  32. ppqm-0.1.0/tests/conftest.py +3 -0
  33. ppqm-0.1.0/tests/test_chembridge.py +437 -0
  34. ppqm-0.1.0/tests/test_gamess.py +432 -0
  35. ppqm-0.1.0/tests/test_gaussian.py +120 -0
  36. ppqm-0.1.0/tests/test_linesio.py +42 -0
  37. ppqm-0.1.0/tests/test_mndo.py +41 -0
  38. ppqm-0.1.0/tests/test_mopac.py +178 -0
  39. ppqm-0.1.0/tests/test_orca.py +462 -0
  40. ppqm-0.1.0/tests/test_shell.py +10 -0
  41. ppqm-0.1.0/tests/test_xtb.py +427 -0
ppqm-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Psi Phi Quantum Mechanics
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
ppqm-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,115 @@
1
+ Metadata-Version: 2.4
2
+ Name: ppqm
3
+ Version: 0.1.0
4
+ Summary: Utilities for running QM calculations with RDKit
5
+ Maintainer: Jimmy Kromann, Hagen Muenkler
6
+ License: MIT
7
+ Classifier: Intended Audience :: Science/Research
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Programming Language :: Python :: 3
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: numpy
14
+ Requires-Dist: tqdm
15
+ Requires-Dist: rmsd
16
+ Requires-Dist: rdkit
17
+ Provides-Extra: test
18
+ Requires-Dist: pytest; extra == "test"
19
+ Requires-Dist: pytest-cov; extra == "test"
20
+ Provides-Extra: dev
21
+ Requires-Dist: build; extra == "dev"
22
+ Requires-Dist: ipython; extra == "dev"
23
+ Requires-Dist: ipywidgets; extra == "dev"
24
+ Requires-Dist: jupytext; extra == "dev"
25
+ Requires-Dist: matplotlib; extra == "dev"
26
+ Requires-Dist: nglview; extra == "dev"
27
+ Requires-Dist: pandas; extra == "dev"
28
+ Requires-Dist: pip; extra == "dev"
29
+ Requires-Dist: pre-commit; extra == "dev"
30
+ Requires-Dist: ruff; extra == "dev"
31
+ Requires-Dist: twine; extra == "dev"
32
+ Requires-Dist: ty; extra == "dev"
33
+ Dynamic: license-file
34
+
35
+ # Psi Phi Package
36
+
37
+ Do you need RDKit? Do you need quantum chemistry? We got you.
38
+ This package is a simple bridge between RDKit and quantum chemistry (QC) packages
39
+ that lack Python interfaces.
40
+
41
+ Current version has calculator wrappers for
42
+
43
+ - GAMESS
44
+ - Gaussian
45
+ - MNDO
46
+ - MOPAC
47
+ - Orca
48
+ - xTB
49
+
50
+ ## Example
51
+
52
+ Assume all codesnippets below are using RDKit molecule objs.
53
+
54
+ ```python
55
+ molecule = Chem.MolFromSmiles("O")
56
+ Chem.AddHydrogens(molecule)
57
+ AllChem.UFFOptimizeMolecule(molecule)
58
+ ```
59
+
60
+ The simple usage is to make an instance of a QC software.
61
+ For example, using the popular package xTB, you can define the amount of cores
62
+ to allocate and the exact path to the executable.
63
+
64
+ ```python
65
+ from ppqm import XtbCalculator
66
+
67
+ xtb = XtbCalculator(cmd="xtb", cores=4)
68
+ ```
69
+
70
+ The format for running calculations are based on Python dictionaries, which are
71
+ translated into the right format. So for example running a GFN2 optimization in
72
+ water, the input would be
73
+
74
+ ```python
75
+ # Define the calculation
76
+ optimize_options = {
77
+ "gfn": 2,
78
+ "alpb": "h2o",
79
+ "opt": None,
80
+ }
81
+
82
+ # Run the calculation
83
+ results = xtb.calculate(molecule, optimize_options)
84
+
85
+ # Results is a List of Dict properties
86
+ for i, propeties in enumerate(results):
87
+ print(f"Conformer {i} properties: {properties}")
88
+ ```
89
+
90
+ For more documentation by example, checkout the `notebooks/` directory.
91
+
92
+ ## Contributions
93
+
94
+ Fork, branch and use pre-commit.
95
+
96
+ ## Other code bases
97
+
98
+ "is this the first python wrapper for quantum chemistry?" No, check the others
99
+ and find the one right for your project. Know one, not on the list? Add it. In
100
+ alphabetic order.
101
+
102
+ - [Moleculekit](https://github.com/Acellera/moleculekit)
103
+ - [stko](https://github.com/JelfsMaterialsGroup/stko)
104
+ - [MolSSI](https://github.com/MolSSI)
105
+ - [cclib](https://github.com/cclib/cclib)
106
+ - [datamol](https://github.com/datamol-org/datamol)
107
+ - [autodE](https://github.com/duartegroup/autodE/)
108
+ - [cctk](https://github.com/ekwan/cctk)
109
+ - [pygamess](https://github.com/kzfm/pygamess)
110
+ - [stk](https://github.com/lukasturcani/stk)
111
+ - [ASE](https://gitlab.com/ase/ase)
112
+
113
+ ## Future work
114
+
115
+ - Separation of concern. The ppqm package should adapt to using `cclib` or similar to collect quantum output.
@@ -0,0 +1,59 @@
1
+ # Copyright (c) 2020-202x The virtualenv developers
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ """
23
+ Activate virtualenv for current interpreter:
24
+
25
+ import runpy
26
+ runpy.run_path(this_file)
27
+
28
+ This can be used when you must use an existing Python interpreter, not the virtualenv bin/python.
29
+ """ # noqa: D415
30
+
31
+ from __future__ import annotations
32
+
33
+ import os
34
+ import site
35
+ import sys
36
+
37
+ try:
38
+ abs_file = os.path.abspath(__file__)
39
+ except NameError as exc:
40
+ msg = "You must use import runpy; runpy.run_path(this_file)"
41
+ raise AssertionError(msg) from exc
42
+
43
+ bin_dir = os.path.dirname(abs_file)
44
+ base = bin_dir[: -len("bin") - 1] # strip away the bin part from the __file__, plus the path separator
45
+
46
+ # prepend bin to PATH (this file is inside the bin directory)
47
+ os.environ["PATH"] = os.pathsep.join([bin_dir, *os.environ.get("PATH", "").split(os.pathsep)])
48
+ os.environ["VIRTUAL_ENV"] = base # virtual env is right above bin directory
49
+ os.environ["VIRTUAL_ENV_PROMPT"] = "" or os.path.basename(base) # noqa: SIM222
50
+
51
+ # add the virtual environments libraries to the host python import mechanism
52
+ prev_length = len(sys.path)
53
+ for lib in "../lib/python3.12/site-packages".split(os.pathsep):
54
+ path = os.path.realpath(os.path.join(bin_dir, lib))
55
+ site.addsitedir(path)
56
+ sys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]
57
+
58
+ sys.real_prefix = sys.prefix
59
+ sys.prefix = base
@@ -0,0 +1,7 @@
1
+ from ppqm import chembridge
2
+ from ppqm.gamess import GamessCalculator
3
+ from ppqm.gaussian import GaussianCalculator
4
+ from ppqm.mopac import MopacCalculator
5
+ from ppqm.orca import OrcaCalculator
6
+ from ppqm.utils.files import WorkDir
7
+ from ppqm.xtb import XtbCalculator
@@ -0,0 +1,110 @@
1
+ import abc
2
+ import copy
3
+ import logging
4
+ from collections import ChainMap
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+ from ppqm import chembridge, constants
9
+ from ppqm.chembridge import Mol
10
+
11
+ _logger = logging.getLogger(__name__)
12
+
13
+
14
+ class BaseCalculator(abc.ABC):
15
+ """Base class for quantum calculators
16
+
17
+ This class should not be used directly, use a class appropriate for your
18
+ quantum calculations (e.g. MopacCalculator or GamessCalculator) instead.
19
+ """
20
+
21
+ def __init__(self, scr: Path = constants.SCR) -> None:
22
+ self.scr = Path(scr)
23
+ # Ensure scrdir
24
+ self.set_scratch_directory()
25
+
26
+ def _health_check(self) -> None:
27
+ raise NotImplementedError
28
+
29
+ def _generate_options(self, **kwargs: Any) -> dict:
30
+ """to be implemented by individual programs"""
31
+ raise NotImplementedError
32
+
33
+ def calculate(self, molobj: Mol, options: dict) -> list[dict | None]:
34
+ raise NotImplementedError
35
+
36
+ def optimize(self, molobj: Mol, options: dict | None = None, return_copy: bool = True) -> Mol:
37
+ """
38
+
39
+ Parameters
40
+ ----------
41
+ molobj: Mol
42
+ A RDkit Molobj
43
+
44
+ return_copy: Bool
45
+ Return a new copy of molobj, instead of overwriting it
46
+
47
+ return_properties: Bool
48
+ Return list of properties for molobj conformers
49
+
50
+ Examples
51
+ --------
52
+ >>> molobj_prime = calc.optimize(molobj)
53
+
54
+ Returns
55
+ -------
56
+ molobj: Mol
57
+ RDKit molobj with updated conformer coordinates
58
+
59
+ properties: List(Dict(Str, Any))
60
+ Properties associated with each conformer
61
+
62
+ """
63
+
64
+ # TODO Embed properties into conformres
65
+
66
+ # Merge options
67
+ if options is None:
68
+ options = {}
69
+ options_ = self._generate_options(optimize=True)
70
+ options_prime = dict(ChainMap(options, options_))
71
+
72
+ if return_copy:
73
+ molobj = copy.deepcopy(molobj)
74
+
75
+ result_properties: list[dict] = self.calculate(molobj, options_prime) # type: ignore
76
+
77
+ for i, properties in enumerate(result_properties):
78
+ # TODO Check if unconverged
79
+ # TODO Check number of steps?
80
+
81
+ if constants.COLUMN_COORDINATES not in properties:
82
+ # TODO Unable to set coordinates, skip for now
83
+ _logger.error(f"Unable to optimize, conformer {i} skipped")
84
+ continue
85
+
86
+ coord = properties[constants.COLUMN_COORDINATES]
87
+
88
+ # Set coord on conformer
89
+ chembridge.molobj_set_coordinates(molobj, coord, confid=i)
90
+
91
+ return molobj
92
+
93
+ def get_gradient(self, molobj: Mol) -> None:
94
+ raise NotImplementedError
95
+
96
+ def get_hessian(self, molobj: Mol) -> None:
97
+ raise NotImplementedError
98
+
99
+ def set_energy_unit(self, unit: Mol) -> None:
100
+ raise NotImplementedError
101
+ # TODO set unit.convert(value, X, to)
102
+
103
+ def set_scratch_directory(self) -> None:
104
+ self.scr.mkdir(parents=True, exist_ok=True)
105
+
106
+ def health_check(self) -> None:
107
+ raise NotImplementedError
108
+
109
+ def __repr__(self) -> str:
110
+ return "CalculatorSkeleton()"