Skip to content

Commit

Permalink
Tidying set_up_calculation code.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjmorgan committed Jul 4, 2021
1 parent 99e97fb commit ca27ba6
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions pyscses/set_up_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
from bisect import bisect_left, bisect_right
from sklearn.cluster import AgglomerativeClustering # type: ignore

def site_from_input_file( site, defect_species, site_charge, core, temperature ):
def site_from_input_file(site,
defect_species,
site_charge,
core,
temperature):
"""
Takes the data from the input file and converts it into a site.
The input data file is a .txt file where each line in the file corresponds to a site. The values in each line are formatted and separated into the corresponding properties before creating a Site object for each site.
The input data file is a .txt file where each line in the file corresponds to a site. The values in each line are formatted and separated into the corresponding properties before creating a Site object for each site.
Args:
site (str): A line in the input file.
Expand Down Expand Up @@ -40,16 +44,18 @@ def site_from_input_file( site, defect_species, site_charge, core, temperature )
#defect_energies = [ 0.0 for e in site[4::2] ]
return Site( label, x, [ defect_species[l] for l in defect_labels ], defect_energies, valence=valence )

def format_line( line, site_charge, offset = 0.0 ):
def format_line(line,
site_charge,
offset = 0.0):
"""
Each line in the input file is formatted into separate site properties.
Each line in the input file is formatted into separate site properties.
Args:
line (str): A line in the input file.
site_charge (bool): The site charge refers to the contribution to the overall charge of a site given by the original, non-defective species present at that site. True if the site charge contribution is to be included in the calculation, False if it is not to be included.
Returns:
list: line from the input file, split into individual values.
Returns:
list: line from the input file, split into individual values.
"""
# x coordinate
Expand All @@ -69,16 +75,20 @@ def format_line( line, site_charge, offset = 0.0 ):
# line[i] = 0.0
return line

def load_site_data( filename, x_min, x_max, site_charge, offset = 0.0 ):
def load_site_data(filename,
x_min,
x_max,
site_charge,
offset = 0.0):
"""
Reads in the input data and formats the input data if the x coordinate values are within the calculation region.
Args:
filename(string): Filename for importing the input data.
x_min(float): Minimum x coordinate value defining the calculation region.
x_max(float): Maximum x coordinate value defining the calculation region.
x_max(float): Maximum x coordinate value defining the calculation region.
site_charge (bool): True if site charges are to be included in the calculation, false if they are not to be included.
Return:
list: formatted data for calculation.
Expand All @@ -93,15 +103,15 @@ def load_site_data( filename, x_min, x_max, site_charge, offset = 0.0 ):

return input_data

def cluster_similar_sites( input_data ):
def cluster_similar_sites(input_data):
"""Clusters data points the input data to be projected onto a site. Clustering criterion is set as 0.01 nm.
Args:
input_data (str): The input file.
Returns:
str: The input file, formatted with x coordinate values with correct clustering coordinates.
"""
coordinates = np.array([[ion[2]] for ion in input_data]) # format data into correct format
# Use sklearn's clustering functionality to assign site clusters
Expand All @@ -121,14 +131,17 @@ def cluster_similar_sites( input_data ):
sites_format += cluster
return sites_format

def calculate_grid_offsets( filename, x_min, x_max, system ):
def calculate_grid_offsets(filename,
x_min,
x_max,
system):
"""Reads in the input data calculates the distance to the next site outside of the defined calculation region. Allows calculation of the delta_x and volume values for the endmost grid points.
Args:
filename(string): Filename for importing the input data.
x_min(float): Minimum x coordinate value defining the calculation region.
x_max(float): Maximum x coordinate value defining the calculation region.
system(str): 'single' for single grain boundary systems, 'double' for systems where the input data has been mirrored to give two grain boundaries.
x_max(float): Maximum x coordinate value defining the calculation region.
system(str): 'single' for single grain boundary systems, 'double' for systems where the input data has been mirrored to give two grain boundaries.
Returns:
list, list: distance between the midpoint of the endmost sites and the midpoint of the next site outside of the calculation region for the first and last sites respectively. Distance between the endmost sites and the next site outside of the calculation region for the first and last sites respectively.
Expand Down

0 comments on commit ca27ba6

Please sign in to comment.