xyz to pdb file type coverter

1,440 views
Skip to first unread message

Peter

unread,
Jun 5, 2020, 8:54:14 PM6/5/20
to fullrmc
Hello All,

I have some ~4000 xyz files that I want to use in fullRMC. I need to convert these to pdb files in order for fullRMC to be able to read them.

I know there is software out there (such as VMD) which can covert them for me, however, given the large quantity of samples I am looking for something that can be automated

Does anyone have some suggestions?

Thank you in advance 
Peter

Robert Koch

unread,
Jun 5, 2020, 9:04:24 PM6/5/20
to fullrmc
Hey Peter,

As far as I know, pdb requires you to supply the cell size, but xyz doesn't have such a requirement. Also, there is other info present in a pdb not present in an xyz. Do you have a strategy for handling this?

If so we could probably modify a cif to pdb creator I wrote using ASE.

Rob

Peter Metz

unread,
Jun 5, 2020, 10:08:46 PM6/5/20
to fullrmc
Hi Peter

I was using pymatgen in workflows to build structures, and the following tools to write pymatgen structure instances to .pdb files 


I believe you should be able to read .xyz files into pymatgen, and you're welcome to use / adopt this code.

- Also Peter 

Bachir Aoun

unread,
Jun 6, 2020, 6:04:43 PM6/6/20
to fullrmc
Hello Peter,

an xyz file is simply a 3 columns file for the x,y and z coordinates of every and each atom.
if you know your atoms element and name in order like in the xyz file. you can create the dummy pdbfile using pdbparser and loop through your files and each time update the atoms coordinates as read from the xyz file

simply do the following by converting this pseudo code into what you need


from pdbparser import pdbparser

PDBS = {}
templatePDB
= pdbparser(filePath='dummy_pdb_file_with_the_correct_atoms')
for path in xyzFiles:
    # this function returns a numpy array of the xyz coordinates
    coords = read_xyz_file_coordinates(path')
    pdb = templatePDB.get_copy()
    pdb.
set_coordinates(coords)
        
PDBS[path] = pdb


This code will give you a dictonnary of pdb instances per xyz file

thanks 

Peter

unread,
Jun 18, 2020, 11:12:52 PM6/18/20
to fullrmc
Hello All,

Thank you for your help on this topic 

Apologies but I am still quite new to python. I have been trying to use the pseudo code that Bachir has sent through, however, I have a few questions to make sure I am approaching this from the right angle

1. For the variable 'xyzFiles' is this variable to be set as the list of all the xyz file names? 

2. Am I supposed to define a function called 'read_xyz_file_coordinates' that extracts the coordinates from each file and returns this as an array of these values? Or is this already an inbuilt function in pdbparser? Because I am getting error messages for this saying it is not defined 

Sorry if these are silly questions, thank you again for your help 

Bachir Aoun

unread,
Jul 5, 2020, 11:48:22 AM7/5/20
to fullrmc
Hi Peter,

I am not really following what you are trying to do here ?
why you want to read the xyz file and and convert it to pdb ?

Don't use the xyz file unless you want to save a trajectory snapshot to visualize in VMD ... this is the only reason why fullrmc's  alows exporting and xyz file upon stochastic engine runtime.


hope that helps 

Peter

unread,
Jul 5, 2020, 11:12:48 PM7/5/20
to fullrmc
Hello Bachir 

Thank you for your response 

I have 4000 gold nanoparticles. I want to be able to generate theoretical PDF functions of these particles (as I was told I could do this with full RMC) 

I have all of their structure files, however, these are in xyz format - thats why I wanted to convert them to a format I could put into full RMC 

Thank you
Peter

Bachir Aoun

unread,
Jul 13, 2020, 2:54:38 PM7/13/20
to fullrmc
Hey Peter, 

to put an end to this thread. Attached is a script to convert xyz to pdb 

use it at your discretion 

thanks 
xyz_to_pdb.py
Reply all
Reply to author
Forward
0 new messages