Module 17: Merging and Growing Systems#

Welcome back, Apprentice Master. In Module 16: Structural Operations, you mastered spatial coordinate transformations and alignment using msm.structure. Now we transition to system composition: Merging and Growing Systems.

Complex molecular simulations frequently require assembling systems from separate components: fusing a receptor protein and a co-crystallized ligand, appending solvent ions into a box, or joining multiple coordinate structures. MolSysMT provides four dedicated composition functions in msm.basic categorized along two operational axes:

Composition Axis

Out-of-Place (Returns New Object)

In-Place (Modifies Target)

Topology

msm.merge()

msm.add()

Structures

msm.concatenate_structures()

msm.append_structures()

1. Merging Independent Systems#

Let’s begin by importing MolSysMT, loading our T4 Lysozyme system, and isolating the protein and co-crystallized small molecules into separate native MolSys objects.

import molsysmt as msm
from molsysmt import systems

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

# Extract protein component and small molecule ligands
protein = msm.extract(lysozyme, selection='molecule_type == "protein"')
ligand = msm.extract(lysozyme, selection='molecule_type == "small molecule"')

The function msm.merge() takes a list of independent molecular systems and fuses their topology and spatial coordinates into a new combined system object, leaving the input systems unchanged:

# Merge protein and ligand out-of-place into a new complex
complex_sys = msm.merge([protein, ligand])

# Inspect topology summary of the merged complex
msm.info(complex_sys)
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

2. Adding Elements In-Place#

While msm.merge() creates a new combined system from a list, msm.add() appends selected elements or molecules directly into an existing target system in place:

# Print atom count of target protein before addition
print(f"Protein atom count before addition: {msm.get(protein, element='system', n_atoms=True)}")

# Add ligand elements directly into the protein system in place
msm.add(protein, ligand)

# Print updated atom count
print(f"Protein atom count after in-place addition: {msm.get(protein, element='system', n_atoms=True)}")
Protein atom count before addition: 1289
Protein atom count after in-place addition: 1303

3. Concatenating Structures#

When you have multiple coordinate datasets representing sequential conformations for systems with matching topology, msm.concatenate_structures() combines their 3D structures out-of-place into a new system along the structure axis:

# Synthesize an Alanine dipeptide peptide model
snap1 = msm.build.build_peptide('AceAlaNme')

# Create a shifted conformer using spatial translation
snap2 = msm.structure.translate(snap1, translation='[0.1, 0.1, 0.1] nanometers')

# Concatenate coordinate structures out-of-place into a multi-structure object
multi_struct_sys = msm.concatenate_structures([snap1, snap2])

n_structs = msm.get(multi_struct_sys, element='system', n_structures=True)
print(f"Concatenated system total structure count: {n_structs}")
Concatenated system total structure count: 2

4. Appending Structures In-Place#

To append new coordinate structures directly into an existing system along the structure axis in place, use msm.append_structures():

# Print structure count of snap1 before appending
print(f"Structure count of snap1 before appending: {msm.get(snap1, element='system', n_structures=True)}")

# Append snap2 coordinate structures directly into snap1 in place
msm.append_structures(snap1, snap2)

# Print updated structure count
print(f"Structure count of snap1 after in-place appending: {msm.get(snap1, element='system', n_structures=True)}")
Structure count of snap1 before appending: 1
Structure count of snap1 after in-place appending: 2

🏆 Challenge 17: The Systems Builder#

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

  2. Extract the protein (molecule_type == 'protein') and small molecule ligands (molecule_type == 'small molecule').

  3. Merge them out-of-place using msm.merge([protein, ligand]) into complex_sys.

  4. Synthesize a peptide using msm.build.build_peptide('AceAlaNme') and concatenate two conformations using msm.concatenate_structures().

  5. Verify atom counts and structure counts of all resulting objects.

Building up molecular systems allows you to construct complex simulation models. In Module 18: Surgical Extraction and Removal, we will learn how to isolate and eliminate specific components using msm.extract() and msm.remove().