Path A - Module 50: Virtual Forms & Memory I/O#
In modern pipelines, you often work with data coming from a web API, a database, or a streaming service. Saving these data as temporary files on your disk is slow and hard to manage.
MolSysMT allows you to treat text strings and memory buffers as valid Forms. In this module, you will learn to process molecular systems entirely in RAM.
import molsysmt as msm
import requests # To simulate a remote API call
1. From Web to MolSysMT (The Disk-less way)#
Let’s download the PDB file for an Amyloid-Beta oligomer (e.g., 1Z0Q) directly as text and process it without saving a file.
pdb_id = "1Z0Q"
url = f"https://files.rcsb.org/view/{pdb_id}.pdb"
response = requests.get(url)
pdb_content = response.text
print(f"Downloaded {len(pdb_content)} characters of PDB data.")
# Now we load it directly using the 'string:pdb_text' form
molsys = msm.convert(pdb_content, from_form='string:pdb_text', to_form='molsysmt.MolSys')
print(f"Successfully loaded {msm.get(molsys, element='system', n_atoms=True)} atoms from memory.")
2. Exporting to a String#
You can also do the reverse: convert your engineered system into a string to send it back to a server or store it in a database.
# Convert our current native system into a PDB formatted string
output_pdb_text = msm.convert(molsys, to_form='string:pdb_text')
print("First 5 lines of the generated PDB text:")
print("\n".join(output_pdb_text.splitlines()[:5]))
3. SMILES as a Virtual Form#
For small molecules (like cofactors or fragments), you can use the SMILES string as a starting point. MolSysMT will use its chemical engine to generate a 3D model in memory.
benzene_smiles = "c1ccccc1"
benzene_molsys = msm.convert(benzene_smiles, from_form='string:smiles', to_form='molsysmt.MolSys')
msm.info(benzene_molsys)
🏆 Path A Challenge: The Cloud Architect#
Download the PDB text for 2BEG (our Alzheimer’s fibril) using
requests.Load it as a native
MolSysobject without using a file.Perform a quick SASA calculation on it.
Convert the result back to a MolSysDict (dictionary) to see how it looks in memory.
Your workflows are now disk-less and cloud-ready! In Module 51, we will learn how to write your own functions that accept any form, just like MolSysMT does.