Usage¶
To use python-nakb in a project:
import nakb
Using the High-Level Query¶
Retrieve the first 10 entries from NAKB, matching all:
client = NAKBClient()
client.query()
This returns a pandas.DataFrame by default.
Selecting specific fields¶
Use the fields parameter:
df = client.query(fields=["pdbid", "resolution"])
If you pass None, Solr returns its default field set.
Filtering using keyword operators¶
The high-level query interface supports convenient Solr filters using
the syntax: field__operator=value
The supported operators are:
Default, exact match or OR query
ltless thangtgreater thanrange=(a,b)range filtercontains="substr"substring search
Let’s make examples:
df = client.query(pdbid="1A1H") # exact match
df = client.query(pdbid=["1A1H", "1AAY"]) # OR query
df = client.query(resolution__lt=2.0) # less than
df = client.query(resolution__gt=1.5) # greater than
df = client.query(resolution__range=(1.0, 2.0)) # range
df = client.query(description__contains="kinase") # substring search
These can be combined:
df = client.query(
fields=["pdbid", "resolution", "polyclass"],
polyclass="Protein/DNA",
resolution__lt=3.5,
)
Using the Low-Level Query¶
query_raw exposes Solr parameters directly:
docs = client.query_raw(
q="*:*",
fl="pdbid,title",
fq=["polyclass:Protein/DNA"],
rows=50,
as_dataframe=False,
)
Returns a list of dictionaries unless as_dataframe=True.
Listing All Available Fields¶
Retrieve the metadata fields stored in NAKB:
client.get_fields()