Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove seemingly unnecessary parsing of material name string #219

Merged
merged 6 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# config = ConfigParser()
# config.read([default_config, ])
# __version__ = config.get('Configuration', 'version')
__version__ = '5.7.7'
__version__ = '5.8.0'

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 5.7.7
current_version = 5.8.0
commit = True
tag = True

Expand Down
43 changes: 26 additions & 17 deletions solcore/absorption_calculator/adachi_alpha.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def create_adachi_alpha(material, Esteps=(1.42, 6, 3000), T=300, wl=None):

:param material: A solcore material
:param Esteps: (1.42, 6, 3000) A tuple with the start, end and step energies in which calculating the optical data
:param T: (300) Temeprature in kelvin
:param T: (300) Temperature in kelvin
:param wl: (None) Optional array indicating the wavelengths in which calculating the data
:return: A tuple containing 4 arrays: (Energy, n, k, alpha)
"""
Expand All @@ -18,27 +18,36 @@ def create_adachi_alpha(material, Esteps=(1.42, 6, 3000), T=300, wl=None):
'S.Adachi, “Optical dispersion relations for GaP, GaAs, GaSb, InP, InAs, InSb, AlxGa1−xAs, '
'and In1−xGaxAsyP1−y” J.Appl.Phys., vol.66, no.12, pp.6030–12, 1989.')

# determine if material is stored in Solcore as an alloy by checking main_fraction
# if not, can simply look up by name. Otherwise, need to pass relevant alloy compositions also

if type(material) != str:
phoebe-p marked this conversation as resolved.
Show resolved Hide resolved
material = material.plain_string()

e0 = get_parameter(material, "E0", T=T) + 0j
Delta0 = get_parameter(material, "E0plusD0", T=T) + 0j - e0
e1 = get_parameter(material, "E1", T=T) + 0j
Delta1 = get_parameter(material, "E1plusD1", T=T) + 0j - e1
e2 = get_parameter(material, "E2", T=T) + 0j
egid = get_parameter(material, "Eg1d", T=T) + 0j
a = get_parameter(material, "A", T=T) + 0j
b1 = get_parameter(material, "B1", T=T) + 0j
b11 = get_parameter(material, "B11", T=T) + 0j
Gamma = get_parameter(material, "Gamma", T=T) + 0j # , "eV",T=T)
cc = get_parameter(material, "C", T=T) + 0j
gamma = get_parameter(material, "gamma", T=T) + 0j
d = get_parameter(material, "D", T=T) + 0j
if material.main_fraction == 0:
material = material.material_string
alloy_args = {}

else:
alloy_args = {material.composition[0]: material.main_fraction}
material = material.material_string

e0 = get_parameter(material, "E0", T=T, **alloy_args) + 0j
Delta0 = get_parameter(material, "E0plusD0", T=T,**alloy_args) + 0j - e0
e1 = get_parameter(material, "E1", T=T, **alloy_args) + 0j
Delta1 = get_parameter(material, "E1plusD1", T=T, **alloy_args) + 0j - e1
e2 = get_parameter(material, "E2", T=T, **alloy_args) + 0j
egid = get_parameter(material, "Eg1d", T=T, **alloy_args) + 0j
a = get_parameter(material, "A", T=T, **alloy_args) + 0j
b1 = get_parameter(material, "B1", T=T, **alloy_args) + 0j
b11 = get_parameter(material, "B11", T=T, **alloy_args) + 0j
Gamma = get_parameter(material, "Gamma", T=T, **alloy_args) + 0j # , "eV",T=T)
cc = get_parameter(material, "C", T=T, **alloy_args) + 0j
gamma = get_parameter(material, "gamma", T=T, **alloy_args) + 0j
d = get_parameter(material, "D", T=T, **alloy_args) + 0j
omegaphonon = 0
b2 = b1
b21 = b11

a0 = get_parameter(material, "lattice_constant", T=T)
a0 = get_parameter(material, "lattice_constant", T=T, **alloy_args)

b2 = 44 * (e1 + 2 * Delta1 / 3.) / (a0 * (e1 + Delta1) ** 2)
b1 = 44 * (e1 + Delta1 / 3) / (a0 * e1 ** 2)
Expand Down
1 change: 1 addition & 0 deletions solcore/material_system/material_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ def __getattr__(self, attrname): # only used for unknown attributes.

kwargs = {element: getattr(self, element) for element in self.composition}
kwargs["T"] = self.T

return ParameterSystem().get_parameter(self.material_string, attrname, **kwargs)

@lru_cache(maxsize=1)
Expand Down
45 changes: 11 additions & 34 deletions solcore/parameter_system/parameter_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from functools import lru_cache # cache function calls to stop things taking forever / recalculating smae things
import numpy
from typing import Optional, Callable
from warnings import warn

import solcore
from solcore import siUnits
Expand Down Expand Up @@ -56,10 +57,12 @@ def get_parameter(self, material, parameter, verbose=False, **others):
"""Calculate/look up parameters for materials, returns in SI units

Usage: .get_parameter(material_name, parameter_name, **kwargs)
- material_name is a string of element symbols/fractions, e.g.: In0.2GaAsP0.1
- parameter_name is a string of
- material_name is a string, the name of the material in Solcore's database. Note that alloy fractions need to be
specified in **others
- parameter_name is a string, name of the parameter to get
- **kwargs captures parameters that may be necessary for some calculations, eg. Temperature
material fractions may also be specified here, e.g.: .get_parameter("InGaAs", "band_gap", In=0.2)
material fractions may also be specified here, e.g.: .get_parameter("InGaAs", "band_gap", In=0.2) for the
bandgap of In0.2Ga0.8As.

If a compound material is bowed between two parent materials, the parent materials' parameters are calculated
recursively with this function. The final parameter is calculated as:
Expand All @@ -68,7 +71,11 @@ def get_parameter(self, material, parameter, verbose=False, **others):
The function is cached, so that multiple calls with the same parameters do not incur additional overhead.

"""
material, relevant_parameters = self.__parse_material_string(material, others)

warn('Passing alloy fractions to get_parameter in the material name (e.g. In0.2GaAs) is now deprecated; \
pass the alloy fraction as an argument instead.', DeprecationWarning)

relevant_parameters = others

def tryget(p, alternative):
try:
Expand Down Expand Up @@ -129,36 +136,6 @@ def tryget(p, alternative):
raise ValueError(
"Parameter '{}' not in material '{}', nor in calculable parameters.".format(parameter, material))

def __parse_material_string(self, material_string, other_parameters):
"""parses the material identifier strings of these types:

- In0.2GaAsP0.01
- InGaAsP {"In":0.2, "P":0.01}

into:
tuple("InGaAsP", {"In":0.2, "P":0.01})

other parameters are passed into the fractions dictionary. Chemical element Symbols are permitted as
sub-material strings, as well as longer words as long as they begin with a capital letter.
"""
if "{" in material_string: # fractions given as a dictionary: InGaAsP {'In':0.2, 'P':0.01}
identifier, arguments = material_string.split(" ")
arguments = ast.literal_eval(arguments)
assert type(arguments) == dict, "{} is not a dict".format(arguments)
arguments.update(other_parameters)
return identifier, arguments

# else: fractions given in parameter or in string: In0.2GaAsP0.01
elements_and_fractions = self.element_RE.split(material_string)[1:]
arguments = {}
for element, fraction in grouper(elements_and_fractions, 2):
try:
arguments[element] = float(fraction)
except:
pass
arguments.update(other_parameters)
# print ("".join(elements_and_fractions[::2]),arguments )
return "".join(elements_and_fractions[::2]), arguments

def __eval_string_expression(self, string_expression, **others):
if " " in string_expression: # treat second part as unit!
Expand Down
2 changes: 1 addition & 1 deletion solcore/solcore_config.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Configuration]
version: 5.7.7
version: 5.8.0
welcome_message: 1
verbose_loading: 1

Expand Down