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
//! # molpack
//!
//! Packmol-grade molecular packing in pure Rust. Produces a non-overlapping
//! arrangement of N molecule types with copy counts and geometric restraints,
//! using a faithful port of Packmol's GENCAN-driven three-phase algorithm
//! (Martínez et al. 2009). Correctness is checked against Packmol's reference
//! output for five canonical workloads.
//!
//! This crate was split out of the molrs workspace in 2026 and is now
//! maintained independently. It depends on the unified `molcrafts-molrs` crate
//! for shared data structures (always-on `core`) and, behind feature flags, its
//! file I/O (`io`) and force-field (`ff`) modules.
//!
//! ## Documentation map
//!
//! This crate is documented in four dedicated modules; start with
//! [`getting_started`] if you are new.
//!
//! - [`getting_started`] — install, hello-world packing, the three
//! restraint scopes, handlers, relaxers, PBC, running the canonical
//! examples.
//! - [`concepts`] — every abstraction defined in one place: `AtomRestraint`,
//! `Region`, `Relaxer`, `Handler`, `Objective`, `Target`, `Molpack`,
//! `PackContext`; the scope equivalence law; the two-scale contract;
//! the direction-3 extension pattern.
//! - [`architecture`] — module map, dependency graph, core-type
//! relationships, full `pack()` lifecycle diagram, hot-path
//! `evaluate()` walkthrough, invariants, design decisions.
//! - [`extending`] — tutorials for writing your own `AtomRestraint` /
//! `Region` / `Handler` / `Relaxer`; testing + benchmarking
//! discipline; common pitfalls; contributing flow.
//!
//! Reference material (not rustdoc):
//!
//! - [Packmol parity](https://github.com/MolCrafts/molpack/blob/master/docs/packmol_parity.md)
//! — kind-number ↔ Rust struct mapping with Fortran pointers.
//!
//! ## Quick example
//!
//! ```rust,no_run
//! use molpack::{InsideBoxRestraint, Molpack, Target};
//!
//! let positions = [[0.0, 0.0, 0.0], [0.96, 0.0, 0.0], [-0.24, 0.93, 0.0]];
//! let radii = [1.52, 1.20, 1.20];
//!
//! let target = Target::from_coords(&positions, &radii, 100)
//! .with_name("water")
//! .with_restraint(InsideBoxRestraint::new([0.0; 3], [40.0, 40.0, 40.0], [false; 3]));
//!
//! let frame = Molpack::new()
//! .with_tolerance(2.0)
//! .with_precision(0.01)
//! .with_seed(42)
//! .pack(&[target], 200)?;
//!
//! let natoms = frame.get("atoms").and_then(|b| b.nrows()).unwrap_or(0);
//! println!("packed {natoms} atoms");
//! # Ok::<(), molpack::PackError>(())
//! ```
//!
//! ## Public surface at a glance
//!
//! | Category | Items |
//! |---|---|
//! | Builder | [`Molpack`], [`MolpackLogLevel`], [`PackResult`] |
//! | Target | [`Target`], [`CenteringMode`] |
//! | AtomRestraint trait + 14 concrete structs | [`AtomRestraint`] + `InsideBox` / `InsideCube` / `InsideSphere` / `InsideEllipsoid` / `InsideCylinder` / `Outside*` variants / `AbovePlane` / `BelowPlane` / `AboveGaussian` / `BelowGaussian` — each suffixed `…AtomRestraint` |
//! | Region trait + combinators + lift | [`Region`], [`RegionExt`], [`And`], [`Or`], [`Not`], [`RegionRestraint`], [`InsideBoxRegion`], [`InsideSphereRegion`], [`OutsideSphereRegion`], [`Aabb`] |
//! | Handler trait + built-ins | [`Handler`], [`NullHandler`], [`LammpsLogHandler`], [`ProgressHandler`], [`EarlyStopHandler`], [`XYZHandler`], [`StepInfo`], [`PhaseInfo`], [`PhaseReport`] |
//! | Relaxer trait + built-ins | [`Relaxer`], [`RelaxerRunner`], [`TorsionMcRelaxer`], `LBFGSRelaxer` (`ff` feature) |
//! | Errors | [`PackError`] |
//! | Validation | [`validate_from_targets`], [`ValidationReport`], [`ViolationMetrics`] |
//! | Examples harness | [`ExampleCase`], [`build_targets`], [`example_dir_from_manifest`], [`render_inp_script`] |
//!
//! ## Feature flags
//!
//! - `rayon` — opt into the parallel evaluator (also forwards to `molrs`'s
//! `rayon`).
//! - `io` — pull in molrs's `io` module so [`script::Script::build`] can read
//! PDB / SDF / XYZ / LAMMPS files directly. PyO3 / WASM / embedding hosts that
//! bring their own loader leave this off and use [`script::Script::lower`]
//! with [`script::StructurePlan::apply`] instead.
//! - `cli` — build the `molpack` binary and its integration tests (pulls in
//! `clap` and implies `io`).
//! - `ff` — pull in molrs's `ff` module (MMFF typifier + L-BFGS) and enable the
//! `LBFGSRelaxer`, which relaxes a flexible molecule's internal geometry
//! during packing under a caller-supplied force field.
//!
//! Precision is fixed at `f64` via `molrs::types::F`.
pub use ;
pub use PackContext;
pub use PackError;
pub use ;
pub use ;
pub use Element;
pub use F;
pub use ;
pub use ;
pub use ;
// Force-field geometry relaxer + the molrs `Potential` trait it relaxes against
// (named in `LBFGSRelaxer::new`). Gated on the `ff` feature.
pub use Potential;
pub use LBFGSRelaxer;
pub use ;
pub use ;
pub use ;
// Custom-objective extension surface. `Molpack::pack` drives a `dyn Objective`
// through GENCAN; downstream code that implements a bespoke objective (or wants
// to evaluate the packing energy/gradient directly) names these at the crate
// root rather than reaching into the `objective` / `constraints` modules.
pub use ;
pub use Objective;
// ────────────────────────────────────────────────────────────────────────────
// Documentation modules (rustdoc-only; no runtime items).
// Content lives in `docs/*.md`, loaded via `include_str!` so each markdown
// file can be edited independently while rustdoc renders the whole chapter.
// ────────────────────────────────────────────────────────────────────────────
// ────────────────────────────────────────────────────────────────────────────
// Prelude — bulk re-export of the vocabulary a typical packing script needs.
// ────────────────────────────────────────────────────────────────────────────
/// Bulk re-export of the items a typical packing script needs.
///
/// ```no_run
/// use molpack::prelude::*;
///
/// let target = Target::from_coords(&[[0.0, 0.0, 0.0]], &[1.0], 10)
/// .with_restraint(InsideBoxRestraint::new([0.0; 3], [10.0; 3], [false; 3]));
/// let frame = Molpack::new().pack(&[target], 100)?;
/// # Ok::<(), molpack::PackError>(())
/// ```
///
/// The crate root still re-exports everything for direct `use molpack::T`
/// access; the prelude exists to avoid a 20-line `use` block at the top of
/// every example.