sdfrust 0.7.0__cp313-cp313-win_amd64.whl

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.
sdfrust/__init__.py ADDED
@@ -0,0 +1,162 @@
1
+ """
2
+ sdfrust - Fast Rust-based SDF, MOL2, and XYZ molecular structure file parser.
3
+
4
+ This package provides high-performance parsing and writing of SDF (Structure Data File),
5
+ MOL2 (TRIPOS), and XYZ molecular structure formats. It is implemented in Rust for speed
6
+ and safety.
7
+
8
+ Quick Start:
9
+ >>> import sdfrust
10
+ >>> mol = sdfrust.parse_sdf_file("molecule.sdf")
11
+ >>> print(f"Name: {mol.name}")
12
+ >>> print(f"Atoms: {mol.num_atoms}")
13
+ >>> print(f"Formula: {mol.formula()}")
14
+
15
+ Features:
16
+ - Parse SDF V2000 and V3000 formats
17
+ - Parse TRIPOS MOL2 format
18
+ - Parse XYZ format
19
+ - Write SDF V2000 and V3000 formats
20
+ - Memory-efficient streaming iterators for large files
21
+ - Molecular descriptors (MW, exact mass, ring count, etc.)
22
+ - NumPy integration for coordinate arrays (optional)
23
+ - Transparent gzip decompression (optional, check with gzip_enabled())
24
+ """
25
+
26
+ from sdfrust._sdfrust import (
27
+ # Version
28
+ __version__,
29
+ # Classes
30
+ Atom,
31
+ Bond,
32
+ BondOrder,
33
+ BondStereo,
34
+ Molecule,
35
+ SdfFormat,
36
+ SdfIterator,
37
+ SdfV3000Iterator,
38
+ Mol2Iterator,
39
+ XyzIterator,
40
+ # SDF V2000 parsing
41
+ parse_sdf_file,
42
+ parse_sdf_string,
43
+ parse_sdf_file_multi,
44
+ parse_sdf_string_multi,
45
+ # SDF V3000 parsing
46
+ parse_sdf_v3000_file,
47
+ parse_sdf_v3000_string,
48
+ parse_sdf_v3000_file_multi,
49
+ parse_sdf_v3000_string_multi,
50
+ # SDF auto-detection parsing (V2000/V3000)
51
+ parse_sdf_auto_file,
52
+ parse_sdf_auto_string,
53
+ parse_sdf_auto_file_multi,
54
+ parse_sdf_auto_string_multi,
55
+ # Unified auto-detection (SDF V2000, V3000, MOL2, XYZ)
56
+ detect_format,
57
+ parse_auto_file,
58
+ parse_auto_string,
59
+ parse_auto_file_multi,
60
+ parse_auto_string_multi,
61
+ # MOL2 parsing
62
+ parse_mol2_file,
63
+ parse_mol2_string,
64
+ parse_mol2_file_multi,
65
+ parse_mol2_string_multi,
66
+ # XYZ parsing
67
+ parse_xyz_file,
68
+ parse_xyz_string,
69
+ parse_xyz_file_multi,
70
+ parse_xyz_string_multi,
71
+ # SDF V2000 writing
72
+ write_sdf_file,
73
+ write_sdf_string,
74
+ write_sdf_file_multi,
75
+ # SDF V3000 writing
76
+ write_sdf_v3000_file,
77
+ write_sdf_v3000_string,
78
+ write_sdf_v3000_file_multi,
79
+ # SDF auto-format writing
80
+ write_sdf_auto_file,
81
+ write_sdf_auto_string,
82
+ # MOL2 writing
83
+ write_mol2_file,
84
+ write_mol2_string,
85
+ write_mol2_file_multi,
86
+ # Iterators
87
+ iter_sdf_file,
88
+ iter_sdf_v3000_file,
89
+ iter_mol2_file,
90
+ iter_xyz_file,
91
+ # Utility functions
92
+ gzip_enabled,
93
+ )
94
+
95
+ __all__ = [
96
+ # Version
97
+ "__version__",
98
+ # Classes
99
+ "Atom",
100
+ "Bond",
101
+ "BondOrder",
102
+ "BondStereo",
103
+ "Molecule",
104
+ "SdfFormat",
105
+ "SdfIterator",
106
+ "SdfV3000Iterator",
107
+ "Mol2Iterator",
108
+ "XyzIterator",
109
+ # SDF V2000 parsing
110
+ "parse_sdf_file",
111
+ "parse_sdf_string",
112
+ "parse_sdf_file_multi",
113
+ "parse_sdf_string_multi",
114
+ # SDF V3000 parsing
115
+ "parse_sdf_v3000_file",
116
+ "parse_sdf_v3000_string",
117
+ "parse_sdf_v3000_file_multi",
118
+ "parse_sdf_v3000_string_multi",
119
+ # SDF auto-detection parsing (V2000/V3000)
120
+ "parse_sdf_auto_file",
121
+ "parse_sdf_auto_string",
122
+ "parse_sdf_auto_file_multi",
123
+ "parse_sdf_auto_string_multi",
124
+ # Unified auto-detection (SDF V2000, V3000, MOL2, XYZ)
125
+ "detect_format",
126
+ "parse_auto_file",
127
+ "parse_auto_string",
128
+ "parse_auto_file_multi",
129
+ "parse_auto_string_multi",
130
+ # MOL2 parsing
131
+ "parse_mol2_file",
132
+ "parse_mol2_string",
133
+ "parse_mol2_file_multi",
134
+ "parse_mol2_string_multi",
135
+ # XYZ parsing
136
+ "parse_xyz_file",
137
+ "parse_xyz_string",
138
+ "parse_xyz_file_multi",
139
+ "parse_xyz_string_multi",
140
+ # SDF V2000 writing
141
+ "write_sdf_file",
142
+ "write_sdf_string",
143
+ "write_sdf_file_multi",
144
+ # SDF V3000 writing
145
+ "write_sdf_v3000_file",
146
+ "write_sdf_v3000_string",
147
+ "write_sdf_v3000_file_multi",
148
+ # SDF auto-format writing
149
+ "write_sdf_auto_file",
150
+ "write_sdf_auto_string",
151
+ # MOL2 writing
152
+ "write_mol2_file",
153
+ "write_mol2_string",
154
+ "write_mol2_file_multi",
155
+ # Iterators
156
+ "iter_sdf_file",
157
+ "iter_sdf_v3000_file",
158
+ "iter_mol2_file",
159
+ "iter_xyz_file",
160
+ # Utility functions
161
+ "gzip_enabled",
162
+ ]
Binary file
sdfrust/py.typed ADDED
File without changes
@@ -0,0 +1,271 @@
1
+ Metadata-Version: 2.4
2
+ Name: sdfrust
3
+ Version: 0.7.0
4
+ Classifier: Development Status :: 4 - Beta
5
+ Classifier: Intended Audience :: Science/Research
6
+ Classifier: License :: OSI Approved :: MIT License
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3.9
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Rust
14
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
15
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
16
+ Requires-Dist: pytest>=7.0 ; extra == 'dev'
17
+ Requires-Dist: numpy>=1.20 ; extra == 'dev'
18
+ Requires-Dist: numpy>=1.20 ; extra == 'numpy'
19
+ Provides-Extra: dev
20
+ Provides-Extra: numpy
21
+ License-File: LICENSE
22
+ Summary: Fast Rust-based SDF, MOL2, and XYZ molecular structure file parser
23
+ Keywords: chemistry,sdf,mol2,xyz,cheminformatics,parsing,molecules
24
+ Author-email: Hosein Fooladi <fooladi.hosein@gmail.com>
25
+ License: MIT
26
+ Requires-Python: >=3.9
27
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
28
+ Project-URL: Documentation, https://github.com/hfooladi/sdfrust#readme
29
+ Project-URL: Homepage, https://github.com/hfooladi/sdfrust
30
+ Project-URL: Repository, https://github.com/hfooladi/sdfrust
31
+
32
+ # sdfrust - Python Bindings
33
+
34
+ Fast Rust-based SDF, MOL2, and XYZ molecular structure file parser with Python bindings, including transparent gzip decompression.
35
+
36
+ ## Installation
37
+
38
+ ### From source (requires Rust toolchain)
39
+
40
+ ```bash
41
+ cd sdfrust-python
42
+ pip install maturin
43
+ maturin develop --features numpy
44
+ ```
45
+
46
+ ### Build wheel
47
+
48
+ ```bash
49
+ maturin build --release --features numpy
50
+ pip install target/wheels/sdfrust-*.whl
51
+ ```
52
+
53
+ ## Quick Start
54
+
55
+ ```python
56
+ import sdfrust
57
+
58
+ # Parse a single SDF file
59
+ mol = sdfrust.parse_sdf_file("molecule.sdf")
60
+ print(f"Name: {mol.name}")
61
+ print(f"Atoms: {mol.num_atoms}")
62
+ print(f"Formula: {mol.formula()}")
63
+ print(f"MW: {mol.molecular_weight():.2f}")
64
+
65
+ # Parse multiple molecules
66
+ mols = sdfrust.parse_sdf_file_multi("database.sdf")
67
+ for mol in mols:
68
+ print(f"{mol.name}: {mol.num_atoms} atoms")
69
+
70
+ # Memory-efficient iteration over large files
71
+ for mol in sdfrust.iter_sdf_file("large_database.sdf"):
72
+ print(f"{mol.name}: MW={mol.molecular_weight():.2f}")
73
+ ```
74
+
75
+ ## Supported Formats
76
+
77
+ - **SDF V2000**: Full support for reading and writing (up to 999 atoms/bonds)
78
+ - **SDF V3000**: Full support for reading and writing (unlimited atoms/bonds)
79
+ - **MOL2 TRIPOS**: Full support for reading and writing
80
+ - **XYZ**: Read support for XYZ coordinate files (single and multi-molecule)
81
+ - **Gzip**: Transparent decompression of `.gz` files for all formats
82
+
83
+ ## API Reference
84
+
85
+ ### Parsing Functions
86
+
87
+ #### SDF Files
88
+
89
+ ```python
90
+ # Single molecule
91
+ mol = sdfrust.parse_sdf_file("file.sdf") # V2000
92
+ mol = sdfrust.parse_sdf_auto_file("file.sdf") # Auto-detect V2000/V3000
93
+ mol = sdfrust.parse_sdf_v3000_file("file.sdf") # V3000 only
94
+
95
+ # Multiple molecules
96
+ mols = sdfrust.parse_sdf_file_multi("file.sdf")
97
+ mols = sdfrust.parse_sdf_auto_file_multi("file.sdf")
98
+
99
+ # From string
100
+ mol = sdfrust.parse_sdf_string(content)
101
+ mols = sdfrust.parse_sdf_string_multi(content)
102
+ ```
103
+
104
+ #### MOL2 Files
105
+
106
+ ```python
107
+ mol = sdfrust.parse_mol2_file("file.mol2")
108
+ mols = sdfrust.parse_mol2_file_multi("file.mol2")
109
+ mol = sdfrust.parse_mol2_string(content)
110
+ ```
111
+
112
+ #### Iterators (Memory-Efficient)
113
+
114
+ ```python
115
+ for mol in sdfrust.iter_sdf_file("large.sdf"):
116
+ process(mol)
117
+
118
+ for mol in sdfrust.iter_mol2_file("large.mol2"):
119
+ process(mol)
120
+ ```
121
+
122
+ ### Writing Functions
123
+
124
+ ```python
125
+ # Single molecule
126
+ sdfrust.write_sdf_file(mol, "output.sdf")
127
+ sdfrust.write_sdf_auto_file(mol, "output.sdf") # Auto V2000/V3000
128
+ sdf_string = sdfrust.write_sdf_string(mol)
129
+
130
+ # Multiple molecules
131
+ sdfrust.write_sdf_file_multi(mols, "output.sdf")
132
+ ```
133
+
134
+ ### Molecule Properties
135
+
136
+ ```python
137
+ mol = sdfrust.parse_sdf_file("aspirin.sdf")
138
+
139
+ # Basic info
140
+ print(mol.name) # Molecule name
141
+ print(mol.num_atoms) # Number of atoms
142
+ print(mol.num_bonds) # Number of bonds
143
+ print(mol.formula()) # Molecular formula
144
+
145
+ # Descriptors
146
+ print(mol.molecular_weight()) # Molecular weight
147
+ print(mol.exact_mass()) # Monoisotopic mass
148
+ print(mol.heavy_atom_count()) # Non-hydrogen atoms
149
+ print(mol.ring_count()) # Number of rings
150
+ print(mol.rotatable_bond_count()) # Rotatable bonds
151
+ print(mol.total_charge()) # Sum of formal charges
152
+
153
+ # Geometry
154
+ centroid = mol.centroid() # (x, y, z) center
155
+ mol.translate(1.0, 0.0, 0.0) # Move molecule
156
+ mol.center() # Center at origin
157
+
158
+ # Properties (from SDF data block)
159
+ cid = mol.get_property("PUBCHEM_CID")
160
+ mol.set_property("SOURCE", "generated")
161
+ ```
162
+
163
+ ### Atom Access
164
+
165
+ ```python
166
+ # Iterate over atoms
167
+ for atom in mol.atoms:
168
+ print(f"{atom.element} at ({atom.x}, {atom.y}, {atom.z})")
169
+
170
+ # Get specific atom
171
+ atom = mol.get_atom(0)
172
+ print(atom.element)
173
+ print(atom.formal_charge)
174
+ print(atom.coords()) # (x, y, z) tuple
175
+
176
+ # Filter atoms
177
+ carbons = mol.atoms_by_element("C")
178
+ neighbors = mol.neighbors(0) # Atom indices bonded to atom 0
179
+ ```
180
+
181
+ ### Bond Access
182
+
183
+ ```python
184
+ # Iterate over bonds
185
+ for bond in mol.bonds:
186
+ print(f"{bond.atom1}-{bond.atom2}: {bond.order}")
187
+
188
+ # Filter bonds
189
+ double_bonds = mol.bonds_by_order(sdfrust.BondOrder.double())
190
+ aromatic = mol.has_aromatic_bonds()
191
+
192
+ # Bond properties
193
+ bond = mol.bonds[0]
194
+ print(bond.is_aromatic())
195
+ print(bond.contains_atom(0))
196
+ print(bond.other_atom(0)) # Other atom in bond
197
+ ```
198
+
199
+ ### NumPy Integration
200
+
201
+ ```python
202
+ import numpy as np
203
+ import sdfrust
204
+
205
+ mol = sdfrust.parse_sdf_file("molecule.sdf")
206
+
207
+ # Get coordinates as NumPy array
208
+ coords = mol.get_coords_array() # Shape: (N, 3)
209
+ print(coords.shape)
210
+
211
+ # Modify and set back
212
+ coords[:, 0] += 10.0 # Translate in x
213
+ mol.set_coords_array(coords)
214
+
215
+ # Get atomic numbers
216
+ atomic_nums = mol.get_atomic_numbers() # Shape: (N,)
217
+ ```
218
+
219
+ ### Creating Molecules
220
+
221
+ ```python
222
+ import sdfrust
223
+
224
+ # Create empty molecule
225
+ mol = sdfrust.Molecule("water")
226
+
227
+ # Add atoms
228
+ mol.add_atom(sdfrust.Atom(0, "O", 0.0, 0.0, 0.0))
229
+ mol.add_atom(sdfrust.Atom(1, "H", 0.96, 0.0, 0.0))
230
+ mol.add_atom(sdfrust.Atom(2, "H", -0.24, 0.93, 0.0))
231
+
232
+ # Add bonds
233
+ mol.add_bond(sdfrust.Bond(0, 1, sdfrust.BondOrder.single()))
234
+ mol.add_bond(sdfrust.Bond(0, 2, sdfrust.BondOrder.single()))
235
+
236
+ # Write to file
237
+ sdfrust.write_sdf_file(mol, "water.sdf")
238
+ ```
239
+
240
+ ## Examples
241
+
242
+ The `examples/` directory contains runnable scripts demonstrating real-world usage:
243
+
244
+ | Script | Description |
245
+ |--------|-------------|
246
+ | [`basic_usage.py`](examples/basic_usage.py) | Core API: parsing, writing, atoms, bonds, descriptors, NumPy |
247
+ | [`format_conversion.py`](examples/format_conversion.py) | Multi-format detection, XYZ parsing, SDF/MOL2 conversion, round-trips |
248
+ | [`batch_analysis.py`](examples/batch_analysis.py) | Drug library processing: filtering, sorting, Lipinski analysis |
249
+ | [`geometry_analysis.py`](examples/geometry_analysis.py) | 3D geometry: distance matrices, RMSD, rotation, transforms |
250
+
251
+ ```bash
252
+ cd sdfrust-python
253
+ maturin develop --features numpy,geometry
254
+ python examples/basic_usage.py
255
+ python examples/format_conversion.py
256
+ python examples/batch_analysis.py
257
+ python examples/geometry_analysis.py
258
+ ```
259
+
260
+ ## Performance
261
+
262
+ sdfrust is implemented in Rust for maximum performance. Benchmarks show it is
263
+ significantly faster than pure Python parsers and comparable to C++ implementations.
264
+
265
+ For large files, use the iterator API (`iter_sdf_file`) to process molecules
266
+ one at a time without loading the entire file into memory.
267
+
268
+ ## License
269
+
270
+ MIT License
271
+
@@ -0,0 +1,8 @@
1
+ sdfrust/__init__.py,sha256=3a5ePmtgX6zt5z2BwnnrPWLlhYJi9gJNDZQYG6sqT68,4303
2
+ sdfrust/_sdfrust.cp313-win_amd64.pyd,sha256=DPpqJRPxZCiGkgyGXexD1DP-jctV0H5IS24MGVoryrU,1512960
3
+ sdfrust/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ sdfrust-0.7.0.dist-info/METADATA,sha256=60GM9vqfb4BxJfce8cqRPDw0ezOl-vzt6iWXERVElhY,7777
5
+ sdfrust-0.7.0.dist-info/WHEEL,sha256=s-xaFzw5tWWSSNKn-DuKhiHUeYX5UHiEcnl_hzDJ9ZY,97
6
+ sdfrust-0.7.0.dist-info/licenses/LICENSE,sha256=5g03Hc1SPZbV5tFuX3Qt6GS0Lc0EaLnzeC8cH4EvNQY,1097
7
+ sdfrust-0.7.0.dist-info/sboms/sdfrust-python.cyclonedx.json,sha256=CV7E1W9n0VG_O2nD9CAC5mFu4yqqHXWwlM7Y5ZrU4QQ,56453
8
+ sdfrust-0.7.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.15.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp313-cp313-win_amd64
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 Hosein Fooladi
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.