Reading variable lattice from Xdatcar and RDF

Hello,
I’m using the following command to read a Xdatcar file from an NPT simulation, which contains variable lattice. I’m not sure why the argument constant_lattice=False doesn’t create a 2D array of variable lattice. I only see the lattice of the 1st frame repeated throughout the snapshots.

from pymatgen.core.trajectory import Trajectory
trj = Trajectory.from_file(‘XDATCAR’, constant_lattice=False)

trj.get_structure(0).lattice
#e.g. output: 9.3569 10.546 44.58
trj.get_structure(1000).lattice
#e.g. output: 9.3569 10.546 44.58

The second question I had is:
Can Pymatgen handle RDF from 2 atom indices? E.g. I see the following code
get_rdf_figure (isite , normalized=True , figsize=None , step_function=None )
where, isite seems to only consider self interaction RDF? Or can isite be [atom_N, atom_M] in the unit cell?

Pymatgen version: 2020.12.18
Python verion: python3.6

The trajectory object should read variable lattice… are you sure the XDATCAR is right?

As for RDF, pymatgen doesn’t have good support for such things at the moment. What MP has is a separate code called MPMorph which contains more MD-focused tools like RDFs. MPMorph is not fully developed, but you can pull it from github, and it can read RDFs from pymatgen structure objects.

Thanks for the response.

I can confirm that XDATCAR is correctly written. My structure contains around 500 atoms with 7 different elements and 6000 snapshots (100ish MB). Is any of this causing an issue?

Thanks for the RDF comment. I’ll check it out.

Hi Satish,

Are you still having an issue with this? I’m looking into it now and the Trajectory class seems to be handling variable lattices correctly. I’m wondering if the XDATCAR assumes constant lattice. I don’t have access to an XDATCAR from an NPT run and don’t know the exact formatting. Can you try the following and let me know if the output is as expected?

from pymatgen.io.vasp.outputs import Xdatcar
xdatcar = Xdatcar('XDATCAR')

structures = xdatcar.structures

print(structures[0].lattice)
print(structures[1000].lattice)

Alternatively, can you supply me with the XDATCAR file you are trying to read? I only need the first 10 or so frames. You can edit the file and delete the extra snapshots.

Thanks,
Eric

Hi Eric,

I created a manual script to parse that information. The command you sent prints out the same lattice constant. I unfortunately can’t send the frames due to proprietary structures. I’ll see if I can reproduce that error with a different run and post the output back.

Hi Satish,

Thanks for getting back to me. Looks like my suspicious were correct. Pymatgen’s Xdatcar parser does not properly handle variable lattice during MD simulations. If you can get me the output of the different run, that would be great!

In the meantime, you should be able to work around this by taking the structures from the ‘vasprun.xml’ rather than the ‘XDATCAR’.

from pymatgen.core.trajectory import Trajectory
trj = Trajectory.from_file(‘vasprun.xml’, constant_lattice=False)

Sorry for the delay. The program I use deletes vasprun.xml :confused:

Nonetheless, here is an example water in a box xdatcar file with a few frames.

The issue remained in both ‘2020.12.18’ and ‘2022.0.4’.

“New users can’t upload attachments”? Why?

Okay, so, here is a plain copy-paste of the XDATCAR file

No title
1
5.346050 0.000000 0.000000
0.000000 4.723860 0.000000
0.000000 0.000000 4.676830
O H
1 2
Direct configuration= 1
0.67129387 0.50589346 0.51850197
0.86531645 0.51195130 0.51278074
0.61353324 0.65912915 0.37378119
No title
1
5.345716 -0.000203 0.001509
0.000000 4.724033 -0.000679
0.000000 0.000000 4.677331
O H
1 2
Direct configuration= 2
0.67088828 0.50648241 0.51829338
0.86250115 0.51457365 0.50844819
0.61092402 0.65193293 0.38025700
No title
1
5.345377 -0.000344 0.003126
-0.000000 4.724291 -0.001284
0.000000 0.000000 4.677605
O H
1 2
Direct configuration= 3
0.67063363 0.50681875 0.51796374
0.85517057 0.51838323 0.50491265
0.60965876 0.64303954 0.38939507
No title
1
5.345151 -0.000415 0.004829
-0.000000 4.724564 -0.001867
0.000000 0.000000 4.677879
O H
1 2
Direct configuration= 4
0.66998261 0.50625822 0.51767064
0.84745539 0.51997611 0.50267309
0.60928873 0.63562662 0.39616150
No title
1
5.345093 -0.000509 0.006381
-0.000000 4.724840 -0.002450
0.000000 -0.000000 4.678197
O H
1 2
Direct configuration= 5
0.66913903 0.50527018 0.51775497
0.84079077 0.52151784 0.50106526
0.60627344 0.63619314 0.39572761
No title
1
5.345069 -0.000520 0.007819
-0.000000 4.725119 -0.003203
0.000000 0.000000 4.678416
O H
1 2
Direct configuration= 6
0.66803794 0.50416334 0.51800266
0.83922917 0.52365196 0.49722605
0.60022674 0.64238828 0.38969579
No title
1
5.344986 -0.000581 0.008968
0.000000 4.725403 -0.003773
-0.000000 0.000000 4.678646
O H
1 2
Direct configuration= 7
0.66650101 0.50344333 0.51843160
0.84224062 0.52642112 0.49264557
0.59357018 0.64946634 0.38324213
No title
1
5.344838 -0.000442 0.010163
-0.000000 4.725582 -0.004265
-0.000000 0.000000 4.678790
O H
1 2
Direct configuration= 8
0.66502511 0.50272761 0.51904085
0.84655766 0.52918476 0.48791539
0.58842733 0.65417723 0.37726194
No title
1
5.344649 -0.000360 0.011296
-0.000000 4.725687 -0.004938
0.000000 0.000000 4.678927
O H
1 2
Direct configuration= 9
0.66359066 0.50201529 0.51955946
0.84790044 0.52983645 0.48174330
0.58423761 0.65348825 0.37521404
No title
1
5.344443 -0.000186 0.012434
-0.000000 4.725847 -0.005728
0.000000 0.000000 4.679009
O H
1 2
Direct configuration= 10
0.66235242 0.50177215 0.51952686
0.84476749 0.53101669 0.47594452
0.58272707 0.64758582 0.37605302

Hi Satish,

Thanks for the file. I looked into this a bit more and it appears to have been fixed a few days after our first correspondence. If you update pymatgen v2022.0.7 or later, the parsing of the Xdatcar to create trajectories should behave as expected.

See pull request #2115:

Thanks,
Eric