<jupyter_start><jupyter_text>pypdb demosThis is a set of basic examples of the usage and outputs of the various individual functions included in. There are generally three types of functions.  Preamble<jupyter_code>%pylab inline
from IPython.display import HTML

# Import from local directory
# import sys
# sys.path.insert(0, '../pypdb')
# from pypdb import *

# Import from installed package
from pypdb import *

%load_ext autoreload
%autoreload 2<jupyter_output>Populating the interactive namespace from numpy and matplotlib
The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload<jupyter_text>Search functions that return lists of PDB IDs  Get a list of PDBs for a specific search term<jupyter_code>found_pdbs = Query("ribosome").search()
print(found_pdbs[:10])<jupyter_output>/Users/williamgilpin/miniconda3/envs/pypdb/lib/python3.8/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)<jupyter_text>Search by PubMed ID Number<jupyter_code>found_pdbs = Query(27499440, "PubmedIdQuery").search()
print(found_pdbs[:10])<jupyter_output>['5IMT', '5IMW', '5IMY']<jupyter_text>Search by source organism using NCBI TaxId<jupyter_code>found_pdbs = Query('6239', 'TreeEntityQuery').search() #TaxID for C elegans
print(found_pdbs[:5])<jupyter_output>['3UTO', '3V71', '3V74', '3V6Y', '3UAF']<jupyter_text>Search by a specific experimental method<jupyter_code>found_pdbs = Query('SOLID-STATE NMR', query_type='ExpTypeQuery').search()
print(found_pdbs[:10])<jupyter_output>['5LCB', '2RLZ', '6WAP', '2MC7', '2MCX', '2MCW', '2MCV', '2MCU', '2MEX', '2MJZ']<jupyter_text>Search by protein structure similarity<jupyter_code>found_pdbs = Query('2E8D', query_type="structure").search()
print(found_pdbs[:10])<jupyter_output>['2E8D', '4OBA', '4OGV', '4JVR', '3LBL', '4QO4', '4JWR', '2WS4', '4ERE', '2CEU']<jupyter_text>Search by Author<jupyter_code>found_pdbs = Query('<NAME>.', query_type='AdvancedAuthorQuery').search()
print(found_pdbs)<jupyter_output>/Users/williamgilpin/miniconda3/envs/pypdb/lib/python3.8/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)<jupyter_text>Search by organism<jupyter_code>q = Query("Dictyostelium", query_type="OrganismQuery")
print(q.search()[:10])<jupyter_output>['2H84', '4AE3', '3MNQ', '5AN9', '6QKL', '2W94', '2W95', '2WN2', '2WN3', '4AKR']<jupyter_text>Information Search functionsWhile the basic functions described in the previous section are useful for looking up and manipulating individual unique entries, these functions are intended to be more user-facing: they take search keywords and return lists of authors or dates  Find papers for a given keyword<jupyter_code>matching_papers = find_papers('crispr', max_results=10)
print(list(matching_papers)[:10])<jupyter_output>/Users/williamgilpin/miniconda3/envs/pypdb/lib/python3.8/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)<jupyter_text>Functions that return information about single PDB IDs  Get the full PDB file<jupyter_code>pdb_file = get_pdb_file('4lza', filetype='cif', compression=False)
print(pdb_file[:400])<jupyter_output>data_4LZA
# 
_entry.id   4LZA 
# 
_audit_conform.dict_name       mmcif_pdbx.dic 
_audit_conform.dict_version    5.281 
_audit_conform.dict_location   http://mmcif.pdb.org/dictionaries/ascii/mmcif_pdbx.dic 
# 
loop_
_database_2.database_id 
_database_2.database_code 
PDB   4LZA         
RCSB  RCSB081269   
WWPDB D_1000081269 
# 
_pdbx_database_related.db_name        TargetTrack 
_pdbx_database_rela<jupyter_text>Get a general description of the entry's metadata<jupyter_code>all_info = get_info('4LZA')
print(list(all_info.keys()))<jupyter_output>['audit_author', 'cell', 'citation', 'diffrn', 'diffrn_detector', 'diffrn_radiation', 'diffrn_source', 'entry', 'exptl', 'exptl_crystal', 'exptl_crystal_grow', 'pdbx_sgproject', 'pdbx_audit_revision_details', 'pdbx_audit_revision_history', 'pdbx_database_related', 'pdbx_database_status', 'pdbx_vrpt_summary', 'rcsb_accession_info', 'rcsb_entry_container_identifiers', 'rcsb_entry_info', 'rcsb_primary_citation', 'refine', 'refine_hist', 'refine_ls_restr', 'reflns', 'reflns_shell', 'software', 'struct', 'struct_keywords', 'symmetry', 'rcsb_id']<jupyter_text>Run a Sequence searchFormerly using BLAST, this method now uses MMseqs2<jupyter_code>q = Query("VLSPADKTNVKAAWGKVGAHAGEYGAEALERMFLSFPTTKTYFPHFDLSHGSAQVKGHGKKVADALTAVAHVDDMPNAL", 
          query_type="sequence", 
          return_type="polymer_entity")

print(q.search())<jupyter_output>{'query_id': '90344865-6c1d-448f-ba5b-64a2d727ade6', 'result_type': 'polymer_entity', 'total_count': 782, 'explain_meta_data': {'total_timing': 71, 'sort_timing': 0, 'terminal_node_timings': {'6469': 70}}, 'result_set': [{'identifier': '1C7D_1', 'score': 1.0, 'services': [{'service_type': 'sequence', 'nodes': [{'node_id': 6469, 'original_score': 164.0, 'norm_score': 1.0, 'match_context': [{'sequence_identity': 0.987, 'evalue': 2.053e-47, 'bitscore': 164, 'alignment_length': 80, 'mismatches': 0, 'gaps_opened': 1, 'query_beg': 1, 'query_end': 79, 'subject_beg': 144, 'subject_end': 223, 'query_length': 79, 'subject_length': 284, 'query_aligned_seq': 'VLSPADKTNVKAAWGKVGAHAGEYGAEALERMFLSFPTTKTYFPHFDLSHGSAQVKGHGKKVADALT-AVAHVDDMPNAL', 'subject_aligned_seq': 'VLSPADKTNVKAAWGKVGAHAGEYGAEALERMFLSFPTTKTYFPHFDLSHGSAQVKGHGKKVADALTNAVAHVDDMPNAL'}]}]}]}, {'identifier': '3OO5_1', 'score': 1.0, 'services': [{'service_type': 'sequence', 'nodes': [{'node_id': 6469, 'original_score': 164.0, 'norm_score':[...]<jupyter_text>Search by PFAM number<jupyter_code>pfam_info = Query("PF00008", query_type="pfam").search()
print(pfam_info[:5])<jupyter_output>['2F8Y', '2F8X', '2EC9', '2EI8', '2EI7']<jupyter_text>New API for advanced searchThe old API will gradually migrate to use these functions<jupyter_code>from pypdb.clients.search.search_client import perform_search
from pypdb.clients.search.search_client import ReturnType
from pypdb.clients.search.operators import text_operators<jupyter_output>/Users/williamgilpin/miniconda3/envs/pypdb/lib/python3.8/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)<jupyter_text>Search for all entries that mention the word 'ribosome'<jupyter_code>search_operator = text_operators.DefaultOperator(value="ribosome")
return_type = ReturnType.ENTRY

results = perform_search(search_operator, return_type)

print(results[:10])<jupyter_output>/Users/williamgilpin/miniconda3/envs/pypdb/lib/python3.8/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)<jupyter_text>Search for polymers from 'Mus musculus'<jupyter_code>search_operator = text_operators.ExactMatchOperator(value="Mus musculus",
                                                    attribute="rcsb_entity_source_organism.taxonomy_lineage.name")
return_type = ReturnType.POLYMER_ENTITY

results = perform_search(search_operator, return_type)

print(results[:5])<jupyter_output>/Users/williamgilpin/miniconda3/envs/pypdb/lib/python3.8/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)<jupyter_text>Search for non-polymers from 'Mus musculus' or 'Homo sapiens'<jupyter_code>search_operator = text_operators.InOperator(values=["Mus musculus", "Homo sapiens"],
                                            attribute="rcsb_entity_source_organism.taxonomy_lineage.name")
return_type = ReturnType.NON_POLYMER_ENTITY

results = perform_search(search_operator, return_type)
print(results[:5])<jupyter_output>/Users/williamgilpin/miniconda3/envs/pypdb/lib/python3.8/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)<jupyter_text>Search for polymer instances whose titles contain "actin" or "binding" or "protein"<jupyter_code>search_operator = text_operators.ContainsWordsOperator(value="actin-binding protein",
                                            attribute="struct.title")
return_type = ReturnType.POLYMER_INSTANCE

results = perform_search(search_operator, return_type)

print(results[:5])<jupyter_output>/Users/williamgilpin/miniconda3/envs/pypdb/lib/python3.8/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)<jupyter_text>Search for assemblies that contain the words "actin binding protein"(must be in that order).For example, "actin-binding protein" and "actin binding protein" will match,but "protein binding actin" will not.<jupyter_code>search_operator = text_operators.ContainsPhraseOperator(value="actin-binding protein",
                                            attribute="struct.title")
return_type = ReturnType.ASSEMBLY

results = perform_search(search_operator, return_type)

print(results[:5])<jupyter_output>Querying RCSB Search using the following parameters:
 {"query": {"type": "terminal", "service": "text", "parameters": {"attribute": "struct.title", "operator": "contains_phrase", "value": "actin-binding protein"}}, "request_options": {"return_all_hits": true}, "return_type": "assembly"} 

['1HQZ-7', '1HQZ-8', '1HQZ-5', '1HQZ-6', '1HQZ-9']<jupyter_text>Search for entries released in 2019 or later<jupyter_code>search_operator = text_operators.ComparisonOperator(
       value="2019-01-01T00:00:00Z",
       attribute="rcsb_accession_info.initial_release_date",
       comparison_type=text_operators.ComparisonType.GREATER)
return_type = ReturnType.ENTRY

results = perform_search(search_operator, return_type)

print(results[:5])<jupyter_output>/Users/williamgilpin/miniconda3/envs/pypdb/lib/python3.8/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)<jupyter_text>Search for entries released only in 2019<jupyter_code>search_operator = text_operators.RangeOperator(
    from_value="2019-01-01T00:00:00Z",
    to_value="2020-01-01T00:00:00Z",
    include_lower=True,
    include_upper=False,
    attribute="rcsb_accession_info.initial_release_date")
return_type = ReturnType.ENTRY

results = perform_search(search_operator, return_type)

print(results[:5])<jupyter_output>/Users/williamgilpin/miniconda3/envs/pypdb/lib/python3.8/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)<jupyter_text>Search by cell length<jupyter_code>from pypdb.clients.search.search_client import perform_search_with_graph, SearchService, ReturnType
from pypdb.clients.search.operators import text_operators

cell_a_operator = text_operators.RangeOperator(
    attribute='cell.length_a',
    from_value=80,
    to_value=84,
    include_upper=True
)

results = perform_search_with_graph(
    query_object=cell_a_operator,
    return_type=ReturnType.ENTRY
)

print(results[:5])<jupyter_output>/Users/williamgilpin/miniconda3/envs/pypdb/lib/python3.8/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)<jupyter_text>Search for structures under 4 angstroms of resolution<jupyter_code>search_operator = text_operators.ComparisonOperator(
           value=4,
           attribute="rcsb_entry_info.resolution_combined",
           comparison_type=text_operators.ComparisonType.LESS)
return_type = ReturnType.ENTRY

results = perform_search(search_operator, return_type)

print(results[:5])<jupyter_output>/Users/williamgilpin/miniconda3/envs/pypdb/lib/python3.8/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)<jupyter_text>Search for structures with a given attribute.(Admittedly every structure has a release date, but the same logic would apply for a more sparse RCSB attribute).<jupyter_code>search_operator = text_operators.ExistsOperator(
    attribute="rcsb_accession_info.initial_release_date")
return_type = ReturnType.ENTRY

results = perform_search(search_operator, return_type)

print(results[:5])<jupyter_output>/Users/williamgilpin/miniconda3/envs/pypdb/lib/python3.8/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)<jupyter_text>Search for 'Mus musculus' or 'Homo sapiens' structures after 2019 using graph search<jupyter_code>from pypdb.clients.search.search_client import perform_search_with_graph
from pypdb.clients.search.search_client import ReturnType
from pypdb.clients.search.search_client import QueryGroup, LogicalOperator
from pypdb.clients.search.operators import text_operators

# SearchOperator associated with structures with under 4 Angstroms of resolution
under_4A_resolution_operator = text_operators.ComparisonOperator(
       value=4,
       attribute="rcsb_entry_info.resolution_combined",
       comparison_type=text_operators.ComparisonType.GREATER)

# SearchOperator associated with entities containing 'Mus musculus' lineage
is_mus_operator = text_operators.ExactMatchOperator(
            value="Mus musculus",
            attribute="rcsb_entity_source_organism.taxonomy_lineage.name")

# SearchOperator associated with entities containing 'Homo sapiens' lineage
is_human_operator = text_operators.ExactMatchOperator(
            value="Homo sapiens",
            attribute="rcsb_entity_source_organism.taxonomy_lineage.name")

# QueryGroup associated with being either human or `Mus musculus`
is_human_or_mus_group = QueryGroup(
    queries = [is_mus_operator, is_human_operator],
    logical_operator = LogicalOperator.OR
)

# QueryGroup associated with being ((Human OR Mus) AND (Under 4 Angstroms))
is_under_4A_and_human_or_mus_group = QueryGroup(
    queries = [is_human_or_mus_group, under_4A_resolution_operator],
    logical_operator = LogicalOperator.AND
)

return_type = ReturnType.ENTRY

results = perform_search_with_graph(
  query_object=is_under_4A_and_human_or_mus_group,
  return_type=return_type)
print("\n", results[:10]) # Huzzah<jupyter_output>Querying RCSB Search using the following parameters:
 {"query": {"type": "group", "logical_operator": "and", "nodes": [{"type": "group", "logical_operator": "or", "nodes": [{"type": "terminal", "service": "text", "parameters": {"attribute": "rcsb_entity_source_organism.taxonomy_lineage.name", "operator": "exact_match", "value": "Mus musculus"}}, {"type": "terminal", "service": "text", "parameters": {"attribute": "rcsb_entity_source_organism.taxonomy_lineage.name", "operator": "exact_match", "value": "Homo sapiens"}}]}, {"type": "terminal", "service": "text", "parameters": {"attribute": "rcsb_entry_info.resolution_combined", "operator": "greater", "value": 4}}]}, "request_options": {"return_all_hits": true}, "return_type": "entry"}

 ['6PYH', '1JL4', '6WOV', '6X5A', '6YAF', '6YAH', '6XJD', '6OE5', '6OEN', '4K24']
{'fraction_non_alphanumeric': 0.10847802726090153, 'fraction_numerical': 0.0254510491488038, 'mean_word_length': 6.993670886075949, 'pattern_counts': {'":': 38, '<': 77, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '25', 'dir': 'jupyter-structured-clean-dedup', 'id': '241536', 'license': 'MIT', 'n_tokens_mistral': 6184, 'n_tokens_neox': 5836, 'n_words': 1261, 'path': 'demos/demos.ipynb', 'repo_name': 'samuelstanton/pypdb', 'size': '17686'}