Packing#
Packing tasks select which blocks may repack or design. Rotamer samplers define
the conformations considered by the packer. tmol.PackerTask,
tmol.PackerPalette, and tmol.pack_rotamers() are imported from
the top-level package and documented in Top-level API. The samplers,
rotamer construction, and tmol.pack.SetPackerTask are exported by
tmol.pack.
Side-chain packing tasks, energy tables, and annealing.
- class tmol.pack.ChiSampler[source]#
Bases:
ConformerSamplerBase class for samplers that define conformers through chi angles.
- annotate_residue_type(rt: RefinedResidueType) None[source]#
Attach optional sampler metadata to one residue type.
- annotate_packed_block_types(packed_block_types: PackedBlockTypes) None[source]#
Attach optional sampler metadata to packed block types.
- defines_rotamers_for_rt(rt: RefinedResidueType) bool[source]#
Return whether this sampler supports a residue type.
- first_sc_atoms_for_rt(rt_name: str) tuple[str, ...][source]#
Return side-chain roots used to transfer main-chain geometry.
- create_samples_for_poses(pose_stack: PoseStack, task: PackerTask) tuple[Tensor, Tensor, dict[str, Any]][source]#
Create chi samples and preserve their defining atoms and angles.
- fill_dofs_for_samples(pose_stack: PoseStack, task: PackerTask, orig_kinforest: KinForest, orig_dofs_kto: Tensor[slice(None, None, None), 9], gbt_for_conformer: Tensor, block_type_ind_for_conformer: Tensor, n_dof_atoms_offset_for_conformer: Tensor, conformer_built_by_sampler: Tensor, conf_inds_for_sampler: Tensor, sampler_n_rots_for_gbt: Tensor, sampler_gbt_for_rotamer: Tensor, sample_dict: dict[str, Any], conf_dofs_kto: Tensor[slice(None, None, None), 9]) None[source]#
Write this sampler’s conformer degrees of freedom in place.
- class tmol.pack.ConjugatedSCSampler(sidechain: SidechainSampler)[source]#
Bases:
objectSample side chains while keeping covalently linked groups together.
A residue with something bonded to its side chain has to be sampled as one unit; moving the two apart would break the bond. This wraps a side-chain bundle so that grouping is applied without the caller repeating the exclusion bookkeeping.
Examples
>>> task.add_conformer_sampler( ... ConjugatedSCSampler( ... SidechainSampler.from_database(database, pose_stack.device) ... ) ... )
- class tmol.pack.DunbrackChiSampler(dun_param_resolver: DunbrackParamResolver, chi_sample_expanded_limit: int = 1000, chi_sample_limit: int = 1000)[source]#
Bases:
ChiSamplerSample amino-acid side-chain conformers from Dunbrack libraries.
- annotate_residue_type(restype: RefinedResidueType)[source]#
TEMP TEMP TEMP: assume the dihedrals we care about are phi and psi
- annotate_packed_block_types(packed_block_types: PackedBlockTypes)[source]#
Attach optional sampler metadata to packed block types.
- defines_rotamers_for_rt(rt: RefinedResidueType)[source]#
Whether a rotamer library reaches this residue type.
A library resolving answers it for most residues: glycine and alanine have nothing to rotate and no library, and a noncanonical has one only where a reference names it. A residue that samples heavy chi of its own is built from those alone.
- first_sc_atoms_for_rt(rt: RefinedResidueType) Tuple[str, ...][source]#
The atom chi1 rotates, which is where the sidechain starts.
Read off the residue rather than named, so a noncanonical whose sidechain does not begin at an atom called CB still transfers its rotamers correctly. Empty for a residue with no chi to rotate.
- class tmol.pack.FallbackSampler[source]#
Bases:
ConformerSamplerInclude the input conformation as a rotamer only for positions that have no rotamers from any other sampler.
This is the default sampler in PackerPalette. Unlike IncludeCurrentSampler, it does not unconditionally add a rotamer for every position; instead it activates only where the other samplers actually produced no rotamers, ensuring that positions covered by, e.g., DunbrackChiSampler do not accumulate an extra current-conformation rotamer.
The trigger is measured rather than declared. A sampler may report through defines_rotamers_for_bts that it handles a block type and still build no rotamers for a given block; trusting the declaration would leave that position with nothing to pack. Sampling last and counting what was built also means a new sampler needs no special registration here.
The disable_packing case (all block types disallowed) is also handled: a rotamer from the input conformation is always produced so the packer has something to represent for fixed residues.
- samples_after_other_samplers: ClassVar[bool] = True#
Sample only after every other sampler has run, receiving the rotamer counts they actually produced. A sampler that fills gaps left by others must measure what was built rather than trust what was declared: a sampler may report that it covers a block type and still return no rotamers for a particular block, which would otherwise leave that position with nothing to pack.
- annotate_residue_type(rt: RefinedResidueType)[source]#
Attach optional sampler metadata to one residue type.
- annotate_packed_block_types(packed_block_types: PackedBlockTypes)[source]#
Attach optional sampler metadata to packed block types.
- defines_rotamers_for_rt(rt: RefinedResidueType)[source]#
Return whether this sampler supports a residue type.
- first_sc_atoms_for_rt(rt: RefinedResidueType) Tuple[str, ...][source]#
Return side-chain roots used to transfer main-chain geometry.
- create_samples_for_poses(pose_stack: PoseStack, task: SetPackerTask, *, built_rotamer_counts: Tensor = None) Tuple[Tensor, Tensor, dict][source]#
Create rotamers for blocks the other samplers left uncovered.
A rotamer of the input conformation is built where the block either (1) has no allowed block types, so the residue is fixed, or (2) received no rotamers from any other sampler.
- Parameters:
built_rotamer_counts – Rotamers actually produced per considered block by every other sampler. Supplied by the rotamer builder, which runs this sampler last.
Nonemeans no other sampler ran.
- fill_dofs_for_samples(pose_stack: PoseStack, task: PackerTask, orig_kinforest: KinForest, orig_dofs_kto: Tensor[slice(None, None, None), 9], gbt_for_conformer: Tensor, block_type_ind_for_conformer: Tensor, n_dof_atoms_offset_for_conformer: Tensor, conformer_built_by_sampler: Tensor, conf_inds_for_sampler: Tensor, sampler_n_rots_for_gbt: Tensor, sampler_gbt_for_rotamer: Tensor, sample_dict: dict, conf_dofs_kto: Tensor[slice(None, None, None), 9])#
Write this sampler’s conformer degrees of freedom in place.
- class tmol.pack.FixedAAChiSampler[source]#
Bases:
ChiSamplerGenerate one ideal side-chain conformer for fixed amino acids.
- defines_rotamers_for_rt(rt: RefinedResidueType)[source]#
Return whether this sampler supports a residue type.
- first_sc_atoms_for_rt(rt: RefinedResidueType) Tuple[str, ...][source]#
CA’s sidechain branches: the substituents that carry further atoms.
With none (glycine), every non-mainchain CA substituent is rebuilt: glycine’s alpha hydrogens exchange under reflection, so rebuilding only one can place it on top of the retained one, and a glycine-to-amino-acid design must not inherit an arbitrary one.
- class tmol.pack.IncludeCurrentSampler[source]#
Bases:
ConformerSamplerAdd each packable residue’s current conformation to its rotamer set.
- annotate_residue_type(rt: RefinedResidueType)[source]#
Attach optional sampler metadata to one residue type.
- annotate_packed_block_types(packed_block_types: PackedBlockTypes)[source]#
Attach optional sampler metadata to packed block types.
- defines_rotamers_for_rt(rt: RefinedResidueType)[source]#
Return whether this sampler supports a residue type.
- first_sc_atoms_for_rt(rt: RefinedResidueType) Tuple[str, ...][source]#
Return side-chain roots used to transfer main-chain geometry.
- create_samples_for_poses(pose_stack: PoseStack, task: SetPackerTask) Tuple[Tensor, Tensor, dict][source]#
Return counts, considered-block index per rotamer, and sampler data.
A sampler that sets
samples_after_other_samplersis called with an extrabuilt_rotamer_countskeyword holding the per considered-block total produced by every other sampler.A producer of joint conformers declares
correlated_gbtsin its data: a tuple of considered-block-index tuples, one per joint group. Rotamer k must correspond across all members. Merging rejects additional states from other samplers on those blocks. Without a declaration, samples are independent even when their residues are covalently connected.Producers of unchanged input conformers may set
copy_input_coordinates=True. Their rows must use the original block type; Cartesian coordinates are copied exactly after DOF construction to avoid rounding from an unnecessary inverse/forward kinematics cycle.
- fill_dofs_for_samples(pose_stack: PoseStack, task: PackerTask, orig_kinforest: KinForest, orig_dofs_kto: Tensor[slice(None, None, None), 9], gbt_for_conformer: Tensor, block_type_ind_for_conformer: Tensor, n_dof_atoms_offset_for_conformer: Tensor, conformer_built_by_sampler: Tensor, conf_inds_for_sampler: Tensor, sampler_n_rots_for_gbt: Tensor, sampler_gbt_for_rotamer: Tensor, sample_dict: dict, conf_dofs_kto: Tensor[slice(None, None, None), 9])[source]#
Write this sampler’s conformer degrees of freedom in place.
- class tmol.pack.NaChiRotamerSampler(params: NaTorsionParams, element_for_atom_type: dict, chi_sample_level: int = 0, sample_syn: bool = True, device: device = device(type='cpu'), chi_sample_expanded_limit: int = 100, chi_sample_limit: int = 1000)[source]#
Bases:
ChiSamplerGlycosidic chi rotamers for DNA and RNA, taken from the na_torsion tables.
Every chi generated sits at a minimum of the term that will score it: the anti rotamer is the per-base, per-pucker mean and the syn rotamer is the fixed syn mean, each expanded in units of that term’s own sdev_chi. The pucker comes from the input sugar, which is not itself a packing degree of freedom.
The 2’-OH proton chi is expanded here rather than left to OptHSampler, which is applied to disjoint blocks; see DunbrackChiSampler, which folds proton chis in the same way.
- classmethod from_database(param_db: ParameterDatabase, device: device, chi_sample_level: int = 0, sample_syn: bool = True) NaChiRotamerSampler[source]#
Create a nucleic-acid chi sampler on a concrete device.
- Parameters:
param_db – Source scoring and chemical parameters.
device – Target device. Unindexed CUDA resolves to the current GPU.
chi_sample_level – Number of standard-deviation expansion levels.
sample_syn – Include eligible syn rotamers when true.
- Returns:
A sampler whose parameters and device metadata agree.
- annotate_residue_type(rt: RefinedResidueType)[source]#
Attach optional sampler metadata to one residue type.
- annotate_packed_block_types(packed_block_types: PackedBlockTypes)[source]#
Attach optional sampler metadata to packed block types.
- defines_rotamers_for_rt(rt: RefinedResidueType)[source]#
Return whether this sampler supports a residue type.
- first_sc_atoms_for_rt(rt: RefinedResidueType) Tuple[str, ...][source]#
Return side-chain roots used to transfer main-chain geometry.
- class tmol.pack.OptHSampler(flip_NHQ: bool = True, chi_sample_expanded_limit: int = 100, chi_sample_limit: int = 1000)[source]#
Bases:
ConformerSamplerBuild rotamers by sampling proton chi angles only, keeping all heavy atoms at their input-conformation positions.
When flip_NHQ is True (default), also builds flip rotamers for:
ASN/GLN: current conformation + 180-degree rotation of the last chi.
HIS/HIS_D: {HIS, HIS_D} x {current chi2, chi2+180} = 4 rotamers. All atoms through CG are taken from the input; ring atoms are rebuilt from ideal geometry for three non-input variants.
Other HIS states: current chi2 + chi2+180, as ASN/GLN.
NOTE: DunbrackChiSampler and OptHSampler must not be assigned to the same block (Dunbrack already samples proton chis, so both on one block oversamples). Assigning them to different blocks in the same task is fine.
- defines_rotamers_for_rt(rt: RefinedResidueType)[source]#
Return whether this sampler supports a residue type.
- first_sc_atoms_for_rt(rt: RefinedResidueType) Tuple[str, ...][source]#
Roots for the chis optH turns: every proton chi, plus the flipped chi.
- create_samples_for_poses(pose_stack: PoseStack, task: SetPackerTask) tuple[Tensor, Tensor, dict[str, Tensor]][source]#
Return counts, considered-block index per rotamer, and sampler data.
A sampler that sets
samples_after_other_samplersis called with an extrabuilt_rotamer_countskeyword holding the per considered-block total produced by every other sampler.A producer of joint conformers declares
correlated_gbtsin its data: a tuple of considered-block-index tuples, one per joint group. Rotamer k must correspond across all members. Merging rejects additional states from other samplers on those blocks. Without a declaration, samples are independent even when their residues are covalently connected.Producers of unchanged input conformers may set
copy_input_coordinates=True. Their rows must use the original block type; Cartesian coordinates are copied exactly after DOF construction to avoid rounding from an unnecessary inverse/forward kinematics cycle.
- fill_dofs_for_samples(pose_stack: PoseStack, task: PackerTask, orig_kinforest: KinForest, orig_dofs_kto: Tensor[slice(None, None, None), 9], gbt_for_conformer: Tensor, block_type_ind_for_conformer: Tensor, n_dof_atoms_offset_for_conformer: Tensor, conformer_built_by_sampler: Tensor, conf_inds_for_sampler: Tensor, sampler_n_rots_for_gbt: Tensor, sampler_gbt_for_rotamer: Tensor, sample_dict: dict[str, Tensor], conf_dofs_kto: Tensor[slice(None, None, None), 9]) None[source]#
Write this sampler’s conformer degrees of freedom in place.
- class tmol.pack.RotamerSet(n_rots_for_pose: Tensor, rot_offset_for_pose: Tensor, n_rots_for_block: Tensor[slice(None, None, None), slice(None, None, None)], rot_offset_for_block: Tensor[slice(None, None, None), slice(None, None, None)], pose_for_rot: Tensor, block_type_ind_for_rot: Tensor, block_ind_for_rot: Tensor, coord_offset_for_rot: Tensor, coords: Tensor[slice(None, None, None), 3], correlated_groups: tuple[CorrelatedBlockGroup, ...] = (), group_for_block: Tensor[slice(None, None, None), slice(None, None, None)] = NOTHING, first_rot_block_type: Tensor[slice(None, None, None), slice(None, None, None)] = NOTHING, max_n_rots_per_pose: int = NOTHING, pose_ind_for_atom: Tensor = NOTHING)[source]#
Bases:
ValidateAttrsPacked coordinates and pose/block indexing for generated rotamers.
- class tmol.pack.SetPackerTask[source]#
Bases:
objectSet as in concrete. Once everything wrt the desired packing task has been determined, pack_rotamers will construct this object to create and hold the many mappings that the various members of the packer need.
- class tmol.pack.SidechainSampler(samplers: tuple[ConformerSampler, ...])[source]#
Bases:
objectEvery sampler needed to move an ordinary protein side chain.
Declaring sampling should not require knowing which sampler covers which residue. A rotamer library handles the residues it has entries for and a fixed-chi sampler handles the rest; callers who just want “sample side chains reasonably” should not have to compose that themselves.
Examples
>>> task.add_conformer_sampler( ... SidechainSampler.from_database(database, pose_stack.device) ... )
- classmethod from_database(database, device) SidechainSampler[source]#
Bundle the rotamer-library and fixed-chi samplers for
database.
- tmol.pack.build_rotamers(poses: PoseStack, task: SetPackerTask, chem_db: ChemicalDatabase) tuple[PoseStack, RotamerSet][source]#
Build coordinates and indexing for every task-allowed conformer.
- Parameters:
poses – Input poses supplying backbone geometry and current conformers.
task – Finalized packing choices and conformer samplers.
chem_db – Chemical definitions used to annotate residue types.
- Returns:
The input poses and a device-resident rotamer set grouped by pose and block.
- tmol.pack.create_dunbrack_sampler_from_database(param_db: ParameterDatabase, device: device) DunbrackChiSampler[source]#
Create a DunbrackChiSampler from the default database.
- Parameters:
param_db – The parameter database containing Dunbrack parameters
device – The device to use for the sampler. An unindexed CUDA device resolves to the current CUDA device.
- Returns:
Configured sampler for rotamer building
- Return type: