From 3011d481cb2a7c29f2623340ff17eda4d03c66bd Mon Sep 17 00:00:00 2001 From: Kristjan Date: Tue, 4 Aug 2020 20:13:07 +0200 Subject: [PATCH] fixed cube swapaxes bug --- cp2k_spm_tools/cp2k_grid_orbitals.py | 2 -- cp2k_spm_tools/cube.py | 18 ++++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cp2k_spm_tools/cp2k_grid_orbitals.py b/cp2k_spm_tools/cp2k_grid_orbitals.py index c1624f6..c5a7c13 100644 --- a/cp2k_spm_tools/cp2k_grid_orbitals.py +++ b/cp2k_spm_tools/cp2k_grid_orbitals.py @@ -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! diff --git a/cp2k_spm_tools/cube.py b/cp2k_spm_tools/cube.py index 3e972fc..ab02f83 100644 --- a/cp2k_spm_tools/cube.py +++ b/cp2k_spm_tools/cube.py @@ -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') @@ -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') @@ -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)