Module contents:

navicatGA.base_solver module

Bases: object

Calculates the fitness of the population using the defined fitness function.

Parameters: :param population: population (array of chromosomes)

Returns: :return fitness: scalarized fitness of the current population, will be used :return pfitness: not-scalarized fitness of the current population, for printing

Function to check that the main arguments have been passed to the GenAlgSolver instance.

Parameters: :param fitness_function: a fitness function that takes a chromosome and returns a fitness :param selection_strategy: a selection strategy string that can be recognized by this class :param pop_size: the number of chromosomes :param excluded_genes: a sequence of genes that should not change or mutate

Closes the logger of this solver. This avoid multiple loggers stacking when another solver is created.

Creates an offspring from 2 parent chromosomes. It uses the crossover point(s) to determine how to perform the crossover. To be implemented on each child class. Must return the resulting offspring chromosome.

Calculates selection probabilities according to a fitness Boltzmann distribution with an increasing temperature.

Retrieves random crossover points.

Returns the number of mutations that need to be performed.

Calculates selection probabilities either randomly or scaled by position.

Initializes the population of the problem. To be implemented in each child class.

Select based on self.prob_intervals, which are given by the selection strategy.

Parameters: :param value: random value defining which individual is selected from the probability intervals

Returns: :return: the selected individual from the population

Mutates the population according to a given user defined rule. To be defined further in each child class. Each direct child class can call this super method to retrieve the mutation rows and mutations columns in population.

Plots the evolution of the mean and max fitness of the population using matplotlib.

Parameters: :param mean_fitness: mean fitness array for each generation :param max_fitness: max fitness array for each generation :param iterations: total number of generations

Prints the statistics of the optimization run.

Selects the parents according to a given selection strategy. Options are: roulette_wheel: Selects individuals from mating pool giving higher probabilities to fitter individuals. two_by_two: Pairs fittest individuals two by two random: Selects individuals from mating pool randomly. tournament: Selects individuals by choosing groups of 3 candidate individuals and then selecting the fittest one from the 3.

Parameters: :param fitness: the fitness values of the whole population at a given iteration

Returns: :return (ma, pa): a tuple containing the selected 2 parents for each mating

Performs the genetic algorithm optimization according to the parameters loaded in __init__. Will run for max_gen or until it converges for max_conv iterations, or for min(niter,max_gen) iterations if niter is an integer. Will start using previous state if available.

Parameters: :param niter: the number of generations to run

Sorts fitness, population and printable fitness according to fitness.

Performs tournament selection.

Parameters: :param fitness: the fitness values of the population at a given iteration :param range_max: range of individuals that can be selected for the tournament

Returns: :return: the selected individuals

Helper for tournament selection method. Selects the fittest individual from a pool of candidate individuals.

navicatGA.cache module

Calculates the fitness of the population using a hashable fitness function.

Parameters: :param population: population state at a given iteration :return: the fitness of the current population

Monkeypatches the calculate_fitness method of the base solver class in order to use a lru cache. If a specific wrapper exists for a given solver, it will try to use the unique expression of genes given by that wrapper to generate a hashable fitness function. If not, it will require a hashable fitness function given by the user AND expect the given fitness_function to generate a unique hash from a gene.

navicatGA.chemistry_selfies module

Check if a list of selfies characters leads to a valid smiles string. Uses sanitize_smiles to check the smiles string from selfies.decoder.

Parameters: :param chromosome: list of selfie characters

Returns: :return: True if the smiles string is deemed valid by sanitize_smiles, False otherwise

Count the number of selfie characters in a selfie string. Returns the number.

Decode a list of smiles to a list of selfies using timed_decoder.

Tries to identify and print to logger whatever was or is wrong with the chemistry_selfies of an rdkit.mol object.

Encode a list of smiles to a list of selfies using selfies.encoder.

Obtain an ordered list of all selfie characters in string selfie padded to maxchars with [nop]s.

Parameters: :param selfie: a selfie string representing a molecule :param maxchars: maximum number of elements in the list

Returns: :return chars_selfie: list of selfie characters present in molecule selfie

Generates a reasonable set of 3D structures using forcefields for a given rdkit.mol object. It will try several 3D generation approaches in rdkit. It will try to sample several conformations and get the minima.

Parameters: :type mol: a rdkit.mol object :type n_confs: the number of conformations to sample

Returns: :return mol_structure: the same rdkit mol with 3D coordinates

Returns True if the rdkit.mol object passed as argument has a (transition)-metal atom, False if else.

Returns True if the rdkit.Atom object passed as argument is a transition metal, False if else.

Calls sanitize_smiles for every item in a list.

Parameters: :param smiles_list list of smiles strings to be sanitized

Returns: :return sanitized_smiles: list of sanitized smile strings with None in errors

Return a canonical smile representation of smi. If there are metals, it will try to fix the bonds as dative.

Parameters: :param smi: smiles string to be sanitized :type smi: smiles string

Returns: :return mol: corresponding rdkit.mol object, None if exception caught :return smi_canon: canonicalized smile representation of smi, None if exception caught :return conversion_successful: True if no exception caught, False if exception caught

Tries to replace bonds with metal atoms by dative bonds, while keeping valence rules enforced. Adapted from G. Landrum.

Decode a selfies string to smiles using selfies.decoder, call exception and return None if decoder takes more than 10 seconds to run.

Convert smiles string to rdkit.mol, call exception and return None if it takes more than 10 seconds to run.

navicatGA.chemistry_smiles module

Tries to identify and print to logger whatever was or is wrong with the chemistry_selfies of an rdkit.mol object.

Generates a reasonable set of 3D structures using forcefields for a given rdkit.mol object. It will try several 3D generation approaches in rdkit. It will try to sample several conformations and get the minima.

Parameters: :param mol: an rdkit mol object :type mol: rdkit.mol :param n_confs: number of conformations to sample :type n_confs: int

Returns: :return mol_structure: mol with 3D coordinate information set

Returns True if the rdkit.mol object passed as argument has a (transition)-metal atom, False if else.

Returns True if the rdkit.Atom object passed as argument is a transition metal, False if else.

Calls sanitize_smiles for every item in a list.

Parameters: :param smiles_list: list of smile strings to be sanitized.

Returns: :return sanitized_smiles: list of sanitized smile strings or None in case a smiles led to error

Return a canonical smile representation of smi. If there are metals, it will try to fix the bonds as dative.

Parameters: :param smi: smile string to be canonicalized :type smi: str

Returns: :return mol: rdkit mol object, None if exception caught :return smi_canon: canonicalized smile representation of smi, None if exception caught. :return conversion_successful: True if no exception caught, False if exception caught.

Tries to replace bonds with metal atoms by dative bonds, while keeping valence rules enforced. Adapted from G. Landrum.

Convert smiles string to rdkit.mol, call exception and return None if it takes more than 10 seconds to run.

navicatGA.chemistry_xyz module

Bases: AaronTools.geometry.Geometry

This is a modified version of the Geometry class in AaronTools.py, which is identical but hashable.

Check if a list of Geometries can lead to a valid structure.

Pads chromosome with empty elements.

Default chromosome manipulator: randomly generates an XYZ structure from fragments.

navicatGA.exception_messages module

navicatGA.exceptions module

Bases: Exception

Bases: Exception

Bases: Exception

navicatGA.fitness_functions_float module

navicatGA.helpers module

Default chromosome manipulator: concatenates all elements of a list.

Default chromosome manipulator: turns list into array.

navicatGA.logger module

Adds a new logging level to the logging module and the currently configured logging class.

navicatGA.progress_bars module

Performs the genetic algorithm optimization according to the parameters loaded in __init__. Will run for max_gen or until it converges for max_conv iterations, or for min(niter,max_gen) iterations if niter is an integer. Will start using previous state if available.

Parameters: :param niter: the number of generations to run

navicatGA.score_modifiers module

navicatGA.selfies_solver module

Bases: navicatGA.base_solver.GenAlgSolver

Pad or truncate starting_population chromosome to build a population chromosome.

Creates an offspring from 2 parents.

Retrieves random crossover points :return: a numpy array with the crossover points

Initializes the population of the problem according to the population size and number of genes and according to the problem type (either integers or floats).

Returns: :return: a numpy array with initialized population

Mutates the population by randomizing specific positions of the population individuals. :param population: the population at a given iteration :param n_mutations: number of mutations to be performed. :return: the mutated population

Print xyz for all the population at the current state.

navicatGA.smiles_solver module

Bases: navicatGA.base_solver.GenAlgSolver

Pad or truncate starting_population chromosome to build a population chromosome.

Creates an offspring from 2 parents.

Retrieves random crossover points :return: a numpy array with the crossover points

Initializes the population of the problem according to the population size and number of genes and according to the problem type (either integers or floats).

Returns: :return: a numpy array with initialized population

Mutates the population by randomizing specific positions of the population individuals. :param population: the population at a given iteration :param n_mutations: number of mutations to be performed. :return: the mutated population

Print xyz for all the population at the current state.

navicatGA.timeout module

Bases: object

navicatGA.wrappers_selfies module

Generate 2D and 3D depictions from an rdkit.mol object with 3D coordinates.

Generate 2D and 3D depictions from a list of selfies characters.

Generates a rdkit.mol object with 3D coordinates from a list of selfies characters.

Generate a selfies string from a list of selfies characters.

Generate a canonical smiles string from a list of selfies characters.

navicatGA.wrappers_smiles module

Checks if a chromosome corresponds to a proper SMILES.

Wrapper function for simplicity.

Generate 2D and 3D depictions from an rdkit.mol object with 3D coordinates.

Generate 2D and 3D depictions from a chromosome.

Generates a rdkit.mol object with 3D coordinates from a list of selfies characters.

Generate a SMILES string from a list of SMILES characters. To be customized.

Generates a rdkit.mol object with 3D coordinates from a SMILES.

navicatGA.wrappers_xyz module

Bases: AaronTools.geometry.Geometry

This is a modified version of the Geometry class in AaronTools.py, which is identical but hashable.

Wrapper function for simplicity.

Check if a chromosome (list of geometries) can lead to a valid structure.

navicatGA.xyz_solver module

Bases: navicatGA.base_solver.GenAlgSolver

Pad or truncate starting_population chromosome to build a population chromosome.

Creates an offspring from 2 parents.

Retrieves random crossover points :return: a numpy array with the crossover points

Initializes the population of the problem according to the population size and number of genes and according to the problem type (XYZ fragments here). :return: a numpy array with a sanitized initialized population

Mutates the population by randomizing specific positions of the population individuals. :param population: the population at a given iteration :param n_mutations: number of mutations to be performed. :return: the mutated population

Print xyz for all the population at the current state.


Indices and tables