moleculekit.rcsb module#

moleculekit.rcsb.fetchResidueCIF(resname, outdir, overwrite=False)#

Download a residue’s reference structure from the RCSB Chemical Component Dictionary and store it as <resname>.cif in outdir.

Used at packaging time to populate moleculekit’s share/residue_cifs with the modified-residue templates that systemPrepare injects into PDB2PQR so those residues can be protonated. NOT called at runtime - runtime reads the already-shipped cifs. No-op if the file exists unless overwrite is set.

Parameters:
  • resname (str) – The PDB chemical-component code, e.g. "HYP".

  • outdir (str) – Directory to write <resname>.cif into.

  • overwrite (bool) – Re-download even if the file already exists.

Returns:

path – Path to the written (or pre-existing) cif file.

Return type:

str

moleculekit.rcsb.rcsbFetchLigandInfo(comp_id)#

Fetch the full RCSB Chemical Component Dictionary record for a ligand.

Queries the RCSB data API for a 3-letter chemical component (CCD) code and returns the complete record, including identifiers, formula, weight and all descriptor variants (InChI plus SMILES from RCSB, CACTVS, OpenEye and ACDLabs).

Parameters:

comp_id (str) – The chemical component (CCD) 3-letter code, e.g. "BEN". Case-insensitive.

Returns:

info – The parsed JSON record. The curated descriptors live under info["rcsb_chem_comp_descriptor"] (SMILES, SMILES_stereo, InChI, InChIKey); per-program variants live under info["pdbx_chem_comp_descriptor"].

Return type:

dict

Examples

>>> info = rcsbFetchLigandInfo('BEN')
>>> info['rcsb_chem_comp_descriptor']['comp_id']
'BEN'
moleculekit.rcsb.rcsbFetchLigandSmiles(comp_id, stereo=True, program='OpenEye')#

Fetch a SMILES string for a ligand by its RCSB CCD code.

Thin wrapper over rcsbFetchLigandInfo(). RCSB stores SMILES computed by several toolkits (OpenEye, CACTVS, ACDLabs). By default this returns the OpenEye descriptor, which RCSB also curates into its top-level rcsb_chem_comp_descriptor block. Pass program to pick a different toolkit; for full control read pdbx_chem_comp_descriptor off rcsbFetchLigandInfo() directly.

Parameters:
  • comp_id (str) – The chemical component (CCD) 3-letter code, e.g. "BEN". Case-insensitive.

  • stereo (bool) – If True (default) return the isomeric SMILES (stereochemistry included); if False return the plain SMILES. RCSB labels the isomeric variant SMILES_CANONICAL. Falls back to the other variant when the preferred one is absent for the chosen program.

  • program (str) – Which toolkit’s descriptor to return. "OpenEye" (default) uses RCSB’s curated descriptor. Other typical values are "CACTVS" and "ACDLabs". Matched case-insensitively as a substring of the program name reported by RCSB; raises if the component has no SMILES from a matching program.

Returns:

smiles – The SMILES string.

Return type:

str

Examples

>>> rcsbFetchLigandSmiles('BEN', stereo=False)
'[H]N=C(c1ccccc1)N'
>>> rcsbFetchLigandSmiles('BEN', program='CACTVS')
'NC(=N)c1ccccc1'
moleculekit.rcsb.rcsbFindLigands(pdbid)#

Find the ligands present in a PDB entry.

Scrapes the RCSB PDB entry page for its table of ligands and returns their residue names.

Parameters:

pdbid (str) – The 4-letter PDB code to look up.

Returns:

ligands – The residue names of the ligands found in the entry (e.g. ['SO4', 'GOL']). Empty if no ligands are found.

Return type:

list

Examples

>>> rcsbFindLigands('3onq')
['SO4', 'GOL']
moleculekit.rcsb.rcsbFindMutatedResidues(pdbid)#

Find the modified/mutated residues of a PDB entry.

Scrapes the RCSB PDB entry page for its table of modified residues and maps each non-standard residue name to the standard residue it derives from.

Parameters:

pdbid (str) – The 4-letter PDB code to look up.

Returns:

tomutate – A mapping from each modified residue name to its parent standard residue name (e.g. {'MSE': 'MET'}). Empty if no modified residues are found.

Return type:

dict

Examples

>>> rcsbFindMutatedResidues('3onq')
{'MSE': 'MET'}
moleculekit.rcsb.rcsbIsMembraneProtein(pdbid)#

Check whether an RCSB entry’s keywords classify it as a membrane protein.

Queries the entry’s struct_keywords block and reports whether the word “membrane” appears in it. This is a best-effort classification based on the depositors’ keywords, not a structural analysis.

Parameters:

pdbid (str) – The 4-letter RCSB PDB id. Case-insensitive.

Returns:

is_membrane – True when the entry’s keywords mention “membrane”.

Return type:

bool

Raises:

RuntimeError – If the RCSB request fails (unknown entry, network failure).

Examples

>>> rcsbIsMembraneProtein("7q5b")
True
moleculekit.rcsb.rcsbSequenceSearch(sequence, identity_cutoff=0.9, rows=10)#

Search the RCSB hosted sequence-similarity service for a protein sequence.

Parameters:
  • sequence (str) – The one-letter protein query sequence.

  • identity_cutoff (float) – Minimum sequence identity (0-1) for a hit to be returned.

  • rows (int) – Maximum number of hits to return.

Returns:

hits{"polymer_entity_id": str, "identity": float, "score": float}, ordered best-first.

Return type:

list

moleculekit.rcsb.resolveFullSequences(mol, pdbid=None)#

Resolve the full target sequence of each protein chain in mol.

When pdbid is given, the exact deposited entity sequence is used (source="pdb_entity", identity=1.0). Otherwise each chain’s observed sequence is run through rcsbSequenceSearch() and the best hit’s full entity sequence is used (source="sequence_search").

Parameters:
  • mol (Molecule) – The (possibly gapped) structure.

  • pdbid (str or None) – The 4-letter RCSB PDB id, if known.

Returns:

resolved{chain: {"sequence": str, "source": str, "identity": float, "entity_id": str | None, "accession": str | None, "uniprot_refs": list}} for each protein chain for which a full sequence could be found. entity_id is the RCSB polymer entity id of the best sequence-search hit (e.g. "132L_1") and None on the pdb_entity path, where the entry is already known. uniprot_refs holds every UniProt cross-reference of the entity as {"accession": str, "aligned_regions": [{"entity_beg_seq_id", "ref_beg_seq_id", "length"}, ...]} - the SIFTS mapping that turns an entity residue number into a UniProt one - and accession is the one of those covering the most entity residues (for display). Both are empty/None when RCSB has no UniProt cross-reference for the chain.

Return type:

dict