Skip to content

Commit

Permalink
Use np.ascontiguousarray rather than np.array (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
awvwgk authored May 4, 2021
1 parent bc55eeb commit 43a680b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
18 changes: 9 additions & 9 deletions xtb/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,23 +276,23 @@ def __init__(
raise ValueError("Dimension missmatch between numbers and positions")

self._natoms = len(numbers)
_numbers = np.array(numbers, dtype="i4")
_positions = np.array(positions, dtype=float)
_numbers = np.ascontiguousarray(numbers, dtype="i4")
_positions = np.ascontiguousarray(positions, dtype=float)

_charge = _ref("double", charge)
_uhf = _ref("int", uhf)

if lattice is not None:
if lattice.size != 9:
raise ValueError("Invalid lattice provided")
_lattice = np.array(lattice, dtype="float")
_lattice = np.ascontiguousarray(lattice, dtype="float")
else:
_lattice = None

if periodic is not None:
if periodic.size != 3:
raise ValueError("Invalid periodicity provided")
_periodic = np.array(periodic, dtype="bool")
_periodic = np.ascontiguousarray(periodic, dtype="bool")
else:
_periodic = None

Expand Down Expand Up @@ -336,12 +336,12 @@ def update(

if 3 * len(self) != positions.size:
raise ValueError("Dimension missmatch for positions")
_positions = np.array(positions, dtype="float")
_positions = np.ascontiguousarray(positions, dtype="float")

if lattice is not None:
if lattice.size != 9:
raise ValueError("Invalid lattice provided")
_lattice = np.array(lattice, dtype="float")
_lattice = np.ascontiguousarray(lattice, dtype="float")
else:
_lattice = None

Expand Down Expand Up @@ -724,9 +724,9 @@ def set_external_charges(
"Dimension missmatch between atomic numbers and cartesian coordinates"
)

_numbers = np.array(numbers, dtype="i4")
_charges = np.array(charges, dtype=float)
_positions = np.array(positions, dtype=float)
_numbers = np.ascontiguousarray(numbers, dtype="i4")
_charges = np.ascontiguousarray(charges, dtype=float)
_positions = np.ascontiguousarray(positions, dtype=float)

_lib.xtb_setExternalCharges(
self._env,
Expand Down
3 changes: 2 additions & 1 deletion xtb/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def test_gfn2_xtb_0d():
[ 5.41408424778406,-9.49239668625902,-0.11022772492007],
[ 8.31919801555568,-9.74947502841788, 1.56539243085954],
[ 8.31511620712388,-9.76854236502758,-1.79108242206824],
]
],
order="F",
)
gradient = np.array(
[
Expand Down

0 comments on commit 43a680b

Please sign in to comment.