opt.single_objective.comb.drug_discovery_problem package

Submodules

opt.single_objective.comb.drug_discovery_problem.drug_discovery_problem module

class opt.single_objective.comb.drug_discovery_problem.drug_discovery_problem.DrugDiscoveryProblem(name: str = 'DrugDiscoveryProblem', is_minimization: bool = False, is_multi_objective: bool = False)

Bases: Problem

Class representing the Drug Discovery Problem.

This class inherits from the Problem class and is used to define and solve the Drug Discovery Problem. The problem is defined by a graph and a list of source terminal pairs.

name

Name of the problem.

Type:

str

is_minimization

Whether the problem is a minimization problem.

Type:

bool

is_multi_objective

Whether the problem has multiple objectives.

Type:

bool

__molecules

List of Individuals loaded from file, representing available candidate molecules.

Type:

list[Individual]

__init__(name

str = “DrugDiscoveryProblem”, is_minimization: bool = False, is_multi_objective: bool = False): Initializes a new instance of DrugDiscoveryProblem.

__load_from_file__(file_path

str) -> list[Individual]: Internal method that loads molecule data from a JSON file and returns a list of Individuals.

from_input_file(file_path

str) -> DrugDiscoveryProblem: Class method that loads molecules from file and returns a new DrugDiscoveryProblem instance with initial molecules.

get_random_individual() Individual

Returns a randomly selected Individual from the list of initial molecules.

copy() DrugDiscoveryProblem

Returns a copy of the current DrugDiscoveryProblem instance.

__str__() str

String representation of the DrugDiscoveryProblem instance.

__repr__() str

Official representation of the DrugDiscoveryProblem instance.

__format__(spec

str) -> str: Formatted representation of the DrugDiscoveryProblem instance.

copy() DrugDiscoveryProblem

Copy the current object

Returns:

new instance with the same properties

Return type:

DrugDiscoveryProblem

classmethod from_input_file(file_path: str) DrugDiscoveryProblem

Additional constructor. Creates a DrugDiscoveryProblem instance from a JSON file.

Parameters:

file_path – path to the JSON file with molecule data

Returns:

initialized DrugDiscoveryProblem instance

get_random_individual() Individual

Returns a randomly selected Individual from the loaded list of molecules.

Returns:

randomly selected Individual

Return type:

Individual

property molecules: list[Individual]

Getter for the list of loaded molecules.

Returns:

List of Individual instances

Return type:

list[Individual]

opt.single_objective.comb.drug_discovery_problem.fitness module

class opt.single_objective.comb.drug_discovery_problem.fitness.Fitness(molecule: Mol, weights: tuple[float, ...] = (0.66, 0.46, 0.05, 0.61, 0.06, 0.65, 0.48, 0.95))

Bases: object

A class used to compute the QED fitness score for a given RDKit molecule.

molecule

RDKit molecule object.

Type:

Mol

weights

Optional weights used in the QED calculation.

Type:

tuple[float]

qed() float

Compute the QED (Quantitative Estimate of Drug-likeness) for the molecule.

Returns:

QED value.

Return type:

float

opt.single_objective.comb.drug_discovery_problem.ga_parameters module

class opt.single_objective.comb.drug_discovery_problem.ga_parameters.GAParameters(application: QApplication)

Bases: object

Widget component for configuring Genetic Algorithm (GA) parameters.

Parameters:

application (QApplication) – Main application instance to interact with GA controls.

get_GA_parameters_widget() QWidget

Returns the main widget containing all GA parameter controls.

Returns:

QWidget with all GA parameter inputs

Return type:

QWidget

on_launch_button_clicked() None

Handles the event when the user clicks the ‘Launch’ button to start the genetic algorithm.

This method performs the following: 1. Retrieves the selected configuration parameters from the GUI. 2. Initializes and runs the genetic algorithm using the solver module. 3. Loads and displays the newly generated population of molecules. 4. Updates the GUI state to reflect that the optimization process has started: - Enables buttons and labels for further interaction. - Sets the progress and generation counter. - Prepares the next generation environment.

Raises:

ValueError – If input parameters are missing or invalid.

on_roulette_changed(state: int) None

Callback function triggered when the roulette checkbox is toggled.

Enables or disables the tournament size input field based on selection mode.

Parameters:

state (int) – The new state of the checkbox (Qt.Checked or Qt.Unchecked)

Return type:

None

opt.single_objective.comb.drug_discovery_problem.hyper_parameters module

class opt.single_objective.comb.drug_discovery_problem.hyper_parameters.HyperParameters(application: QApplication)

Bases: object

GUI widget for adjusting hyperparameter weights via sliders.

Parameters:

application – Reference to the main QApplication object

get_sliders_widget() QWidget

Returns the QWidget containing the full layout for sliders.

Returns:

The widget containing sliders and labels

Return type:

QWidget

on_reset_button_clicked() None

Resets all sliders to their default values and updates the display.

update_param_label(idx: int) None

Updates the label for a hyperparameter based on the slider value. Also triggers updates of molecule boxes based on new weights.

Parameters:

index (int) – Index of the slider and label to update

opt.single_objective.comb.drug_discovery_problem.individual module

class opt.single_objective.comb.drug_discovery_problem.individual.Individual(smiles: str, description: str, weights: Tuple[float, ...] = (0.66, 0.46, 0.05, 0.61, 0.06, 0.65, 0.48, 0.95))

Bases: object

Represents a molecular individual characterized by its SMILES string, weights for property importance, and computed QED fitness value.

get_description() str

Returns the description of the molecule.

get_qed() float

Returns the QED fitness value.

get_smiles() str

Returns the SMILES string of the molecule.

get_weights() Tuple[float, ...]

Returns the weights used for fitness evaluation.

is_valid_smiles() bool

Checks whether the current SMILES string can be parsed into a valid molecule.

Returns:

True if valid, False otherwise

Return type:

bool

set_description(description: str) None

Updates the description of the molecule.

Parameters:

description – New description string

set_smiles(smiles: str) None

Updates the SMILES string.

Parameters:

smiles – New SMILES representation

set_weights(weights: Tuple[float, ...]) None

Updates the weights and recalculates fitness.

Parameters:

weights – New weights for fitness evaluation

opt.single_objective.comb.drug_discovery_problem.insert_molecule module

class opt.single_objective.comb.drug_discovery_problem.insert_molecule.NewMoleculeForm(application: QApplication)

Bases: object

GUI component for adding a custom molecule via SMILES input and description.

get_form() QWidget

Returns the QWidget container holding the form.

Returns:

QWidget with the input layout

Return type:

QWidget

get_input_description_text() str

Returns the current text from the molecule description input field.

Returns:

Description string entered by the user

Return type:

str

get_input_smiles_text() str

Returns the current text from the SMILES input field.

Returns:

SMILES string entered by the user

Return type:

str

opt.single_objective.comb.drug_discovery_problem.molecule_boxes module

class opt.single_objective.comb.drug_discovery_problem.molecule_boxes.ClickableGroupBox(molecule_boxes: QWidget, index: int, role: int, parent: QWidget | None = None)

Bases: QGroupBox

A custom QGroupBox that represents a clickable molecule box for selection and deselection between available and selected molecules.

enterEvent(event: QEvent) None

Highlights the SMILES label when mouse hovers over the box (if not blocked).

Parameters:

event – Enter event object.

leaveEvent(event: QEvent) None

Resets the SMILES label style when mouse leaves the box (if not blocked).

Parameters:

event – Leave event object.

mousePressEvent(event: QEvent) None

Handles the logic of moving a molecule from one list to the other on left-click.

If the application is not currently blocking transfer, and the role is valid (0 or 1), the molecule is moved to the opposite list.

Parameters:

event – Mouse event object.

class opt.single_objective.comb.drug_discovery_problem.molecule_boxes.MoleculeBoxes(application: QApplication)

Bases: QWidget

A widget that displays molecule representations in scrollable boxes, and allows user to select molecules for the first generation of the genetic algorithm.

add_to_catalogue(smiles: str, description: str | None) None

Add a new molecule to the catalogue and save it to the JSON file.

calculate_average_qed() None

Calculate the average QED coefficient for the current new generation of molecules and append the result with a timestamp to a file.

create_molecule_box(smiles: str, description: str, qed: float, index: int, ind: int) ClickableGroupBox

Create a styled box widget representing a molecule with its image and properties.

get_best() QWidget

Get the widget displaying the current best molecule.

Returns:

Widget showing the best molecule of the current generation.

Return type:

QWidget

get_precedent_scroll_area() QWidget

Get the widget displaying selected molecules.

Returns:

Widget containing precedent scroll area.

Return type:

QWidget

get_second_scroll_area() QWidget

Get the widget displaying new generation molecules.

Returns:

Widget containing scroll area for subsequent generation.

Return type:

QWidget

get_selection_widget() QWidget

Get the widget that contains the molecule selection interface.

Returns:

Widget with selectable molecule grid.

Return type:

QWidget

load_boxes(weights: tuple[float, ...] = (0.66, 0.46, 0.05, 0.61, 0.06, 0.65, 0.48, 0.95)) None

Load unselected molecule boxes into the main grid layout.

Parameters:

weights – Weights used to compute the QED score for each molecule.

load_new_generation(weights: tuple[float, ...] = (0.66, 0.46, 0.05, 0.61, 0.06, 0.65, 0.48, 0.95)) None

Load boxes for the newly generated molecules.

Also updates the current best molecule display.

Parameters:

weights – Weights used to compute the QED score for each new generation molecule.

load_selected_boxes(weights: tuple[float, ...] = (0.66, 0.46, 0.05, 0.61, 0.06, 0.65, 0.48, 0.95)) None

Load selected molecules into their display area.

Parameters:

weights – Weights used to compute the QED score for each selected molecule.

on_final_button_clicked() None

Complete the full number of generations using the ‘Generate’ button logic.

on_generate_button_clicked() None

Generate a new generation using selected molecules and update all related UI elements.

on_restart_button_clicked() None

Reset the entire optimization process to the initial state. This method is typically called when the ‘Restart’ button is clicked. It clears molecule displays, resets all controls and progress indicators, and prepares the interface for a fresh run.

on_save_button_clicked() None

Save the best candidate molecule to a file and prompt user for additional statistics.

on_select_all_button_clicked() None

Move all molecules from the current list to the selected list and refresh the display.

remove_boxes() None

Remove all unselected molecule boxes from the layout.

remove_new_generation_boxes() None

Remove all new generation molecule boxes.

remove_selected_boxes() None

Remove all selected molecule boxes.

tanimoto() None

Calculate pairwise Tanimoto similarity coefficients between molecules in the current new generation and save the results to a file.

opt.single_objective.comb.drug_discovery_problem.mutation_info module

class opt.single_objective.comb.drug_discovery_problem.mutation_info.MutationInfo

Bases: object

Loads mutation rules for atoms, groups, and insertions from predefined text files.

These rules are later used by the genetic algorithm for mutating molecular structures.

opt.single_objective.comb.drug_discovery_problem.solver module

opt.single_objective.comb.drug_discovery_problem.solver.atom_switch_mutation(individual: Individual, mi: MutationInfo) None

Perform atom switch mutation.

Parameters:
  • individual – The individual to mutate

  • mi – MutationInfo with atom switch map

Return type:

None

opt.single_objective.comb.drug_discovery_problem.solver.crossover(parent1: Individual, parent2: Individual, child1: Individual, child2: Individual) None

Perform crossover on two parent individuals to generate two child individuals.

Parameters:
  • parent1 – First parent individual

  • parent2 – Second parent individual

  • child1 – First child individual (result)

  • child2 – Second child individual (result)

Return type:

None

opt.single_objective.comb.drug_discovery_problem.solver.deletion_mutation(individual: Individual, mi: MutationInfo) None

Perform deletion mutation.

Parameters:
  • individual – The individual to mutate

  • mi – MutationInfo (not used but included for consistency)

Return type:

None

opt.single_objective.comb.drug_discovery_problem.solver.genetic_algorithm(population: List[Individual], only_one_generation: bool, number_of_generations: int, roulette_selection: bool, tournament_size: int, elitism_size: int, mutation_probability: float, mi: MutationInfo, individual_label: QLabel, individual_progress: QProgressBar) List[Individual]

Genetic algorithm for molecule evolution.

Parameters:
  • population – Initial population of individuals

  • only_one_generation – If True, run only one generation regardless of number_of_generations

  • number_of_generations – Total number of generations to evolve

  • roulette_selection – Whether to use roulette wheel selection or tournament selection

  • tournament_size – Size of the tournament if tournament selection is used

  • elitism_size – Number of elite individuals preserved between generations

  • mutation_probability – Probability of mutation

  • mi – Mutation information structure

  • individual_label – Label object for GUI update

  • individual_progress – Progress bar object for GUI update

Returns:

Evolved population after all generations

Return type:

List[Individual]

opt.single_objective.comb.drug_discovery_problem.solver.group_switch_mutation(individual: Individual, mi: MutationInfo) None

Perform group switch mutation.

Parameters:
  • individual – The individual to mutate

  • mi – MutationInfo with group switch map

Return type:

None

opt.single_objective.comb.drug_discovery_problem.solver.insertion_mutation(individual: Individual, mi: MutationInfo) None

Perform insertion mutation.

Parameters:
  • individual – The individual to mutate

  • mi – MutationInfo with list of insertions

Return type:

None

opt.single_objective.comb.drug_discovery_problem.solver.is_valid_smiles(smiles: str) bool

Validate SMILES string.

Parameters:

smiles – SMILES string

Returns:

True if valid, False otherwise

Return type:

bool

opt.single_objective.comb.drug_discovery_problem.solver.mutation(individual: Individual, mutation_probability: float, mi: MutationInfo) None

Mutate an individual with a given mutation probability.

Parameters:
  • individual – The individual to mutate

  • mutation_probability – Probability of mutation

  • mi – MutationInfo object with mutation rules

Return type:

None

opt.single_objective.comb.drug_discovery_problem.solver.roulette_wheel_selection(population: List[Individual]) Individual

Roulette wheel selection based on QED.

Parameters:

population – Population to select from

Returns:

Selected individual

Return type:

Individual

opt.single_objective.comb.drug_discovery_problem.solver.selection(population: List[Individual], roulette_selection: bool, tournament_size: int) Individual

Select an individual from the population.

Parameters:
  • population – Current population

  • roulette_selection – Whether to use roulette selection

  • tournament_size – Tournament size if using tournament selection

Returns:

Selected individual

Return type:

Individual

opt.single_objective.comb.drug_discovery_problem.solver.suppress_rdkit_warnings() Generator[None, None, None]

Context manager to suppress RDKit warnings/errors.

opt.single_objective.comb.drug_discovery_problem.solver.tournament_selection(population: List[Individual], tournament_size: int) Individual

Tournament selection based on QED.

Parameters:
  • population – Population to select from

  • tournament_size – Number of individuals in tournament

Returns:

Best individual from tournament

Return type:

Individual

Module contents