cif 2 xyz conversions

2,782 views
Skip to first unread message

Iuri Segtovich

unread,
Feb 17, 2017, 6:12:34 PM2/17/17
to diffpy-users
Hi, I would like to be able to create a .xyz file suitable to an atomistic classical molecular dynamics simulation of a "box" the size of a few unit cells of some crystalline solid, starting from a given .cif file from http://www.crystallography.net/cod/ for example.
I am writing to ask if this can be done automatically or semi-automatically using diffpy-structure, but also because I don't understand the logic behind a cif to xyz conversion under some space group and I would like directions to some book for some theoretical reference.
Thanks for your consideration.

Pavol Juhas

unread,
Feb 18, 2017, 8:18:22 PM2/18/17
to diffpy...@googlegroups.com
Hi Iuri,

diffpy.Structure includes a "transtru" utility which converts
between supported structure formats. Here is how to use it for
xyz conversion of the attached example sphalerite.cif

python -m diffpy.Structure.applications.transtru cif..xyz sphalerite.cif > zns.xyz

For CIF files the conversion to xyz format expands the asymmetric
unit and then writes out coordinates of all atoms in the unit cell.
To generate a box of several unit cells, say 2x2x2, you can use
the supercell expansion as follows:

# --------------------------------------------------------------
from diffpy.Structure import loadStructure
from diffpy.Structure.expansion import supercell
zns = loadStructure('sphalerite.cif')
zns222 = supercell(zns, [2, 2, 2])
zns222.write('zns222.xyz')
# --------------------------------------------------------------

Hope this helps,

Pavol
sphalerite.cif

Pavol Juhas

unread,
Feb 18, 2017, 8:23:49 PM2/18/17
to diffpy...@googlegroups.com
On Sat, Feb 18, 2017 at 08:18:19PM -0500, Pavol Juhas wrote:
...
> zns222.write('zns222.xyz')

Sorry - it should have been zns222.write('zns222.xyz', 'xyz')
The fixed conversion stanza is

# --------------------------------------------------------------
from diffpy.Structure import loadStructure
from diffpy.Structure.expansion import supercell
zns = loadStructure('sphalerite.cif')
zns222 = supercell(zns, [2, 2, 2])
zns222.write('zns222.xyz', 'xyz')
# --------------------------------------------------------------

Daniel Paley

unread,
Feb 18, 2017, 8:26:19 PM2/18/17
to diffpy-users
Hello,

Olex2 (olexsys.org) can generate an xyz file containing whatever atoms are currently on the screen. You can follow these steps:
-Open the cif file
-Use the tools under View--Symmetry Generation--Packing to generate enough atoms.
-Select and delete atoms (shift-click and drag; then type "kill" or fn-delete on a Mac) to trim down to the box that you need.
-Type "file name.xyz"

Best,
Dan

Iuri Segtovich

unread,
Feb 20, 2017, 9:16:22 PM2/20/17
to diffpy-users
Daniel, thank you for your suggestion, this seems like a manual but effective way to achieve the kind of file that I need.
Would you also recommend me to any reading material for theoretical reference on space groups, the cif to xyz conversion and the other information contained in cif files?
thanks for your consideration

Iuri Segtovich

unread,
Feb 20, 2017, 9:16:22 PM2/20/17
to diffpy-users, pju...@bnl.gov
Hi Pavol, thank you for your reply
I was able to follow your snippet and generate a xyz file for zns222
I was also able to do the same procedure with my personal cif file (see CS1.cif) ( CS1 methane hydrate from http://www.crystallography.net/cod/cod/4112809.html
 ), (see CS1lattice.png), however I still have problems regarding creation of a "box suitable to an atomistic classical molecular dynamics simulation "

1) in my case, the resulting box has a carbon atom coordinated by 12 hydrogen atoms (see badMETHANE.png) where there should be a methane molecule - i believe this means the code placed hydrogen atoms in every position where there might be a hydrogen atom, neglecting fractional occupancy, 

2) I want to run simulations using a software that will apply "periodic boundary conditions", therefore I  also need to make a box that has no atoms in a given boundary wall that would overlap with other boundary wall. (see good2d.png vs bad2d.png)

!) I don't yet understand the logic behind a cif to xyz conversion under some space group and I would really like directions to some book for some theoretical reference.

Thanks for your consideration again
CS1.cif
badMETHANE.png
CS1lattice.png
bad2d.png
good2d.png

Pavol Juhas

unread,
Feb 21, 2017, 12:32:10 PM2/21/17
to diffpy...@googlegroups.com
On Mon, Feb 20, 2017 at 01:27:22PM -0800, Iuri Segtovich wrote:
...
> 1) in my case, the resulting box has a carbon atom coordinated by 12
> hydrogen atoms (see badMETHANE.png) where there should be a methane
> molecule - i believe this means the code placed hydrogen atoms in every
> position where there might be a hydrogen atom, neglecting fractional
> occupancy,

Hi Yuri, Indeed. In an expanded unit cell the C1 site is coordinated
with 12 symmetry-equivalent H7 sites with an occupancy of 1/3 each -
producing a total stoichiometry "C1" 1 "H7" 4. The hydrogen occupancy
is lost when writing the xyz format, as xyz to my knowledge has no
support for occupancy information. To restore the correct
stoichiometry you'd need to come up with some rule to pick 4 out of 12
hydrogen neighbors at each C1 site and remove the excess sites. This
seems somewhat tricky because the 12 hydrogens are roughly at
icosahedral sites and do not form tetrahedron.

Here is a snippet to identify the 12-atom hydrogen neighborhood and
the H7-C1-H7 angles, however to design some selection rule is
up to you. :)

# --------------------------------------------------------------------
import numpy as np
from diffpy.srreal.bondcalculator import BondCalculator
from diffpy.Structure import loadStructure, Lattice

cs = loadStructure('CS1.cif')
c1sites = np.flatnonzero(cs.label.startswith('C1'))
# c1sites = array([230, 231])
ic1 = c1sites[0] # here ic1 = 230

bc = BondCalculator(rmax=1.3)
bc.setPairMask(ic1, 'all', True, others=False)
bc(cs)
# bonds are calculated in both directions.
# get indices of bonds that start at the explored C1 site
bidx = np.flatnonzero(bc.sites0 == ic1)
# Cartesian directions of the (C1-H7) vectors
chvec = bc.directions[bidx]
# get angles between the first C1-H7 vector an all others:
lat = Lattice()
print lat.angle(chvec[0], chvec)
# --------------------------------------------------------------------

> 2) I want to run simulations using a software that will apply "periodic
> boundary conditions", therefore I also need to make a box that has no
> atoms in a given boundary wall that would overlap with other boundary wall.
> (see good2d.png vs bad2d.png)

That is already done with the supercell function. All atoms should
have fractional coordinates in the [0, 1) semi-open interval in the
final-box structure. You can also verify if composition is correct
by checking `outstru.composition`; it would be noticeably off if
the boundary atoms were repeated.

> 3) I don't yet understand the logic behind a cif to xyz conversion under
> some space group and I would really like directions to some book for some
> theoretical reference.

diffpy.Structure expands the asymmetric unit in the CIF file to
a full unit cell with all the core and symmetry-related sites;
in other words it converts it to a P1 symmetry. The xyz output
then writes out the sites in Cartesian coordinates. Of
course, a plenty of fields (occupancies, ADPs, cell parameters,
space group) from the CIF file gets lost as there is no equivalent
for them in xyz format. Perhaps someone else in this group
might be aware of a book that deals with xyz format.

Hope this helps,

Pavol

--
Dr. Pavol Juhas
Computational Science Initiative
Brookhaven National Laboratory
P.O. Box 5000
Upton, NY 11973-5000
Reply all
Reply to author
Forward
0 new messages