forked from davidsousarj/GPFPlot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpfplot_figure.py
More file actions
150 lines (118 loc) · 4.37 KB
/
Copy pathgpfplot_figure.py
File metadata and controls
150 lines (118 loc) · 4.37 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#! /usr/bin/env python3.8
#
# GPFPlot Figure Generation
# Created by David W. O. de Sousa, david.sousarj@yahoo.com.br
# Version 0.2.1, February 2025.
#
# Imports and functions ################################################
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import gridspec
# Uncomment the lines below if gpfplot_figure.py is not in the GPFPlot
# parent directory. Edit the variable GPFPATH adequately.
#GPFPATH = "/home/david/bin/gpfplot-0.2.1"
#import sys
#sys.path.append(GPFPATH)
from core.parse_input import *
from core.parse_vb import parse_geom
from core.plot_utils import Plot_Function, Plot_Settings
from core.operations import RAng
# Read variables #######################################################
figure_name = "C2H4_sigmaCC"
n_cols = 3
n_rows = 1
# List of *.txt and *.gpfplot files to open
p_list = ["example_fig1", "example_fig2", "example_fig3"]
# Title of every plot
titles = ["\\rho^{INT}", "\\rho^{QC}", "\\rho^{TOT}"]
# Superior Title
suptitle = "C_2 H_4\ \sigma(C-C)\ Density\ Partitioning"
# print size of each graph in inches
p_size = 3
# Dots per inch (resolution)
DPI = 300
# Generate EPS vector
EPS = True
# Create Figure ########################################################
fig = plt.figure(figsize=(1 + p_size*n_cols, p_size*n_rows))
gs = gridspec.GridSpec(n_rows, n_cols)
axes = []
for i in range(n_rows):
for j in range(n_cols):
axes.append( plt.subplot(gs[i,j]) )
suptitle = r"$\mathdefault{" + suptitle + "}$"
titles=[ r"$\mathdefault{" + i + "}$" for i in titles]
# For each p_list object ###############################################
for i in range(len(p_list)):
# Parse text grids
f = open(p_list[i]+".txt")
ln = f.readline()
ln = f.readline()
out_file = ln[23:-1]
ln = f.readline()
#dens_file = ln[23:-1]
ln = f.readline()
gpf_file = ln[23:-1]
ln = f.readline()
mode = ln[2:-1]
ln = f.readline()
plane = ln[9:11]
ln = f.readline()
Xrng = ln[11:-1]
ln = f.readline()
Yrng = ln[11:-1]
ln = f.readline()
offset = float( ln[11:-1] )
ln = f.readline()
gridp = int( ln[13:].split("x")[0] )
f.close()
Xlim = tuple(map(float, Xrng.replace("(","").replace(")","").split(",")))
Ylim = tuple(map(float, Yrng.replace("(","").replace(")","").split(",")))
XX = np.linspace(Xlim[0], Xlim[1], gridp)
YY = np.linspace(Ylim[0], Ylim[1], gridp)
X, Y = np.meshgrid(XX, YY)
PSI = np.loadtxt(p_list[i]+".txt", skiprows=10)
mode0 = mode.split(" ")[0]
gpf_text = open(gpf_file,'r').read().split('\n')
c_fill, color_f, c_lines, color_l, c_label,\
min_c, max_c, nconts, auto_c,\
p_unit, draw_atom, draw_name = parse3(gpf_text, mode0)
out_text = open(out_file,'r').readlines()
NATOMS, CHARGE, ATOMS, R = parse_geom(out_text)
# in Plot_Settings grid enters in bohrs
X /= RAng; Y /= RAng
Atom_posx, Atom_posy, Atom_labl,\
label_x, label_y, X, Y = Plot_Settings(ATOMS, NATOMS, R,
draw_atom, plane, offset,
p_unit, X, Y)
Plot_Function(axes[i], c_fill, color_f, c_lines, color_l, c_label,
min_c, max_c, nconts, auto_c, p_unit,
draw_atom, draw_name, Atom_posx, Atom_posy,
Atom_labl, label_x, label_y, X, Y, PSI, 1)
axes[i].text(np.median(XX), Ylim[1]-0.1, titles[i],
verticalalignment='top',
horizontalalignment='center',
fontsize=14)
# for all rows except the last one
if i < (n_cols)*(n_rows-1):
plt.setp(axes[i].get_xticklabels(), visible=False)
axes[i].set_xlabel("")
# for all columns except the first one
if i not in list(range(0, n_cols*n_rows, n_cols)):
plt.setp(axes[i].get_yticklabels(), visible=False)
axes[i].set_ylabel("")
print( p_list[i]+" PLOTTED." )
#end
fig.suptitle(suptitle, fontsize=16)
plt.tight_layout()
# Manual adjustments ###################################################
fig.subplots_adjust(left=0.08)
fig.subplots_adjust(bottom=0.08)
fig.subplots_adjust(right=0.96)
fig.subplots_adjust(top=0.92)
fig.subplots_adjust(wspace=0.16)
fig.subplots_adjust(hspace=0.17)
########################################################################
fig.savefig("%s.png" %figure_name, dpi=300)
fig.savefig("%s.eps" %figure_name, dpi=300)
plt.show()