Outcar method read_elastic_tensor() broken?

I generated the elastic tensor (for Silicon) using ISIF=3 and IBRION=6 in both Vasp 5.4.4 and Vasp 6.3.2. I can see the elastic tensor being output in the OUTCAR file for both versions (see below). There is no problem with the elastic tensor in the output. On the other hand when using the Outcar class to read in the output using pymatgen (2023.3.10), the method Outcar.read_elastic_tensor() returns NoneType. It thus appears that the read_elastic_tensor() method is broken – or am I misunderstanding the use of the function. How does one read in the elastic tensor? The output below is for the Vasp 6 run, but the result is identical when trying to parse the Vasp 5 run.

In [1]: run = Vasprun("vasprun.xml")

In [2]: from pymatgen.io.vasp.outputs import Outcar

In [3]: outcar = Outcar("OUTCAR")
In [4]: outcar.read_elastic_tensor()

(blank output)

Vasp 5.4.4


  ELASTIC MODULI  (kBar)
 Direction    XX          YY          ZZ          XY          YZ          ZX
 --------------------------------------------------------------------------------
 XX        1606.7175    634.6464    634.6464      0.0000      0.0000      0.0000
 YY         637.9345   1607.6271    637.9345      0.0000      0.0000      0.0000
 ZZ         636.3157    636.3157   1607.0401      0.0000      0.0000      0.0000
 XY          -6.8857     -6.9820     -4.9206   1039.8595      0.0000      0.0000
 YZ           0.2226      0.1665      0.4836      0.0000   1039.4210      0.0000
 ZX           0.8753      0.1857      0.3031     -0.0000      0.0000   1038.4366
 --------------------------------------------------------------------------------


  SYMMETRIZED ELASTIC MODULI (kBar)
 Direction    XX          YY          ZZ          XY          YZ          ZX
 --------------------------------------------------------------------------------
 XX        1607.1282    636.2989    636.2989      0.0000      0.0000      0.0000
 YY         636.2989   1607.1282    636.2989      0.0000     -0.0000      0.0000
 ZZ         636.2989    636.2989   1607.1282      0.0000      0.0000     -0.0000
 XY           0.0000      0.0000      0.0000   1039.2393     -0.0000     -0.0000
 YZ           0.0000     -0.0000      0.0000     -0.0000   1039.2393      0.0000
 ZX           0.0000      0.0000     -0.0000     -0.0000      0.0000   1039.2393
 --------------------------------------------------------------------------------

and Vasp 6.3.2

  ELASTIC MODULI  (kBar)
 Direction    XX          YY          ZZ          XY          YZ          ZX
 --------------------------------------------------------------------------------
 XX        1608.8387    631.6045    631.6045     -0.0000     -0.0000     -0.0000
 YY         632.1761   1606.8207    632.1761      0.0000     -0.0000     -0.0000
 ZZ         629.6030    629.6030   1606.6463     -0.0000     -0.0000      0.0000
 XY         -15.1798    -15.2782    -13.3931   1019.6901      0.0000     -0.0000
 YZ           0.4596     -0.0631     -0.0568      0.0000   1025.7382     -0.0000
 ZX           1.5293     -1.4897     -1.4680      0.0000     -0.0000   1013.2504
 --------------------------------------------------------------------------------


  SYMMETRIZED ELASTIC MODULI (kBar)
 Direction    XX          YY          ZZ          XY          YZ          ZX
 --------------------------------------------------------------------------------
 XX        1607.4352    631.1279    631.1279     -0.0000      0.0000      0.0000
 YY         631.1279   1607.4352    631.1279     -0.0000      0.0000      0.0000
 ZZ         631.1279    631.1279   1607.4352     -0.0000     -0.0000      0.0000
 XY          -0.0000     -0.0000     -0.0000   1019.5661      0.0000     -0.0000
 YZ           0.0000      0.0000     -0.0000      0.0000   1019.5661     -0.0000
 ZX           0.0000      0.0000      0.0000     -0.0000     -0.0000   1019.5661
 --------------------------------------------------------------------------------

Hi @111457 ,

I do not think there should be a printout. Look at the method in pymatgen.io.vasp.outputs.Outcar:

def read_elastic_tensor(self):
        """
        Parse the elastic tensor data.

        Returns:
            6x6 array corresponding to the elastic tensor from the OUTCAR.
        """
        header_pattern = r"TOTAL ELASTIC MODULI \(kBar\)\s+" r"Direction\s+([X-Z][X-Z]\s+)+" r"\-+"
        row_pattern = r"[X-Z][X-Z]\s+" + r"\s+".join([r"(\-*[\.\d]+)"] * 6)
        footer_pattern = r"\-+"
        et_table = self.read_table_pattern(header_pattern, row_pattern, footer_pattern, postprocess=float)
        self.data["elastic_tensor"] = et_table

There is no print function. The table is just saved in the object.

Maybe run
print(outcar.data['elastic_tensor']) after?

I have no OUTCAR handy from a IBRION 6 run, so I cannot check, but just the name of the method (read_elastic_tensor()) suggest to me that it is not automatically parsed when loading an OUTCAR. This makes sense because not all OUTCARS have it. So you are just parsing it when calling the method, and then you have the data in the outcar object to do with as you please. I think.

Hi, @111457

Use this code to parse ELASTIC MODULI from OUTCAR

import numpy as np

def get_elastic_tensor(filename):
    ''' Reads the elastic tensor from the OUTCAR. 
    Args:
        filename : the name of the vasp OUTCAR
    Returns:
        elastic_tensor : 6x6 tensor of the elastic moduli
    '''
    f = open(filename,"r")
    lines = f.readlines()
    f.close()
    copy = False
    elastic_tensor = []
    for line in lines:
        inp = line.split()
        if inp == []:
            continue 
        if len(inp) < 4 or len(inp) > 7:
            continue
        if len(inp) == 4 and inp[0] == 'TOTAL':
            copy = True
        if copy:
            if len(inp) == 7 and len(inp[0]) == 2:
                elastic_tensor.append(inp[1:])
    return np.asarray(elastic_tensor).astype(np.float)

elastic_tensor = get_elastic_tensor('OUTCAR')
elastic_tensor

This code print ELASTIC TENSOR as follows:

array([[ 3.4321309e+03, 1.2749883e+03, 8.5950540e+02, 2.5250000e-01,
3.1143380e+02, 1.1520000e-01],
[ 1.2749883e+03, 3.4470139e+03, 8.6468770e+02, 1.1830000e-01,
-3.0792610e+02, -8.7600000e-02],
[ 8.5950540e+02, 8.6468770e+02, 3.8213918e+03, 1.8310000e-01,
-6.5310000e-01, 6.3400000e-02],
[ 2.5250000e-01, 1.1830000e-01, 1.8310000e-01, 1.0863535e+03,
2.8100000e-02, 3.1771430e+02],
[ 3.1143380e+02, -3.0792610e+02, -6.5310000e-01, 2.8100000e-02,
1.1149789e+03, -7.1400000e-02],
[ 1.1520000e-01, -8.7600000e-02, 6.3400000e-02, 3.1771430e+02,
-7.1400000e-02, 1.1113660e+03]])

Is this result what you want?

1 Like