1
$\begingroup$

I have an xyz file formatted in the following way (just a snapshot of the 192 atoms is shown) its cell information is given in #

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
       H  8.62187e-01  3.56549e+00  1.63636e+00
       H -2.92706e-01  3.06970e+00  2.81900e+00
       H -1.31912e-01  3.72346e+00  3.15581e+00
       H  5.38656e-01  3.94306e+00  4.92234e+00
       H  1.16999e+00  3.77125e+00  4.72771e+00
       H -2.68720e-01  3.52200e+00  6.82601e+00
       H  1.29835e-02  3.20666e+00  6.15759e+00
       H  7.83492e-01  4.21326e+00  7.79948e+00
       H  1.08183e+00  3.56220e+00  7.95853e+00
       H  1.10954e+00  5.13513e+00 -3.05944e-01
       H  8.09089e-01  5.18557e+00  9.55863e+00
       H  1.78392e+00  5.54388e+00  1.25293e+00
       H  1.76018e+00  5.18439e+00  1.92600e+00
       H  9.58592e-01  5.39614e+00  2.97232e+00
       H  1.03674e+00  4.70948e+00  3.39153e+00
       H  1.99327e+00  5.83024e+00  4.68857e+00
       H  1.81876e+00  5.22605e+00  4.33652e+00
       H  8.92271e-01  4.78003e+00  5.72944e+00
       H  6.53431e-01  4.92438e+00  6.47633e+00
       H  1.62820e+00  5.67492e+00  7.80865e+00
       H  2.01922e+00  5.05032e+00  7.38402e+00

I want ASE to read the cell information from the line with the #. Right now if I read in this xyz file from ase, it gives me the cell unit vectors as 0,0,0 and pbc false. Although all the atom positions come out fine. Note, these files were originally generated after running Path Integral Molecular Dynamics from I-PY.

How do I read this file into ASE in with the right cell parameters?

$\endgroup$

1 Answer 1

2
$\begingroup$

I ended up writing a script that will just read an output xyz i-py file to something ase can read easily. Here is the code if needed

    # Open the file

def convert_ipi_to_ase(filename,outfilename):
    with open(filename, 'r') as file:
        lines = file.readlines()

    # Process the lines to find CELL values
    for i, line in enumerate(lines):
        cell_values = []
        if 'CELL(abcABC):' in line:
            split_line = line.split()
            idx_cell= [idx for idx,s in enumerate(split_line) if 'CELL' in s][0]
            cell_values = split_line[idx_cell+1:idx_cell+4]  # Extracting the three numeric values after CELL

            # Construct the new line with the desired format
            new_line = f'Lattice=\"{cell_values[0]} 0.0 0.0 0.0 {cell_values[1]} 0.0 0.0 0.0 {cell_values[2]}\" '

            # Insert the new line before the original '# CELL...' line
            lines[i] = new_line+line

    # Write the updated content back to the file
    with open(outfilename, 'w+') as file:
        file.writelines(lines)

The ase xyz file has a Lattice="--a 3x3 matrix written as a 9 length vector--" that contains the cell information. So this code just adds that to each of the CELL lines.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .