Skip to content

Commit

Permalink
fixed cube swapaxes bug
Browse files Browse the repository at this point in the history
  • Loading branch information
eimrek committed Aug 4, 2020
1 parent 553382d commit 3011d48
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 0 additions & 2 deletions cp2k_spm_tools/cp2k_grid_orbitals.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,6 @@ def extrapolate_morbs(self, vacuum_pot=None, hart_plane=None, use_weighted_avg=T
def extrapolate_morbs_spin(self, ispin, vacuum_pot=None, hart_plane=None, use_weighted_avg=True):
"""
Extrapolate molecular orbitals from a specified plane to a box or another plane
in case of "single_plane = True", the orbitals will be only extrapolated on
a plane "extent" distance away
Extent in bohr !!!
Either the vacuum potential or the hartree plane is needed!
Expand Down
18 changes: 10 additions & 8 deletions cp2k_spm_tools/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ def __init__(self, title=None, comment=None, ase_atoms=None,

def write_cube_file(self, filename):

positions = self.ase_atoms.positions * ang_2_bohr
numbers = self.ase_atoms.get_atomic_numbers()

natoms = len(self.ase_atoms)

f = open(filename, 'w')
Expand All @@ -58,9 +55,13 @@ def write_cube_file(self, filename):
for i in range(3):
f.write("%5d %12.6f %12.6f %12.6f\n"%(self.data.shape[i], dv_br[i][0], dv_br[i][1], dv_br[i][2]))

for i in range(natoms):
at_x, at_y, at_z = positions[i]
f.write("%5d %12.6f %12.6f %12.6f %12.6f\n"%(numbers[i], 0.0, at_x, at_y, at_z))
if natoms > 0:

positions = self.ase_atoms.positions * ang_2_bohr
numbers = self.ase_atoms.get_atomic_numbers()
for i in range(natoms):
at_x, at_y, at_z = positions[i]
f.write("%5d %12.6f %12.6f %12.6f %12.6f\n"%(numbers[i], 0.0, at_x, at_y, at_z))

self.data.tofile(f, sep='\n', format='%12.6e')

Expand Down Expand Up @@ -126,11 +127,12 @@ def swapaxes(self, ax1, ax2):

# Atomic positions: careful, the ase cell is not modified
p = self.ase_atoms.positions
p[:, ax1], p[:, ax2] = p[:, ax1], p[:, ax2].copy()
p[:, ax1], p[:, ax2] = p[:, ax2], p[:, ax1].copy()

self.origin[ax1], self.origin[ax2] = self.origin[ax2], self.origin[ax1].copy()

self.cell[:, ax1], self.cell[:, ax2] = self.cell[:, ax1], self.cell[:, ax2].copy()
self.cell[:, ax1], self.cell[:, ax2] = self.cell[:, ax2], self.cell[:, ax1].copy()
self.cell[ax1, :], self.cell[ax2, :] = self.cell[ax2, :], self.cell[ax1, :].copy()

self.data = np.swapaxes(self.data, ax1, ax2)

Expand Down

0 comments on commit 3011d48

Please sign in to comment.