NPSpec  0.2.0
Solve for the spectral properties of nanoparticles easily
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
Nanoparticle Class Reference

Class to hold nanoparticle definition and calculate its spectrum. The interface for Python is the same as this C++ API. More...

#include <nanoparticle.hpp>

Public Member Functions

 Nanoparticle ()
 Constructor. More...
 
int calculateSpectrum ()
 Calculate the spectra. More...
 
void getSpectrum (double spec[NPSpec::NLAMBDA]) const
 Get the calculated spectrum. More...
 
void getRGB (double &r, double &g, double &b) const
 Get the color associated with the calculated spectrum in RGB color space. More...
 
void getHSV (double &h, double &s, double &v) const
 Get the color associated with the calculated spectrum in HSV color space. More...
 
double getOpacity () const
 Get the opacity of the color associated with the calculated spectrum. More...
 
int getNLayers () const
 Get the number of layers currently in the nanoparticle. More...
 
NPSpec::NanoparticleShape getShape () const
 Get the current shape of the nanoparticle. More...
 
NPSpec::SpectraType getSpectraType () const
 Get the current spectra type of the nanoparticle. More...
 
NPSpec::SpectraProperty getSpectraProperty () const
 Get the current spectra property of the nanoparticle. More...
 
double getSphereRadius () const
 Get the current sphere radius. More...
 
double getEllipsoidZRadius () const
 Get the current Z-component of the ellipsoid radius in nm. More...
 
double getEllipsoidXYRadius () const
 Get the current XY-component of the ellipsoid radius in nm. More...
 
double getSphereLayerRelativeRadius (int layer_num) const
 Get the sphere's relative radius in nm of a particular layer. More...
 
double getEllipsoidLayerZRelativeRadius (int layer_num) const
 Get the ellipsoid's relative radius of a particular layer in the Z-direction. More...
 
double getEllipsoidLayerXYRelativeRadius (int layer_num) const
 Get the ellipsoid's relative radius of a particular layer in the XY-direction. More...
 
std::string getLayerMaterial (int layer_num) const
 Get the material for the given layer. More...
 
int getLayerIndex (int layer_num) const
 Get the index corresponding to the material for the given layer. More...
 
int getIncrement () const
 Get the increment used when calculating the spectrum. More...
 
double getPathLength () const
 Get the Beer's law path length in centimeters. More...
 
double getConcentration () const
 Get the Beer's law concentration in molarity. More...
 
bool getSizeCorrect () const
 Get the size correction flag. More...
 
double getMediumRefractiveIndex () const
 Get the refractive index of the surrounding medium. More...
 
void setNLayers (int nlay)
 Sets the number of layers currently in the nanoparticle. More...
 
void setShape (NPSpec::NanoparticleShape npshape)
 Sets the current nanoparticle shape.
 
void setSpectraType (NPSpec::SpectraType stype)
 Sets the type of spectrum to calculate. More...
 
void setSpectraProperty (NPSpec::SpectraProperty spec)
 Sets the property of the spectrum for which to calculate. More...
 
void setSphereRadius (double rad)
 Sets the current spherical radius in nm. More...
 
void setEllipsoidRadius (double zrad, double xyrad)
 Sets the current ellipsoid radius in nm. More...
 
void setSphereLayerRelativeRadius (int layer_num, double rrad)
 Sets the spherical relative radius for the given layer. More...
 
void setEllipsoidLayerRelativeRadius (int layer_num, double zrrad, double xyrrad)
 Sets the ellipsoid relative radiis for the given layer. More...
 
void setLayerMaterial (int layer_num, std::string mat)
 Sets the material for a particular layer of the nanoparticle. More...
 
void setIncrement (int i)
 Sets the increment used when calculating the spectrum. More...
 
void setPathLength (double len)
 Sets the Beer's law path length in centimeters. More...
 
void setConcentration (double conc)
 Sets the Beer's law concentration in molarity. More...
 
void setSizeCorrect (bool corr)
 Sets whether size correction will be used in the spectrum calculation or not. More...
 
void setMediumRefractiveIndex (double mref)
 Sets the refractive index of the surrounding medium. More...
 

Detailed Description

Class to hold nanoparticle definition and calculate its spectrum. The interface for Python is the same as this C++ API.

Currently, the following materials are implemented: Ag, AlAs, AlSb, Au, Be, CdS, CdSe, Co, Cr, Cu, Cu2O, CuO, Diamond, Diamond_film, GaAs, GaP, Ge, Glass, Graphite, InAs, InP, InSb, Ir, K, Li, Mo, Na, Nb, Ni, Os, PbS, PbSe, PbTe, Pd, Pt, Quartz, Rh, Si, SiC, SiO, Ta, Te, TiO2, V, W, ZnS, ZnSe, ZnTe

A maximum of 10 nanoparticle layers is allowed (layer numbers are 1 - 10).

Constructor & Destructor Documentation

Nanoparticle::Nanoparticle ( )

Constructor.

The constructor makes the following initiallizations:

  • All layers are Ag
  • The nanoparticle is one layer
  • The shape is a sphere with a radius of 10 nm
  • The spectra type is Efficiency
  • The spectra proprty is Absorbance
  • The spectra will not be calculated with size correction
  • The Beer's law path length and concentration is 1 cm and \(10^{-6}\) M, respectively
  • The surrounding medium's refractive index is 1.0

Member Function Documentation

int Nanoparticle::calculateSpectrum ( )

Calculate the spectra.

This should only be used after the nanoparticle is defined.

Returns
Returns 0 if the calculation was sucessful and returns 1 if the nanoparticle may be too large and thus the spectrum may not be trustworthy.
Exceptions
std::out_of_rangeThis is thrown if the number of layers is out of range
std::invalid_argumentUnknown material or invalid increment
std::domain_errorRadii, path length, concentration, or refractive index is negative, relative radii don't sum to 1.0
Note
For Python, the above exceptions are mapped as:
  • out_of_range -> IndexError
  • domain_error -> ValueError
  • invalid_argument -> ValueError
double Nanoparticle::getConcentration ( ) const

Get the Beer's law concentration in molarity.

Returns
The Beer's law concentration in molarity.
double Nanoparticle::getEllipsoidLayerXYRelativeRadius ( int  layer_num) const

Get the ellipsoid's relative radius of a particular layer in the XY-direction.

Parameters
layer_numThe layer of which you wish to know the relative radius.
Returns
The ellispoid's relative radius in the XY-direction of the chosen layer.
Exceptions
std::out_of_rangeThe layer number is invalid.
Remarks
Internally, the sphere radius and ellipsoid radius are stored in different variables, so this will return the same value no matter if the nanoparticle is currently a sphere or ellipsoid.
The X- and Y- components of the radius are locked so that there are only two degrees of freedom of the radius (Z and XY). This allows us to use analytical formulas for the polarizabilty.
Note
For Python, an IndexError is raised instead of out_of_range.
double Nanoparticle::getEllipsoidLayerZRelativeRadius ( int  layer_num) const

Get the ellipsoid's relative radius of a particular layer in the Z-direction.

Parameters
layer_numThe layer of which you wish to know the relative radius.
Returns
The ellipsoid's relative radius in the Z-direction of the chosen layer.
Exceptions
std::out_of_rangeThe layer number is invalid.
Remarks
Internally, the sphere radius and ellipsoid radius are stored in different variables, so this will return the same value no matter if the nanoparticle is currently a sphere or ellipsoid.
The X- and Y- components of the radius are locked so that there are only two degrees of freedom of the radius (Z and XY). This allows us to use analytical formulas for the polarizabilty.
Note
For Python, an IndexError is raised instead of out_of_range.
double Nanoparticle::getEllipsoidXYRadius ( ) const

Get the current XY-component of the ellipsoid radius in nm.

Returns
The XY-component of the ellipsoid radius in nm.
Remarks
Internally, the sphere radius and ellipsoid radius are stored in different variables, so this will return the same value no matter if the nanoparticle is currently a sphere or ellipsoid.
The X- and Y- components of the radius are locked so that there are only two degrees of freedom of the radius (Z and XY). This allows us to use analytical formulas for the polarizabilty.
double Nanoparticle::getEllipsoidZRadius ( ) const

Get the current Z-component of the ellipsoid radius in nm.

Returns
The Z-component of the ellipsoid radius in nm.
Remarks
Internally, the sphere radius and ellipsoid radius are stored in different variables, so this will return the same value no matter if the nanoparticle is currently a sphere or ellipsoid.
void Nanoparticle::getHSV ( double &  h,
double &  s,
double &  v 
) const

Get the color associated with the calculated spectrum in HSV color space.

This should only be used after calling getSpectrum.

TODO: Calculate the color for absorbtion and transmission differently.

Parameters
hThe HUE of the color space, between 0 and 360 (inclusive).
sThe SATURATION part of the color space, between 0 and 1 (inclusive).
vThe VALUE part of the color space, between 0 and 1 (inclusive).
Note
For Python, h, s, and v are returned as a 3-tuple, so this would be called as h, s, v = Nanoparticle.getHSV().
int Nanoparticle::getIncrement ( ) const

Get the increment used when calculating the spectrum.

Returns
The increment for calculating the spectrum.
int Nanoparticle::getLayerIndex ( int  layer_num) const

Get the index corresponding to the material for the given layer.

Parameters
layer_numThe material index of which you wish to know the relative radius.
Returns
The material index for the chosen layer.
Exceptions
std::out_of_rangeThe layer number is invalid.
Note
For Python, an IndexError is raised instead of out_of_range.
std::string Nanoparticle::getLayerMaterial ( int  layer_num) const

Get the material for the given layer.

Parameters
layer_numThe layer of which you wish to know the relative radius.
Returns
The material for the chosen layer.
Exceptions
std::out_of_rangeThe layer number is invalid.
Note
For Python, an IndexError is raised instead of out_of_range.
double Nanoparticle::getMediumRefractiveIndex ( ) const

Get the refractive index of the surrounding medium.

Returns
The surrounding medium's refractive index.
int Nanoparticle::getNLayers ( ) const

Get the number of layers currently in the nanoparticle.

Returns
The number of layers in the nanoparticle.
double Nanoparticle::getOpacity ( ) const

Get the opacity of the color associated with the calculated spectrum.

This should only be used after calling getSpectrum.

double Nanoparticle::getPathLength ( ) const

Get the Beer's law path length in centimeters.

Returns
The Beer's law path length in centimeters.
void Nanoparticle::getRGB ( double &  r,
double &  g,
double &  b 
) const

Get the color associated with the calculated spectrum in RGB color space.

This should only be used after calling getSpectrum.

TODO: Calculate the color for absorbtion and transmission differently.

Parameters
rThe RED part of the color space, between 0 and 1 (inclusive).
gThe GREEN part of the color space, between 0 and 1 (inclusive).
bThe BLUE part of the color space, between 0 and 1 (inclusive).
Note
For Python, r, g, and b are returned as a 3-tuple, so this would be called as r, g, b = Nanoparticle.getRGB().
NanoparticleShape Nanoparticle::getShape ( ) const

Get the current shape of the nanoparticle.

Returns
The nanoparticle shape.
bool Nanoparticle::getSizeCorrect ( ) const

Get the size correction flag.

Returns
True if size correction is enabled, False otherwise.
SpectraProperty Nanoparticle::getSpectraProperty ( ) const

Get the current spectra property of the nanoparticle.

Returns
The property the spectrum was calculated.
SpectraType Nanoparticle::getSpectraType ( ) const

Get the current spectra type of the nanoparticle.

Returns
The type of the spectrum.
void Nanoparticle::getSpectrum ( double  spec[NPSpec::NLAMBDA]) const

Get the calculated spectrum.

This should only be used after calling calculateSpectrum.

Parameters
specThe calculated spectrum.
Note
For Python, spec is a numpy array that is returned by the function, so this would be called as spec = Nanoparticle.calculateSpectrum().
double Nanoparticle::getSphereLayerRelativeRadius ( int  layer_num) const

Get the sphere's relative radius in nm of a particular layer.

Parameters
layer_numThe layer of which you wish to know the relative radius.
Returns
The sphere's relative radius in nm of the chosen layer.
Exceptions
std::out_of_rangeThe layer number is invalid.
Remarks
Internally, the sphere radius and ellipsoid radius are stored in different variables, so this will return the same value no matter if the nanoparticle is currently a sphere or ellipsoid.
The X- and Y- components of the radius are locked so that there are only two degrees of freedom of the radius (Z and XY). This allows us to use analytical formulas for the polarizabilty.
Note
For Python, an IndexError is raised instead of out_of_range.
double Nanoparticle::getSphereRadius ( ) const

Get the current sphere radius.

Returns
The nanoparticle sphere radius.
Remarks
Internally, the sphere radius and ellipsoid radius are stored in different variables, so this will return the same value no matter if the nanoparticle is currently a sphere or ellipsoid.
void Nanoparticle::setConcentration ( double  conc)

Sets the Beer's law concentration in molarity.

Parameters
concWhen calculating absorption, this is the Beer's law path concentration in molarity to use. The default is \(10^{-6}\) M.
void Nanoparticle::setEllipsoidLayerRelativeRadius ( int  layer_num,
double  zrrad,
double  xyrrad 
)

Sets the ellipsoid relative radiis for the given layer.

Parameters
layer_numThe layer of which you wish to change the relative radius.
zrradThe new Z-component relative radius of the given layer. The relative radius must be between 0 and 1.
xyrradThe new XY-component relative radius of the given layer. The relative radius must be between 0 and 1.
Exceptions
std::out_of_rangeThe requested number of layers is illegal.
std::domain_errorA non-positive relative radius was given.
Remarks
The sum of the relative radii must be 1.0. When a new relative radius for a layer is set, the program will attempt to adjust the other relative radii so that the sum remains 1.0. Layers higher than the given layer will be adjusted first, and then the lower layers in decreasing order.
The X- and Y- components of the radius are locked so that there are only two degrees of freedom of the radius (Z and XY). This allows us to use analytical formulas for the polarizabilty.
Note
For Python, the above exceptions are mapped as:
  • out_of_range -> IndexError
  • domain_error -> ValueError
void Nanoparticle::setEllipsoidRadius ( double  zrad,
double  xyrad 
)

Sets the current ellipsoid radius in nm.

Parameters
zradThe Z-component radius to set for a spherical nanoparticle.
xyradThe XY-component radius to set for a spherical nanoparticle.
Exceptions
std::domain_errorA non-positive radius was given.
Remarks
Internally, the sphere radius and ellipsoid radius are stored in different variables, so this can be set no matter if the nanoparticle is currently a sphere or ellipsoid.
The X- and Y- components of the radius are locked so that there are only two degrees of freedom of the radius (Z and XY). This allows us to use analytical formulas for the polarizabilty.
Note
For Python, a ValueError is raised in place of domain_error.
void Nanoparticle::setIncrement ( int  i)

Sets the increment used when calculating the spectrum.

Parameters
iThis is the increment to use when looping over the wavelengths. There are 800 wavelengths in increments of 1 nm. This value must be a factor 800. This is useful if you have to repeatedly calculate the spectrum such as in a real-time GUI. The default is 1.
void Nanoparticle::setLayerMaterial ( int  layer_num,
std::string  mat 
)

Sets the material for a particular layer of the nanoparticle.

Parameters
layer_numThe layer to set the material for.
matString specifying the material to set. The default for all layers is "Ag".
Exceptions
std::out_of_rangeThe requested number of layers is illegal.
std::invalid_argumentUnknown material.
Note
For Python, the above exceptions are mapped as:
  • out_of_range -> IndexError
  • invalid_argument -> ValueError
void Nanoparticle::setMediumRefractiveIndex ( double  mref)

Sets the refractive index of the surrounding medium.

Parameters
mrefThe refracive index of the surrounding medium. The default is 1.0.
void Nanoparticle::setNLayers ( int  nlay)

Sets the number of layers currently in the nanoparticle.

Parameters
nlayThe number of layers you wish the nanoparticle to have. The default is 1.
Exceptions
std::out_of_rangeThe requested number of layers is illegal.
Warning
When you change the number of layers, the relative radii of each layer is not adjusted so you should reset the relative radii after changing the number of layers.
Note
For Python, an IndexError is raised in place of out_of_range.
void Nanoparticle::setPathLength ( double  len)

Sets the Beer's law path length in centimeters.

Parameters
lenWhen calculating absorption, this is the Beer's law path length in cm to use. The default is 1.0 cm.
void Nanoparticle::setSizeCorrect ( bool  corr)

Sets whether size correction will be used in the spectrum calculation or not.

Parameters
corrIf true size correction will be enabled, if false it will not. The default is false.
Remarks
Not all materials have size correction parameters implemented. Currently, only Ag, Al, Au, Be, Cu, Pd and Pt are implemented. Other materials will simply silently ignore this value.
void Nanoparticle::setSpectraProperty ( NPSpec::SpectraProperty  spec)

Sets the property of the spectrum for which to calculate.

Parameters
specThe property of the spectrum you wish to calculate.
void Nanoparticle::setSpectraType ( NPSpec::SpectraType  stype)

Sets the type of spectrum to calculate.

Parameters
stypeThe type of the spectrum you wish to calculate.
void Nanoparticle::setSphereLayerRelativeRadius ( int  layer_num,
double  rrad 
)

Sets the spherical relative radius for the given layer.

Parameters
layer_numThe layer of which you wish to change the relative radius.
rradThe new relative radius of the given layer. The relative radius must be between 0 and 1.
Exceptions
std::out_of_rangeThe requested number of layers is illegal.
std::domain_errorA non-positive relative radius was given.
Remarks
The sum of the relative radii must be 1.0. When a new relative radius for a layer is set, the program will attempt to adjust the other relative radii so that the sum remains 1.0. Layers higher than the given layer will be adjusted first, and then the lower layers in decreasing order.
Note
For Python, the above exceptions are mapped as:
  • out_of_range -> IndexError
  • domain_error -> ValueError
void Nanoparticle::setSphereRadius ( double  rad)

Sets the current spherical radius in nm.

Parameters
radThe radius to set for a spherical nanoparticle.
Exceptions
std::domain_errorA non-positive radius was given.
Remarks
Internally, the sphere radius and ellipsoid radius are stored in different variables, so this can be set no matter if the nanoparticle is currently a sphere or ellipsoid.
Note
For Python, a ValueError is raised in place of domain_error.

The documentation for this class was generated from the following files: