This skill should be used when the user asks to "create a packmol input", "pack molecules with packmol", "solvate a protein", "build an initial configuration", "setup molecular dynamics", or discusses molecular packing, solvation, or building simulation starting structures.
Build initial configurations for molecular dynamics simulations using Packmol.
Packmol creates initial configurations for MD simulations by packing molecules according to spatial constraints. It places molecules in boxes, around proteins, at interfaces, or within complex geometries (spheres, cylinders, ellipsoids) while ensuring no overlaps.
Install Packmol via pip:
pip install packmol
Verify installation:
packmol -h
For more installation options, see the Packmol website.
Create a simple box of water molecules:
# water_box.inp
tolerance 2.0
filetype pdb
output water_box.pdb
structure water.pdb
number 1000
inside box 0. 0. 0. 40. 40. 40.
end structure
Run Packmol:
packmol < water_box.inp
Solvate a protein with water and ions:
# solvation.inp
tolerance 2.0
filetype pdb
output solvated.pdb
structure protein.pdb
number 1
fixed 0. 0. 0. 0. 0. 0.
center
end structure
structure water.pdb
number 5000
inside box -10. -10. -10. 50. 50. 50.
end structure
structure SOD.pdb
number 10
inside box -10. -10. -10. 50. 50. 50.
end structure
structure CLA.pdb
number 10
inside box -10. -10. -10. 50. 50. 50.
end structure
Build a water/chloroform interface:
# interface.inp
tolerance 2.0
filetype pdb
output interface.pdb
pbc -20. -20. -30. 20. 20. 30.
structure water.pdb
number 1000
below plane 0. 0. 1. 0.
end structure
structure chloroform.pdb
number 200
above plane 0. 0. 1. 0.
end structure
Every Packmol input file requires:
structure molecule.pdb
number <N> # Number of molecules
inside|outside <constraint> # Spatial constraint
[optional parameters]
end structure
inside box xmin ymin zmin xmax ymax zmaxinside sphere xcenter ycenter zcenter radiusinside cylinder x1 y1 z1 dx dy dz radius lengthabove plane a b c d or below plane a b c dinside ellipsoid xc yc zc xa yb zc scaleSee references/constraints.md for complete constraint documentation.
Build boxes with multiple molecule types.
Example: Water/ethanol mixture
tolerance 2.0
output mixture.pdb
filetype pdb
structure water.pdb
number 800
inside box 0. 0. 0. 40. 40. 40.
end structure
structure ethanol.pdb
number 200
inside box 0. 0. 0. 40. 40. 40.
end structure
Solvate biomolecules with water and ions for neutralization.
Key parameters:
fixed with center for the proteinAutomatic solvation helper:
python scripts/solvate_helper.py protein.pdb --shell 15.0 --charge +4
Build liquid-liquid or liquid-vapor interfaces using plane constraints.
Example: Water/hexane interface
tolerance 2.0
output interface.pdb
pbc -20. -20. -30. 20. 20. 30.
structure water.pdb
number 1000
below plane 0. 0. 1. 0.
end structure
structure hexane.pdb
number 200
above plane 0. 0. 1. 0.
end structure
Use spherical, cylindrical, or ellipsoidal constraints for complex geometries.
Example: Spherical vesicle
structure lipid.pdb
number 2000
inside sphere 0. 0. 0. 40.
atoms 1 2 3 4
outside sphere 0. 0. 0. 35.
end atoms
end structure
structure water.pdb
number 2000
inside sphere 0. 0. 0. 35.
end structure
structure water.pdb
number 5000
outside sphere 0. 0. 0. 45.
end structure
<distance>: Minimum intermolecular distance (Å). Default: 2.0 for all-atom<filename>: Output file name<format>: pdb, xyz, or tinker<dimensions>: Periodic boundary conditions (e.g., pbc 30. 30. 60.)<integer>: Random seed for reproducibility<factor>: Distance scaling for optimization (default: 1.0)<N>: Maximum iterations (default: 20)<value>: Convergence precision (default: 0.01)See references/parameters.md for complete parameter reference.
constrain_rotation x 180. 20. # Constrain rotation around x-axis
constrain_rotation y 180. 20. # Constrain rotation around y-axis
constrain_rotation z 180. 20. # Constrain rotation around z-axis
Apply constraints to specific atoms within molecules:
structure molecule.pdb
number 100
inside box 0. 0. 0. 30. 30. 30.
atoms 1 2 3
inside box 0. 0. 25. 30. 30. 30.
end atoms
end structure
packmol < input.inp
Success message:
------------------------------
Success!
Final objective function value: .22503E-01
Maximum violation of target distance: 0.000000
Maximum violation of the constraints: .78985E-02
------------------------------
Check that both violations are < 0.01 for a valid solution.
python scripts/check_overlaps.py output.pdb --tolerance 2.0
python scripts/verify_success.py input.inp output.pdb
python scripts/analyze_density.py output.pdb
python scripts/validate_input.py input.inp
"Killed" error: System too large
No convergence:
discale 1.5 to scale distancesmaxitStrange geometries:
check keyword to validate constraints without packingIncorrect atom count:
scripts/validate_input.pySee references/troubleshooting.md for detailed solutions.
Explore example input files in the examples/ directory:
Use templates in templates/ as starting points:
Use Python scripts in scripts/ for automation:
Use pbc for periodic systems:
pbc 30. 30. 60. # or pbc xmin ymin zmin xmax ymax zmax
Build large systems incrementally:
structure water.pdb
number 1000
inside box 0. 0. 0. 40. 40. 40.
restart_to water1.pack
end structure
Then restart:
structure water.pdb
number 1000
restart_from water1.pack
end structure
Set different radii for multiscale models:
structure molecule.pdb
number 100
radius 1.5 # All atoms
end structure
structure molecule.pdb
number 100
atoms 1 2
radius 1.5 # Specific atoms
end atoms
end structure
Validate constraints without packing:
structure molecule.pdb
number 100
inside box 0. 0. 0. 30. 30. 30.
check
end structure
check keyword to validate regionsseed for repeatable resultsN_ions = charge / efixed with center for protein positioningconstrain_rotation to orient lipidscylinder constraint for pore regionoutside constraint for bulk regionFor detailed information on specific topics, see: