[docs]classDescriptor:""" A strategy class for calculating the descriptor vector of a molecule. """def__init__(self,config)->None:self.properties=[]self.ranges=config.rangesself.property_names=config.propertiesfornameinself.property_names:module,function=name.split(".")module=getattr(sys.modules[__name__],module)self.properties.append(getattr(module,function))self.dimensionality=len(self.property_names)returnNonedef__call__(self,molecule)->None:""" Updates the descriptor vector of a molecule. """descriptor=[]molecular_graph=Chem.MolFromSmiles(molecule.smiles)forproperty,rangeinzip(self.properties,self.ranges):descriptor.append(self.rescale(property(molecular_graph),range))molecule.descriptor=descriptorreturnmolecule
[docs]@staticmethoddefrescale(feature:List[float],range:List[float])->List[float]:""" Rescales the feature to the unit range. """rescaled_feature=(feature-range[0])/(range[1]-range[0])returnrescaled_feature
[docs]classSurrogate:""" A factory class for creating instances of various surrogate functions based on the provided configuration. The supported surrogate function types are "Smiles" and "Fingerprint". Note that Fingerprint acquisition functions need further specifications by passing on the config file. Methods: __new__: Static method for creating and returning an instance of a specific fitness function based on the configuration. """@staticmethoddef__new__(self,config):""" Static method for creating and returning an instance of a specific fitness function based on the configuration. Parameters: - config: An object specifying the configuration for the fitness function, including the type. Returns: An instance of a fitness function based on the specified type in the configuration. """matchconfig.type:case"String":returnString_Surrogate(config)case"Fingerprint":returnFingerprint_Surrogate(config)case_:raiseValueError(f"{config.type} is not a supported surrogate function type.")
classFitness:""" A factory class for creating instances of various fitness functions based on the provided configuration. The supported fitness function types are "Fingerprint", "USRCAT", and "Zernike". Methods: __new__: Static method for creating and returning an instance of a specific fitness function based on the configuration. """@staticmethoddef__new__(self,config):""" Static method for creating and returning an instance of a specific fitness function based on the configuration. Parameters: - config: An object specifying the configuration for the fitness function, including the type. Returns: An instance of a fitness function based on the specified type in the configuration. """print(config.type)matchconfig.type:case"Fingerprint":returnFingerprint_Fitness(config)case"Guacamol":returnGaucamol_Fitness(config)case"USRCAT":returnUSRCAT_Fitness(config)case"Zernike":returnZernike_Fitness(config)case"OVC":returnOVC_Fitness(config)case"Docking":returnDocking_Fitness(config)case_:raiseValueError(f"{config.type} is not a supported fitness function type.")
[docs]classAcquisition:""" A factory class for creating instances of various acquisition functions based on the provided configuration. Requires an Archive instance to be passed with the configuration file. The supported acquisition function types are "Mean", "UCB", "EI", and "logEI". Methods: __new__: Static method for creating and returning an instance of a specific acquisition function based on the configuration. """@staticmethoddef__new__(self,config):""" Static method for creating and returning an instance of a specific acquisition function based on the configuration. Parameters: - config: An object specifying the configuration for the acquisition function, including the type. Returns: An instance of an acquisition function based on the specified type in the configuration. """matchconfig.type:case"Mean":returnPosterior_Mean(config)case"UCB":returnUpper_Confidence_Bound(config)case"EI":returnExpected_Improvement(config)case"logEI":returnLog_Expected_Improvement(config)case_:raiseValueError(f"{config.type} is not a supported acquisition function type.")