molpy.pack¶
BoxRegion ¶
BoxRegion(lengths, origin=None, coord_field='xyz')
Bases: Region
Source code in src/molpy/core/region.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
mask ¶
mask(block)
Extract coordinates from block and apply geometric predicate.
Source code in src/molpy/core/region.py
92 93 94 95 | |
Molpack ¶
Molpack(workdir, packer='packmol')
High-level molecular packing interface.
This class provides a clean API for molecular packing with the ability to choose different packer backends.
Usage
packer = Molpack(workdir=Path("packing"), packer="packmol") packer.add_target(frame, number=100, constraint=box_constraint) result = packer.optimize(max_steps=1000, seed=42)
Initialize Molpack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workdir
|
Path
|
Working directory for packing operations |
required |
packer
|
Literal['packmol', 'nlopt']
|
Packer backend to use ("packmol" or "nlopt") |
'packmol'
|
Source code in src/molpy/pack/molpack.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
add_target ¶
add_target(frame, number, constraint)
Add a packing target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
Frame
|
Frame containing the molecule structure |
required |
number
|
int
|
Number of copies to pack |
required |
constraint
|
Any
|
Spatial constraint for packing |
required |
Returns:
| Type | Description |
|---|---|
Target
|
Target object |
Source code in src/molpy/pack/molpack.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
optimize ¶
optimize(max_steps=1000, seed=None)
Run packing optimization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_steps
|
int
|
Maximum optimization steps |
1000
|
seed
|
int | None
|
Random seed. If None, uses random seed. |
None
|
Returns:
| Type | Description |
|---|---|
Frame
|
Packed Frame |
Source code in src/molpy/pack/molpack.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
Packmol ¶
Packmol(executable=None, workdir=None)
Bases: Packer
Packer implementation using Packmol binary.
This class provides a packer that uses Packmol binary for packing molecules.
Usage
packer = Packmol(executable="packmol") result = packer(targets, max_steps=1000, seed=4628)
Initialize Packmol packer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
executable
|
str | None
|
Path to packmol executable. If None, uses: 1. PACKMOL_BIN environment variable 2. "packmol" on PATH |
None
|
workdir
|
Path | None
|
Working directory for temporary files. If None, creates a temporary directory. |
None
|
Source code in src/molpy/pack/packer/packmol.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
generate_input_only ¶
generate_input_only(targets=None, max_steps=1000, seed=4628, tolerance=2.0, workdir=None)
Generate Packmol input file without running the packing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
targets
|
list[Target] | None
|
List of packing targets. If None, uses stored targets. |
None
|
max_steps
|
int
|
Maximum optimization steps |
1000
|
seed
|
int
|
Random seed for packing |
4628
|
tolerance
|
float
|
Distance tolerance in Angstroms |
2.0
|
workdir
|
Path | None
|
Optional working directory |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to generated input file |
Source code in src/molpy/pack/packer/packmol.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |
generate_input_script ¶
generate_input_script(targets=None, max_steps=1000, seed=4628, tolerance=2.0, workdir=None)
Generate Packmol input script as a Script object without saving.
This allows you to preview, edit, or format the script before saving.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
targets
|
list[Target] | None
|
List of packing targets. If None, uses stored targets. |
None
|
max_steps
|
int
|
Maximum optimization steps |
1000
|
seed
|
int
|
Random seed for packing |
4628
|
tolerance
|
float
|
Distance tolerance in Angstroms |
2.0
|
workdir
|
Path | None
|
Optional working directory (for structure file paths) |
None
|
Returns:
| Type | Description |
|---|---|
Script
|
Script object containing Packmol input |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no targets provided |
Source code in src/molpy/pack/packer/packmol.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
pack ¶
pack(targets=None, max_steps=1000, seed=None)
Pack molecules using Packmol backend.
This method implements the abstract pack() method from Packer base class. It delegates to call() for the actual implementation.
Source code in src/molpy/pack/packer/packmol.py
548 549 550 551 552 553 554 555 556 557 558 559 | |
SphereRegion ¶
SphereRegion(radius, center=None, coord_field='xyz')
Bases: Region
Source code in src/molpy/core/region.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
mask ¶
mask(block)
Extract coordinates from block and apply geometric predicate.
Source code in src/molpy/core/region.py
163 164 165 166 | |
get_packer ¶
get_packer(name, *args, **kwargs)
Factory function to get a packer by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Packer name ("packmol" or "nlopt") |
required |
*args
|
Any
|
Positional arguments passed to packer constructor |
()
|
**kwargs
|
Any
|
Keyword arguments passed to packer constructor |
{}
|
Returns:
| Type | Description |
|---|---|
Packmol
|
Packer instance |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If packer name is not recognized |
Source code in src/molpy/pack/packer/__init__.py
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 | |