This is a very basic question, but I can't find anything helpful on the internet: I created a molecule on Pymol; is there a way to extract its cartesian coordinate file in xyz-format?
Thank you very much in advance!
XYZ file format from Wikipedia
<number of atoms>
comment line
<element> <X> <Y> <Z>
...
EDITED SORRY JUST REALIZED YOU WERE ASKING ABOUT .xyz format NOT JUST COORDINATES
People suggest using openbabel ( github openbabel ) see here :
Converting a PDB file to XYZ file
From PyMOL old documentation https://pymol.org/dokuwiki/doku.php?id=start seems that it does support loading
.xyz
format but not saving to it.Latest PyMOL version shows
.xyz
format too for exportjust select
XYZ (*.xyz)
as File type when saving exportedmolecule , result using file
test.pdb
below :PyMOL API would be :
cmd.save('selection' , 'output.xyz')
, but it doesn't work.output
from PyMOL Wiki! usin PyMOL API:
try :
xyz = cmd.get_coords('sele', 1)
as explained inGet Coordinates I
or from PyMOL console as per in :
Thread: [PyMOL] How do you show the coordinates of an atom? :
try :
iterate_state 1, <selection_name>, print (x,y,z)
see Iterate and the iterate-family exposed the variables.
More in details using PyMOL console ,
loading file
test.pdb
in PyMOL :using :
select pippo ,resi 1 AND name CA
--->Selector: selection "pippo" defined with 1 atoms.
Then :
iterate_state 1, pippo , print ( x,y,z)
--->33.805999755859375 36.685001373291016 19.868999481201172 IterateState: iterated over 1 atom coordinate states.
While using PyMOL API on same file
test.pdb
with code :Output :
adding this bit of code to the previous one :
ouput will have added :
and the
output_xyz.xyz
file in.xyz***
format will be written :this is funny because the original
test.pdb
had only three decimal places in its cartesian coordinates .*** still wasnt able to figure out if
.xyz
format uses space delimited column for the x , y, z values of it there is a fixed column size for them.EDITED BIS
After a little bit of googling I finally ended up at :
XYZ cartesian coordinates format (xyz) Openbabel
where is written :
So the part of my code writing the
output_xyz.xyz
file has to be modify accordingly , while the PyMOL exportedXYZ (*.xyz)
file seems to carry problems tooUse :
cmd.iterate_state("-1" , "test" , "stored.xyz_full.append([elem.rjust(3 , ' ') , f'{x:15.5f}' , f'{y:15.5f}' , f'{z:15.5f}'])")
to get
output_xyz.xyz
as :