Skip to content
This repository has been archived by the owner on Jan 9, 2021. It is now read-only.

Commit

Permalink
created a diagram of the classes and inheritances in pbcpy
Browse files Browse the repository at this point in the history
  • Loading branch information
alesgenova committed Apr 23, 2018
1 parent 92bfbf1 commit b66b700
Show file tree
Hide file tree
Showing 4 changed files with 267 additions and 15 deletions.
126 changes: 126 additions & 0 deletions 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
```

129 changes: 129 additions & 0 deletions classes/classes.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/pbcpy/atom.py
Expand Up @@ -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))
Expand All @@ -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])


Expand Down
23 changes: 10 additions & 13 deletions src/pbcpy/field.py
Expand Up @@ -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
Expand All @@ -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)

Expand Down

0 comments on commit b66b700

Please sign in to comment.