Database Models - acelot-inc/boltzmann GitHub Wiki

Database Models

Related Files

  • boltzmann/models.py

Related Pages

Related topics: Architecture and Components

Database Models in Boltzmann

This page details the database models used in the Boltzmann project, as defined in boltzmann/models.py. These models use SQLAlchemy, an Object Relational Mapper (ORM), to represent the structure of data and facilitate database interactions using Python objects.

Purpose and Functionality

The database models define the structure of database tables and relationships between entities, enabling:

  • Data Persistence: Storage and retrieval of application data.
  • Data Validation: Enforcement of data integrity through constraints.
  • Abstraction: A high-level interface for database interaction.
  • Relationship Management: Definition of relationships between data entities.

Key Models

The boltzmann/models.py file defines models such as:

  • Session: Represents a user session.
  • Protein: Represents a protein target.
  • Ligand: Represents a ligand.
  • Job: Represents a docking job.

Code Snippets

Example of a model definition using SQLAlchemy:

from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    username = Column(String(50), unique=True, nullable=False)
    email = Column(String(120), unique=True, nullable=False)

    def __repr__(self):
        return f"<User(username='{self.username}', email='{self.email}')>"

This code defines a User model with columns for id, username, and email.

Integration with Overall Architecture

The database models are integral to the Boltzmann application's backend. The API uses them to:

  1. Store data (protein structures, ligand SMILES).
  2. Retrieve data for the user interface.
  3. Manage docking job queues.
  4. Persist docking simulation results.

Here's a sequence diagram illustrating model usage in a docking workflow:

sequenceDiagram
    participant User
    participant WebApp
    participant API
    participant Database

    User->>WebApp: Submits docking job
    activate WebApp
    WebApp->>API: Sends job request
    activate API
    API->>Database: Creates new Job entry
    activate Database
    Database-->>API: Job ID
    deactivate Database
    API-->>WebApp: Job enqueued
    deactivate API
    WebApp-->>User: Confirmation
    deactivate WebApp
Loading

Data Flow Diagram

This diagram illustrates the flow of data related to database models.

graph TD
    A[User Input] --> B{Validate Data}
    B --> C{Is Valid?}
    C -- Yes --> D[Create/Update Model Instance]
    D --> E[Persist to Database]
    C -- No --> F[Return Error to User]
    E --> G[Data Stored]
Loading

Conclusion

The database models in boltzmann/models.py are essential for data management within the Boltzmann application, providing a structured way to interact with the database.

Sources: SOURCE_DISPLAY


⚠️ **GitHub.com Fallback** ⚠️