Révision 10

analysis/MeanRhoH2O_z.py (revision 10)
1
######################################################################################## 
2
#       Python script to calculate the mean density of a 			       #
3
#	       H2O along z. 							       #
4
#										       #
5
#       Written by Rodrigo F. de Morais                                                #
6
#       Date: 08/04/2016                                                               #
7
#       Updated: 25/04/2016      						       #
8
########################################################################################
9

  
10
#!/usr/bin/python
11

  
12
import sys
13
from numpy import sqrt
14
from netCDF4 import Dataset
15

  
16
###################### Functions #############################################
17

  
18

  
19
#----------------------------------------------------------------------------
20
#
21
########################### Main code #######################################
22

  
23
#---Definition of variables---
24

  
25
# ---Definition of code inicialiazation---
26
try:
27
   type=sys.argv[1] # Name of the PDB file to read
28
   type=sys.argv[2] # Traj file
29

  
30
except:
31
    print '----------------------------------------------------------------------'
32
    print 'The correct use of this script is:    '
33
    print 'python MeanRhoH2O_z.py prmtop mdcrd' 
34
    print '----------------------------------------------------------------------'
35
    sys.exit(2)
36

  
37

  
38
# ----------- Read Topology file
39

  
40
file=open(sys.argv[1],"r")
41
linhas=file.readlines()
42
file.close()
43

  
44

  
45
# ----------- Get total atoms
46

  
47
for i in range(0,len(linhas)):
48
	if len(linhas[i].split())>0 and linhas[i].split()[0]=='%FLAG':
49
		if linhas[i].split()[1]=='POINTERS':
50
			n_atoms = linhas[i+2].split()[0] 
51
			break
52

  
53
for i in range(0,len(linhas)):
54
        if len(linhas[i].split())>0 and linhas[i].split()[0]=='%FLAG':
55
                if linhas[i].split()[1]=='ATOM_NAME':
56
                        inicio=i+1
57
        if len(linhas[i].split())>0 and linhas[i].split()[0]=='%FLAG':
58
                if linhas[i].split()[1]=='CHARGE':
59
                        fim=i-1
60
			break
61

  
62
AtomNames=[]
63
PosOAtoms=[]
64
PosPtAtoms=[]
65

  
66
# ------------ Get the position of O and Pt atoms
67

  
68
for i in range(inicio+1,fim):
69
	for j in range(0,20):
70
		AtomNames.append(linhas[i].split()[j])
71

  
72
for j in range(0,len(linhas[fim].split())):
73
                AtomNames.append(linhas[fim].split()[j])
74

  
75
for j in range(0,len(AtomNames)):
76
	if AtomNames[j]=='O':
77
		PosOAtoms.append(j)
78
	if AtomNames[j]=='Pt' or AtomNames[j]=='PU':
79
		PosPtAtoms.append(j)
80

  
81
#---------- Open the traj file in netcdf format
82

  
83
file=Dataset(sys.argv[2],"r",format='NETCDF4')
84

  
85
faixa=18.0
86
step=0.25
87
volume=24.031*19.424*step
88

  
89
goz=[0]*int(faixa/step)
90

  
91
zmax=0.0
92

  
93
for j in range(0,len(PosPtAtoms)):
94
		if zmax<float(file.variables['coordinates'][0][PosPtAtoms[j]][2]):
95
                       zmax=float(file.variables['coordinates'][0][PosPtAtoms[j]][2])
96

  
97
for i in range(0,len(file.variables['time'])/100): 
98

  
99
  CoordOtempz=[]
100

  
101
  for k in range(0,len(PosOAtoms)):
102
	CoordOtempz.append(float(file.variables['coordinates'][i*100][PosOAtoms[k]][2]))
103

  
104
  for j in range(0,int(faixa/step)):
105
	temp=0.0
106
	pos=0.0
107
	for k in range(0,len(CoordOtempz)):
108
		if CoordOtempz[k]>=zmax+step*(j-1) and CoordOtempz[k] <zmax+step*(j):
109
				temp=temp+1
110

  
111
	if temp>0:
112
		goz[j]=goz[j]+temp/volume
113

  
114
FFile=open('goz',"w\n")
115
for i in range(0,len(goz)):
116
	FFile.write("%6.3f %6.3f %6.3f %6.3f\n" %(step*i,goz[i]/(len(file.variables['time'])/100)/0.033))
117

  
118
FFile.close()
119

  
120
file.close()
121

  
122
#----------------------------------------------------------------------------
0 123

  

Formats disponibles : Unified diff