navicatGA.selfies_solver¶
Attributes¶
Classes¶
Shared base for solvers whose chromosome genes are drawn from a |
Module Contents¶
- class navicatGA.selfies_solver.SelfiesGenAlgSolver(starting_selfies: list = ['[nop]'], starting_random: bool = False, starting_stoned: bool = False, alphabet_list: list = list(get_semantic_robust_alphabet()), chromosome_to_selfies=concatenate_list(), multi_alphabet: bool = False, equivalences: Sequence = None, branching: bool = False, variables_limits: bool = False, max_counter: int = 10, n_genes: int = 1, fitness_function=None, excluded_genes: Sequence = None, **base_kwargs)¶
Bases:
navicatGA.alphabet_solver.AlphabetGenAlgSolverShared base for solvers whose chromosome genes are drawn from a per-gene alphabet (SMILES fragments, SELFIES tokens, XYZ fragments).
Factors out the alphabet/equivalences setup, population init/refill, crossover-point sampling, and mutation logic that SmilesGenAlgSolver/SelfiesGenAlgSolver/XYZGenAlgSolver used to each reimplement independently. Subclasses still own create_offspring (crossover behaviour genuinely differs between them) and write_population (different depiction backend per representation).
Example child solver class for the GA. This child solver class is an example meant for a particular purpose, which also shows how to use the GA with SELFIES as a core molecular representation. It might require heavy modification for other particular usages. Only the parameters specific for this child class are covered here.
Parameters: :param starting_selfies: list containing the starting SELFIES elements for all chromosomes; overridden by starting_random=True :type starting_selfies: list :param starting_random: whether to initialize all chromosomes with random elements from alphabet; overrides starting_selfies :type starting_random: bool :param starting_stoned: whether to use the STONED methodology to generate a chemical subspace from starting_selfies; incompatible with starting_random :type starting_stoned: bool :param alphabet_list: list containing the alphabets for the individual genes; or a single alphabet for all :type alphabet_list: list :param chromosome_to_selfies: object that can take a chromosome and generate a selfies string :type chromosome_to_selfies: object :param multi_alphabet: whether alphabet_list contains a single alphabet or a list of n_genes alphabet :type multi_alphabet: bool :param equivalences: list of integers that set the equivalent genes of a chromosome; see examples for clarification :type equivalences: list :param branching: whether to add random branches covering all possible branching possibilities to the alphabets :type branching: bool :param variable_limits: will set semantic constraints on alphabets if set True :type variable_limits: bool :param max_counter: maximum number of times a wrong structure will try to be corrected before skipping :type max_counter: int :param base_kwargs: any GenAlgSolver parameter (max_gen, pop_size, mutation_rate, …); see GenAlgSolver for the full list and defaults
- chromosomize(str_list)¶
Pad or truncate starting_population chromosome to build a population chromosome.
Extends AlphabetGenAlgSolver.chromosomize with the ability to split a raw SELFIES string (rather than a pre-tokenized list) into genes.
- create_offspring(first_parent, sec_parent, crossover_pt, offspring_number)¶
Creates an offspring from 2 parents.
- write_population(basename='chromosome')¶
Print xyz for all the population at the current state.
- max_counter = 10¶
- starting_random = False¶
- navicatGA.selfies_solver.logger¶