Path A - Module 26: Attribute Engineering (Patching)#

No matter how good your building tools are, you will often find small errors in your topology: a chain named “A” that should be “P”, or a water residue with a non-standard name.

In this module, you will learn to use set() to “patch” your molecular system on the fly.

import molsysmt as msm
from molsysmt import systems

# Load our solvated complex from the previous module logic
fibril = msm.convert('pdb:2BEG', to_form='molsysmt.MolSys')
peptide = msm.build.build_peptide('KLVFF')
complex_sys = msm.merge([fibril, peptide])

1. Renaming Chains#

When you merged the fibril and the peptide, they might have overlapping chain IDs or names. Let’s make the peptide chain stand out by naming it “THERAPY”.

# Let's identify the chain index of our peptide (it's the last chain after merge)
n_chains = msm.get(complex_sys, element='system', n_chains=True)
peptide_chain_idx = n_chains - 1

# Update the chain name and ID
msm.set(complex_sys, element='chain', selection='chain_index=='+str(peptide_chain_idx), 
        chain_name='THERAPY', chain_id='T')

msm.info(complex_sys, element='chain')

2. Updating Entity Names#

Entities define the identity of the molecules. Let’s rename the “AMYLOID BETA” entity to something more scientific for our report.

# Find the entity index
ent_idx = msm.select(complex_sys, selection='entity_name=="AMYLOID-BETA PROTEIN"', element='entity')

if len(ent_idx) > 0:
    msm.set(complex_sys, element='entity', selection=ent_idx[0], name='A-beta Fibril')

msm.info(complex_sys, element='entity')

3. Patching Coordinates#

set() is not only for names. You can use it to update coordinates if you have performed an external calculation (like a rotation or an alignment).

import numpy as np

# Get current coordinates
coords = msm.get(complex_sys, selection='chain_name=="THERAPY"', coordinates=True)

# Apply a dummy shift of 0.5 nm in the X axis
new_coords = coords + np.array([0.5, 0.0, 0.0]) * msm.pyunitwizard.unit('nm')

# Patch the system with new coordinates
msm.set(complex_sys, selection='chain_name=="THERAPY"', coordinates=new_coords)

print("Peptide coordinates updated successfully.")

🏆 Path A Challenge: The Data Polisher#

  1. Take the final_sys (the one with water and ions) from Module 25.

  2. Rename the Chloride ions entity to “Anion_CL”.

  3. Change the Chain ID of all water molecules to “W”.

  4. Verify the changes with a single msm.info() call.

Your system is now perfectly documented and cleaned. In Module 27, we will dive into Conformational Engineering: changing the shape of our peptide by rotating its internal bonds.