[CP2K-user] [CP2K:12539] merging cube filed for the aimd simulation

Patrick Gono patri... at gmail.com
Tue Dec 3 09:40:53 UTC 2019

```Dear Raitis,

You may take a look at Cube-Toolz (
https://github.com/funkymunkycool/Cube-Toolz).

However, as cube files are human readable and quite easy to parse, you can
always do the operations you need yourself. For example, the following
Python3 script implements a class that can parse a density cube file:

import scipy as sp
class Cube:
def __init__(self, filename):
self.filename = filename

with open(self.filename, 'r') as f:

self.natoms = int(raw_data[2].split()[0])
self.nx, self.ny, self.nz = [int(line.split()[0]) for line in
raw_data[3:6]]

self.parse_density(raw_data)
print('Cube file {:s} parsed'.format(filename))

def parse_density(self, raw_data):
""" builds an nx times ny times nz array representing the spin
density """

data = []
for line in raw_data[self.natoms + 6:]:
data.extend(float(x) for x in line.split())

self.density = sp.zeros((self.nx, self.ny, self.nz))
for i in range(self.nx):
for j in range(self.ny):
for k in range(self.nz):
self.density[i, j, k] = data[i * self.ny * self.nz + j
* self.nz + k]

You can then calculate the average density by simply summing up the density
array of each cube file.

Yours sincerely,
Patrick Gono

On Mon, Nov 25, 2019 at 9:58 AM Raitis <raitis... at gmail.com> wrote:

> Dear all,
>
> I am trying to compute Raman spectra for my system by following this
> tutorial: https://brehm-research.de/files/spec_tutorial_2018.pdf
>
> At the electron density data calculation step I messed up and got cube
> files for each frame separately (I believe it is because I forgot to put
> "=" in front of results.cube).
> Is there a way to merge all the cube files of md simulation in one?
>
> Raitis
>
> --
> You received this message because you are subscribed to the Google Groups
> "cp2k" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cp... at googlegroups.com.
> To view this discussion on the web visit