File: writeHIST.py

package info (click to toggle)
abinit 9.10.4-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 518,712 kB
  • sloc: xml: 877,568; f90: 577,240; python: 80,760; perl: 7,019; ansic: 4,585; sh: 1,925; javascript: 601; fortran: 557; cpp: 454; objc: 323; makefile: 77; csh: 42; pascal: 31
file content (96 lines) | stat: -rwxr-xr-x 3,424 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Abinit Post Process Application
author: Martin Alexandre
last edited: May 2013
"""

import sys,os,commands
import string, math, shutil
from scipy.io import netcdf
import numpy as np

class writeHIST:

    def __init__(self,pfile,pname,pni,pnf):
        self.namefile = pname
        self.file     = pfile
        self.ni       = pni
        self.nf       = pnf
        self.write()

    def write(self):
        
#       Copy _OUT.nc file
        name_out_nc = str(self.file.getNameFile(fullpath=True)).replace('_HIST','_OUT.nc')
        self.new_out_nc = str(self.namefile).replace('_HIST','_OUT.nc')
        shutil.copyfile(name_out_nc,self.new_out_nc)

#       Creation of new HIST file
        f = netcdf.netcdf_file(self.namefile, 'w')

#       dimensions:
        f.createDimension('natom',self.file.getNatom()) 
        f.createDimension('xyz',3) 
        f.createDimension('time',self.file.getNbStep())
        f.createDimension('six', 6) 

#       variables:
        xcart = f.createVariable('xcart','d',('time','natom','xyz'))
        xcart[:,:,:] = self.file.xcart[self.ni-1:self.nf,0]
        xcart.units = "bohr"
        xcart.mnemonics = "vectors (X) of atom positions in CARTesian coordinates" ;

        xred = f.createVariable('xred','d',('time','natom','xyz'))
        xred[:,:,:] = self.file.xred[self.ni-1:self.nf,0]
        xred.units = "dimensionless" ;
        xred.mnemonics = "vectors (X) of atom positions in REDuced coordinates" ;

        fcart = f.createVariable('fcart','d',('time','natom','xyz'))
        fcart[:,:,:] = self.file.fcart[self.ni-1:self.nf,0]
        fcart.units = "Ha/bohr" ;
        fcart.mnemonics = "atom Forces in CARTesian coordinates" ;

        fred = f.createVariable('fred','d',('time','natom','xyz'))
        fred[:,:,:] = self.file.fred[self.ni-1:self.nf,0]
        fred.units = "dimensionless" ;
        fred.mnemonics = "atom Forces in REDuced coordinates" ;

        vel = f.createVariable('vel','d',('time','natom','xyz'))
        vel[:,:,:] = self.file.vel[self.ni-1:self.nf,0]
        vel.units = "bohr*Ha/hbar" ;
        vel.mnemonics = "VELocity" ;

        acell = f.createVariable('acell','d',('time','xyz'))
        acell[:,:] = self.file.acell[self.ni-1:self.nf,0]
        acell.units = "bohr" ;
        acell.mnemonics = "CELL lattice vector scaling" ;

        rprimd = f.createVariable('rprimd','d',('time','xyz','xyz'))
        rprimd[:,:,:] = self.file.rprimd[self.ni-1:self.nf,0]
        rprimd.units = "bohr" ;
        rprimd.mnemonics = "Real space PRIMitive translations, Dimensional" ;

        etotal = f.createVariable('etotal','d',('time',))
        etotal[:] = self.file.E_pot[self.ni-1:self.nf]
        etotal.units = "Ha" ;
        etotal.mnemonics = "TOTAL Energy" ;

        ekin = f.createVariable('ekin','d',('time',))
        ekin[:] = self.file.E_kin_ion[self.ni-1:self.nf]
        ekin.units = "Ha" ;
        ekin.mnemonics = "Energy KINetic ionic" ;

        mdtime = f.createVariable('mdtime','d',('time',))
        mdtime[:] = self.file.mdtime[self.ni-1:self.nf]
        mdtime.units = "hbar/Ha" ;
        mdtime.mnemonics = "Molecular Dynamics TIME" ;

        strten = f.createVariable('strten','d',('time','six'))
        strten[:,:] = self.file.stress[self.ni-1:self.nf,0]
        strten.units = "Ha/bohr^3" ;
        strten.mnemonics = "STRess tensor" ;

        f.close()