raman-sc / VASP

Python program to evaluate off-resonance Raman activity using VASP code as the backend.
MIT License
165 stars 79 forks source link

A problem reading the DIELECTRIC TENSOR #1

Open alonkukl opened 9 years ago

alonkukl commented 9 years ago

Hi

I came a cross a problem with vasp and the dielectric tensor, sometimes when the valuesof the tensor are very big the numbers in the OUTCAR are mixedup and so the python script doesn't read them correctly. For example see the following sinnpet

MACROSCOPIC STATIC DIELECTRIC TENSOR (including local field effects in DFT)
  ------------------------------------------------------
       13738.431079-16959.202530     2.426989
        -7663.060793 23943.531628    -3.049640
            2.471794    -5.009690  1175.736030
  ------------------------------------------------------

In vasprun.xml the data is printed correctly, so I suggest to try and read the OUTCAR, and if it doesn't succeed then read the data from the xml with the following commands:

from lxml import etree
doc = etree.parse('vasprun.xml')
values = [c.text for c in doc.xpath("/modeling/calculation/varray")[3].getchildren()]
alonkukl commented 9 years ago

Or even try and use this code:

        if "MACROSCOPIC STATIC DIELECTRIC TENSOR" in line:
            outcar_fh.readline()
            try:
                epsilon.append([float(x) for x in outcar_fh.readline().split()])
                epsilon.append([float(x) for x in outcar_fh.readline().split()])
                epsilon.append([float(x) for x in outcar_fh.readline().split()])
            except:
                doc = etree.parse('vasprun.xml')
                epsilon = [[float(x) for x in c.text.split()] for c in doc.xpath("/modeling/calculation/varray")[3].getchildren()]
            return epsilon
arkamita1 commented 6 years ago

Hi , Using this code I had some problem and I modified it in the following way:

    if "MACROSCOPIC STATIC DIELECTRIC TENSOR" in line:
        outcar_fh.readline()
        try:
            epsilon.append([float(x) for x in outcar_fh.readline().split()])
            epsilon.append([float(x) for x in outcar_fh.readline().split()])
            epsilon.append([float(x) for x in outcar_fh.readline().split()])
        except:
            import xml.etree.ElementTree as ET
            doc = ET.parse('vasprun.xml')
            epsilon = [[float(x) for x in c.text.split()] for c in doc.xpath("/modeling/calculation/varray")[3].getchildren()]
        return epsilon

I got a error message: ElementTree instance has no attribute 'xpath' How to get rid of this problem?

afonari commented 6 years ago

Maybe related: https://mailman-mail5.webfaction.com/pipermail/lxml/20090921/020761.html