Molecule
- class specatalog.models.molecules.Molecule(**kwargs)[source]
Base clase representing a molecule.
This class represents a chemical molecule, including both basic descriptive metadata (name, molecular formula) and a structural representation. It serves as the base class for a polymorphic hierarchy of molecule types, enabling specialised subclasses to extend the core attributes defined here.
The
measurementsrelationship links each molecule to all associated spectroscopic measurements, with deletions cascading automatically to dependent measurement entries.- id
Primary key of the molecule entry.
- Type:
int
- name
Human-readable molecular name. Must be unique.
- Type:
str
- molecular_formula
Standard chemical formula such as
C20H14O.- Type:
str
- structural_formula
Path to a file with the structural formula (e.g. .cdx and .pdf format). The file should be saved at
/molecules/MOLxy. Must be unique.- Type:
str
- measurements
All spectroscopic measurements associated with this molecule.
- Type:
list[Measurement]
- additional_info
Optional free-text field containing supplementary information about the molecule.
- Type:
str or None
- group
Polymorphic discriminator used by SQLAlchemy to select the correct molecule subclass upon loading.
- Type:
str
Notes
The tablename is
molecules.This class forms the base of a polymorphic SQLAlchemy hierarchy.
Subclasses define their own
polymorphic_identityvalues.The
measurementsrelationship usespassive_deletes=Trueso that deleting a molecule cascades to related measurement entries automatically.Timestamp fields
created_atandupdated_atare inherited fromTimeStampedModel.
Examples
Creating a molecule:
>>> from models import Molecule >>> mol = Molecule( ... name="Perylene", ... molecular_formula="C20H12", ... structural_formula="/molecule/MOL5", ... group="base", ... ) >>> session.add(mol) >>> session.commit()
Accessing linked measurements:
>>> mol = session.get(Molecule, 5) >>> mol.measurements [Measurement(...), TREPR(...), PulseEPR(...)]