QuantumWise Forum
May 19, 2013, 12:05 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: 1 [2]   Go Down
  Print  
Author Topic: Exporting electron density etc to XYZ file for plotting in other software  (Read 3792 times)
0 Members and 1 Guest are viewing this topic.
serhan
Heavy ATK user
***

Reputation: 1
Offline Offline

Posts: 98



View Profile WWW
« Reply #15 on: April 30, 2009, 21:56 »

Thank you very much.

Cheers,
Serhan
Logged

Serhanis Yamaclis

ad aperturam libri
serhan
Heavy ATK user
***

Reputation: 1
Offline Offline

Posts: 98



View Profile WWW
« Reply #16 on: July 14, 2009, 21:06 »

Hi all,

I'm trying to export electron density to file using the script given in this thread. I need to extract electron densities of lots of .nc files.

If the exportED.py is like this
Code:
scf=restoreSelfConsistenCalculation('/home/master/atk/1.nc')
electron_density=calculateElectronDensity(scf)
from export3d import *
export3D(electron_density)

And I execute this file as

/home/master/atk/atk /home/master/atk/exportED.py > /home/master/atk/electronDensity1.dat &

then, a file named electrondensity1.dat is successfully created in the directory. The code is excellent. However, I have dozens of .nc files of which the electron densities are to be extracted as:

1.nc -> electronDensity1.dat
2.nc -> electronDensity2.dat
.
.
.

etc. How can I achieve this as a batch mode instead of executing

/home/master/atk/atk /home/master/atk/exportED.py > /home/master/atk/electronDensity1.dat & (when 1.nc is pointed in exportED.py)
/home/master/atk/atk /home/master/atk/exportED.py > /home/master/atk/electronDensity2.dat & (when 2.nc is pointed in exportED.py)
.
.

etc. Any help is greatly appreciated  Wink

Cheers,
Serhan

« Last Edit: July 14, 2009, 21:08 by serhan » Logged

Serhanis Yamaclis

ad aperturam libri
Nordland
QuantumWise Staff
Supreme ATK Wizard
*****

Reputation: 14
Offline Offline

Posts: 730



View Profile
« Reply #17 on: July 14, 2009, 22:11 »

Dear Serhan.

I would do it like this.

Quote
import glob
import sys
from export3d import *
nc_files = glob.glob('*.nc')

for nc_file in nc_files:
    sys.stdout = file('electronDensity'+nc_file[:-3]+'.dat','w')
    scf=restoreSelfConsistenCalculation(nc_file)
    electron_density=calculateElectronDensity(scf)
    export3D(electron_density)
    sys.stdout.close()

Copy this script (call it serhan.py ) into the folder with all the nc-files in, and run it using atk serhan.py in that folder,
and wolla! Smiley No shell scripts needed Smiley

Edit: Ups - correct an error in the script.
« Last Edit: July 16, 2009, 13:19 by Nordland » Logged
Anders Blom
QuantumWise Staff
Supreme ATK Wizard
*****

Reputation: 36
Offline Offline

Denmark Denmark

Posts: 2802



View Profile WWW
« Reply #18 on: July 14, 2009, 22:19 »

There are a couple of ways to approach this.

You can handle the many files within the script itself, using the "glob" module. This is a bit more complex, however, so I'd recommend using simple bash looping.

To do this, first we need to modify the code slightly, so that we can pass the name of the NC file on the command line:

Code:
import sys
scf=restoreSelfConsistenCalculation(sys.argv[2])

Then, we execute the script as

Quote
for i in *.nc ; do atk exportED.py $i > electronDensity$i.dat ; done

You need to add paths etc. This has the slight disadvantage that the files will be called "electronDensity1.nc.dat". If you can live with that, all ok. If you prefer the filename "electronDensity1.dat", we just need to change it a bit:

Quote
for i in *.nc ; do j=`echo $i | sed 's/.nc//g'` ; atk exportED.py $i > $j.dat ; done
Logged
serhan
Heavy ATK user
***

Reputation: 1
Offline Offline

Posts: 98



View Profile WWW
« Reply #19 on: July 16, 2009, 07:27 »

Thank you very much for your answers. I could do it now.

Cheers,
Serhan
Logged

Serhanis Yamaclis

ad aperturam libri
Nordland
QuantumWise Staff
Supreme ATK Wizard
*****

Reputation: 14
Offline Offline

Posts: 730



View Profile
« Reply #20 on: July 16, 2009, 13:20 »

Serhan, I have correct a bug in my script, if you are using my script, look above for the modification.
Logged
Pages: 1 [2]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!