gt4sd.algorithms.conditional_generation.reinvent.core module

Summary

Classes:

Reinvent

Reinvent sample generation algorithm.

ReinventGenerator

Configuration to generate molecules using the REINVENT algorithm.

Reference

class Reinvent(configuration, target)[source]

Bases: GeneratorAlgorithm[S, T]

Reinvent sample generation algorithm.

__init__(configuration, target)[source]

Instantiate Reinvent ready to generate samples.

Parameters
  • configuration (AlgorithmConfiguration[~S, ~T]) – domain and application specification defining parameters, types and validations.

  • target (Optional[~T, None]) – a target for which to generate items.

Example

An example for predicting topics for a given text:

config = ReinventGenerator()
algorithm = Reinvent(configuration=config, target="CCO")
items = list(algorithm.sample(1))
print(items)
get_generator(configuration, target)[source]

Get the function to perform the prediction via Reinvent’s generator.

Parameters
  • configuration (AlgorithmConfiguration[~S, ~T]) – helps to set up specific application of Reinvent.

  • target (Optional[~T, None]) – context or condition for the generation.

Return type

Callable[[~T], Iterable[Any]]

Returns

callable with target generating samples.

__abstractmethods__ = frozenset({})
__annotations__ = {'generate': 'Untargeted', 'generator': 'Union[Untargeted, Targeted[T]]', 'max_runtime': 'int', 'max_samples': 'int', 'target': 'Optional[T]'}
__doc__ = 'Reinvent sample generation algorithm.'
__module__ = 'gt4sd.algorithms.conditional_generation.reinvent.core'
__orig_bases__ = (gt4sd.algorithms.core.GeneratorAlgorithm[~S, ~T],)
__parameters__ = (~S, ~T)
_abc_impl = <_abc._abc_data object>
class ReinventGenerator(*args, **kwargs)[source]

Bases: ReinventGenerator, Generic[T]

Configuration to generate molecules using the REINVENT algorithm. It generates the molecules minimizing the distances between the scaffolds.

algorithm_name: ClassVar[str] = 'Reinvent'

Name of the algorithm to use with this configuration.

Will be set when registering to ApplicationsRegistry

algorithm_type: ClassVar[str] = 'conditional_generation'

General type of generative algorithm.

domain: ClassVar[str] = 'materials'

General application domain. Hints at input/output types.

algorithm_version: str = 'v0'

To differentiate between different versions of an application.

There is no imposed naming convention.

batch_size: int = 20
randomize: bool = True
sample_uniquely: bool = True
max_sequence_length: int = 256
get_target_description()[source]

Get description of the target for generation.

Return type

Dict[str, str]

Returns

target description.

get_conditional_generator(resources_path)[source]

Instantiate the actual generator implementation.

Parameters

resources_path (str) – local path to model files.

Return type

ReinventConditionalGenerator

Returns

instance with generate_samples method for targeted generation.

validate_item(item)[source]

Check that item is a valid SMILES.

Parameters

item (str) – a generated item that is possibly not valid.

Raises

InvalidItem – in case the item can not be validated.

Return type

str

Returns

the validated SMILES.

__annotations__ = {'algorithm_application': 'ClassVar[str]', 'algorithm_name': typing.ClassVar[str], 'algorithm_type': typing.ClassVar[str], 'algorithm_version': <class 'str'>, 'batch_size': <class 'int'>, 'domain': typing.ClassVar[str], 'max_sequence_length': <class 'int'>, 'randomize': <class 'bool'>, 'sample_uniquely': <class 'bool'>}
__dataclass_fields__ = {'algorithm_application': Field(name='algorithm_application',type=typing.ClassVar[str],default='ReinventGenerator',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=<dataclasses._MISSING_TYPE object>,_field_type=_FIELD_CLASSVAR), 'algorithm_name': Field(name='algorithm_name',type=typing.ClassVar[str],default='Reinvent',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=<dataclasses._MISSING_TYPE object>,_field_type=_FIELD_CLASSVAR), 'algorithm_type': Field(name='algorithm_type',type=typing.ClassVar[str],default='conditional_generation',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=<dataclasses._MISSING_TYPE object>,_field_type=_FIELD_CLASSVAR), 'algorithm_version': Field(name='algorithm_version',type=<class 'str'>,default='v0',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'batch_size': Field(name='batch_size',type=<class 'int'>,default=20,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'description': 'Number of samples to generate per scaffold'}),kw_only=False,_field_type=_FIELD), 'domain': Field(name='domain',type=typing.ClassVar[str],default='materials',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=<dataclasses._MISSING_TYPE object>,_field_type=_FIELD_CLASSVAR), 'max_sequence_length': Field(name='max_sequence_length',type=<class 'int'>,default=256,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'description': 'Maximal length of SMILES sequences'}),kw_only=False,_field_type=_FIELD), 'randomize': Field(name='randomize',type=<class 'bool'>,default=True,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'description': 'Randomize the scaffolds if set to true'}),kw_only=False,_field_type=_FIELD), 'sample_uniquely': Field(name='sample_uniquely',type=<class 'bool'>,default=True,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({'description': 'Generate unique sample sequences if set to true'}),kw_only=False,_field_type=_FIELD)}
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False)
__doc__ = 'Configuration to generate molecules using the REINVENT algorithm. It generates the molecules minimizing the distances between the scaffolds.'
__eq__(other)

Return self==value.

__hash__ = None
__init__(*args, **kwargs)
__match_args__ = ('algorithm_version', 'batch_size', 'randomize', 'sample_uniquely', 'max_sequence_length')
__module__ = 'gt4sd.algorithms.conditional_generation.reinvent.core'
__orig_bases__ = (<class 'types.ReinventGenerator'>, typing.Generic[~T])
__parameters__ = (~T,)
__pydantic_complete__ = True
__pydantic_config__ = {}
__pydantic_core_schema__ = {'cls': <class 'gt4sd.algorithms.conditional_generation.reinvent.core.ReinventGenerator'>, 'config': {'title': 'ReinventGenerator'}, 'fields': ['algorithm_version', 'batch_size', 'randomize', 'sample_uniquely', 'max_sequence_length'], 'frozen': False, 'metadata': {'pydantic_js_annotation_functions': [], 'pydantic_js_functions': [functools.partial(<function modify_model_json_schema>, cls=<class 'gt4sd.algorithms.conditional_generation.reinvent.core.ReinventGenerator'>, title=None)]}, 'post_init': False, 'ref': 'types.ReinventGenerator:94662817384176', 'schema': {'collect_init_only': False, 'computed_fields': [], 'dataclass_name': 'ReinventGenerator', 'fields': [{'type': 'dataclass-field', 'name': 'algorithm_version', 'schema': {'type': 'default', 'schema': {'type': 'str'}, 'default': 'v0'}, 'kw_only': False, 'init': True, 'metadata': {'pydantic_js_functions': [], 'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>]}}, {'type': 'dataclass-field', 'name': 'batch_size', 'schema': {'type': 'default', 'schema': {'type': 'int'}, 'default': 20}, 'kw_only': False, 'init': True, 'metadata': {'pydantic_js_functions': [], 'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>]}}, {'type': 'dataclass-field', 'name': 'randomize', 'schema': {'type': 'default', 'schema': {'type': 'bool'}, 'default': True}, 'kw_only': False, 'init': True, 'metadata': {'pydantic_js_functions': [], 'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>]}}, {'type': 'dataclass-field', 'name': 'sample_uniquely', 'schema': {'type': 'default', 'schema': {'type': 'bool'}, 'default': True}, 'kw_only': False, 'init': True, 'metadata': {'pydantic_js_functions': [], 'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>]}}, {'type': 'dataclass-field', 'name': 'max_sequence_length', 'schema': {'type': 'default', 'schema': {'type': 'int'}, 'default': 256}, 'kw_only': False, 'init': True, 'metadata': {'pydantic_js_functions': [], 'pydantic_js_annotation_functions': [<function get_json_schema_update_func.<locals>.json_schema_update_func>]}}], 'type': 'dataclass-args'}, 'slots': True, 'type': 'dataclass'}
__pydantic_decorators__ = DecoratorInfos(validators={}, field_validators={}, root_validators={}, field_serializers={}, model_serializers={}, model_validators={}, computed_fields={})
__pydantic_fields__ = {'algorithm_version': FieldInfo(annotation=str, required=False, default='v0', init=True, init_var=False, kw_only=False), 'batch_size': FieldInfo(annotation=int, required=False, default=20, description='Number of samples to generate per scaffold', init=True, init_var=False, kw_only=False), 'max_sequence_length': FieldInfo(annotation=int, required=False, default=256, description='Maximal length of SMILES sequences', init=True, init_var=False, kw_only=False), 'randomize': FieldInfo(annotation=bool, required=False, default=True, description='Randomize the scaffolds if set to true', init=True, init_var=False, kw_only=False), 'sample_uniquely': FieldInfo(annotation=bool, required=False, default=True, description='Generate unique sample sequences if set to true', init=True, init_var=False, kw_only=False)}
__pydantic_serializer__ = SchemaSerializer(serializer=Dataclass(     DataclassSerializer {         class: Py(             0x00005618679a86f0,         ),         serializer: Fields(             GeneralFieldsSerializer {                 fields: {                     "algorithm_version": SerField {                         key_py: Py(                             0x00007f1dca917b90,                         ),                         alias: None,                         alias_py: None,                         serializer: Some(                             WithDefault(                                 WithDefaultSerializer {                                     default: Default(                                         Py(                                             0x00007f1ea52cf3f0,                                         ),                                     ),                                     serializer: Str(                                         StrSerializer,                                     ),                                 },                             ),                         ),                         required: true,                     },                     "batch_size": SerField {                         key_py: Py(                             0x00007f1dca9218f0,                         ),                         alias: None,                         alias_py: None,                         serializer: Some(                             WithDefault(                                 WithDefaultSerializer {                                     default: Default(                                         Py(                                             0x00007f1ea9468350,                                         ),                                     ),                                     serializer: Int(                                         IntSerializer,                                     ),                                 },                             ),                         ),                         required: true,                     },                     "randomize": SerField {                         key_py: Py(                             0x00007f1dca9218b0,                         ),                         alias: None,                         alias_py: None,                         serializer: Some(                             WithDefault(                                 WithDefaultSerializer {                                     default: Default(                                         Py(                                             0x000056185a4635a0,                                         ),                                     ),                                     serializer: Bool(                                         BoolSerializer,                                     ),                                 },                             ),                         ),                         required: true,                     },                     "sample_uniquely": SerField {                         key_py: Py(                             0x00007f1dca921930,                         ),                         alias: None,                         alias_py: None,                         serializer: Some(                             WithDefault(                                 WithDefaultSerializer {                                     default: Default(                                         Py(                                             0x000056185a4635a0,                                         ),                                     ),                                     serializer: Bool(                                         BoolSerializer,                                     ),                                 },                             ),                         ),                         required: true,                     },                     "max_sequence_length": SerField {                         key_py: Py(                             0x00007f1dca917be0,                         ),                         alias: None,                         alias_py: None,                         serializer: Some(                             WithDefault(                                 WithDefaultSerializer {                                     default: Default(                                         Py(                                             0x00007f1ea946a0d0,                                         ),                                     ),                                     serializer: Int(                                         IntSerializer,                                     ),                                 },                             ),                         ),                         required: true,                     },                 },                 computed_fields: Some(                     ComputedFields(                         [],                     ),                 ),                 mode: SimpleDict,                 extra_serializer: None,                 filter: SchemaFilter {                     include: None,                     exclude: None,                 },                 required_fields: 5,             },         ),         fields: [             Py(                 0x00007f1ea52ed250,             ),             Py(                 0x00007f1ea52ccc70,             ),             Py(                 0x00007f1ea7047f30,             ),             Py(                 0x00007f1dcaa69ab0,             ),             Py(                 0x00007f1de9b6d840,             ),         ],         name: "ReinventGenerator",     }, ), definitions=[])
__pydantic_validator__ = SchemaValidator(title="ReinventGenerator", validator=Dataclass(     DataclassValidator {         strict: false,         validator: DataclassArgs(             DataclassArgsValidator {                 fields: [                     Field {                         kw_only: false,                         name: "algorithm_version",                         py_name: Py(                             0x00007f1ea52ed250,                         ),                         init: true,                         init_only: false,                         lookup_key: Simple {                             key: "algorithm_version",                             py_key: Py(                                 0x00007f1dca917aa0,                             ),                             path: LookupPath(                                 [                                     S(                                         "algorithm_version",                                         Py(                                             0x00007f1dca917af0,                                         ),                                     ),                                 ],                             ),                         },                         validator: WithDefault(                             WithDefaultValidator {                                 default: Default(                                     Py(                                         0x00007f1ea52cf3f0,                                     ),                                 ),                                 on_error: Raise,                                 validator: Str(                                     StrValidator {                                         strict: false,                                         coerce_numbers_to_str: false,                                     },                                 ),                                 validate_default: false,                                 copy_default: false,                                 name: "default[str]",                                 undefined: Py(                                     0x00007f1ea71db950,                                 ),                             },                         ),                         frozen: false,                     },                     Field {                         kw_only: false,                         name: "batch_size",                         py_name: Py(                             0x00007f1ea52ccc70,                         ),                         init: true,                         init_only: false,                         lookup_key: Simple {                             key: "batch_size",                             py_key: Py(                                 0x00007f1dca90fd70,                             ),                             path: LookupPath(                                 [                                     S(                                         "batch_size",                                         Py(                                             0x00007f1dca90d8b0,                                         ),                                     ),                                 ],                             ),                         },                         validator: WithDefault(                             WithDefaultValidator {                                 default: Default(                                     Py(                                         0x00007f1ea9468350,                                     ),                                 ),                                 on_error: Raise,                                 validator: Int(                                     IntValidator {                                         strict: false,                                     },                                 ),                                 validate_default: false,                                 copy_default: false,                                 name: "default[int]",                                 undefined: Py(                                     0x00007f1ea71db950,                                 ),                             },                         ),                         frozen: false,                     },                     Field {                         kw_only: false,                         name: "randomize",                         py_name: Py(                             0x00007f1ea7047f30,                         ),                         init: true,                         init_only: false,                         lookup_key: Simple {                             key: "randomize",                             py_key: Py(                                 0x00007f1dca90d870,                             ),                             path: LookupPath(                                 [                                     S(                                         "randomize",                                         Py(                                             0x00007f1dcab99a70,                                         ),                                     ),                                 ],                             ),                         },                         validator: WithDefault(                             WithDefaultValidator {                                 default: Default(                                     Py(                                         0x000056185a4635a0,                                     ),                                 ),                                 on_error: Raise,                                 validator: Bool(                                     BoolValidator {                                         strict: false,                                     },                                 ),                                 validate_default: false,                                 copy_default: false,                                 name: "default[bool]",                                 undefined: Py(                                     0x00007f1ea71db950,                                 ),                             },                         ),                         frozen: false,                     },                     Field {                         kw_only: false,                         name: "sample_uniquely",                         py_name: Py(                             0x00007f1dcaa69ab0,                         ),                         init: true,                         init_only: false,                         lookup_key: Simple {                             key: "sample_uniquely",                             py_key: Py(                                 0x00007f1dcab99c70,                             ),                             path: LookupPath(                                 [                                     S(                                         "sample_uniquely",                                         Py(                                             0x00007f1dca9207f0,                                         ),                                     ),                                 ],                             ),                         },                         validator: WithDefault(                             WithDefaultValidator {                                 default: Default(                                     Py(                                         0x000056185a4635a0,                                     ),                                 ),                                 on_error: Raise,                                 validator: Bool(                                     BoolValidator {                                         strict: false,                                     },                                 ),                                 validate_default: false,                                 copy_default: false,                                 name: "default[bool]",                                 undefined: Py(                                     0x00007f1ea71db950,                                 ),                             },                         ),                         frozen: false,                     },                     Field {                         kw_only: false,                         name: "max_sequence_length",                         py_name: Py(                             0x00007f1de9b6d840,                         ),                         init: true,                         init_only: false,                         lookup_key: Simple {                             key: "max_sequence_length",                             py_key: Py(                                 0x00007f1dca917a50,                             ),                             path: LookupPath(                                 [                                     S(                                         "max_sequence_length",                                         Py(                                             0x00007f1dca917b40,                                         ),                                     ),                                 ],                             ),                         },                         validator: WithDefault(                             WithDefaultValidator {                                 default: Default(                                     Py(                                         0x00007f1ea946a0d0,                                     ),                                 ),                                 on_error: Raise,                                 validator: Int(                                     IntValidator {                                         strict: false,                                     },                                 ),                                 validate_default: false,                                 copy_default: false,                                 name: "default[int]",                                 undefined: Py(                                     0x00007f1ea71db950,                                 ),                             },                         ),                         frozen: false,                     },                 ],                 positional_count: 5,                 init_only_count: None,                 dataclass_name: "ReinventGenerator",                 validator_name: "dataclass-args[ReinventGenerator]",                 extra_behavior: Ignore,                 extras_validator: None,                 loc_by_alias: true,             },         ),         class: Py(             0x00005618679a86f0,         ),         fields: [             Py(                 0x00007f1ea52ed250,             ),             Py(                 0x00007f1ea52ccc70,             ),             Py(                 0x00007f1ea7047f30,             ),             Py(                 0x00007f1dcaa69ab0,             ),             Py(                 0x00007f1de9b6d840,             ),         ],         post_init: None,         revalidate: Never,         name: "ReinventGenerator",         frozen: false,         slots: true,     }, ), definitions=[], cache_strings=True)
__repr__()

Return repr(self).

__signature__ = <Signature (algorithm_version: str = 'v0', batch_size: int = 20, randomize: bool = True, sample_uniquely: bool = True, max_sequence_length: int = 256) -> None>
__wrapped__

alias of ReinventGenerator