1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
//! # PDBRust
//!
//! A high-performance Rust library for parsing and analyzing Protein Data Bank (PDB)
//! and mmCIF structure files.
//!
//! PDBRust provides comprehensive tools for working with molecular structure data,
//! from simple file parsing to advanced structural analysis. It's designed for
//! bioinformatics pipelines, structural biology research, and machine learning
//! applications that work with protein structures.
//!
//! For detailed documentation, examples, and best practices, see the [guide] module.
//!
//! ## Quick Start
//!
//! ```rust,no_run
//! use pdbrust::{parse_pdb_file, PdbStructure};
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Parse a PDB file
//! let structure = parse_pdb_file("protein.pdb")?;
//!
//! println!("Atoms: {}", structure.atoms.len());
//! println!("Chains: {:?}", structure.get_chain_ids());
//!
//! Ok(())
//! }
//! ```
//!
//! ## Feature Flags
//!
//! PDBRust uses feature flags to keep the core library lightweight while offering
//! extensive optional functionality:
//!
//! | Feature | Description | Default |
//! |---------|-------------|---------|
//! | `filter` | Structure filtering, extraction, and cleaning | No |
//! | `descriptors` | Structural descriptors (Rg, composition, B-factor, pLDDT) | No |
//! | `quality` | Quality assessment and reports | No |
//! | `summary` | Unified summaries (requires descriptors + quality) | No |
//! | `rcsb` | RCSB PDB search and download | No |
//! | `rcsb-async` | Async/concurrent bulk downloads with rate limiting | No |
//! | `parallel` | Parallel processing with Rayon | No |
//! | `geometry` | RMSD calculation and structure alignment (Kabsch) | No |
//! | `dssp` | DSSP-like secondary structure assignment | No |
//! | `dockq` | DockQ v2 interface quality for protein complexes | No |
//! | `gzip` | Parse gzip-compressed files (.ent.gz, .pdb.gz) | No |
//! | `analysis` | All analysis features combined | No |
//! | `full` | Everything | No |
//!
//! Enable features in your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! pdbrust = { version = "0.7", features = ["filter", "descriptors"] }
//! ```
//!
//! ## Core Features
//!
//! ### Parsing
//!
//! - Parse both PDB and mmCIF files with comprehensive error handling
//! - Automatic format detection based on file content
//! - Support for multiple models (NMR ensembles)
//! - Handle alternate conformations (altlocs)
//!
//! ### Structure Data
//!
//! - ATOM/HETATM records with full coordinate data
//! - SEQRES sequence information
//! - CONECT connectivity records
//! - SSBOND disulfide bond definitions
//! - Header, title, and remark metadata
//!
//! ## Optional Features
//!
//! ### Filtering (`filter` feature)
//!
//! ```rust,ignore
//! // Remove ligands and keep only chain A
//! let cleaned = structure
//! .remove_ligands()
//! .keep_only_chain("A")
//! .keep_only_backbone();
//!
//! // Extract CA coordinates
//! let ca_coords = structure.get_ca_coords(None);
//! ```
//!
//! ### Structural Descriptors (`descriptors` feature)
//!
//! ```rust,ignore
//! // Compute structural properties
//! let rg = structure.radius_of_gyration();
//! let composition = structure.aa_composition();
//! let hydrophobic = structure.hydrophobic_ratio();
//! ```
//!
//! ### Quality Assessment (`quality` feature)
//!
//! ```rust,ignore
//! // Get comprehensive quality report
//! let report = structure.quality_report();
//!
//! if report.is_analysis_ready() {
//! println!("Structure is ready for analysis");
//! }
//! ```
//!
//! ### RCSB Integration (`rcsb` feature)
//!
//! ```rust,ignore
//! use pdbrust::rcsb::{download_structure, rcsb_search, SearchQuery, FileFormat};
//!
//! // Download from RCSB PDB
//! let structure = download_structure("1UBQ", FileFormat::Pdb)?;
//!
//! // Search RCSB
//! let query = SearchQuery::new()
//! .with_text("kinase")
//! .with_resolution_max(2.0);
//! let results = rcsb_search(&query, 10)?;
//! ```
//!
//! ### Async RCSB Downloads (`rcsb-async` feature)
//!
//! ```rust,ignore
//! use pdbrust::rcsb::{download_multiple_async, AsyncDownloadOptions, FileFormat};
//!
//! // Download multiple structures concurrently
//! let pdb_ids = vec!["1UBQ", "8HM2", "4INS"];
//! let results = download_multiple_async(&pdb_ids, FileFormat::Pdb, None).await;
//!
//! // With rate limiting options
//! let options = AsyncDownloadOptions::default()
//! .with_max_concurrent(10)
//! .with_rate_limit_ms(50);
//! let results = download_multiple_async(&pdb_ids, FileFormat::Cif, Some(options)).await;
//! ```
//!
//! ### Geometry (`geometry` feature)
//!
//! ```rust,ignore
//! use pdbrust::geometry::AtomSelection;
//!
//! // Calculate RMSD between structures
//! let rmsd = structure1.rmsd_to(&structure2)?; // CA atoms by default
//!
//! // Align structures using Kabsch algorithm
//! let (aligned, result) = mobile.align_to(&target)?;
//! println!("RMSD: {:.4} Å ({} atoms)", result.rmsd, result.num_atoms);
//!
//! // Per-residue RMSD for flexibility analysis
//! let per_res = mobile.per_residue_rmsd_to(&target)?;
//! ```
//!
//! ### Secondary Structure (`dssp` feature)
//!
//! ```rust,ignore
//! // DSSP-like secondary structure assignment
//! let ss = structure.assign_secondary_structure();
//! println!("Helix: {:.1}%", ss.helix_fraction * 100.0);
//! println!("Sheet: {:.1}%", ss.sheet_fraction * 100.0);
//!
//! // Compact string representation (e.g., "HHHHEEEECCCC")
//! let ss_string = structure.secondary_structure_string();
//! ```
//!
//! ### Gzip Support (`gzip` feature)
//!
//! ```rust,ignore
//! use pdbrust::{parse_gzip_structure_file, parse_gzip_pdb_file};
//!
//! // Parse gzip-compressed files directly
//! let structure = parse_gzip_structure_file("pdb1ubq.ent.gz")?;
//! let structure = parse_gzip_pdb_file("protein.pdb.gz")?;
//! ```
//!
//! ## Format Support
//!
//! ### PDB Format
//!
//! Traditional fixed-width text format with support for:
//! - ATOM/HETATM records
//! - HEADER, TITLE, REMARK records
//! - SEQRES, CONECT, SSBOND records
//! - MODEL/ENDMDL for multi-model structures
//!
//! ### mmCIF Format
//!
//! Modern dictionary-based format with support for:
//! - `_atom_site` category (converted to ATOM records)
//! - `_entity_poly_seq` category (converted to SEQRES records)
//! - `_struct_disulfid` category (converted to SSBOND records)
//! - Header and metadata information
//!
//! ## Examples
//!
//! ### Auto-detect Format
//!
//! ```rust,no_run
//! use pdbrust::parse_structure_file;
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Works with both .pdb and .cif files
//! let structure = parse_structure_file("example.cif")?;
//!
//! // Get all chain IDs
//! let chains = structure.get_chain_ids();
//!
//! // Get sequence for a specific chain
//! if let Some(chain_id) = chains.first() {
//! let sequence = structure.get_sequence(chain_id);
//! println!("Sequence for chain {}: {:?}", chain_id, sequence);
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ### Format-Specific Parsing
//!
//! ```rust,no_run
//! use pdbrust::{parse_pdb_file, parse_mmcif_file};
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Parse PDB format explicitly
//! let pdb_structure = parse_pdb_file("structure.pdb")?;
//!
//! // Parse mmCIF format explicitly
//! let mmcif_structure = parse_mmcif_file("structure.cif")?;
//!
//! Ok(())
//! }
//! ```
//!
//! ## Performance
//!
//! PDBRust is designed for high performance. Benchmarks against the Python
//! `libraryPDB` library show 40-260x speedups for common operations:
//!
//! | Operation | Python | Rust | Speedup |
//! |-----------|--------|------|---------|
//! | Parse PDB file | 15ms | 0.36ms | 42x |
//! | Remove ligands | 8ms | 0.03ms | 267x |
//! | Radius of gyration | 2ms | 0.05ms | 40x |
//!
//! ## Error Handling
//!
//! All parsing functions return `Result<T, PdbError>` with detailed error context:
//!
//! ```rust,no_run
//! use pdbrust::{parse_pdb_file, PdbError};
//!
//! match parse_pdb_file("structure.pdb") {
//! Ok(structure) => println!("Loaded {} atoms", structure.atoms.len()),
//! Err(PdbError::IoError(e)) => eprintln!("File error: {}", e),
//! Err(e) => eprintln!("Parse error: {}", e),
//! }
//! ```
// Module exports
// Conditional modules
// Re-export selection error type for convenience
pub use SelectionError;
// Re-export descriptor types for convenience
pub use ;
// Re-export AlphaFold/pLDDT types
pub use ;
// Re-export protein-ligand interaction types
pub use ;
// Re-export dihedral types (requires dssp + descriptors)
pub use ;
// Re-export hydrogen bond types (requires dssp + descriptors)
pub use ;
// Re-export ligand quality types for convenience
pub use ;
// Re-exports for convenience
pub use PdbStructure;
pub use PdbError;
pub use ;
pub use ;
pub use ;
// Gzip parsing functions (requires "gzip" feature)
pub use ;
// Gzip writing functions (requires "gzip" feature)
pub use write_gzip_mmcif_file;