Work with Proteins
This document describes how to work with proteins and use them in Deep Origin tools.
The Protein class¶
The Protein class is the primary way to work with proteins in Deep Origin.
Constructing a protein¶
From a file¶
A protein can be constructed from a file:
from deeporigin.drug_discovery import Protein, BRD_DATA_DIR
protein = Protein.from_file(BRD_DATA_DIR / "brd.pdb")
From a PDB ID¶
A protein can also be constructed from a PDB ID:
from deeporigin.drug_discovery import Protein
protein = Protein.from_pdb_id("1EBY")
From a name¶
You can search for a protein by name and create a Protein instance from the top search result:
from deeporigin.drug_discovery import Protein
protein = Protein.from_name("insulin")
From a UniProt accession (recommended PDB)¶
Import the platform-recommended experimental PDB for a UniProtKB accession into a
project. This is sugar over
UniprotDiscovery.import_proteins; use
UniprotDiscovery directly to browse all candidates or import multiple PDBs:
from deeporigin.drug_discovery import Protein
protein = Protein.from_uniprot(
"P00533",
project_id=client.project_id,
client=client,
)
protein.pdb_id, protein.uniprot_accession
From a Deep Origin Data Platform ID¶
You can create a Protein instance directly from a Deep Origin Data Platform ID. This method fetches the protein data from the platform, downloads the structure file, and creates a Protein instance with metadata from the platform:
from deeporigin.drug_discovery import Protein
protein = Protein.from_id("08AD337N5YV4Y")
The method automatically:
- Downloads the structure file from the Deep Origin Data Platform
- Sets the protein's ID, name, and PDB ID (if available) from the platform metadata
- Creates a Protein instance from the downloaded file
You can optionally provide a custom DeepOriginClient instance:
from deeporigin.drug_discovery import Protein
from deeporigin.platform.client import DeepOriginClient
client = DeepOriginClient()
protein = Protein.from_id("08AD337N5YV4Y", client=client)
Records without file_path
If the platform record has no file_path, from_id returns metadata only:
structure is None and remote_path is unset unless you pass
remote_path_override. Call download() only after a structure file path
is available on the record or via override.
Automatic metadata
The method automatically populates the protein's name field from the platform data, preferring protein_name, then pdb_id, then gene_symbol (in that order).
Importing a folder of structures¶
To add many structures to your project at once, point projects.sync_proteins at a folder of .pdb, .cif, .mmcif or .ent files. It uploads the files, runs the import on Deep Origin, and returns the project's proteins once the import has finished.
You need to be signed in (see authentication) and have a current project (see projects).
from deeporigin import projects
projects.load("my-project")
proteins = projects.sync_proteins("~/structures/brd4")
sync_proteins also accepts a single file or a list of files. Pass recursive=True to include files in subfolders:
proteins = projects.sync_proteins("~/structures", recursive=True)
proteins = projects.sync_proteins(["~/structures/brd4_holo.pdb", "~/structures/brd4_apo.cif"])
Each file becomes one protein, named after its file name without extension, as Protein.from_file(path).sync() does. So brd4_holo.pdb becomes brd4_holo, and two files called model.pdb in different subfolders become two proteins named model. A structure that is already in the project is reused and keeps its existing name. A file stamped by Protein Prep is recorded as prepared, with its PDB ID.
sync_proteins returns every protein in the project, not only the ones from this folder, without downloading their structures. Call download() on a protein when you need its structure.
Files are checked before upload
Before uploading anything, sync_proteins checks every file and raises one error that lists each file it can't import: missing files, unsupported file types, compressed files such as .pdb.gz (decompress them first), empty files, and files with no atom records. Nothing is uploaded until every file passes.
Errors
sync_proteins raises DeepOriginException if the import fails, with the reason in the message, and TimeoutError if it hasn't finished within timeout seconds (one hour by default). Both messages include the import's execution id, for support. If live updates aren't available, sync_proteins warns and checks the import's progress periodically instead.
Inspecting the Protein¶
PDB ID¶
To view the PDB ID of a Protein (if it exists), use:
from deeporigin.drug_discovery import Protein
protein = Protein.from_pdb_id("1EBY")
protein.pdb_id
Expected output
1EBY
Getting the protein sequence¶
You can retrieve the amino acid sequences of all polypeptide chains in a protein structure using the sequence property:
from deeporigin.drug_discovery import Protein
protein = Protein.from_pdb_id("1EBY")
sequences = protein.sequence
for seq in sequences:
print(seq)
This property returns a list of amino acid sequences (as Bio.Seq objects) for each polypeptide chain found in the structure. If the structure contains multiple chains, each chain's sequence is included as a separate entry in the list. This is useful for analyzing the primary structure of the protein or for downstream sequence-based analyses.
Expected output
PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMNLPGRWKPKMIGGIGGFIKVRQYDQILIEICGHKAIGTVLVGPTPVNIIGRNLLTQIGCTLNF
PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMNLPGRWKPKMIGGIGGFIKVRQYDQILIEICGHKAIGTVLVGPTPVNIIGRNLLTQIGCTLNF
Finding missing residues¶
You can identify missing residues (gaps) in the protein structure using the find_missing_residues method:
from deeporigin.drug_discovery import Protein
protein = Protein.from_pdb_id("5QSP")
missing = protein.find_missing_residues()
print(missing)
This method scans each chain in the protein and returns a dictionary where the keys are chain IDs and the values are lists of tuples, each representing a gap. Each tuple is of the form (start_resseq, end_resseq), indicating that residues between start_resseq and end_resseq (exclusive) are missing from the structure.
Expected output
{'A': [(511, 514), (547, 550), (679, 682), (841, 855)],
'B': [(509, 516), (546, 551), (679, 684), (840, 854)]}
Listing chain names¶
You can list all unique chain IDs in the protein structure:
from deeporigin.drug_discovery import Protein
protein = Protein.from_pdb_id("1EBY")
chain_names = protein.list_chain_names()
print(chain_names)
Expected output
['A', 'B']
Listing hetero residue names¶
You can list all unique hetero (non-protein) residue names in the structure:
from deeporigin.drug_discovery import Protein
protein = Protein.from_pdb_id("1EBY")
hetero_names = protein.list_hetero_names(exclude_water=True)
print(hetero_names)
This is useful for identifying ligands, cofactors, and other heteroatoms present in the structure.
Extracting metals and cofactors¶
You can extract and categorize metal ions and cofactors from the protein structure:
from deeporigin.drug_discovery import Protein
protein = Protein.from_pdb_id("1EBY")
metals, cofactors = protein.extract_metals_and_cofactors()
print(f"Metals: {metals}")
print(f"Cofactors: {cofactors}")
This method returns a tuple of two lists: metal residue names and cofactor residue names.
Getting the number of atoms¶
You can get the total number of atoms in the protein structure:
from deeporigin.drug_discovery import Protein
protein = Protein.from_pdb_id("1EBY")
num_atoms = protein.num_atoms
print(num_atoms)
Finding pockets¶
When the structure has a co-crystallized ligand, get its pocket from
Protein Prep with find_pockets="from-crystal-ligand"
(see Preparing a protein below). To discover novel
pockets on a target without a known site, use find_pockets="novel" or the
PocketFinder tool:
from deeporigin.drug_discovery import PocketFinder, Protein
protein = Protein.from_pdb_id("1EBY")
protein.sync()
pf = PocketFinder(protein, pocket_count=5)
pockets = pf.run()
pockets[0].show()
Pocket.show() overlays that pocket on its parent protein (the same as
protein.show(pockets=[pocket])). To show every pocket from the run, call
protein.show(pockets=pockets).
Preparing a protein¶
Inventory components and prepare the structure with
ProteinPrep. Use standalone
StructureReport when you want a source-structure
grade. recommend() updates the same object with an editable Selection.
Resolve any review decisions, then either:
- call
run()for a blocking prepared protein (loops on or off, with or without a crystal-ligand pocket); or - set
find_pockets="novel", then callstart()(usequote=True/confirm()when pockets are billable).
To dock into the site of a co-crystallized ligand, extract the ligand and request its pocket:
from deeporigin.drug_discovery import Protein, ProteinPrep
protein = Protein.from_pdb_id("1EBY")
protein.sync()
prep = ProteinPrep(
protein,
find_pockets="from-crystal-ligand",
component_id="ligand:B:BEB:501:",
)
prep.recommend()
prep.recommendation[prep.recommendation["decision"] == "review"]
prep.skip(decision="review")
prepared = prep.run()
pocket = prep.get_pockets()[0]
For a target without a known site, request novel pockets instead:
prep = ProteinPrep(protein, find_pockets="novel", pocket_count=3)
prep.recommend()
prep.skip(decision="review")
prep.start()
prep.wait()
prepared = prep.get_results()
pockets = prep.get_pockets()
Visualizing a protein¶
Browser support
These visualizations work best on Google Chrome. We are aware of issues on other browsers, especially Safari on macOS.
A protein object can be visualized using show:
from deeporigin.drug_discovery import Protein
protein = Protein.from_pdb_id("1EBY")
protein.show()
A visualization such as this will be shown:
Jupyter notebook required
Visualizations such as these require this code to be run in a jupyter notebook. We recommend using these instructions to install Jupyter.
Modifying and preparing a protein¶
Extract crystal ligands¶
When PDB files contain a crystal ligand, the crystal ligand can be removed from the structure and used as a Ligand.
from deeporigin.drug_discovery import Protein
protein = Protein.from_pdb_id("1EBY")
ligand = protein.extract_ligand()
Check ligand pose clashes¶
Use :meth:Protein.has_ligand_clashes to verify that a docked ligand pose does not
sterically overlap the receptor. The ligand SDF must already be in the same coordinate
frame as the protein structure.
from deeporigin.drug_discovery import BRD_DATA_DIR, Protein
protein = Protein.from_file(BRD_DATA_DIR / "brd.pdb")
if protein.has_ligand_clashes(BRD_DATA_DIR / "brd-2.sdf"):
raise ValueError("Pose has steric clashes with receptor")
# Use a stricter cutoff (default is 2.5 Å)
if protein.has_ligand_clashes(BRD_DATA_DIR / "brd-2.sdf", contact_distance=2.0):
raise ValueError("Pose is too close to receptor atoms")
By default, the check compares the ligand against protein atoms only (excluding HETATM
records and waters) and ignores hydrogens. Customize this with protein_atoms_only,
exclude_waters, and heavy_atoms_only.
Method mutates the Protein object
The extract_ligand() method not only extracts the ligand but also mutates the protein object by removing the ligand from the protein structure. This means that after calling this method, the protein will no longer contain the ligand atoms.
Water molecules are automatically excluded
The extract_ligand() method automatically filters out water molecules (HOH, WAT, H2O) and other excluded residue names. You can customize which residues to exclude by passing the exclude_resnames parameter:
# Exclude custom residue names
ligand = protein.extract_ligand(exclude_resnames={"HOH", "CUSTOM_RES"})
Bond orders come from the Chemical Component Dictionary
PDB files record which ligand atoms are bonded but not the bond orders. extract_ligand() looks up each ligand residue's bond orders and formal charges in the wwPDB Chemical Component Dictionary by atom name, so aromatic rings, carbonyls and charged groups come out as in the deposited molecule. If a residue can't be matched (an unknown code, or atom names that don't match the dictionary entry), a warning is raised and that residue's bonds are left as parsed, which usually means all single; build such ligands from SMILES or SDF instead.
Note about atom counts
In this example, the atom count might not change significantly because the ligand atoms are typically a small fraction of the total protein structure. However, the protein's internal structure and block_content are updated to exclude the ligand. Additionally, the PDB file's MASTER record is automatically updated to reflect the new atom and CONECT record counts.
Loop modelling¶
Gaps in a deposited structure can be filled during preparation. Loop modelling is part of Protein Prep: it is on by default when the structure has chain breaks, and runs when you call run() on a ProteinPrep session after you resolve component decisions. It is not a method on Protein itself.
The example below uses PDB entry 5QSP, which has missing segments (dashed
lines in the viewer). Use find_missing_residues
to list gaps before preparation.
from deeporigin.drug_discovery import Protein
protein = Protein.from_pdb_id("5QSP")
protein.show()
Register the structure, recommend keep/skip settings, then prepare:
from deeporigin.drug_discovery import Protein, ProteinPrep
protein = Protein.from_pdb_id("5QSP")
protein.sync()
prep = ProteinPrep(protein, find_pockets="no")
prep.recommend()
prep.skip(decision="review")
prepared = prep.run()
prepared.download()
prepared.show()
skip(decision="review") extracts any ligand left in review, and an extracted ligand requests a crystal-ligand pocket unless you set find_pockets yourself. find_pockets="no" keeps this example to preparation only.
Prepared protein is a new object
run() returns a new registered Protein, and the input protein is unchanged. Loop modelling needs a four-character PDB ID, which Protein.from_pdb_id sets for you. See Blocking prepare for what run() returns and for preparing with loop modelling off.
On the prepared structure, the gaps are filled. It keeps only chain A, with the ligand extracted and the waters removed:
prepared.find_missing_residues()
Expected output
{}
See Preparing a protein for pockets and async start(), and Use a saved Selection to reuse your keep/skip decisions.
How does loop modelling work?
Protein Prep fills missing loops using experimental or predicted templates.
For each chain, the full sequence and the resolved structure are aligned to find continuous gaps. The Protein Data Bank (PDB) is searched for templates above a sequence-identity threshold. When UniProt IDs are present, predicted AlphaFold structures from the AlphaFold Protein Structure Database may be considered as well.
For each template, a global 3D alignment is attempted and structural motifs for missing residues are transferred when the gap edges and sequence identity look consistent. If global alignment fails, a local alignment around the gap is tried.
Successful transfers are assembled into models per template. Mixed models can
combine motifs from several templates (ordered by resolution) when a single
template does not cover every gap. Results for all chains are merged into the
prepared structure returned by ProteinPrep.run().
Removing specific residues¶
You can remove specific residue names from a protein structure using the remove_resnames method:
from deeporigin.drug_discovery import Protein
protein = Protein.from_pdb_id("1EBY")
# Remove water molecules (HOH) and ions (NA, CL)
protein.remove_resnames(exclude_resnames=["HOH", "NA", "CL"])
Residue name format
Residue names in PDB files are always uppercase (e.g., "HOH" for water, "NA" for sodium, "CL" for chloride).
This method modifies the protein structure in place by removing the specified residue names. If no residue names are provided, the protein structure remains unchanged.
Removing HETATM records¶
You can remove HETATM records from the protein structure using the remove_hetatm method:
from deeporigin.drug_discovery import Protein
protein = Protein.from_pdb_id("1EBY")
# Remove all HETATM records except water and zinc
protein.remove_hetatm(keep_resnames=["HOH"], remove_metals=["ZN"])
This method modifies the protein structure in place by removing HETATM records (heteroatoms) from the structure. You can:
- Keep specific residues by providing their names in
keep_resnames - Keep specific metals by providing their names in
remove_metals(these metals will be excluded from removal) - If no arguments are provided, all HETATM records will be removed
Metal names
Metal names should be provided in uppercase (e.g., "ZN" for zinc, "FE" for iron).
Removing water molecules¶
You can remove all water molecules from a protein structure using the remove_water method:
from deeporigin.drug_discovery import Protein
protein = Protein.from_pdb_id("1EBY")
protein.remove_water()
This method modifies the protein structure in place by removing all water molecules (residue name "HOH"). Unlike remove_resnames, this method does not return a new protein structure but instead modifies the existing one.
Removing Specific Residues¶
You can remove specific residue types while keeping others:
from deeporigin.drug_discovery import Protein
protein = Protein.from_pdb_id("1EBY")
# Remove specific residue names
protein.remove_resnames(exclude_resnames=["HOH", "SO4"])
# Remove only water molecules (mutates in place)
protein.remove_water()
Chain Selection¶
You can select specific chains from the protein structure. These methods return new Protein objects and do not modify the original:
# Select a single chain (returns new Protein object)
chain_a = protein.select_chain('A')
# Select multiple chains (returns new Protein object)
chains_ab = protein.select_chains(['A', 'B'])
Returns new object
Unlike most modification methods, select_chain() and select_chains() return new Protein objects rather than mutating the original.
Saving a protein structure¶
You can save the protein structure to a PDB file:
from deeporigin.drug_discovery import Protein
protein = Protein.from_pdb_id("1EBY")
protein.remove_water()
file_path = protein.to_pdb("prepared_protein.pdb")
If no file path is provided, the protein will be saved to a default location based on its hash.
For structures that cannot be represented as classic PDB (for example residue names
longer than three characters, common in modern mmCIF files), use to_cif():
protein.to_cif("prepared_protein.cif")
Protein.show() also falls back to mmCIF automatically when dumping state for the
viewer, so visualization still works for those structures.
Platform prepared state vs file stamp¶
| Concern | API | Effect |
|---|---|---|
Platform proteins-table state |
Protein.mark_prepared() |
Sets state=prepared via protein-prep mark_prepared; refreshes lifecycle fields. No file change. |
| Local Prepared Protein stamp | Protein.mark_as_prepared() |
Writes REMARK 99 DO_PREPARED / mmCIF stamp on disk. Call sync() separately to upload. |
Fetched proteins expose lifecycle metadata (state, preparation, origin_*)
after from_id or refresh().
protein = Protein.from_id("…", client=client)
print(protein.state) # e.g. "unprocessed" or "prepared"
protein.mark_prepared(client=client) # platform state only; idempotent
assert protein.state == "prepared"
Marking a local file as prepared (stamp)¶
If you prepared the structure outside Deep Origin, stamp the local file so downstream tools skip automatic protein cleanup. See Prepared Protein stamp.
protein = Protein.from_file("my_prepared.pdb") # or .cif
protein.mark_as_prepared()
protein.sync()
This does not run Protein Prep and does not set platform state — it only
writes the file-borne stamp in the file's native format (no CIF↔PDB conversion).
Platform proteins without a local file
If the protein was loaded with from_id(..., download=False), it has remote_path
but no local file yet. Call download(client=...) before to_pdb() or to_file(),
or use from_id(..., download=True).
Docking ligands¶
Dock ligands with Docking, passing the prepared protein
and a pocket explicitly. See the docking tutorial and
the Docking tool guide for details.
from deeporigin.drug_discovery import Docking, Ligand
# prepared and pocket from ProteinPrep with find_pockets="from-crystal-ligand"
ligand = Ligand.from_smiles("CC(=O)Nc1ccc(O)cc1")
ligand.sync()
docking = Docking(protein=prepared, pocket=pocket, ligand=ligand)
poses = docking.run()
Best Practices¶
- Always visualize the structure before and after preparation to ensure the desired changes were made
- When working with metalloproteins, use
remove_hetatm()with appropriatekeep_resnamesorremove_metalsparameters - For multi-chain proteins, consider selecting specific chains before preparation
- Save the prepared structure using
to_pdb()if you need to use it outside of Deep Origin APIs.
# Save the prepared structure
protein.to_pdb("prepared_protein.pdb")
Common Use Cases¶
Preparing a Protein for Docking¶
# Load and prepare protein
protein = Protein.from_pdb_id("1EBY")
protein.remove_water() # Remove water molecules
protein.remove_hetatm(keep_resnames=['ZN']) # Keep important cofactors
Working with Metalloproteins¶
# Load and prepare metalloprotein
protein = Protein.from_pdb_id("1XYZ")
protein.remove_hetatm(remove_metals=['ZN', 'MG']) # Keep metal ions
protein.show()
Multi-chain Protein Preparation¶
# Load and prepare multi-chain protein
protein = Protein.from_pdb_id("1ABC")
chains_ab = protein.select_chains(['A', 'B']) # Select chains A and B
chains_ab.remove_water() # Remove water from selected chains
chains_ab.show()