3 |
|
import logging |
4 |
|
import os |
5 |
|
import subprocess |
6 |
+ |
import logging |
7 |
|
|
8 |
|
fraw_list = []#List of all .md files found (even the includes). |
9 |
|
fmd_list = []#List of all config .md files that can be run (not the includes). |
13 |
|
dir_openmd = ""#Absolute path for openmd |
14 |
|
dir_base = ""#Directory where the script is run from. |
15 |
|
|
16 |
+ |
FORMAT = '%(asctime)-15s %(message)s' |
17 |
+ |
logging.basicConfig(format=FORMAT) |
18 |
+ |
|
19 |
|
""" |
20 |
|
Function sets up the dir_base and dir_openmd. If an openmd executable is not |
21 |
|
found, script exits. Function looks for the openmd in the relative location |
24 |
|
""" |
25 |
|
def setupDirectories(): |
26 |
|
global dir_base, dir_openmd, dir_cwd |
27 |
+ |
logger = logging.getLogger("tcpserver") |
28 |
|
dir_base = os.getcwd() |
29 |
|
if(os.path.isfile("../build/bin/openmd")): |
30 |
< |
os.chdir("../build/bin/") |
31 |
< |
dir_openmd = os.getcwd() |
32 |
< |
os.chdir(dir_base) |
30 |
> |
dir_openmd = os.path.abspath("../build/bin/openmd") |
31 |
> |
elif(os.path.isfile("../bin/openmd")): |
32 |
> |
dir_openmd = os.path.abspath("../bin/openmd") |
33 |
|
else: |
34 |
< |
print "OpenMD executable not found." |
34 |
> |
logger.error("OpenMD : %s", "openmd executable not found at the expected location. Script Will Quit...") |
35 |
|
sys.exit() |
36 |
+ |
forcefld_path = os.path.abspath("../forceFields") |
37 |
+ |
os.environ["FORCE_PARAM_PATH"] = forcefld_path |
38 |
|
|
32 |
– |
|
39 |
|
""" |
40 |
|
Function checks if the sample_file and validate_file (.md files) have the same |
41 |
|
statusTime = interval time for the stats file. |
51 |
|
validate_status_time = 0 |
52 |
|
validate_sample_time = 0 |
53 |
|
validate_run_time = 0 |
54 |
< |
|
54 |
> |
logger = logging.getLogger("tcpserver") |
55 |
> |
|
56 |
|
samplefh = open(sample_file, "r") |
57 |
|
validatefh = open(validate_file, "r") |
58 |
|
|
93 |
|
if (sample_status_time > 0) or (validate_status_time > 0): |
94 |
|
if sample_status_time == validate_status_time: |
95 |
|
return True |
89 |
– |
else: |
90 |
– |
return False |
96 |
|
|
97 |
|
if (sample_sample_time > 0) or (validate_sample_time > 0): |
98 |
|
if sample_sample_time == validate_sample_time: |
99 |
|
return True |
95 |
– |
else: |
96 |
– |
return False |
100 |
|
|
101 |
|
if (sample_run_time > 0) or (validate_run_time > 0): |
102 |
|
if sample_run_time == validate_run_time: |
103 |
|
return True |
101 |
– |
else: |
102 |
– |
return False |
104 |
|
|
105 |
+ |
logger.warning("MD File: %s", "Sample/Validation times do not match.") |
106 |
|
return False |
107 |
|
|
108 |
|
""" |
138 |
|
""" |
139 |
|
Function compares two files. |
140 |
|
@author Samuel Njoroge and (). |
141 |
< |
@param string fExpected - name of the expected file. |
142 |
< |
@param string fNew - name of the new test file. |
141 |
> |
@param string fExpected - name of the validation file. |
142 |
> |
@param string fNew - name of the file to validate. |
143 |
|
@param float epsilon - Precision of the comparison of the files. |
144 |
|
@param boolean ignore_sign - if sign will be a factor in comparing the digits. |
145 |
|
@return boolean |
146 |
|
""" |
147 |
|
def compare(fExpected, fNew, epsilon = 0.00001, ignore_sign=False): |
148 |
+ |
logger = logging.getLogger("tcpserver") |
149 |
|
fone = open(fExpected, 'r') |
150 |
|
ftwo = open(fNew, 'r') |
151 |
|
|
165 |
|
|
166 |
|
if lenone != lentwo: |
167 |
|
diffs = diffs + 1 |
168 |
< |
print "Line " + str(i) + " do not match in the files." |
168 |
> |
logger.warning("Line: %d - %s", i, "no mach") |
169 |
|
return True |
170 |
|
else: |
171 |
|
for j in range(lenone): |
222 |
|
@author Samuel Njoroge |
223 |
|
""" |
224 |
|
def runMdFiles(): |
225 |
+ |
logger = logging.getLogger("tcpserver") |
226 |
|
global dir_base, dir_openmd, dir_cwd |
227 |
|
output = [] |
228 |
|
for x in range(0, len(fmd_list)): |
225 |
– |
#subprocess.call(["export FORCE_PARAM_PATH=/Users/snjoroge/Documents/openmd/development/forceFields"]) |
229 |
|
if "argon" in fmd_list[x]: |
230 |
< |
print "Switching to Directory: " + os.path.dirname(fmd_list[x]) |
230 |
> |
logger.debug("Switching to Directory: %s", os.path.dirname(fmd_list[x])) |
231 |
|
os.chdir(os.path.dirname(fmd_list[x])) |
232 |
< |
print "Running file: " + fmd_list[x] |
232 |
> |
logger.debug("Running: %s", fmd_list[x]) |
233 |
|
output = subprocess.call([dir_openmd + "/openmd", fmd_list[x]]) |
234 |
< |
if(os.path.exists(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat")): |
234 |
> |
if(os.path.exists(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat") and os.path.exists(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + "_v.stat")): |
235 |
|
#print "Renaming File: " + fmd_base_list[x] + ".stat - " + fmd_base_list[x] + "_v.stat" |
236 |
|
#subprocess.call(["cp", os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat", os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + "_v.stat"]) |
237 |
< |
print "Comparing: " + fmd_base_list[x] + ".stat <=> " + fmd_base_list[x] + "_v.stat" |
238 |
< |
if(compare(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat", os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + "_v.stat")): |
239 |
< |
print "Files Do not match." |
237 |
> |
logger.debug("Comparing: %s", "Comparing: " + fmd_base_list[x] + ".stat <=> " + fmd_base_list[x] + "_v.stat") |
238 |
> |
if(compare(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat", os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + "_v.stat")): |
239 |
> |
logger.warning("Files: Files do not match.") |
240 |
|
else: |
241 |
< |
print "Files match." |
241 |
> |
logger.debug("Files Match") |
242 |
> |
else: |
243 |
> |
logger.warning("Stat Files: one of the files was not found: %s \n %s", os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat", os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + "_v.stat") |
244 |
> |
|
245 |
> |
if(os.path.exists(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".eor") and os.path.exists(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + "_v.eor")): |
246 |
> |
#print "Renaming File: " + fmd_base_list[x] + ".stat - " + fmd_base_list[x] + "_v.stat" |
247 |
> |
#subprocess.call(["cp", os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat", os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + "_v.stat"]) |
248 |
> |
logger.debug("Comparing: %s", "Comparing: " + fmd_base_list[x] + ".eor <=> " + fmd_base_list[x] + "_v.eor") |
249 |
> |
if(compare(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".eor", os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + "_v.eor")): |
250 |
> |
logger.warning("Files: Files do not match.") |
251 |
> |
else: |
252 |
> |
logger.debug("Files Match") |
253 |
> |
else: |
254 |
> |
logger.warning("Eor Files: one of the files was not found: %s \n %s", os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".eor", os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + "_v.eor") |
255 |
|
os.chdir(dir_base) |
256 |
|
|
257 |
|
def cleanUp(): |
258 |
< |
print "delete all files generated so not to commit" |
258 |
> |
print "Delete all files generated." |
259 |
|
for x in range(0, len(fmd_list)): |
260 |
< |
print "DELETE:" + os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".eor" |
261 |
< |
os.remove(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".eor") |
262 |
< |
print "DELETE:" + os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat" |
263 |
< |
os.remove(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat") |
264 |
< |
print "DELETE:" + os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".dump" |
265 |
< |
os.remove(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".dump") |
260 |
> |
if(os.path.exists(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".eor")): |
261 |
> |
print "DELETE:" + os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".eor" |
262 |
> |
os.remove(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".eor") |
263 |
> |
if(os.path.exists(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat")): |
264 |
> |
print "DELETE:" + os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat" |
265 |
> |
os.remove(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat") |
266 |
> |
if(os.path.exists(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".dump")): |
267 |
> |
print "DELETE:" + os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".dump" |
268 |
> |
os.remove(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".dump") |
269 |
> |
|
270 |
> |
""" |
271 |
> |
Function compares .eor files. It compares sections <StuntDoubles> for position and section <FrameData> for time. |
272 |
> |
@author Samuel Njoroge and Dr. Charles Vardeman |
273 |
> |
@param string file_validate - name of the validation file. |
274 |
> |
@param string file_validate - name of the file to validate. |
275 |
> |
@param float epsilon - Precision of the comparison of the files. |
276 |
> |
@param boolean ignore_sign - if sign will be a factor in comparing the digits. |
277 |
> |
@return boolean |
278 |
> |
""" |
279 |
> |
def compareEor(file_validate, file_new, epsilon = 0.00001, ignore_sign=False): |
280 |
> |
logger = logging.getLogger("tcpserver") |
281 |
> |
handlerv = open(file_validate, 'r')#Validate file handler. |
282 |
> |
handlern = open(file_new, 'r')#New file handler. |
283 |
|
|
284 |
+ |
#Variables. |
285 |
+ |
indexv = indexn = 0 |
286 |
+ |
xv = xn = 0.0 |
287 |
+ |
yv = yn = 0.0 |
288 |
+ |
zv = zn = 0.0 |
289 |
+ |
|
290 |
+ |
#Read first line. |
291 |
+ |
linev = handlerv.readline() |
292 |
+ |
linen = handlern.readline() |
293 |
+ |
|
294 |
+ |
while linev: |
295 |
+ |
if '<StuntDoubles>' in linev: |
296 |
+ |
linev = handlerv.readline() |
297 |
+ |
linen = handlern.readline() |
298 |
+ |
while 2: |
299 |
+ |
Lv = linev.split() |
300 |
+ |
Ln = linen.split() |
301 |
+ |
|
302 |
+ |
#If any of these fail, then the files do not match line by line. |
303 |
+ |
try: |
304 |
+ |
indexv = int(Lv[0]) |
305 |
+ |
indexn = int(Ln[0]) |
306 |
+ |
xv = float(Lv[2]) |
307 |
+ |
yv = float(Lv[3]) |
308 |
+ |
zv = float(Lv[4]) |
309 |
+ |
xn = float(Ln[2]) |
310 |
+ |
yn = float(Ln[3]) |
311 |
+ |
zn = float(Ln[4]) |
312 |
+ |
except: |
313 |
+ |
logger.warning("Format: files do not follow the same format \n '%s' \n '%s'", linev.strip(), linen.strip()) |
314 |
+ |
return True |
315 |
+ |
|
316 |
+ |
if indexv != indexn: |
317 |
+ |
logger.warning("Indexes do not match: %d | %d", indexv, indexn) |
318 |
+ |
|
319 |
+ |
fediff = absDiff(xv, xn, ignore_sign) |
320 |
+ |
if fediff > epsilon: |
321 |
+ |
logger.warning("Line: position x on index %d do not match", indexv) |
322 |
+ |
return True |
323 |
+ |
|
324 |
+ |
fediff = absDiff(yv, yn, ignore_sign) |
325 |
+ |
if fediff > epsilon: |
326 |
+ |
logger.warning("Line: position y on index %d do not match", indexv) |
327 |
+ |
return True |
328 |
+ |
|
329 |
+ |
fediff = absDiff(zv, zn, ignore_sign) |
330 |
+ |
if fediff > epsilon: |
331 |
+ |
logger.warning("Line: position z on index %d do not match", indexv) |
332 |
+ |
return True |
333 |
+ |
|
334 |
+ |
linev = handlerv.readline() |
335 |
+ |
linen = handlern.readline() |
336 |
+ |
|
337 |
+ |
if '</StuntDoubles>' in linev: |
338 |
+ |
break |
339 |
+ |
elif '<FrameData>' in linev: |
340 |
+ |
|
341 |
+ |
linev = handlerv.readline() |
342 |
+ |
linen = handlern.readline() |
343 |
+ |
|
344 |
+ |
while 1: |
345 |
+ |
if 'Time' in linev: |
346 |
+ |
Ltv = linev.split(':') |
347 |
+ |
Ltn = linen.split(':') |
348 |
+ |
|
349 |
+ |
if int(Ltv[1]) != int(Ltn[1]): |
350 |
+ |
logger.warning("Time: FrameData time does not match.") |
351 |
+ |
return True |
352 |
+ |
elif '</FrameData>' in linev: |
353 |
+ |
break |
354 |
+ |
linev = handlerv.readline() |
355 |
+ |
linen = handlern.readline() |
356 |
+ |
|
357 |
+ |
linev = handlerv.readline() |
358 |
+ |
linen = handlern.readline() |
359 |
+ |
return False |
360 |
+ |
|