Python library to interact with NanoHUB Results API
Project description
nanohub-results
Python library to interact with the NanoHUB Results API. This library provides a Pythonic interface for searching, filtering, and downloading simulation results from NanoHUB tools.
Features
- Pythonic Query Builder: Fluent interface with method chaining
- Field Validation: Automatic validation against tool schemas
- Operation Validation: Only valid operations (
=,!=,>,<,>=,<=,like,in) - Pagination: Automatic iteration over large result sets
- Complete API Coverage: Access to all dbexplorer and download endpoints
Installation
cd nanohub-results
pip install .
Quick Start
import nanohubremote as nr
from nanohubresults import Results
# Initialize session with authentication
auth_data = {
"grant_type": "personal_token",
"token": "your_token_here"
}
session = nr.Session(auth_data, url="https://nanohub.org/api")
results = Results(session)
# Get list of available tools
tools = results.get_tools(simtool=False)
print(tools)
# Search for results using the Query builder
response = results.query("2dfets") \
.filter("output.Id", ">", 1e-6) \
.select("output.Id", "output.Vt") \
.limit(10) \
.execute()
print(response)
Available Tools
Some example tools available on NanoHUB:
Rappture Tools:
2dfets- 2D FET I-V characteristics simulator1dphononbte- 1D Phonon BTE Solver for heat transportabinit- DFT calculations for molecules and periodic solids1dchainmd- 1D Chain Dispersions1dfdmht- 1D Finite Different Method Heat Transfer2dmatstacks- Electrostatic Properties of Layered 2D Materialsadept- Solar cell and semiconductor device modelingadvte- Advanced Thermoelectric Power Generation
Sim2L Tools:
alphafold231- AlphaFold 2.3.1 protein structure predictioncellrelaxdft- Cell Relax DFT calculationselasticdft- Elastic Constants with DFTgaussianthermo- First-Principles Thermochemical Dataset
[!NOTE] Rappture vs Sim2L Tools: Rappture tools use
simtool=False(default), while Sim2L tools requiresimtool=True.
Usage Examples
1. List Available Tools
# Get all simulation tools
tools = results.get_tools(simtool=True)
for tool in tools['results']:
print(f"{tool['tool_name']}: {tool['title']}")
2. Get Tool Schema
# Get detailed schema for a tool
schema = results.get_tool_detail("2dfets")
print(schema)
3. Search with Filters
# Search with multiple filters
query = results.query("1dphononbte") \
.filter("input.acoustic_length", ">", 1) \
.filter("output.temperature", ">", 300) \
.select("input.acoustic_length", "output.temperature", "output.heat_flux") \
.sort("output.temperature", asc=True) \
.limit(20)
response = query.execute()
4. Pagination
# Iterate over all results
for result in results.query("abinit") \
.filter("output.energy", "<", 0) \
.select("output.energy", "output.forces") \
.paginate(per_page=50):
print(result)
5. Download Files
# Download a specific output field
file_content = results.download(
tool="abinit",
squid="simulation_id_here",
field="output.wavefunction"
)
with open("wavefunction.dat", "wb") as f:
f.write(file_content)
Testing Without Installation
All examples include path configuration for testing without installation:
cd examples
python3 01_basic_search.py
API Reference
Results Class
query(tool, simtool=False)
Create a Query builder for a tool.
get_tools(simtool=False, description_active=False)
Get list of available tools.
get_tool_detail(tool, revision=0, simtool=False)
Get tool schema and metadata.
search(tool, filters, results_fields, ...)
Direct search (or use Query builder).
download(tool, squid, field=None, ...)
Download files or output fields.
Query Class
Methods (all return self for chaining):
filter(field, op, value)- Add filter conditionselect(*fields)- Specify fields to returnlimit(limit)- Set result limitoffset(offset)- Set pagination offsetsort(field, asc=True)- Set sort orderexecute()- Execute the querypaginate(per_page=50)- Iterate over all results
Valid Operations
=- Equal!=- Not equal>- Greater than<- Less than>=- Greater than or equal<=- Less than or equallike- Pattern matchingin- In list
Examples Directory
See the examples/ directory for complete examples:
01_basic_search.py- Basic query usage02_advanced_filtering.py- Multiple filters and sorting03_downloading_files.py- File downloads04_pagination.py- Automatic pagination
License
See LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nanohub_results-1.0.0.tar.gz.
File metadata
- Download URL: nanohub_results-1.0.0.tar.gz
- Upload date:
- Size: 29.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ebf324b57666fc3c9260d0d14bebfad4afdcd6a1d175423656ad74240e25ded
|
|
| MD5 |
df1ab616459c1b1abcade91111f63db1
|
|
| BLAKE2b-256 |
f9878544f1c034fd3dc0919ef443ed19607b12affae3cb0a4358af96e055c0b2
|
File details
Details for the file nanohub_results-1.0.0-py3-none-any.whl.
File metadata
- Download URL: nanohub_results-1.0.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f3db23d03124a81e62a72657aa9a42f7ab7baeb145fcdc58e3b67c5655af332
|
|
| MD5 |
4cf46f6b76ba70f89f9daa002f91550b
|
|
| BLAKE2b-256 |
330628c509fc6aebfc136bc6cd6c124a361181a620e2b0bf301b30db6b4cd6b0
|