Candidate¶
The Candidate dataclass represents a single candidate sequence or design to be evaluated.
It contains the sequence representation and associated metadata.
- class alf_core.dataclasses.candidate.Candidate(data, modality, features=None)[source]¶
Bases:
objectA candidate is a data point with a modality and features.
- data¶
The raw data of the candidate (e.g., a sequence string, a SMILES string, a feature vector).
- modality¶
The data’s domain (see
Modality) — what it represents, e.g."sequence"or"molecule". Not its storage type.
- features¶
Optional dictionary of precomputed features for the candidate.
- data: Any¶
- features: dict | None = None¶
- to_serializable()[source]¶
Convert candidate data to a format suitable for pandas DataFrame storage.
Dispatch is based on the type of
data, not onmodality. Modality describes the data’s domain (seeModality); how it is stored — and therefore how it is serialised — is determined by its Python type:str(sequences, SMILES, JSON-encoded payloads): returned unchanged.torch.Tensor: converted to a numpy array for compact storage.numpy array, scalar (Python
int/float/boolor a numpy scalar such asnp.int64),dict,list,tuple, pandasSeries: returned unchanged.None: returned asNone.
- Returns:
- The candidate data in a DataFrame-compatible format.
Common types include str, dict, np.ndarray, pd.Series, or torch.Tensor.
- Return type:
Union[str,int,float,bool,dict,list,tuple,ndarray,Any,None]- Raises:
TypeError – If the data type is not DataFrame-compatible.
Examples
>>> # A sequence or SMILES string is stored as-is >>> Candidate(data="ACDEFG", modality=Modality.SEQUENCE).to_serializable() 'ACDEFG'
>>> Candidate(data="CC(=O)O", modality=Modality.MOLECULE).to_serializable() 'CC(=O)O'
>>> # A feature dict is stored as-is >>> c = Candidate(data={"age": 32, "height": 178}, modality=Modality.TABULAR) >>> c.to_serializable() {'age': 32, 'height': 178}
- class alf_core.dataclasses.candidate.Modality(*values)[source]¶
Bases:
EnumThe kind of candidate — used to match datasets with compatible models and metrics.
It is the data’s domain where one exists, not how the data is stored. This is why a protein sequence and a SMILES string are distinct modalities (
SEQUENCEvsMOLECULE) even though both are stored asstr: they pair with different models and metrics. Storage type is never encoded here — it is inferred fromtype(data)(seeCandidate.to_serializable).- Members:
SEQUENCE: Biological sequences (protein / nucleotide), as strings. MOLECULE: Small molecules, as SMILES strings. TABULAR: Domain-agnostic numeric feature vectors (arrays, tensors, scalars, dicts).
- MOLECULE = 'molecule'¶
- SEQUENCE = 'sequence'¶
- TABULAR = 'tabular'¶