cgexplore.systems_optimisation.ChromosomeGenerator¶
- class cgexplore.systems_optimisation.ChromosomeGenerator(present_beads, vdw_bond_cutoff, prefix, chromosome_map=<factory>, chromosome_types=<factory>, chromosomed_terms=<factory>, definer_dict=<factory>)[source]¶
Bases:
objectHold all information for chromosome iteration.
Methods
Add genes based on a forcefield dictionary.
Add a gene to the chromosome generator, to be iterated over.
Crossover chromosomes.
Deduplicate the list of chromosomes.
Get all chromosomes that have been defined.
Get chromosome indices associated with building block configs.
Return the number of chromosomes.
Get all nearest neighbours of provided chromosomes.
Get chromosome indices associated with precursors.
Get chromosome indices associated with terms.
Get chromosome indices associated with topology.
Get chromosome indices associated with vertex alignments.
Mutate chromosomes in the gene range only.
Get chromosome.
Select size instances from population.
Select chromosomes where only one gene is allowed to change.
Yield chromosomes.
Attributes
- Parameters:
- add_gene(iteration, gene_type)[source]¶
Add a gene to the chromosome generator, to be iterated over.
- crossover_population(chromosomes, generator, selection, num_to_select, database)[source]¶
Crossover chromosomes.
Available selections for which chromosomes to mutate:
- random:
uses generator.choice()
- roulette:
adds weight to generator.choice() based on fitness/sum(fitness)
- Parameters:
chromosomes (dict[str, Chromosome]) – Dictionary of chromosomes with keys corresponding to their keys in the provided database.
generator (Generator) – Random number generator.
selection (str) – How to select chromosomes to mutate (random or roulette).
num_to_select (int) – Number of chromosomes to mutate.
database (AtomliteDatabase) – atomlite database containing the chromosome data.
- Returns:
List of chromosomes to add to population.
- Return type:
- dedupe_population(list_of_chromosomes)[source]¶
Deduplicate the list of chromosomes.
- Parameters:
list_of_chromosomes (Sequence[Chromosome])
- Return type:
- define_chromosomes()[source]¶
Get all chromosomes that have been defined.
If the chromosome space is large, this can be super expensive!
- Return type:
None
- get_population_neighbours(chromosomes, gene_range, selection)[source]¶
Get all nearest neighbours of provided chromosomes.
Available selections for which chromosomes to mutate:
- all:
selects all chromosomes.
- Parameters:
- Returns:
List of chromosomes to add to population.
- Return type:
- mutate_population(chromosomes, generator, gene_range, selection, num_to_select, database)[source]¶
Mutate chromosomes in the gene range only.
Available selections for which chromosomes to mutate:
- random:
uses generator.choice()
- roulette:
adds weight to generator.choice() based on fitness/sum(fitness)
- Parameters:
chromosomes (dict[str, Chromosome]) – Dictionary of chromosomes with keys corresponding to their keys in the provided database.
generator (Generator) – Random number generator.
gene_range (Sequence[int]) – Range of genes, by their indices in the chromosome, to mutate.
selection (str) – How to select chromosomes to mutate (random or roulette).
num_to_select (int) – Number of chromosomes to mutate.
database (AtomliteDatabase) – atomlite database containing the chromosome data.
- Returns:
List of chromosomes to add to population.
- Return type:
- select_random_population(generator, size)[source]¶
Select size instances from population.
- Parameters:
generator (Generator)
size (int)
- Return type:
- select_similar_chromosome(chromosome, free_gene_id)[source]¶
Select chromosomes where only one gene is allowed to change.
- Parameters:
chromosome (Chromosome)
free_gene_id (int)
- Return type: