Class design¶
Class Diagram Description¶
This class diagram outlines the main components and their interactions in our Python package for handling molecules in HELM notation. This is a sketch and can be edited.
Key Points:¶
- Molecule:
- Central coordinator for reading, writing, and visualizing molecular data.
-
Uses services and factories to perform these operations.
-
MoleculeData:
- Core data structure representing parsed molecular information.
- Provides methods to access detailed molecular components and summaries.
- Core idea of the package is to have only one internal technical representation of the molecule and all operations are performed on this object. We therefore do not need to convert from format x to y but only need to be able to read into the MoleculeData object and write it to our specifications.
-
Each information piece should only be materialized once, no duplication within the MoleculeData object.
-
Factories and Readers:
ReaderFactorydynamically provides readers (HelmReader,XnaReader, ...to be extended) based on notation.-
WriterFactorysimilarly provides writers. -
Services:
VisualizationServicehandles specific tasks related to modifying, visualizing, and validatingMoleculeData.
This structure ensures modularity and extensibility, allowing easy addition of new readers, writers, and modifiers.
classDiagram
direction TB
%% Main Classes
class Molecule {
+ MoleculeData _molecule_data
+ from_helm(data: str) : Molecule
+ from_xna(data: Dict) : Molecule
+ from_sequence(data: str) : Molecule
+ read(data: str, notation: str) : Molecule
+ to_helm() : str
+ to_xna() : Dict
+ to_fasta() : str
+ write(notation: str) : Any
+ visualize_cartoon() : Tuple
}
namespace Datastructures {
class MoleculeData {
+ Dict~str, Polymer~ polymers
+ List~Connection~ connections
+ Dict~str, str~ annotations
+ str version
}
class Monomer {
+ str id
+ str type
+ str uuid
}
class Polymer {
+ str type
+ str index
+ List~Residue~ residues
+ id : str (property)
}
class Residue {
+ str type
+ List~Monomer~ monomers
}
class Connection {
+ Monomer monomer1
+ str attachment1
+ Monomer monomer2
+ str attachment2
}
}
%% Reader Classes
class ReaderFactory {
+ __init__()
+ get_reader(notation: str) : BaseReader
}
class BaseReader {
+ read(data: Any) : MoleculeData
}
class HelmReader {
+ read(data: str) : MoleculeData
}
class XnaReader {
+ read(data: Dict) : MoleculeData
}
%% Writer Classes
class WriterFactory {
+ __init__()
+ get_writer(notation: str) : BaseWriter
}
class BaseWriter {
+ write(molecule_data: MoleculeData) : Any
}
class HelmWriter {
+ write(molecule_data: MoleculeData) : str
}
class XnaWriter {
+ write(molecule_data: MoleculeData) : Dict
}
%% Service Classes
class VisualizationService {
+ __init__(visualizer)
+ cartoon(molecule_data: MoleculeData) : Tuple
+ display(molecule_data: MoleculeData)
}
class Visualizer {
+ visualize(molecule_data: MoleculeData)
+ display(molecule_data: MoleculeData)
}
%% Relationships
Molecule --> MoleculeData
Molecule --> ReaderFactory
Molecule --> WriterFactory
Molecule --> VisualizationService
ReaderFactory --> BaseReader
BaseReader <|-- HelmReader
BaseReader <|-- XnaReader
WriterFactory --> BaseWriter
BaseWriter <|-- HelmWriter
BaseWriter <|-- XnaWriter
VisualizationService --> Visualizer
MoleculeData *-- Monomer
MoleculeData *-- Polymer
MoleculeData *-- Residue
MoleculeData *-- Connection
Polymer *-- Residue
Residue *-- Monomer
Legend for Reading the Class Diagram¶
Class Definitions:¶
ClassA, ClassB, ClassC, ClassD, ClassE, and ClassF are defined. ClassA includes examples of public, private, and protected attributes and methods. Visibility Modifiers:
+ for public attributes and methods.
- for private attributes and methods.
# for protected attributes and methods.
Relationships:
- Inheritance (<|--): ClassB inherits from ClassA.
- Composition (*--): ClassA contains ClassC.
- Aggregation (o--): ClassA references ClassD without owning it.
- Association (-->): ClassA is associated with ClassE.
- Dependency (..>): ClassA depends on ClassF.
classDiagram class ClassA { +publicAttribute: Type -privateAttribute: Type #protectedAttribute: Type +publicMethod(param: Type): ReturnType -privateMethod(param: Type): ReturnType #protectedMethod(param: Type): ReturnType } class ClassB { +attribute: Type } class ClassC { +attribute: Type } class ClassD { +attribute: Type } class ClassE { +attribute: Type } class ClassF { +attribute: Type } %% Inheritance ClassA <|-- ClassB : Inheritance %% Composition ClassA *-- ClassC : Composition %% Aggregation ClassA o-- ClassD : Aggregation %% Association ClassA --> ClassE : Association %% Dependency ClassA ..> ClassF : Dependency