Population.py

This describe the population in the genetic algorithm

class Organisms.GA.Population.Population(name, size, user_initialised_population_folder=None, write_data=True)

This class stores all the clusters that are in the population.

Parameters:
  • name (str.) – Name of the Collection. This can be any name you like, it is just to note what the collection is. All collections should have a unique name if possible to prevent confusion, however this will not break the program.

  • size (int) – This is the number of clusters that should be in the collection. In this version of the Organisms program, the number of clusters in the population and made during Creation of Offspring should be consistant throughout the genetic algorithm process.

  • user_initialised_population_folder (str.) – Indicates the directory to obtain clusters to place in the initial population. If None, there are no user created clusters to obtained. Default: None.

  • write_data (bool.) – Write the clusters to disk in a database. Default: True.

backup_files()

Backup the database and the current state file

backup_state_file()

This method will make a backup of all the clusters in the Collection as a ASE database

current_state_file(generation_number)

Write the current state file for the population for this generation.

Parameters:

generation_number (int) – The curent generation.

get_current_generation_from_state_file()

This method is used to get the current generation from the Organisms program if it had already run previously. This method is used at the beginnning of the Organisms program to get the current generation if the Organisms program has been restarted.

Returns:

The current generation of the Organisms program if it has already run previously and is being restarted. The names of the clusters in the population at that generation.

get_data_from_current_state_file(current_state_file)

Get data about the current population from the state file on disk.

Parameters:

current_state_file (str.) – The path to the curent state file.

:returns the generation the state file was made, a list of the names of the clusters in the population, and a list of the energies of the clusters in the population. :rtype float, list of int, and list of float

get_details()

Debugging tool for the Population Class.

This definition is designed to print all the details about the population.

get_pool_folder_size(folder_to_look_at=False)

This definition will count the number of clusters in the population that the user places into the GA before it runs. It does this by counting the number of numbered folders (these in this program hold information about each cluster created during a GA Run). This method is only needed before the GA begins.

Inputs:

folder_to_look_at (False/None/str.): Indicate the number of clusters in the population as stored on the disk.

returns: len(clusters_in_population): The size of the population, measured by counting the number of folders named by a number (which this program will interpret as a cluster in the population). rtypes: int

move_backup_to_current_files()

This method reove the last state file if one exists, and replace it with the backup.

print_clusters()

Debugging tool for the Population Class.

This definition is designed to print all the details about the clusters in the population.

remove_backup_files()

Remove the backup the database and the current state file

remove_backup_state_file()

This method will remove the backup of all the clusters in the Collection, which will be in the format of a ASE database.

remove_backup_state_file_if_exists()

This method will remove the backup of all the clusters in the Collection, which will be in the format of a ASE database.

repair_current_state_file(generation_number, cluster_names, cluster_energies)

Write the current state file for the population for this generation. This method is used if the state file or a back up could not be found or were incomplete. This method will get the data from the information from the energyprofile.txt file

Parameters:
  • generation_number (int) – The current generation.

  • cluster_names (list of ints.) – The names of the clusters in the population.

  • cluster_energies (list of floats) – The energies of the clusters in the population.