Skip to main content

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 simulator
  • 1dphononbte - 1D Phonon BTE Solver for heat transport
  • abinit - DFT calculations for molecules and periodic solids
  • 1dchainmd - 1D Chain Dispersions
  • 1dfdmht - 1D Finite Different Method Heat Transfer
  • 2dmatstacks - Electrostatic Properties of Layered 2D Materials
  • adept - Solar cell and semiconductor device modeling
  • advte - Advanced Thermoelectric Power Generation

Sim2L Tools:

  • alphafold231 - AlphaFold 2.3.1 protein structure prediction
  • cellrelaxdft - Cell Relax DFT calculations
  • elasticdft - Elastic Constants with DFT
  • gaussianthermo - First-Principles Thermochemical Dataset

[!NOTE] Rappture vs Sim2L Tools: Rappture tools use simtool=False (default), while Sim2L tools require simtool=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 condition
  • select(*fields) - Specify fields to return
  • limit(limit) - Set result limit
  • offset(offset) - Set pagination offset
  • sort(field, asc=True) - Set sort order
  • execute() - Execute the query
  • paginate(per_page=50) - Iterate over all results

Valid Operations

  • = - Equal
  • != - Not equal
  • > - Greater than
  • < - Less than
  • >= - Greater than or equal
  • <= - Less than or equal
  • like - Pattern matching
  • in - In list

Examples Directory

See the examples/ directory for complete examples:

  • 01_basic_search.py - Basic query usage
  • 02_advanced_filtering.py - Multiple filters and sorting
  • 03_downloading_files.py - File downloads
  • 04_pagination.py - Automatic pagination

License

See LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nanohub_results-1.0.0.tar.gz (29.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nanohub_results-1.0.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

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

Hashes for nanohub_results-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3ebf324b57666fc3c9260d0d14bebfad4afdcd6a1d175423656ad74240e25ded
MD5 df1ab616459c1b1abcade91111f63db1
BLAKE2b-256 f9878544f1c034fd3dc0919ef443ed19607b12affae3cb0a4358af96e055c0b2

See more details on using hashes here.

File details

Details for the file nanohub_results-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for nanohub_results-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f3db23d03124a81e62a72657aa9a42f7ab7baeb145fcdc58e3b67c5655af332
MD5 4cf46f6b76ba70f89f9daa002f91550b
BLAKE2b-256 330628c509fc6aebfc136bc6cd6c124a361181a620e2b0bf301b30db6b4cd6b0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page