Module 18: Extracting and Removing Elements#

Welcome back, Apprentice Master. In Module 17: Merging and Growing Systems, you learned how to assemble complex molecular systems using msm.merge() and msm.add(). Now we explore the inverse operations: Extracting and Removing Elements.

Large simulation boxes often contain tens of thousands of water molecules, counterions, or bulk solvent. Analyzing a binding pocket or isolated protein domain requires cutting away non-essential components without corrupting atomic indices or structural topology. MolSysMT provides dedicated extraction and removal engines (msm.extract() and msm.remove()) for precise sub-system manipulation.

1. Extracting Sub-Systems#

Let’s begin by importing MolSysMT and loading our T4 Lysozyme demonstration system.

import molsysmt as msm
from molsysmt import systems

# Load T4 Lysozyme as native MolSys
lysozyme = msm.convert(systems['T4 lysozyme L99A']['181l.bcif.gz'], to_form='molsysmt.MolSys')

msm.extract() creates a new independent molecular system containing only the selected atoms or components, leaving the original system untouched:

# Extract only the protein component
protein_only = msm.extract(lysozyme, selection='molecule_type == "protein"')

# Inspect topology overview of extracted protein
msm.info(protein_only)
form n_atoms n_groups n_components n_chains n_molecules n_entities n_proteins n_structures
molsysmt.MolSys 1289 162 1 1 1 1 1 1

2. Removing Elements#

If you want to keep everything in the system except specific unwanted elements (such as removing solvent water or counterions), use msm.remove():

# Remove water molecules and ions from the system
dry_system = msm.remove(lysozyme, selection='molecule_type == "water" or molecule_type == "ion"')

# Inspect topology overview of dry system
msm.info(dry_system)
form n_atoms n_groups n_components n_chains n_molecules n_entities n_small_molecules n_proteins n_structures
molsysmt.MolSys 1303 164 3 3 3 3 2 1 1

🏆 Challenge 18: The Subsystem Specialist#

  1. Load the T4 Lysozyme system (systems['T4 lysozyme L99A']['181l.bcif.gz']).

  2. Extract groups 10 through 20 into a new object called sub_domain using msm.extract().

  3. Use msm.remove() to delete all water molecules from lysozyme.

  4. Verify that the atom count of sub_domain matches the extracted group selection.

Subsystem extraction allows you to isolate active sites and reduce computational overhead. In Module 19: Structures and Trajectories, we will explore multi-structure datasets and trajectory slicing.