Troubles writing XYZ file

18 views
Skip to first unread message

rafaelpapp

unread,
Jul 16, 2022, 6:08:48 AMJul 16
to MDnalysis discussion
Hi,
I am trying to read an XYZ file and write another with the atoms reordered.

The initial XYZ file is:
3
frame 0  
      O     0.00000    0.00000    0.00000
      N     2.00000    0.00000    0.00000
      H     0.00000    1.50000    0.00000


The script I am using is:
import MDAnalysis as mda

u = mda.Universe("uno.xyz")

firstframe = 0
lastframe = 1
increment = 1
frames = slice(firstframe,lastframe,increment)
for ts in u.trajectory[frames]:
   idx_lst_sort = [0, 2, 1]
   ordenados = u.atoms[idx_lst_sort]
   print(u.atoms)
   print(u.atoms.positions)
   print(ordenados.atoms)
   print(ordenados.atoms.positions)
   with mda.Writer("dos.xyz", ordenados.n_atoms) as W:
       W.write(ordenados)
   with mda.Writer("dos.pdb", ordenados.n_atoms) as W:
       W.write(ordenados)

The order of symbols in both the XYZ and the PDB files are correct but the coordinates in the XYZ file are not changed from the original one whereas the PDB file has the correct coordinates.

I have been banging my head against a wall for a few hours.
Does somebody spot where is my error?

Thanks in advance,
Rafael RP

rafaelpapp

unread,
Jul 16, 2022, 11:54:01 AMJul 16
to MDnalysis discussion
The dos.xyz file is:
3
frame 0 | Written by MDAnalysis XYZWriter (release 2.2.0)
      O     0.00000    0.00000    0.00000
      H     2.00000    0.00000    0.00000
      N     0.00000    1.50000    0.00000

and the dos.pdb:

TITLE     MDANALYSIS FRAMES FROM 0, STEP 1: Created by PDBWriter
CRYST1    1.000    1.000    1.000  90.00  90.00  90.00 P 1           1
REMARK     285 UNITARY VALUES FOR THE UNIT CELL AUTOMATICALLY SET
REMARK     285 BY MDANALYSIS PDBWRITER BECAUSE UNIT CELL INFORMATION
REMARK     285 WAS MISSING.
REMARK     285 PROTEIN DATA BANK CONVENTIONS REQUIRE THAT
REMARK     285 CRYST1 RECORD IS INCLUDED, BUT THE VALUES ON
REMARK     285 THIS RECORD ARE MEANINGLESS.
MODEL        1
ATOM      1  O   UNK X   1       0.000   0.000   0.000  1.00  0.00      SYST O
ATOM      2  H   UNK X   1       0.000   1.500   0.000  1.00  0.00      SYST H
ATOM      3  N   UNK X   1       2.000   0.000   0.000  1.00  0.00      SYST N
ENDMDL
END


Reply all
Reply to author
Forward
0 new messages