I-PI xyz file to an ase readable xyz file

80 views
Skip to first unread message

Shubhang Goswami

unread,
Dec 4, 2023, 12:30:03 PM12/4/23
to ipi-users
Hello,
I have outputs generated from I-Pi saved as xyz files. Although these files are readable from the atomic simulation environment, but it doesnt read any of the cell dimension information.

The xyz file from I-py written as,
192
# CELL(abcABC): 7.63946 6.61313 9.30182 89.61648 90.34115 90.22212 Step: 0 Bead: 11 positions{angstrom} cell{angstrom}

H -8.98498e-03 3.73538e+00 -8.74215e-02
H -1.67969e-01 3.16369e+00 9.38250e+00
H 9.32450e-01 4.21329e+00 1.66229e+00
 
and so on

if you read through ase.io.read() , the atom files obtained do not contain any of the #CELL dimension information.

Is there a nice way to convert the I-py output xyz format to an ase one (that can take in cell dimension information)?

Mariana Rossi

unread,
Dec 4, 2023, 3:19:38 PM12/4/23
to ipi-users
So, if you have ASE installed in your system, it is possible to set the i-PI output to extxyz format directly.
Check here:

choose 'ase' as the mode.

Otherwise, if you want to convert something you already have, I think the best is to write a quick script. Maybe someone knows of some other way, but I just did it in the past by making my script write the comment line in the ASE format, and just echoing all other lines.

Michele Ceriotti

unread,
Dec 4, 2023, 5:07:00 PM12/4/23
to ipi-users
I should just add that I used many times `bin/i-pi-contract-trajectory` to do this, but it's not very well documented. might be useful and interesting to make a small script to convert trajectories, but I (and I think we) don't have the bandwidth right now, so if you feel like doing it, it'd be a very well appreciated contribution.
Michele

Mariana Rossi

unread,
Dec 19, 2023, 8:26:26 AM12/19/23
to ipi-users
Just in case this is still useful, here is a small code using ase:

import numpy as np
from ase.io import read, write
from sys import argv

# change here for your actual lattice vectors
a=11.554971
b=10.0069
c=65.000001

trajname=argv[1]

trajectory=read(trajname, index=':', format='xyz')

for i in trajectory:
    i.set_cell([a,b,c])
    i.set_pbc([True,True,True])
    i.wrap()

output=write('wrapped.xyz', trajectory, format='extxyz')

Janos Daru

unread,
May 6, 2024, 3:14:37 AMMay 6
to ipi-users
Dear All,

I have a related question. 
Is there a way to dump bead-wise a single file containing coordinates, forces, cell parameters, and energies in ASE like manner?

Eg:
10
Lattice="10.0 0.0 0.0 0.0 10.0 0.0 0.0 0.0 10.0" Properties=species:S:1:pos:R:3:forces:R:3  energy=-314.2384855360319 pbc="TTT" 
C        0.14088468       0.71747048       0.58595283      -0.06500885       0.06629617      -0.11803488
...

many thanks in advance, 

Best,

Janos

Michele Ceriotti

unread,
May 6, 2024, 2:17:39 PMMay 6
to ipi-users
Showt anwser is no, but you can do this easily as a post-processing step.
Assuming you are using the same output stride, something like

```
from ipi import read_output, read_trajectory
data, description = read_output("simulation.out")
traj = read_trajectory("simulation.pos_0.xyz")
force = read_trajectory("simulation.for_0.xyz")
for t, f, e in zip(traj, force, data["potential"]):
    t.arrays["force"] = f.positions
    t.info["energy"] = e
ase.write("combo.xyz", traj)
```
Should do to collate information from the standard output files
M

Reply all
Reply to author
Forward
0 new messages