Skip to content

Commit

Permalink
More edits
Browse files Browse the repository at this point in the history
  • Loading branch information
bjmorgan committed Jul 4, 2021
1 parent 42f75c7 commit 2d184fe
Show file tree
Hide file tree
Showing 18 changed files with 200 additions and 149 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ docs/.DS_Store
**/.ipynb_checkpoints
docs/build
**/generated_outputs
.nova
152 changes: 86 additions & 66 deletions pyscses/calculation.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyscses/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ def subgrid( self, subset_species ):
@classmethod
def grid_from_set_of_sites( cls, set_of_sites, limits, limits_for_laplacian, b, c ):
"""
Creates a grid from a given Set_of_Sites object.
Creates a grid from a given SetOfSites object.
Args:
set_of_sites (object): Set_of_Sites object containing a set of all Site objects.
set_of_sites (object): SetOfSites object containing a set of all Site objects.
limits (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.
limits_for_laplacian (list): distance between the endmost sites and the next site outside of the calculation region for the first and last sites respectively.
b (float): b dimension for every grid-point.
Expand Down
24 changes: 12 additions & 12 deletions pyscses/set_of_sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
from pyscses.constants import boltzmann_eV
from bisect import bisect_left

class Set_of_Sites:
"""The Set_of_Sites object groups together all of the Site objects into one object and contains functions for the calculations that provide properties of all of the sites together rather than individually. """
class SetOfSites:
"""The SetOfSites object groups together all of the Site objects into one object and contains functions for the calculations that provide properties of all of the sites together rather than individually. """
def __init__( self, sites ):
self.sites = sites

def __add__( self, other ):
""" Allows the concatenation of multiple Set_of_Sites objects"""
if type( other ) is not Set_of_Sites:
""" Allows the concatenation of multiple SetOfSites objects"""
if type( other ) is not SetOfSites:
raise TypeError
return Set_of_Sites( self.sites + other.sites )
return SetOfSites( self.sites + other.sites )

def __getitem__( self, index ):
""" Returns the site corresponding to a given index """
Expand Down Expand Up @@ -131,10 +131,10 @@ def subgrid_calculate_defect_density( self, sub_grid, full_grid, phi, temp ):
def form_continuum_sites( all_sites, x_min, x_max, n_points, b, c, defect_species, limits_for_laplacian, site_labels, defect_labels ):

"""
Creates a Set_of_Sites object for sites interpolated onto a regular grid, this is equivalent to assuming a continuum approximation.
Creates a SetOfSites object for sites interpolated onto a regular grid, this is equivalent to assuming a continuum approximation.
Args:
all_sites (object): Orginal Set_of_Sites object from full data.
all_sites (object): Orginal SetOfSites object from full data.
x_min (float): Minimum x coordinate value defining the calculation region.
x_max (float): Maximum x coordinate value defining the calculation region.
n_points (int): Number of points that the data should be interpolated on to.
Expand All @@ -146,7 +146,7 @@ def form_continuum_sites( all_sites, x_min, x_max, n_points, b, c, defect_specie
defect_labels (list): List of strings for the different defect species.
Returns:
:obj:`Set_of_Sites`: Sites interpolated onto a regular grid.
:obj:`SetOfSites`: Sites interpolated onto a regular grid.
"""

Expand All @@ -160,12 +160,12 @@ def form_continuum_sites( all_sites, x_min, x_max, n_points, b, c, defect_specie
new_energies = griddata( ( [ site.x for site in all_sites.subset( label ) ] ), average_energies, grid, method = 'nearest' )
for x, e in zip( grid, new_energies):
sites.append( Site( label, x, [ defect_species[ d_label ] ], [e], scaling = np.array( scaling ) ) )
return Set_of_Sites( sites ), limits
return SetOfSites( sites ), limits

@ classmethod
def set_of_sites_from_input_data( cls, input_data, limits, defect_species, site_charge, core, temperature, offset=0.0 ):
"""
Takes the data from the input file and creates a Set_of_Sites object for those sites.
Takes the data from the input file and creates a SetOfSites object for those sites.
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:
Expand All @@ -177,7 +177,7 @@ def set_of_sites_from_input_data( cls, input_data, limits, defect_species, site_
temperature (float): Temperature that the calculation is being run at.
Returns:
:obj:`Set_of_Sites`: `Set_of_Sites` object for the input data.
:obj:`SetOfSites`: `SetOfSites` object for the input data.
"""
site_data = load_site_data( input_data, limits[0], limits[1], site_charge, offset )
Expand All @@ -191,7 +191,7 @@ def set_of_sites_from_input_data( cls, input_data, limits, defect_species, site_
for line in site_data:
if ( -boltzmann_eV * temperature) <= line[4] <= ( boltzmann_eV * temperature ):
line[4] = 0.0
return Set_of_Sites( [ site_from_input_file( line, defect_species, site_charge, core, temperature ) for line in site_data ] )
return SetOfSites( [ site_from_input_file( line, defect_species, site_charge, core, temperature ) for line in site_data ] )

@ classmethod
def core_width_analysis( cls, input_data, limits, defect_species, site_charge, core, temperature ):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_grid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
from pyscses.grid import Grid, Grid_Point, delta_x_from_grid
from pyscses.set_of_sites import Set_of_Sites
from pyscses.set_of_sites import SetOfSites
from pyscses.site import Site
from pyscses.defect_species import DefectSpecies
from unittest.mock import Mock, MagicMock, patch, call
Expand All @@ -22,7 +22,7 @@ def test_grid_instance_is_initialised( self, mock_Grid_Point, mock_index ):
c = 0.1
limits = [ 1.0, 1.0 ]
limits_for_laplacian = [1.0, 1.0]
set_of_sites = MagicMock( spec=Set_of_Sites )
set_of_sites = MagicMock( spec=SetOfSites )
sites = [ Mock( spec=Site ), Mock( spec=Site ) ]
sites[0].x = 1.0
sites[1].x = 3.0
Expand Down
72 changes: 51 additions & 21 deletions tests/test_notebooks/test_1/test_notebook_1.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions tests/test_notebooks/test_2/test_notebook_2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"outputs": [],
"source": [
"from pyscses.defect_species import DefectSpecies\n",
"from pyscses.set_of_sites import Set_of_Sites\n",
"from pyscses.set_of_sites import SetOfSites\n",
"from pyscses.constants import boltzmann_eV\n",
"from pyscses.calculation import Calculation, calculate_activation_energies\n",
"from pyscses.set_up_calculation import calculate_grid_offsets\n",
Expand Down Expand Up @@ -126,9 +126,9 @@
" \n",
" defect_species = { l : DefectSpecies( l, v, m, mob ) for l, v, m, mob in zip( defect_labels, valence, m, mobilities ) }\n",
"\n",
" all_sites = Set_of_Sites.set_of_sites_from_input_data( data, [grid_x_min, grid_x_max], defect_species, site_charges, core_models, t )\n",
" all_sites = SetOfSites.set_of_sites_from_input_data( data, [grid_x_min, grid_x_max], defect_species, site_charges, core_models, t )\n",
" if site_models == 'continuum':\n",
" all_sites, limits = Set_of_Sites.form_continuum_sites( all_sites, grid_x_min, grid_x_max, 1000, b, c, defect_species, laplacian_limits, site_labels, defect_labels )\n",
" all_sites, limits = SetOfSites.form_continuum_sites( all_sites, grid_x_min, grid_x_max, 1000, b, c, defect_species, laplacian_limits, site_labels, defect_labels )\n",
" if systems == 'mott-schottky':\n",
" for site in all_sites.subset( 'Ce' ):\n",
" site.defect_with_label('Gd').fixed = True\n",
Expand Down
6 changes: 3 additions & 3 deletions tests/test_notebooks/test_3/test_notebook_3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"outputs": [],
"source": [
"from pyscses.defect_species import DefectSpecies\n",
"from pyscses.set_of_sites import Set_of_Sites\n",
"from pyscses.set_of_sites import SetOfSites\n",
"from pyscses.constants import boltzmann_eV\n",
"from pyscses.calculation import Calculation, calculate_activation_energies\n",
"from pyscses.set_up_calculation import calculate_grid_offsets\n",
Expand Down Expand Up @@ -128,9 +128,9 @@
" \n",
" defect_species = { l : DefectSpecies( l, v, m, mob ) for l, v, m, mob in zip( defect_labels, valence, m, mobilities ) }\n",
"\n",
" all_sites = Set_of_Sites.set_of_sites_from_input_data( data, [grid_x_min, grid_x_max], defect_species, site_charges, core_models, t )\n",
" all_sites = SetOfSites.set_of_sites_from_input_data( data, [grid_x_min, grid_x_max], defect_species, site_charges, core_models, t )\n",
" if site_models == 'continuum':\n",
" all_sites, limits = Set_of_Sites.form_continuum_sites( all_sites, grid_x_min, grid_x_max, 1000, b, c, defect_species, laplacian_limits, site_labels, defect_labels )\n",
" all_sites, limits = SetOfSites.form_continuum_sites( all_sites, grid_x_min, grid_x_max, 1000, b, c, defect_species, laplacian_limits, site_labels, defect_labels )\n",
" if systems == 'mott-schottky':\n",
" for site in all_sites.subset( 'Ce' ):\n",
" site.defect_with_label('Gd').fixed = True\n",
Expand Down
6 changes: 3 additions & 3 deletions tests/test_notebooks/test_4/test_notebook_4.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"outputs": [],
"source": [
"from pyscses.defect_species import DefectSpecies\n",
"from pyscses.set_of_sites import Set_of_Sites\n",
"from pyscses.set_of_sites import SetOfSites\n",
"from pyscses.constants import boltzmann_eV\n",
"from pyscses.calculation import Calculation, calculate_activation_energies\n",
"from pyscses.set_up_calculation import calculate_grid_offsets\n",
Expand Down Expand Up @@ -126,9 +126,9 @@
" \n",
" defect_species = { l : DefectSpecies( l, v, m, mob ) for l, v, m, mob in zip( defect_labels, valence, m, mobilities ) }\n",
"\n",
" all_sites = Set_of_Sites.set_of_sites_from_input_data( data, [grid_x_min, grid_x_max], defect_species, site_charges, core_models, t )\n",
" all_sites = SetOfSites.set_of_sites_from_input_data( data, [grid_x_min, grid_x_max], defect_species, site_charges, core_models, t )\n",
" if site_models == 'continuum':\n",
" all_sites, limits = Set_of_Sites.form_continuum_sites( all_sites, grid_x_min, grid_x_max, 1000, b, c, defect_species, laplacian_limits, site_labels, defect_labels )\n",
" all_sites, limits = SetOfSites.form_continuum_sites( all_sites, grid_x_min, grid_x_max, 1000, b, c, defect_species, laplacian_limits, site_labels, defect_labels )\n",
" if systems == 'mott-schottky':\n",
" for site in all_sites.subset( 'Ce' ):\n",
" site.defect_with_label('Gd').fixed = True\n",
Expand Down
8 changes: 4 additions & 4 deletions tests/test_set_of_sites.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import unittest
from pyscses.set_of_sites import Set_of_Sites
from pyscses.set_of_sites import SetOfSites

class TestSetOfSites( unittest.TestCase ):

def test_set_of_sites_is_initialised( self ):
sites = [ 1,2,3,4 ]
set_of_sites = Set_of_Sites( sites )
set_of_sites = SetOfSites( sites )
self.assertEqual( set_of_sites.sites, sites )

def test_set_of_sites_addition( self ):
sites1 = [ 1, 2, 3, 4 ]
sites2 = [ 5, 6, 7, 8 ]
set_of_sites_1 = Set_of_Sites( sites1 )
set_of_sites_2 = Set_of_Sites( sites2 )
set_of_sites_1 = SetOfSites( sites1 )
set_of_sites_2 = SetOfSites( sites2 )
combined_set_of_sites = set_of_sites_1 + set_of_sites_2
self.assertEqual( combined_set_of_sites.sites, sites1 + sites2 )

Expand Down
18 changes: 9 additions & 9 deletions userguides/notebooks/Ex_1_BC.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"outputs": [],
"source": [
"from pyscses.defect_species import DefectSpecies\n",
"from pyscses.set_of_sites import Set_of_Sites\n",
"from pyscses.set_of_sites import SetOfSites\n",
"from pyscses.constants import boltzmann_eV\n",
"from pyscses.calculation import Calculation, calculate_activation_energies\n",
"from pyscses.set_up_calculation import calculate_grid_offsets\n",
Expand Down Expand Up @@ -131,9 +131,9 @@
" \n",
" defect_species = { l : DefectSpecies( l, v, m, mob ) for l, v, m, mob in zip( defect_labels, valence, m, mobilities ) }\n",
"\n",
" all_sites = Set_of_Sites.set_of_sites_from_input_data( data, [grid_x_min, grid_x_max], defect_species, site_charges, core_models, t )\n",
" all_sites = SetOfSites.set_of_sites_from_input_data( data, [grid_x_min, grid_x_max], defect_species, site_charges, core_models, t )\n",
" if site_models == 'continuum':\n",
" all_sites, limits = Set_of_Sites.form_continuum_sites( all_sites, grid_x_min, grid_x_max, 1000, b, c, defect_species, laplacian_limits, site_labels, defect_labels )\n",
" all_sites, limits = SetOfSites.form_continuum_sites( all_sites, grid_x_min, grid_x_max, 1000, b, c, defect_species, laplacian_limits, site_labels, defect_labels )\n",
" if systems == 'mott-schottky':\n",
" for site in all_sites.subset( 'site_2' ):\n",
" site.defect_with_label('defect_2').fixed = True\n",
Expand Down Expand Up @@ -260,9 +260,9 @@
" \n",
" defect_species = { l : DefectSpecies( l, v, m, mob ) for l, v, m, mob in zip( defect_labels, valence, m, mobilities ) }\n",
"\n",
" all_sites = Set_of_Sites.set_of_sites_from_input_data( data_1, [grid_x_min, grid_x_max], defect_species, site_charges, core_models, t )\n",
" all_sites = SetOfSites.set_of_sites_from_input_data( data_1, [grid_x_min, grid_x_max], defect_species, site_charges, core_models, t )\n",
" if site_models == 'continuum':\n",
" all_sites, limits = Set_of_Sites.form_continuum_sites( all_sites, grid_x_min, grid_x_max, 1000, b, c, defect_species, laplacian_limits, site_labels, defect_labels )\n",
" all_sites, limits = SetOfSites.form_continuum_sites( all_sites, grid_x_min, grid_x_max, 1000, b, c, defect_species, laplacian_limits, site_labels, defect_labels )\n",
" if systems == 'mott-schottky':\n",
" for site in all_sites.subset( 'site_2' ):\n",
" site.defect_with_label('defect_2').fixed = True\n",
Expand Down Expand Up @@ -379,9 +379,9 @@
" \n",
" defect_species = { l : DefectSpecies( l, v, m, mob ) for l, v, m, mob in zip( defect_labels, valence, m, mobilities ) }\n",
"\n",
" all_sites = Set_of_Sites.set_of_sites_from_input_data( data_1, [grid_x_min, grid_x_max], defect_species, site_charges, core_models, t )\n",
" all_sites = SetOfSites.set_of_sites_from_input_data( data_1, [grid_x_min, grid_x_max], defect_species, site_charges, core_models, t )\n",
" if site_models == 'continuum':\n",
" all_sites, limits = Set_of_Sites.form_continuum_sites( all_sites, grid_x_min, grid_x_max, 1000, b, c, defect_species, laplacian_limits, site_labels, defect_labels )\n",
" all_sites, limits = SetOfSites.form_continuum_sites( all_sites, grid_x_min, grid_x_max, 1000, b, c, defect_species, laplacian_limits, site_labels, defect_labels )\n",
" if systems == 'mott-schottky':\n",
" for site in all_sites.subset( 'site_2' ):\n",
" site.defect_with_label('defect_2').fixed = True\n",
Expand Down Expand Up @@ -501,9 +501,9 @@
" \n",
" defect_species = { l : DefectSpecies( l, v, m, mob ) for l, v, m, mob in zip( defect_labels, valence, m, mobilities ) }\n",
"\n",
" all_sites = Set_of_Sites.set_of_sites_from_input_data( data_2, [grid_x_min, grid_x_max], defect_species, site_charges, core_models, t )\n",
" all_sites = SetOfSites.set_of_sites_from_input_data( data_2, [grid_x_min, grid_x_max], defect_species, site_charges, core_models, t )\n",
" if site_models == 'continuum':\n",
" all_sites, limits = Set_of_Sites.form_continuum_sites( all_sites, grid_x_min, grid_x_max, 1000, b, c, defect_species, laplacian_limits, site_labels, defect_labels )\n",
" all_sites, limits = SetOfSites.form_continuum_sites( all_sites, grid_x_min, grid_x_max, 1000, b, c, defect_species, laplacian_limits, site_labels, defect_labels )\n",
" if systems == 'mott-schottky':\n",
" for site in all_sites.subset( 'site_2' ):\n",
" site.defect_with_label('defect_2').fixed = True\n",
Expand Down
10 changes: 5 additions & 5 deletions userguides/notebooks/Ex_2_MSGC.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"outputs": [],
"source": [
"from pyscses.defect_species import DefectSpecies\n",
"from pyscses.set_of_sites import Set_of_Sites\n",
"from pyscses.set_of_sites import SetOfSites\n",
"from pyscses.constants import boltzmann_eV\n",
"from pyscses.calculation import Calculation, calculate_activation_energies\n",
"from pyscses.set_up_calculation import calculate_grid_offsets\n",
Expand Down Expand Up @@ -124,9 +124,9 @@
" \n",
" defect_species = { l : DefectSpecies( l, v, m, mob ) for l, v, m, mob in zip( defect_labels, valence, m, mobilities ) }\n",
"\n",
" all_sites = Set_of_Sites.set_of_sites_from_input_data( data, [grid_x_min, grid_x_max], defect_species, site_charges, core_models, t )\n",
" all_sites = SetOfSites.set_of_sites_from_input_data( data, [grid_x_min, grid_x_max], defect_species, site_charges, core_models, t )\n",
" if site_models == 'continuum':\n",
" all_sites, limits = Set_of_Sites.form_continuum_sites( all_sites, grid_x_min, grid_x_max, 1000, b, c, defect_species, laplacian_limits, site_labels, defect_labels )\n",
" all_sites, limits = SetOfSites.form_continuum_sites( all_sites, grid_x_min, grid_x_max, 1000, b, c, defect_species, laplacian_limits, site_labels, defect_labels )\n",
" if systems == 'mott-schottky':\n",
" for site in all_sites.subset( 'site_2' ):\n",
" site.defect_with_label('defect_2').fixed = True\n",
Expand Down Expand Up @@ -246,9 +246,9 @@
" \n",
" defect_species = { l : DefectSpecies( l, v, m, mob ) for l, v, m, mob in zip( defect_labels, valence, m, mobilities ) }\n",
"\n",
" all_sites = Set_of_Sites.set_of_sites_from_input_data( data, [grid_x_min, grid_x_max], defect_species, site_charges, core_models, t )\n",
" all_sites = SetOfSites.set_of_sites_from_input_data( data, [grid_x_min, grid_x_max], defect_species, site_charges, core_models, t )\n",
" if site_models == 'continuum':\n",
" all_sites, limits = Set_of_Sites.form_continuum_sites( all_sites, grid_x_min, grid_x_max, 1000, b, c, defect_species, laplacian_limits, site_labels, defect_labels )\n",
" all_sites, limits = SetOfSites.form_continuum_sites( all_sites, grid_x_min, grid_x_max, 1000, b, c, defect_species, laplacian_limits, site_labels, defect_labels )\n",
" if systems == 'mott-schottky':\n",
" for site in all_sites.subset( 'site_2' ):\n",
" site.defect_with_label('defect_2').fixed = True\n",
Expand Down
Loading

0 comments on commit 2d184fe

Please sign in to comment.