[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:
raw_data = f.readlines()
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
> https://groups.google.com/d/msgid/cp2k/86012e05-b236-4bd4-8106-ce1adf3aad07%40googlegroups.com
> <https://groups.google.com/d/msgid/cp2k/86012e05-b236-4bd4-8106-ce1adf3aad07%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cp2k.org/archives/cp2k-user/attachments/20191203/e6a003a1/attachment.htm>
More information about the CP2K-user
mailing list