示例#1
0
文件: fields.py 项目: gmatteo/abipy
    def to_chgcar(self, filename=None):
        """
        Convert a :class:`Density` object into a ``Chgar`` object.
        If ``filename`` is not None, density is written to this file in Chgar format

        Return:
            :class:`Chgcar` instance.

        .. note::

            From: http://cms.mpi.univie.ac.at/vasp/vasp/CHGCAR_file.html:

            This file contains the total charge density multiplied by the volume
            For spinpolarized calculations, two sets of data can be found in the CHGCAR file.
            The first set contains the total charge density (spin up plus spin down),
            the second one the magnetization density (spin up minus spin down).
            For non collinear calculations the CHGCAR file contains the total charge density
            and the magnetisation density in the x, y and z direction in this order.
        """
        myrhor = self.datar * self.structure.volume

        if self.nspinor == 1:
            if self.nsppol == 1:
                data_dict = {"total": myrhor[0]}
            if self.nsppol == 2:
                data_dict = {"total": myrhor[0] + myrhor[1], "diff": myrhor[0] - myrhor[1]}

        elif self.nspinor == 2:
            raise NotImplementedError("pymatgen Chgcar does not implement nspinor == 2")

        chgcar = Chgcar(Poscar(self.structure), data_dict)
        if filename is not None:
            chgcar.write_file(filename)

        return chgcar
示例#2
0
    def to_chgcar(self, filename=None):
        from pymatgen.io.vasp.inputs import Poscar
        from pymatgen.io.vasp.outputs import Chgcar

        # From: http://cms.mpi.univie.ac.at/vasp/vasp/CHGCAR_file.html
        # This file contains the total charge density multiplied by the volume
        # For spinpolarized calculations, two sets of data can be found in the CHGCAR file.
        # The first set contains the total charge density (spin up plus spin down),
        # the second one the magnetization density (spin up minus spin down).
        # For non collinear calculations the CHGCAR file contains the total charge density
        # and the magnetisation density in the x, y and z direction in this order.
        myrhor = self.datar * self.structure.volume
        data_dict = {"total": myrhor[0]}
        if self.nsppol == 2: {"diff": myrhor[0] - myrhor[1]}
        if self.nspinor == 2: raise NotImplementedError("pymatgen Chgcar does not implement nspinor == 2")

        chgcar = Chgcar(Poscar(self.structure), data_dict)
        if filename is not None: chgcar.write_file(filename)
        return chgcar
示例#3
0
#%%

from pymatgen.io.vasp.outputs import Chgcar
from pymatgen.io.cube import Cube
import os

os.chdir('/home/jinho93/molecule/ddt/cp2k/bulk/asym/t1')
cub = Cube('s1-SPIN_DENSITY-1_0.cube')
cub.NZ
for i in range(cub.NX):
    for j in range(cub.NY):
        for k in range(cub.NZ):
            if i + k > cub.NZ + 2 or i + k < cub.NZ / 2 + 5:
                cub.data[i, j, k] = 0
chg = Chgcar(cub.structure, {'total': cub.data})
chg.write_file('NEW_CHGCAR')

# chg = Chgcar(cub.structure, cub.data)

# %%