Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #34 from molsturm/dev-mfh
Browse files Browse the repository at this point in the history
Extend Structure object to allow for empty structures
  • Loading branch information
mfherbst committed Dec 2, 2017
2 parents b3ba603 + 37abbfe commit bb20a0f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,6 @@ Further external dependencies required by `libcint`:
- BLAS

### Sturmians: sturmint
Sturmint is currently not released (but this is planned for the near future).
[`sturmint`](https://molsturm.org/sturmint)
is currently not released (but this is planned for the near future).
It can be enabled using the option `-DGINT_ENABLE_STURMINT=ON`.
26 changes: 15 additions & 11 deletions src/interface/python/gint/Structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,22 @@


class Structure:
def __init__(self, atoms, coords=None):
"""Setup a structure object.
def __init__(self, atoms=[], coords=[]):
"""Setup a structure object representing the structure of a chemical system.
atoms: List of all atoms of the structure. Either symbol or atomic numbers
or names are accepted.
or names of the elements are accepted.
coords: List of the coordinates of the involved atoms.
If there is only a single atom, then coords may be absent and atoms may be just
a single atom number or atom name/symbol.
"""
if not isinstance(atoms, (list, tuple, np.ndarray)):
if coords is None:
atoms = [atoms]
else:
raise TypeError("atoms needs to be a list or tuple")
if isinstance(atoms, (int, str)):
atoms = [atoms]
elif not isinstance(atoms, (list, tuple, np.ndarray)):
raise TypeError("atoms needs to be a list or tuple")

if coords is None:
if atoms and not coords:
if len(atoms) == 1:
coords = [[0, 0, 0]]
else:
Expand All @@ -54,7 +53,8 @@ def __init__(self, atoms, coords=None):

self.atom_numbers = np.array(element.to_atom_numbers(atoms))
self.coords = np.array(coords)
if self.coords.shape[1] != 3:

if coords and self.coords.shape[1] != 3:
raise ValueError("The coords list needs to have exactly 3 items per "
"coordinate.")

Expand All @@ -70,4 +70,8 @@ def n_atoms(self):
@property
def total_charge(self):
"""Compute the total charge of the atoms in the structure"""
return sum(self.atom_numbers)
return self.atom_numbers.sum()

@property
def empty(self):
return self.n_atoms == 0
4 changes: 2 additions & 2 deletions src/interface/python/gint/gaussian/_gaussian_shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def cartesian_shell(x, y, z, l, centre, coefficient, zeta, ordering):
# _shell_expressions.py
norm = expr.normalisation_cartesian_gaussians(l, zeta)

if np.all(centre != np.zeros(3)):
if np.any(centre != np.zeros(3)):
xs = x - centre[0]
ys = y - centre[1]
zs = z - centre[2]
Expand Down Expand Up @@ -194,7 +194,7 @@ def pure_shell(x, y, z, l, centre, coefficient, zeta):
if np.min(zeta) <= 0:
raise ValueError("All exponents (zeta) need to be larger than zero")

if np.all(centre != np.zeros(3)):
if np.any(centre != np.zeros(3)):
xs = x - centre[0]
ys = y - centre[1]
zs = z - centre[2]
Expand Down

0 comments on commit bb20a0f

Please sign in to comment.