-
Notifications
You must be signed in to change notification settings - Fork 0
/
reindex.py
executable file
·141 lines (107 loc) · 5.09 KB
/
reindex.py
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
import xml.etree.ElementTree as ET
import numpy as np
import re, os, time
current_directory = os.getcwd()
root_name = current_directory.rpartition('/')
fichier_PES = root_name[2] + '_PES.xml'
#q20_spacing = 2
#q30_spacing = 2
#rowMax = 75
#-------------------------------------------------#
# Read in the XML data #
#-------------------------------------------------#
os.chdir("out-archive")
#infile = raw_input("\n Please list the name of the xml file: \n")
#tree = ET.parse( infile )
tree = ET.parse('%s' %fichier_PES)
root = tree.getroot()
os.chdir(os.pardir)
#-------------------------------------------------#
# Some useful modules #
#-------------------------------------------------#
def not_empty(chaine): return chaine != ''
def breakLine(element):
currentLine = re.split("\n",element)
brokenLine = re.split(" ",currentLine[0])
strippedLine = filter(not_empty, brokenLine)
return strippedLine
#-------------------------------------------------------------------------#
# Next you should form an array(?) of all the points as independent trees #
#-------------------------------------------------------------------------#
points = root.findall("./PES/point") # The xml tree 'points' contains addresses for each individual grid point
numPoints = len(points)
#----------------------------------------------------------------#
# Then, cycling through points, pick out multipole #
# moments, etc., and write to hfodd_path.d #
#----------------------------------------------------------------#
#print_array = ['Old file is being moved to new file']
qp_print_array = ['######']
out_print_array = ['#####']
rec_print_array = ['#####']
for point in points:
for line in point.iter('file'):
oldindex = line.get('name') # "nom" typically has the form "hfodd_000002.out"
# print(oldindex)
oldindex = oldindex.split('_')[1]
oldindex = oldindex.split('.')[0]
oldindex = int(oldindex)
for line in point.iter('constraint'):
qtype = line.get('type')
value = line.get('val')
value = re.search('\D\d*\.\d*',value).group(0)
# print(qtype, value)
if qtype == 'q20':
q20 = int(round(float(value),0))
elif qtype == 'q22':
q22 = int(round(float(value),0))
elif qtype == 'q30':
q30 = int(round(float(value),0))
else:
print 'Error!!'
# archiveIndex = (q30 / q30_spacing) * rowMax + (q20 / q20_spacing + 1)
# q30 = oldindex/rowMax * q30_spacing
# q20 = (oldindex - 1 - (oldindex/rowMax * rowMax) ) * q20_spacing
archiveIndex = str(q20).zfill(3) + str(q22).zfill(3) + str(q30).zfill(3)
oldRec = 'HFODD_' + str(oldindex).zfill(9) + '.REC'
archiveRec = 'HFODD_' + str(int(archiveIndex)).zfill(9) + '.REC-bak'
oldOut = 'hfodd_' + str(oldindex).zfill(9) + '.out'
archiveOut = 'hfodd_' + str(int(archiveIndex)).zfill(9) + '.out-bak'
oldQP = 'HFODD_' + str(oldindex).zfill(9) + '.QP'
archiveQP = 'HFODD_' + str(int(archiveIndex)).zfill(9) + '.QP-bak'
oldLoc = 'local_' + str(oldindex).zfill(9) + '.out'
archiveLoc = 'local_' + str(int(archiveIndex)).zfill(9) + '.out-bak'
# print oldQP, 'is being moved to', archiveQP
qpRow = 'mv ' + oldQP + ' ' + archiveQP
outRow = 'mv ' + oldOut + ' ' + archiveOut
recRow = 'mv ' + oldRec + ' ' + archiveRec
qp_print_array = np.vstack (( qp_print_array, qpRow ))
out_print_array = np.vstack (( out_print_array, outRow ))
rec_print_array = np.vstack (( rec_print_array, recRow ))
#----------------------------------------------------------------#
# Rename the .REC files, which are currently indexed #
# according to hfodd_path_new.d, according to their #
# new indices in hfodd_path.d #
#----------------------------------------------------------------#
# os.system('mv rec-archive/%s rec-archive/%s' %(oldRec, archiveRec))
# os.system('hsi "cd 294Og/3D/rec-archive/; cput rec-archive/%s : %s"' %(oldRec, oldRec))
# os.system('mv out-archive/%s out-archive/%s' %(oldOut, archiveOut))
# To remove four characters from the end of the string use ${var%????}
qp_print_array = qp_print_array.astype(str) # This converts the whole array back to the string, in case you decide you need it as float for some reason in between
out_print_array = out_print_array.astype(str)
rec_print_array = rec_print_array.astype(str)
col_width = max(len(word) for row in qp_print_array for word in row) + 1 # padding
data_file = open('qp-reindex.sh','w')
for row in qp_print_array:
data_file.write( "".join(word.center(col_width) for word in row) )
data_file.write('\n')
data_file.close()
data_file = open('out-reindex.sh','w')
for row in out_print_array:
data_file.write( "".join(word.center(col_width) for word in row) )
data_file.write('\n')
data_file.close()
data_file = open('rec-reindex.sh','w')
for row in rec_print_array:
data_file.write( "".join(word.center(col_width) for word in row) )
data_file.write('\n')
data_file.close()