QuantumATK Forum

QuantumATK => Scripts, Tutorials and Applications => Topic started by: Anders Blom on December 5, 2008, 23:43

Title: Exporting XYZ files from VNL and ATK
Post by: Anders Blom on December 5, 2008, 23:43
A recent post (http://quantumwise.com/forum/index.php?topic=4.0) asked about importing XYZ files into VNL. Here is a way to export XYZ files from VNL! It is not possible as a direct function in the program, but it is relatively simple anyway, by using just a few lines of NanoLanguage code.

1. Open an editor (it can be the Script Editor in VNL) and make a NanoLanguage script that contains the following code:

Code
from ATK.KohnSham import *

def printXYZFile (configuration):
    elements = configuration.elements()
    coordinates = configuration.cartesianCoordinates()
    print len(elements)
    print 'From VNL'
    for elem,coords in zip(elements,coordinates):
        print elem.symbol(),
        for i in coords:
            print i.inUnitsOf(Angstrom),
        print

2. If you are using Windows, you first need to make a new directory called site-packages in the directory atk\lib in the VNL installation.

On Linux, this directory already exists, but is located in atk\lib\python2.4.

3. Save the file in the directory site-packages. Call it xyzexport.py for instance.

4. Now, assume we have a molecule in VNL, built e.g. in the Molecular Builder. Drag the molecule from the Molecular Builder to the Script Editor (make sure the editor is empty, in case you used it to create the script above). The corresponding NanoLanguage code will be shown in the editor. Now add these two lines at the bottom of the script:

Code
from xyzexport import printXYZFile
printXYZFile(molecule_configuration)

5. Drop the script on the Job Manager, and behold - an XYZ listing of the molecule will be printed in the Log Window. From there, you can just copy/paste the lines and save them as an XYZ file. (To copy lines from the Log Window, mark them and press Ctrl-C!)

In the future, whenever you want to export an XYZ file, you just follow steps 4 and 5 each time.

A ready file xyzexport.py is attached for convenience, you can copy it into the site-packages directory.

Title: Re: Exporting XYZ files from VNL and ATK
Post by: serhan on January 2, 2009, 21:00
Hi Dr. Blom,

I've tried the script for exporting atomic coordinates to a XYZ file. I tried it in this script:

Code
from ATK.TwoProbe import *
# Some sample data.
lattice_constant = 2.2 * Units.Ang
xy_padding = 2
electrode_deepth = 7
central_region_width = 4
wire_element = PeriodicTable.Lithium

# Setup an electrode.
electrode = PeriodicAtomConfiguration([[xy_padding, 0.0, 0.0] * lattice_constant,
                                       [0.0, xy_padding, 0.0] * lattice_constant,
                                       [0.0, 0.0, electrode_deepth] * lattice_constant],
                                       [wire_element]*electrode_deepth,
                                       [ (0,0,i+0.5)*lattice_constant for i in range(electrode_deepth)])
# Setup the twoprobe.
twoprobe = TwoProbeConfiguration([electrode,electrode],
                                 [wire_element]*central_region_width,
                                 [ (0,0,i)*lattice_constant for i in range(central_region_width)])
from xyztool import printXYZFile
printXYZFile(twoprobe)

The configuration is a 1-D chain that was sent by Nordland in another thread.

But I got these lines from ATK:

Quote
4
From VNL
Li 0.0 0.0 0.0
Li 0.0 0.0 2.2
Li 0.0 0.0 4.4
Li 0.0 0.0 6.6

It gives only the positions of the atoms in the channel, but how can we include the atoms of the electrodes as well?

Regards

Serhan
Title: Re: Exporting XYZ files from VNL and ATK
Post by: Anders Blom on January 2, 2009, 21:21
Fortunately, this is very easy! :)

Instead of calling the routine as

Code
printXYZFile(twoprobe)

as in the original example, you should instead use

Code
printXYZFile(twoprobe.equivalentBulkSystem())

One might argue that this should be done internally in the utility script, but sometimes it's nice to extract only the central region (for external relaxations, for instance), so I think it's easier this way, to let the user control it by this simple change in the call statement. The simpler the better, I think.
Title: Re: Exporting XYZ files from VNL and ATK
Post by: serhan on January 3, 2009, 06:49
Thanks  Dr. Blom  :)

Serhan