Database Models - acelot-inc/boltzmann GitHub Wiki
boltzmann/models.py
Related topics: Architecture and Components
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.
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.
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.
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
.
The database models are integral to the Boltzmann application's backend. The API uses them to:
- Store data (protein structures, ligand SMILES).
- Retrieve data for the user interface.
- Manage docking job queues.
- 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
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]
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