"""Base class and utilities"""fromtypingimportCollectionfrommore_itertoolsimporttake
[docs]classStarter:"""Template for classes which select an initial set of calculations to run. Args: max_to_consider: Only select from the up to the first ``max_to_consider`` molecules in the search space, if set. """def__init__(self,max_to_consider:int|None=None):self.max_to_consider=max_to_consider
[docs]defselect(self,to_select:Collection[str],count:int)->list[str]:"""Select a subset of molecules to run Args: to_select: Collection of SMILES strings count: Number of computations to select Returns: List of at least :attr:`min_to_select` chosen SMILES strings """# Make sure there are enough moleculesifcount>len(to_select):raiseValueError(f"Cannot select {count} molecules from {len(to_select)} molecules.")# Get the pool to draw from (TODO: draw randomly rather than the first)ifself.max_to_considerisnotNone:pool=take(self.max_to_consider,to_select)else:pool=list(to_select)returnself._select(pool,count)
def_select(self,to_select:list[str],count:int)->list[str]:"""Perform the selection Args: to_select: List from which to draw candidates count: Number to draw Returns: Selected subset """raiseNotImplementedError()