im-rdkit-utilities 1.2.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.
- im_rdkit_utilities-1.2.0/LICENSE +21 -0
- im_rdkit_utilities-1.2.0/MANIFEST.in +4 -0
- im_rdkit_utilities-1.2.0/PKG-INFO +164 -0
- im_rdkit_utilities-1.2.0/README.rst +126 -0
- im_rdkit_utilities-1.2.0/im_rdkit_utilities.egg-info/PKG-INFO +164 -0
- im_rdkit_utilities-1.2.0/im_rdkit_utilities.egg-info/SOURCES.txt +18 -0
- im_rdkit_utilities-1.2.0/im_rdkit_utilities.egg-info/dependency_links.txt +1 -0
- im_rdkit_utilities-1.2.0/im_rdkit_utilities.egg-info/not-zip-safe +1 -0
- im_rdkit_utilities-1.2.0/im_rdkit_utilities.egg-info/requires.txt +2 -0
- im_rdkit_utilities-1.2.0/im_rdkit_utilities.egg-info/top_level.txt +1 -0
- im_rdkit_utilities-1.2.0/pyproject.toml +5 -0
- im_rdkit_utilities-1.2.0/rdkit_utils/__init__.py +57 -0
- im_rdkit_utilities-1.2.0/rdkit_utils/_cli.py +140 -0
- im_rdkit_utilities-1.2.0/rdkit_utils/_core.py +710 -0
- im_rdkit_utilities-1.2.0/requirements.txt +2 -0
- im_rdkit_utilities-1.2.0/setup.cfg +4 -0
- im_rdkit_utilities-1.2.0/setup.py +60 -0
- im_rdkit_utilities-1.2.0/tests/test_cli.py +186 -0
- im_rdkit_utilities-1.2.0/tests/test_rdkit_utils.py +282 -0
- im_rdkit_utilities-1.2.0/tests/test_smiles_writer_columns.py +63 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Informatics Matters Ltd
|
|
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.
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: im-rdkit-utilities
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Summary: RDKit utilities for Squonk2 Data Manager Jobs
|
|
5
|
+
Home-page: https://github.com/informaticsmatters/squonk2-rdkit-utilities
|
|
6
|
+
Author: Informatics Matters
|
|
7
|
+
Author-email: info@informaticsmatters.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: rdkit
|
|
10
|
+
Platform: any
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Environment :: Other Environment
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: rdkit>=2026.3.6
|
|
25
|
+
Requires-Dist: im-data-manager-job-utilities>=1.3.0
|
|
26
|
+
Dynamic: author
|
|
27
|
+
Dynamic: author-email
|
|
28
|
+
Dynamic: classifier
|
|
29
|
+
Dynamic: description
|
|
30
|
+
Dynamic: home-page
|
|
31
|
+
Dynamic: keywords
|
|
32
|
+
Dynamic: license
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
Dynamic: platform
|
|
35
|
+
Dynamic: requires-dist
|
|
36
|
+
Dynamic: requires-python
|
|
37
|
+
Dynamic: summary
|
|
38
|
+
|
|
39
|
+
Informatics Matters RDKit Utilities
|
|
40
|
+
====================================
|
|
41
|
+
|
|
42
|
+
.. image:: https://badge.fury.io/py/im-rdkit-utilities.svg
|
|
43
|
+
:target: https://badge.fury.io/py/im-rdkit-utilities
|
|
44
|
+
:alt: PyPI package (latest)
|
|
45
|
+
|
|
46
|
+
.. image:: https://github.com/InformaticsMatters/squonk2-rdkit-utilities/actions/workflows/build.yaml/badge.svg
|
|
47
|
+
:target: https://github.com/InformaticsMatters/squonk2-rdkit-utilities/actions/workflows/build.yaml
|
|
48
|
+
:alt: Build
|
|
49
|
+
|
|
50
|
+
.. image:: https://github.com/InformaticsMatters/squonk2-rdkit-utilities/actions/workflows/publish.yaml/badge.svg
|
|
51
|
+
:target: https://github.com/InformaticsMatters/squonk2-rdkit-utilities/actions/workflows/publish.yaml
|
|
52
|
+
:alt: Publish
|
|
53
|
+
|
|
54
|
+
A Python package of RDKit-specific helpers shared by **Squonk2 Data Manager
|
|
55
|
+
Jobs**: molecule readers/writers over SDF and delimited-SMILES text formats,
|
|
56
|
+
fragment selection, and a handful of small molecule-inspection helpers.
|
|
57
|
+
|
|
58
|
+
This consolidates the ``rdkit_utils.py`` module that had been copy-pasted,
|
|
59
|
+
and had begun to diverge, across several Job repositories
|
|
60
|
+
(``squonk2-desc-rdkit``, ``squonk2-desc-mordred``, ``squonk2-jaqpot`` and
|
|
61
|
+
``virtual-screening``) into a single, tested, authoritative source.
|
|
62
|
+
|
|
63
|
+
Installation (Python)
|
|
64
|
+
======================
|
|
65
|
+
|
|
66
|
+
The package is published on `PyPI`_ and can be installed from there::
|
|
67
|
+
|
|
68
|
+
pip install im-rdkit-utilities
|
|
69
|
+
|
|
70
|
+
Once installed, import it as ``rdkit_utils`` (matching the module name it
|
|
71
|
+
replaces, so existing call sites need no changes beyond the import path)::
|
|
72
|
+
|
|
73
|
+
>>> import rdkit_utils
|
|
74
|
+
>>> reader = rdkit_utils.create_reader('molecules.smi', delimiter='\t')
|
|
75
|
+
|
|
76
|
+
Public surface
|
|
77
|
+
==============
|
|
78
|
+
|
|
79
|
+
- ``create_reader()`` / ``create_writer()`` — construct a reader/writer for
|
|
80
|
+
a .sdf, .sdf.gz or delimited-SMILES file, based on its extension.
|
|
81
|
+
- ``SdfReader`` / ``SdfWriter`` / ``SmilesReader`` / ``SmilesWriter`` — the
|
|
82
|
+
underlying reader/writer implementations.
|
|
83
|
+
- ``generate_headers()`` — build output headers for a tab/comma separated
|
|
84
|
+
file, given the ID column configuration.
|
|
85
|
+
- ``fragment()`` — pick the largest fragment of a (typically salted)
|
|
86
|
+
molecule, by heavy-atom count or molecular weight.
|
|
87
|
+
- ``fragmentAndFingerprint()`` — fragment a stream of molecules and
|
|
88
|
+
fingerprint the result.
|
|
89
|
+
- ``get_num_chiral_centers()`` / ``get_num_sp3_centres()`` — small
|
|
90
|
+
molecule-inspection helpers.
|
|
91
|
+
- ``check_molecules_are_3d()`` — check whether the molecules in a .sdf file
|
|
92
|
+
have 3D conformers.
|
|
93
|
+
- ``rdk_read_single_mol()`` / ``rdk_read_mols()`` / ``rdk_read_molecule_files()``
|
|
94
|
+
/ ``rdk_merge_mols()`` / ``rdk_mol_supplier()`` / ``sdf_record_gen()`` —
|
|
95
|
+
molecule-file reading helpers.
|
|
96
|
+
- ``updateChargeFlagInAtomBlock()`` — adds the legacy charge-flag encoding
|
|
97
|
+
to a full CTAB molblock (counts line included), for tools such as rDock
|
|
98
|
+
that only understand the old syntax. This is **not** the same as
|
|
99
|
+
``dm_job_utilities.utils.update_charge_flag_in_atom_block()``, which
|
|
100
|
+
operates on just the atom-block portion of a molblock (one line further
|
|
101
|
+
in) — the two take different input shapes and are not interchangeable.
|
|
102
|
+
This RDKit-oriented variant lives here because it's used directly
|
|
103
|
+
alongside the readers/writers above; the job-utilities function remains
|
|
104
|
+
the natural home for pure string manipulation with no RDKit dependency.
|
|
105
|
+
|
|
106
|
+
Command-line helpers
|
|
107
|
+
====================
|
|
108
|
+
|
|
109
|
+
- ``add_common_molecule_io_args(parser)`` — adds the "Input/output options"
|
|
110
|
+
argument group shared by the molecule processing Jobs (``-i/--infile``,
|
|
111
|
+
``-o/--outfile``, ``-d/--delimiter``, ``--id-column``, ``--mol-column``,
|
|
112
|
+
``--read-header``, ``--write-header``, ``--read-records``,
|
|
113
|
+
``-k/--omit-fields``, and optionally ``--y-column``), and returns the group
|
|
114
|
+
so more options can be added to it. Keyword arguments ``output_default``,
|
|
115
|
+
``output_required`` and ``include_y_column`` cover the variations between
|
|
116
|
+
Jobs.
|
|
117
|
+
- ``str_or_int()`` — an argparse ``type`` for a column specifier given either
|
|
118
|
+
as a zero-based index or as a field name.
|
|
119
|
+
|
|
120
|
+
The group's namespace feeds ``create_reader()`` directly::
|
|
121
|
+
|
|
122
|
+
>>> import argparse, rdkit_utils
|
|
123
|
+
>>> from dm_job_utilities.utils import read_delimiter
|
|
124
|
+
>>> parser = argparse.ArgumentParser()
|
|
125
|
+
>>> _ = rdkit_utils.add_common_molecule_io_args(parser)
|
|
126
|
+
>>> args = parser.parse_args(['-i', 'molecules.smi', '-d', 'tab'])
|
|
127
|
+
>>> reader = rdkit_utils.create_reader(
|
|
128
|
+
... args.input,
|
|
129
|
+
... delimiter=read_delimiter(args.delimiter),
|
|
130
|
+
... read_header=args.read_header,
|
|
131
|
+
... id_column=args.id_column,
|
|
132
|
+
... mol_column=args.mol_column,
|
|
133
|
+
... read_records=args.read_records,
|
|
134
|
+
... )
|
|
135
|
+
|
|
136
|
+
``--infile`` and ``--outfile`` are the canonical long spellings. The parsed
|
|
137
|
+
values are always available as ``args.input`` and ``args.output``.
|
|
138
|
+
|
|
139
|
+
``--input`` and ``--output`` are **deprecated aliases**, retained only so that
|
|
140
|
+
adopting the helper did not break existing Job manifests. They are due to be
|
|
141
|
+
removed — see `issue #5
|
|
142
|
+
<https://github.com/InformaticsMatters/squonk2-rdkit-utilities/issues/5>`_. Job
|
|
143
|
+
Definitions should invoke ``-i``/``-o``: they are canonical, unaffected by that
|
|
144
|
+
removal, and work against container images built before the Job adopted the
|
|
145
|
+
helper.
|
|
146
|
+
|
|
147
|
+
Defaults follow the ``create_reader()`` / ``create_writer()`` signatures rather
|
|
148
|
+
than the values the Job scripts hand-type today — in particular ``--mol-column``
|
|
149
|
+
defaults to ``None`` so that ``SmilesReader`` can infer it, where most Jobs
|
|
150
|
+
currently pass an explicit ``0``.
|
|
151
|
+
|
|
152
|
+
Progress and cost reporting (``--interval``, ``ProgressReporter``) is
|
|
153
|
+
deliberately **not** here — that is a Data Manager logging concern and lives in
|
|
154
|
+
`im-data-manager-job-utilities`_.
|
|
155
|
+
|
|
156
|
+
.. _PyPI: https://pypi.org/project/im-rdkit-utilities
|
|
157
|
+
.. _im-data-manager-job-utilities: https://pypi.org/project/im-data-manager-job-utilities
|
|
158
|
+
|
|
159
|
+
Get in touch
|
|
160
|
+
============
|
|
161
|
+
|
|
162
|
+
- Report bugs, suggest features or view the source code `on GitHub`_.
|
|
163
|
+
|
|
164
|
+
.. _on GitHub: https://github.com/informaticsmatters/squonk2-rdkit-utilities
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
Informatics Matters RDKit Utilities
|
|
2
|
+
====================================
|
|
3
|
+
|
|
4
|
+
.. image:: https://badge.fury.io/py/im-rdkit-utilities.svg
|
|
5
|
+
:target: https://badge.fury.io/py/im-rdkit-utilities
|
|
6
|
+
:alt: PyPI package (latest)
|
|
7
|
+
|
|
8
|
+
.. image:: https://github.com/InformaticsMatters/squonk2-rdkit-utilities/actions/workflows/build.yaml/badge.svg
|
|
9
|
+
:target: https://github.com/InformaticsMatters/squonk2-rdkit-utilities/actions/workflows/build.yaml
|
|
10
|
+
:alt: Build
|
|
11
|
+
|
|
12
|
+
.. image:: https://github.com/InformaticsMatters/squonk2-rdkit-utilities/actions/workflows/publish.yaml/badge.svg
|
|
13
|
+
:target: https://github.com/InformaticsMatters/squonk2-rdkit-utilities/actions/workflows/publish.yaml
|
|
14
|
+
:alt: Publish
|
|
15
|
+
|
|
16
|
+
A Python package of RDKit-specific helpers shared by **Squonk2 Data Manager
|
|
17
|
+
Jobs**: molecule readers/writers over SDF and delimited-SMILES text formats,
|
|
18
|
+
fragment selection, and a handful of small molecule-inspection helpers.
|
|
19
|
+
|
|
20
|
+
This consolidates the ``rdkit_utils.py`` module that had been copy-pasted,
|
|
21
|
+
and had begun to diverge, across several Job repositories
|
|
22
|
+
(``squonk2-desc-rdkit``, ``squonk2-desc-mordred``, ``squonk2-jaqpot`` and
|
|
23
|
+
``virtual-screening``) into a single, tested, authoritative source.
|
|
24
|
+
|
|
25
|
+
Installation (Python)
|
|
26
|
+
======================
|
|
27
|
+
|
|
28
|
+
The package is published on `PyPI`_ and can be installed from there::
|
|
29
|
+
|
|
30
|
+
pip install im-rdkit-utilities
|
|
31
|
+
|
|
32
|
+
Once installed, import it as ``rdkit_utils`` (matching the module name it
|
|
33
|
+
replaces, so existing call sites need no changes beyond the import path)::
|
|
34
|
+
|
|
35
|
+
>>> import rdkit_utils
|
|
36
|
+
>>> reader = rdkit_utils.create_reader('molecules.smi', delimiter='\t')
|
|
37
|
+
|
|
38
|
+
Public surface
|
|
39
|
+
==============
|
|
40
|
+
|
|
41
|
+
- ``create_reader()`` / ``create_writer()`` — construct a reader/writer for
|
|
42
|
+
a .sdf, .sdf.gz or delimited-SMILES file, based on its extension.
|
|
43
|
+
- ``SdfReader`` / ``SdfWriter`` / ``SmilesReader`` / ``SmilesWriter`` — the
|
|
44
|
+
underlying reader/writer implementations.
|
|
45
|
+
- ``generate_headers()`` — build output headers for a tab/comma separated
|
|
46
|
+
file, given the ID column configuration.
|
|
47
|
+
- ``fragment()`` — pick the largest fragment of a (typically salted)
|
|
48
|
+
molecule, by heavy-atom count or molecular weight.
|
|
49
|
+
- ``fragmentAndFingerprint()`` — fragment a stream of molecules and
|
|
50
|
+
fingerprint the result.
|
|
51
|
+
- ``get_num_chiral_centers()`` / ``get_num_sp3_centres()`` — small
|
|
52
|
+
molecule-inspection helpers.
|
|
53
|
+
- ``check_molecules_are_3d()`` — check whether the molecules in a .sdf file
|
|
54
|
+
have 3D conformers.
|
|
55
|
+
- ``rdk_read_single_mol()`` / ``rdk_read_mols()`` / ``rdk_read_molecule_files()``
|
|
56
|
+
/ ``rdk_merge_mols()`` / ``rdk_mol_supplier()`` / ``sdf_record_gen()`` —
|
|
57
|
+
molecule-file reading helpers.
|
|
58
|
+
- ``updateChargeFlagInAtomBlock()`` — adds the legacy charge-flag encoding
|
|
59
|
+
to a full CTAB molblock (counts line included), for tools such as rDock
|
|
60
|
+
that only understand the old syntax. This is **not** the same as
|
|
61
|
+
``dm_job_utilities.utils.update_charge_flag_in_atom_block()``, which
|
|
62
|
+
operates on just the atom-block portion of a molblock (one line further
|
|
63
|
+
in) — the two take different input shapes and are not interchangeable.
|
|
64
|
+
This RDKit-oriented variant lives here because it's used directly
|
|
65
|
+
alongside the readers/writers above; the job-utilities function remains
|
|
66
|
+
the natural home for pure string manipulation with no RDKit dependency.
|
|
67
|
+
|
|
68
|
+
Command-line helpers
|
|
69
|
+
====================
|
|
70
|
+
|
|
71
|
+
- ``add_common_molecule_io_args(parser)`` — adds the "Input/output options"
|
|
72
|
+
argument group shared by the molecule processing Jobs (``-i/--infile``,
|
|
73
|
+
``-o/--outfile``, ``-d/--delimiter``, ``--id-column``, ``--mol-column``,
|
|
74
|
+
``--read-header``, ``--write-header``, ``--read-records``,
|
|
75
|
+
``-k/--omit-fields``, and optionally ``--y-column``), and returns the group
|
|
76
|
+
so more options can be added to it. Keyword arguments ``output_default``,
|
|
77
|
+
``output_required`` and ``include_y_column`` cover the variations between
|
|
78
|
+
Jobs.
|
|
79
|
+
- ``str_or_int()`` — an argparse ``type`` for a column specifier given either
|
|
80
|
+
as a zero-based index or as a field name.
|
|
81
|
+
|
|
82
|
+
The group's namespace feeds ``create_reader()`` directly::
|
|
83
|
+
|
|
84
|
+
>>> import argparse, rdkit_utils
|
|
85
|
+
>>> from dm_job_utilities.utils import read_delimiter
|
|
86
|
+
>>> parser = argparse.ArgumentParser()
|
|
87
|
+
>>> _ = rdkit_utils.add_common_molecule_io_args(parser)
|
|
88
|
+
>>> args = parser.parse_args(['-i', 'molecules.smi', '-d', 'tab'])
|
|
89
|
+
>>> reader = rdkit_utils.create_reader(
|
|
90
|
+
... args.input,
|
|
91
|
+
... delimiter=read_delimiter(args.delimiter),
|
|
92
|
+
... read_header=args.read_header,
|
|
93
|
+
... id_column=args.id_column,
|
|
94
|
+
... mol_column=args.mol_column,
|
|
95
|
+
... read_records=args.read_records,
|
|
96
|
+
... )
|
|
97
|
+
|
|
98
|
+
``--infile`` and ``--outfile`` are the canonical long spellings. The parsed
|
|
99
|
+
values are always available as ``args.input`` and ``args.output``.
|
|
100
|
+
|
|
101
|
+
``--input`` and ``--output`` are **deprecated aliases**, retained only so that
|
|
102
|
+
adopting the helper did not break existing Job manifests. They are due to be
|
|
103
|
+
removed — see `issue #5
|
|
104
|
+
<https://github.com/InformaticsMatters/squonk2-rdkit-utilities/issues/5>`_. Job
|
|
105
|
+
Definitions should invoke ``-i``/``-o``: they are canonical, unaffected by that
|
|
106
|
+
removal, and work against container images built before the Job adopted the
|
|
107
|
+
helper.
|
|
108
|
+
|
|
109
|
+
Defaults follow the ``create_reader()`` / ``create_writer()`` signatures rather
|
|
110
|
+
than the values the Job scripts hand-type today — in particular ``--mol-column``
|
|
111
|
+
defaults to ``None`` so that ``SmilesReader`` can infer it, where most Jobs
|
|
112
|
+
currently pass an explicit ``0``.
|
|
113
|
+
|
|
114
|
+
Progress and cost reporting (``--interval``, ``ProgressReporter``) is
|
|
115
|
+
deliberately **not** here — that is a Data Manager logging concern and lives in
|
|
116
|
+
`im-data-manager-job-utilities`_.
|
|
117
|
+
|
|
118
|
+
.. _PyPI: https://pypi.org/project/im-rdkit-utilities
|
|
119
|
+
.. _im-data-manager-job-utilities: https://pypi.org/project/im-data-manager-job-utilities
|
|
120
|
+
|
|
121
|
+
Get in touch
|
|
122
|
+
============
|
|
123
|
+
|
|
124
|
+
- Report bugs, suggest features or view the source code `on GitHub`_.
|
|
125
|
+
|
|
126
|
+
.. _on GitHub: https://github.com/informaticsmatters/squonk2-rdkit-utilities
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: im-rdkit-utilities
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Summary: RDKit utilities for Squonk2 Data Manager Jobs
|
|
5
|
+
Home-page: https://github.com/informaticsmatters/squonk2-rdkit-utilities
|
|
6
|
+
Author: Informatics Matters
|
|
7
|
+
Author-email: info@informaticsmatters.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: rdkit
|
|
10
|
+
Platform: any
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Environment :: Other Environment
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: rdkit>=2026.3.6
|
|
25
|
+
Requires-Dist: im-data-manager-job-utilities>=1.3.0
|
|
26
|
+
Dynamic: author
|
|
27
|
+
Dynamic: author-email
|
|
28
|
+
Dynamic: classifier
|
|
29
|
+
Dynamic: description
|
|
30
|
+
Dynamic: home-page
|
|
31
|
+
Dynamic: keywords
|
|
32
|
+
Dynamic: license
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
Dynamic: platform
|
|
35
|
+
Dynamic: requires-dist
|
|
36
|
+
Dynamic: requires-python
|
|
37
|
+
Dynamic: summary
|
|
38
|
+
|
|
39
|
+
Informatics Matters RDKit Utilities
|
|
40
|
+
====================================
|
|
41
|
+
|
|
42
|
+
.. image:: https://badge.fury.io/py/im-rdkit-utilities.svg
|
|
43
|
+
:target: https://badge.fury.io/py/im-rdkit-utilities
|
|
44
|
+
:alt: PyPI package (latest)
|
|
45
|
+
|
|
46
|
+
.. image:: https://github.com/InformaticsMatters/squonk2-rdkit-utilities/actions/workflows/build.yaml/badge.svg
|
|
47
|
+
:target: https://github.com/InformaticsMatters/squonk2-rdkit-utilities/actions/workflows/build.yaml
|
|
48
|
+
:alt: Build
|
|
49
|
+
|
|
50
|
+
.. image:: https://github.com/InformaticsMatters/squonk2-rdkit-utilities/actions/workflows/publish.yaml/badge.svg
|
|
51
|
+
:target: https://github.com/InformaticsMatters/squonk2-rdkit-utilities/actions/workflows/publish.yaml
|
|
52
|
+
:alt: Publish
|
|
53
|
+
|
|
54
|
+
A Python package of RDKit-specific helpers shared by **Squonk2 Data Manager
|
|
55
|
+
Jobs**: molecule readers/writers over SDF and delimited-SMILES text formats,
|
|
56
|
+
fragment selection, and a handful of small molecule-inspection helpers.
|
|
57
|
+
|
|
58
|
+
This consolidates the ``rdkit_utils.py`` module that had been copy-pasted,
|
|
59
|
+
and had begun to diverge, across several Job repositories
|
|
60
|
+
(``squonk2-desc-rdkit``, ``squonk2-desc-mordred``, ``squonk2-jaqpot`` and
|
|
61
|
+
``virtual-screening``) into a single, tested, authoritative source.
|
|
62
|
+
|
|
63
|
+
Installation (Python)
|
|
64
|
+
======================
|
|
65
|
+
|
|
66
|
+
The package is published on `PyPI`_ and can be installed from there::
|
|
67
|
+
|
|
68
|
+
pip install im-rdkit-utilities
|
|
69
|
+
|
|
70
|
+
Once installed, import it as ``rdkit_utils`` (matching the module name it
|
|
71
|
+
replaces, so existing call sites need no changes beyond the import path)::
|
|
72
|
+
|
|
73
|
+
>>> import rdkit_utils
|
|
74
|
+
>>> reader = rdkit_utils.create_reader('molecules.smi', delimiter='\t')
|
|
75
|
+
|
|
76
|
+
Public surface
|
|
77
|
+
==============
|
|
78
|
+
|
|
79
|
+
- ``create_reader()`` / ``create_writer()`` — construct a reader/writer for
|
|
80
|
+
a .sdf, .sdf.gz or delimited-SMILES file, based on its extension.
|
|
81
|
+
- ``SdfReader`` / ``SdfWriter`` / ``SmilesReader`` / ``SmilesWriter`` — the
|
|
82
|
+
underlying reader/writer implementations.
|
|
83
|
+
- ``generate_headers()`` — build output headers for a tab/comma separated
|
|
84
|
+
file, given the ID column configuration.
|
|
85
|
+
- ``fragment()`` — pick the largest fragment of a (typically salted)
|
|
86
|
+
molecule, by heavy-atom count or molecular weight.
|
|
87
|
+
- ``fragmentAndFingerprint()`` — fragment a stream of molecules and
|
|
88
|
+
fingerprint the result.
|
|
89
|
+
- ``get_num_chiral_centers()`` / ``get_num_sp3_centres()`` — small
|
|
90
|
+
molecule-inspection helpers.
|
|
91
|
+
- ``check_molecules_are_3d()`` — check whether the molecules in a .sdf file
|
|
92
|
+
have 3D conformers.
|
|
93
|
+
- ``rdk_read_single_mol()`` / ``rdk_read_mols()`` / ``rdk_read_molecule_files()``
|
|
94
|
+
/ ``rdk_merge_mols()`` / ``rdk_mol_supplier()`` / ``sdf_record_gen()`` —
|
|
95
|
+
molecule-file reading helpers.
|
|
96
|
+
- ``updateChargeFlagInAtomBlock()`` — adds the legacy charge-flag encoding
|
|
97
|
+
to a full CTAB molblock (counts line included), for tools such as rDock
|
|
98
|
+
that only understand the old syntax. This is **not** the same as
|
|
99
|
+
``dm_job_utilities.utils.update_charge_flag_in_atom_block()``, which
|
|
100
|
+
operates on just the atom-block portion of a molblock (one line further
|
|
101
|
+
in) — the two take different input shapes and are not interchangeable.
|
|
102
|
+
This RDKit-oriented variant lives here because it's used directly
|
|
103
|
+
alongside the readers/writers above; the job-utilities function remains
|
|
104
|
+
the natural home for pure string manipulation with no RDKit dependency.
|
|
105
|
+
|
|
106
|
+
Command-line helpers
|
|
107
|
+
====================
|
|
108
|
+
|
|
109
|
+
- ``add_common_molecule_io_args(parser)`` — adds the "Input/output options"
|
|
110
|
+
argument group shared by the molecule processing Jobs (``-i/--infile``,
|
|
111
|
+
``-o/--outfile``, ``-d/--delimiter``, ``--id-column``, ``--mol-column``,
|
|
112
|
+
``--read-header``, ``--write-header``, ``--read-records``,
|
|
113
|
+
``-k/--omit-fields``, and optionally ``--y-column``), and returns the group
|
|
114
|
+
so more options can be added to it. Keyword arguments ``output_default``,
|
|
115
|
+
``output_required`` and ``include_y_column`` cover the variations between
|
|
116
|
+
Jobs.
|
|
117
|
+
- ``str_or_int()`` — an argparse ``type`` for a column specifier given either
|
|
118
|
+
as a zero-based index or as a field name.
|
|
119
|
+
|
|
120
|
+
The group's namespace feeds ``create_reader()`` directly::
|
|
121
|
+
|
|
122
|
+
>>> import argparse, rdkit_utils
|
|
123
|
+
>>> from dm_job_utilities.utils import read_delimiter
|
|
124
|
+
>>> parser = argparse.ArgumentParser()
|
|
125
|
+
>>> _ = rdkit_utils.add_common_molecule_io_args(parser)
|
|
126
|
+
>>> args = parser.parse_args(['-i', 'molecules.smi', '-d', 'tab'])
|
|
127
|
+
>>> reader = rdkit_utils.create_reader(
|
|
128
|
+
... args.input,
|
|
129
|
+
... delimiter=read_delimiter(args.delimiter),
|
|
130
|
+
... read_header=args.read_header,
|
|
131
|
+
... id_column=args.id_column,
|
|
132
|
+
... mol_column=args.mol_column,
|
|
133
|
+
... read_records=args.read_records,
|
|
134
|
+
... )
|
|
135
|
+
|
|
136
|
+
``--infile`` and ``--outfile`` are the canonical long spellings. The parsed
|
|
137
|
+
values are always available as ``args.input`` and ``args.output``.
|
|
138
|
+
|
|
139
|
+
``--input`` and ``--output`` are **deprecated aliases**, retained only so that
|
|
140
|
+
adopting the helper did not break existing Job manifests. They are due to be
|
|
141
|
+
removed — see `issue #5
|
|
142
|
+
<https://github.com/InformaticsMatters/squonk2-rdkit-utilities/issues/5>`_. Job
|
|
143
|
+
Definitions should invoke ``-i``/``-o``: they are canonical, unaffected by that
|
|
144
|
+
removal, and work against container images built before the Job adopted the
|
|
145
|
+
helper.
|
|
146
|
+
|
|
147
|
+
Defaults follow the ``create_reader()`` / ``create_writer()`` signatures rather
|
|
148
|
+
than the values the Job scripts hand-type today — in particular ``--mol-column``
|
|
149
|
+
defaults to ``None`` so that ``SmilesReader`` can infer it, where most Jobs
|
|
150
|
+
currently pass an explicit ``0``.
|
|
151
|
+
|
|
152
|
+
Progress and cost reporting (``--interval``, ``ProgressReporter``) is
|
|
153
|
+
deliberately **not** here — that is a Data Manager logging concern and lives in
|
|
154
|
+
`im-data-manager-job-utilities`_.
|
|
155
|
+
|
|
156
|
+
.. _PyPI: https://pypi.org/project/im-rdkit-utilities
|
|
157
|
+
.. _im-data-manager-job-utilities: https://pypi.org/project/im-data-manager-job-utilities
|
|
158
|
+
|
|
159
|
+
Get in touch
|
|
160
|
+
============
|
|
161
|
+
|
|
162
|
+
- Report bugs, suggest features or view the source code `on GitHub`_.
|
|
163
|
+
|
|
164
|
+
.. _on GitHub: https://github.com/informaticsmatters/squonk2-rdkit-utilities
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.rst
|
|
4
|
+
pyproject.toml
|
|
5
|
+
requirements.txt
|
|
6
|
+
setup.py
|
|
7
|
+
im_rdkit_utilities.egg-info/PKG-INFO
|
|
8
|
+
im_rdkit_utilities.egg-info/SOURCES.txt
|
|
9
|
+
im_rdkit_utilities.egg-info/dependency_links.txt
|
|
10
|
+
im_rdkit_utilities.egg-info/not-zip-safe
|
|
11
|
+
im_rdkit_utilities.egg-info/requires.txt
|
|
12
|
+
im_rdkit_utilities.egg-info/top_level.txt
|
|
13
|
+
rdkit_utils/__init__.py
|
|
14
|
+
rdkit_utils/_cli.py
|
|
15
|
+
rdkit_utils/_core.py
|
|
16
|
+
tests/test_cli.py
|
|
17
|
+
tests/test_rdkit_utils.py
|
|
18
|
+
tests/test_smiles_writer_columns.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rdkit_utils
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""RDKit utilities for Squonk2 Data Manager Jobs.
|
|
2
|
+
|
|
3
|
+
Everything in ``_core`` is re-exported here so callers can keep using the
|
|
4
|
+
flat ``import rdkit_utils`` / ``rdkit_utils.create_reader(...)`` style that
|
|
5
|
+
predates this package.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from rdkit_utils._cli import add_common_molecule_io_args, str_or_int
|
|
9
|
+
from rdkit_utils._core import (
|
|
10
|
+
ID_COL_NAME,
|
|
11
|
+
SMILES_COL_NAME,
|
|
12
|
+
SdfReader,
|
|
13
|
+
SdfWriter,
|
|
14
|
+
SmilesReader,
|
|
15
|
+
SmilesWriter,
|
|
16
|
+
check_molecules_are_3d,
|
|
17
|
+
create_reader,
|
|
18
|
+
create_writer,
|
|
19
|
+
fragment,
|
|
20
|
+
fragmentAndFingerprint,
|
|
21
|
+
generate_headers,
|
|
22
|
+
get_num_chiral_centers,
|
|
23
|
+
get_num_sp3_centres,
|
|
24
|
+
rdk_merge_mols,
|
|
25
|
+
rdk_mol_supplier,
|
|
26
|
+
rdk_read_molecule_files,
|
|
27
|
+
rdk_read_mols,
|
|
28
|
+
rdk_read_single_mol,
|
|
29
|
+
sdf_record_gen,
|
|
30
|
+
updateChargeFlagInAtomBlock,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
__all__ = [
|
|
34
|
+
"ID_COL_NAME",
|
|
35
|
+
"SMILES_COL_NAME",
|
|
36
|
+
"SdfReader",
|
|
37
|
+
"SdfWriter",
|
|
38
|
+
"SmilesReader",
|
|
39
|
+
"SmilesWriter",
|
|
40
|
+
"add_common_molecule_io_args",
|
|
41
|
+
"check_molecules_are_3d",
|
|
42
|
+
"create_reader",
|
|
43
|
+
"create_writer",
|
|
44
|
+
"fragment",
|
|
45
|
+
"fragmentAndFingerprint",
|
|
46
|
+
"generate_headers",
|
|
47
|
+
"get_num_chiral_centers",
|
|
48
|
+
"get_num_sp3_centres",
|
|
49
|
+
"rdk_merge_mols",
|
|
50
|
+
"rdk_mol_supplier",
|
|
51
|
+
"rdk_read_molecule_files",
|
|
52
|
+
"rdk_read_mols",
|
|
53
|
+
"rdk_read_single_mol",
|
|
54
|
+
"sdf_record_gen",
|
|
55
|
+
"str_or_int",
|
|
56
|
+
"updateChargeFlagInAtomBlock",
|
|
57
|
+
]
|