htmd.builder.solvate module#
- htmd.builder.solvate.solvate(mol: Molecule, pad: float | None = None, minmax: list | ndarray | None = None, centersel: str | ndarray | None = None, boxsize: float | list | ndarray | None = None, negx: float = 0, posx: float = 0, negy: float = 0, posy: float = 0, negz: float = 0, posz: float = 0, buffer: float = 2.4, watsize: float = 65.4195, prefix: str = 'W', rotate: bool = False, spdb: str | None = None) Molecule#
Solvate a molecular system in a water box.
Places water molecules around the input molecule by tiling a pre-built water box and removing waters that clash with existing atoms or fall outside the specified box boundaries.
- Parameters:
mol (
Molecule) – The molecule to solvate.pad (float, optional) – Uniform padding in Angstroms to add around the molecule in all six directions. Overrides negx, posx, negy, posy, negz, posz.
minmax (list or np.ndarray, optional) – Explicit box boundaries as a 2D array of the form
[[minx, miny, minz], [maxx, maxy, maxz]]. If None, derived from the molecule’s own coordinates.centersel (str or np.ndarray, optional) – An atom selection string, a boolean mask, or an integer index array (see
Molecule.atomselect) defining the center of the solvation box. The geometric center of the selected atoms is used. Must be combined with boxsize.boxsize (float or list or np.ndarray, optional) – Dimensions of the solvation box. A single float creates a cubic box; a 3-element list
[sx, sy, sz]creates an axis-aligned box. Must be combined with centersel.negx (float, optional) – Padding in Angstroms in the -x direction.
posx (float, optional) – Padding in Angstroms in the +x direction.
negy (float, optional) – Padding in Angstroms in the -y direction.
posy (float, optional) – Padding in Angstroms in the +y direction.
negz (float, optional) – Padding in Angstroms in the -z direction.
posz (float, optional) – Padding in Angstroms in the +z direction.
buffer (float, optional) – Minimum distance in Angstroms between water molecules and other atoms.
watsize (float, optional) – Edge length in Angstroms of the pre-built water box tile.
prefix (str, optional) – Prefix string used for water segment names.
rotate (bool, optional) – If True, rotate the molecule to minimize box volume (not yet implemented).
spdb (str, optional) – Path to a custom water PDB file. If None, uses the built-in water box.
- Returns:
mol – A copy of the input molecule with water molecules added.
- Return type:
Examples
>>> smol = solvate(mol, pad=10) >>> smol = solvate(mol, minmax=[[-20, -20, -20],[20, 20, 20]]) >>> smol = solvate(mol, centersel="protein", boxsize=100) >>> smol = solvate(mol, centersel="protein", boxsize=[80, 80, 120])