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.
Learning Outcomes
By the end of this module, you will be able to:
Extract isolated sub-systems into new objects using
msm.extract().Purge unwanted molecules (such as water or ions) using
msm.remove().Verify structural and topological consistency after element extraction and removal.
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 |
Hint
msm.extract(): Creates a new independent molecular system from selected atoms, groups, or components. See API doc: molsysmt.basic.extract().
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#
Load the T4 Lysozyme system (
systems['T4 lysozyme L99A']['181l.bcif.gz']).Extract groups 10 through 20 into a new object called
sub_domainusingmsm.extract().Use
msm.remove()to delete all water molecules fromlysozyme.Verify that the atom count of
sub_domainmatches 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.
See also
API Documentation for Functions in this Module:
molsysmt.basic.extract()— Sub-system extraction engine.molsysmt.basic.remove()— Element removal tool.
Related Course Modules & Guides:
Previous Module: Module 17: Merging and Growing Systems
Next Module: Module 19: Structures and Trajectories
User Guide: user-foundations