From b66b700b8a679bb5f04116a3e38742b81fad4122 Mon Sep 17 00:00:00 2001 From: Alessandro Genova Date: Sun, 22 Apr 2018 20:54:25 -0400 Subject: [PATCH] created a diagram of the classes and inheritances in pbcpy --- classes/README.md | 126 +++++++++++++++++++++++++++++++++++++++++++ classes/classes.svg | 129 ++++++++++++++++++++++++++++++++++++++++++++ src/pbcpy/atom.py | 4 +- src/pbcpy/field.py | 23 ++++---- 4 files changed, 267 insertions(+), 15 deletions(-) create mode 100644 classes/README.md create mode 100644 classes/classes.svg diff --git a/classes/README.md b/classes/README.md new file mode 100644 index 0000000..17b5734 --- /dev/null +++ b/classes/README.md @@ -0,0 +1,126 @@ +# PbcPy - Class Diagram + +![Class Diagram](classes.svg) + +```plantuml +@startuml + +class NumpyArray{ + +} + +package "pbcpy.base" #EEEEEE { + +Abstract BaseCell{ + + __init__(lattice, origin) + + __eq__(other) + + lattice() : float[3,3] + + origin() : float[3] + + volume() : float + # _lattice : float[3,3] + # _volume : float + # _origin : float[3] +} + +Class DirectCell{ + + get_reciprocal() : ReciprocalCell +} + +Class ReciprocalCell{ + + get_direct() : DirectCell +} + +Class Coord{ + + __new__(pos, cell, basis) + + __add__(other) + + __mul__(scalar) + + cell() : DirectCell + + basis() : string + + to_cart() : Coord + + to_crys() : Coord + + to_basis(basis) : Coord + + d_mic(other) : Coord + + dd_mic(other) : float + + length() : float + # _cell : DirectCell + # _basis : string +} + +} + + +package "pbcpy.grid" #EEEEEE { + +Abstract BaseGrid{ + + __init__(lattice, nr, origin) + + nr : int[3] + + nnr : int + + dV : float + # _nr : int[3] + # _nnr : int + # _dV : float +} + +Class DirectGrid{ + # _r : float[*nr, 3] + # _s : float[*nr, 3] + + r() : float[*nr, 3] + + s() : float[*nr, 3] + + get_reciprocal() : ReciprocalGrid +} + +Class ReciprocalGrid{ + # _g : float[*nr, 3] + # _gg : float[*nr] + + g() : float[*nr, 3] + + gg() : float[*nr] + + get_direct() : DirectGrid +} + +} + + +package "pbcpy.field" #EEEEEE { + +Abstract BaseField{ + + __init__(grid, rank, griddata_F, griddata_C, griddata_3d) + + grid : Grid + + span : int + + rank : int + + integral() : float +} + +Class DirectField{ + + gradient() : DirectField + + sigma() : DirectField + + fft() : ReciprocalField + + get_3dinterpolation(nr) : DirectField + + get_cut(r0, r1, r2, origin, center, nr) : DirectField +} + +Class ReciprocalField{ + + ifft() : DirectField +} + +} + +BaseCell <|-- DirectCell +BaseCell <|-- ReciprocalCell + +NumpyArray <|-- Coord + +BaseCell <|-- BaseGrid +BaseGrid <|-- DirectGrid +BaseGrid <|-- ReciprocalGrid + +DirectCell <|-- DirectGrid +ReciprocalCell <|-- ReciprocalGrid + +NumpyArray <|----- BaseField + +BaseField <|-- DirectField +BaseField <|-- ReciprocalField + +@enduml +``` + diff --git a/classes/classes.svg b/classes/classes.svg new file mode 100644 index 0000000..f6d940e --- /dev/null +++ b/classes/classes.svg @@ -0,0 +1,129 @@ +pbcpy.basepbcpy.gridpbcpy.fieldBaseCell_lattice : float[3,3]_volume : float_origin : float[3]__init__(lattice, origin)__eq__(other)lattice() : float[3,3]origin() : float[3]volume() : floatDirectCellget_reciprocal() : ReciprocalCellReciprocalCellget_direct() : DirectCellCoord_cell : DirectCell_basis : string__new__(pos, cell, basis)__add__(other)__mul__(scalar)cell() : DirectCellbasis() : stringto_cart() : Coordto_crys() : Coordto_basis(basis) : Coordd_mic(other) : Coorddd_mic(other) : floatlength() : floatBaseGridnr : int[3]nnr : intdV : float_nr : int[3]_nnr : int_dV : float__init__(lattice, nr, origin)DirectGrid_r : float[*nr, 3]_s : float[*nr, 3]r() : float[*nr, 3]s() : float[*nr, 3]get_reciprocal() : ReciprocalGridReciprocalGrid_g : float[*nr, 3]_gg : float[*nr]g() : float[*nr, 3]gg() : float[*nr]get_direct() : DirectGridBaseFieldgrid : Gridspan : intrank : int__init__(grid, rank, griddata_F, griddata_C, griddata_3d)integral() : floatDirectFieldgradient() : DirectFieldsigma() : DirectFieldfft() : ReciprocalFieldget_3dinterpolation(nr) : DirectFieldget_cut(r0, r1, r2, origin, center, nr) : DirectFieldReciprocalFieldifft() : DirectFieldNumpyArray \ No newline at end of file diff --git a/src/pbcpy/atom.py b/src/pbcpy/atom.py index ab7d162..28927c5 100644 --- a/src/pbcpy/atom.py +++ b/src/pbcpy/atom.py @@ -40,7 +40,7 @@ def set_PP(self,outfile): if '1000' in lines[iend]: print('Recpot pseudopotential ' +outfile+ ' loaded') else: - return Exception + raise Exception("Error reading the pseudopotential {}".format(outfile)) gmax = np.float(lines[ibegin-1].strip())*BOHR2ANG v = np.array(line.split()).astype(np.float)/HARTREE2EV/BOHR2ANG**3 g = np.linspace(0,gmax,num=len(v)) @@ -62,7 +62,7 @@ def strf(self,reciprocal_grid): ''' Returns the Structure Factor associated to this ion ''' - a=-self.Zval*np.exp(-1j*np.einsum('ijkl,l->ijk',reciprocal_grid.g,self.pos)) + a = -(self.Zval*np.exp(-1j*np.einsum('ijkl,l->ijk',reciprocal_grid.g,self.pos))) return np.reshape(a,[reciprocal_grid.nr[0],reciprocal_grid.nr[1],reciprocal_grid.nr[2],1]) diff --git a/src/pbcpy/field.py b/src/pbcpy/field.py index 4adfb93..4842e6f 100644 --- a/src/pbcpy/field.py +++ b/src/pbcpy/field.py @@ -120,16 +120,15 @@ def _calc_spline(self): padded_values, order=self.spl_order) return - def numerically_smooth_gradient(self): + def _numerically_smooth_gradient(self): sq_self = np.sqrt(self) - grad = (sq_self.standard_gradient()) + grad = (sq_self._standard_gradient()) if grad.rank != np.shape(grad)[3]: raise ValueError("Gradient rank incompatible with shape") final = 2.0*sq_self*grad return final - - def standard_gradient(self): + def _standard_gradient(self): reciprocal_self = self.fft() imag = (0 + 1j) nr = *self.grid.nr, 3 @@ -144,25 +143,23 @@ def standard_gradient(self): raise ValueError("Standard Gradient: Gradient rank incompatible with shape") return grad - - - def gradient(self,flag='smooth'): + def gradient(self, flag='smooth'): if self.rank > 1: raise Exception("gradient is only implemented for scalar fields") if flag is 'standard': - return self.standard_gradient(self) + return self._standard_gradient(self) elif flag is 'smooth': - return self.numerically_smooth_gradient() - - + return self._numerically_smooth_gradient() + else: + raise Exception("Unknown gradient method: {}".format(flag)) - def sigma(self): + def sigma(self, flag='smooth'): """ \sigma(r) = |\grad rho(r)|^2 """ if self.rank > 1: raise Exception("sigma is only implemented for scalar fields") - gradrho = self.gradient() + gradrho = self.gradient(flag) griddata_3d = np.einsum("ijkl,ijkl->ijk", gradrho, gradrho) return DirectField(self.grid, rank=1, griddata_3d=griddata_3d)