Structural Surgery: In-memory Mutagenesis#
Task: Mutate a residue in a protein and automatically fix the local structural errors (clashes and missing atoms).
Preparing mutants is a common task in rational design. This recipe shows how to perform a mutation and repair the side-chains in a single step.
import molsysmt as msm
from molsysmt import systems
# Load the T4 Lysozyme
lysozyme = systems['T4 lysozyme L99A']['181l.bcif.gz']
molsys = msm.convert(lysozyme, to_form='molsysmt.MolSys')
1. Perform the Mutation#
We mutate the Lysine at index 18 to an Alanine. MolSysMT will handle the topological change.
mutated_system = msm.build.mutate(molsys, selection='group_index==18',
to_group='ALA')
msm.info(mutated_system, element='group', selection=18)
2. Auto-Repair#
After a mutation, some atoms might be missing or in poor positions. We use the build module to refine the local environment. A mutation can also change bonds, covalent components, formal charge, aromaticity, implicit hydrogens, or stereochemistry. Treat those values as chemical-state information and verify them after rebuilding instead of assuming the original state is still valid. When reactant and product structures coexist in one MolSys, assign their nullable structure_chemical_state_index values and use chemical_state='structure' with get(), set(), has_attribute(), and select(). This prevents an accidental global reference from being mistaken for per-frame chemical evidence.
final_system = msm.build.add_missing_heavy_atoms(mutated_system)
print("System mutated and repaired successfully.")