Skip to content

Compound

compound

Compound Value Object

Represents a chemical compound in the system.

Classes

Compound dataclass

Compound(cpd: str, name: str, smiles: Optional[str] = None, chebi: Optional[str] = None)

Value Object for chemical compound.

Parameters:

Name Type Description Default
cpd str

Compound identifier code (e.g., 'C00001')

required
name str

Compound name (e.g., 'H2O', 'Water')

required
smiles Optional[str]

SMILES notation of the compound

None
chebi Optional[str]

ChEBI identifier

None

Raises:

Type Description
ValueError

If cpd or name are empty

Notes

Compounds are uniquely identified by cpd code. SMILES and ChEBI are optional for data enrichment.

Functions
__post_init__
__post_init__()

Validates required compound fields.

Raises:

Type Description
ValueError

If cpd or name are invalid.

Source code in src/domain/value_objects/compound.py
def __post_init__(self):
    """
    Validates required compound fields.

    Raises
    ------
    ValueError
        If cpd or name are invalid.
    """
    if not self.cpd or not self.cpd.strip():
        raise ValueError("Compound code (cpd) cannot be empty")

    if not self.name or not self.name.strip():
        raise ValueError("Compound name cannot be empty")
__str__
__str__() -> str

Returns string representation of compound.

Returns:

Type Description
str

Compound name.

Source code in src/domain/value_objects/compound.py
def __str__(self) -> str:
    """
    Returns string representation of compound.

    Returns
    -------
    str
        Compound name.
    """
    return self.name
__repr__
__repr__() -> str

Returns debug representation of compound.

Returns:

Type Description
str

Representation with cpd and name.

Source code in src/domain/value_objects/compound.py
def __repr__(self) -> str:
    """
    Returns debug representation of compound.

    Returns
    -------
    str
        Representation with cpd and name.
    """
    return f"Compound('{self.cpd}', '{self.name}')"
__hash__
__hash__() -> int

Hash based on compound code.

Returns:

Type Description
int

Hash of cpd.

Source code in src/domain/value_objects/compound.py
def __hash__(self) -> int:
    """
    Hash based on compound code.

    Returns
    -------
    int
        Hash of cpd.
    """
    return hash(self.cpd)
has_structure
has_structure() -> bool

Checks if compound has structural information (SMILES).

Returns:

Type Description
bool

True if SMILES is defined.

Source code in src/domain/value_objects/compound.py
def has_structure(self) -> bool:
    """
    Checks if compound has structural information (SMILES).

    Returns
    -------
    bool
        True if SMILES is defined.
    """
    return self.smiles is not None and len(self.smiles.strip()) > 0
has_chebi
has_chebi() -> bool

Checks if compound has ChEBI reference.

Returns:

Type Description
bool

True if ChEBI is defined.

Source code in src/domain/value_objects/compound.py
def has_chebi(self) -> bool:
    """
    Checks if compound has ChEBI reference.

    Returns
    -------
    bool
        True if ChEBI is defined.
    """
    return self.chebi is not None and len(self.chebi.strip()) > 0