ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/validation/comp_md.py
(Generate patch)

Comparing branches/development/validation/comp_md.py (file contents):
Revision 1659 by chuckv, Thu Nov 3 13:16:29 2011 UTC vs.
Revision 1661 by chuckv, Mon Nov 7 13:05:14 2011 UTC

# Line 3 | Line 3 | import subprocess
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).
# Line 12 | Line 13 | dir_base = ""#Directory where the script is run from.
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
# Line 20 | Line 24 | def setupDirectories():
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)
33 +        elif(os.path.isfile("../bin/openmd")):
34 +                os.chdir("../bin/")
35 +                dir_openmd = os.getcwd()
36 +                os.chdir(dir_base)      
37          else:
38 <                print "OpenMD executable not found."
38 >                logger.error("OpenMD : %s", "openmd executable not found at the expected location. Script Will Quit...")
39                  sys.exit()
40 +        forcefld_path = os.path.abspath("../forceFields")
41 +        os.environ["FORCE_PARAM_PATH"] = forcefld_path
42          
32        
43   """
44   Function checks if the sample_file and validate_file (.md files) have the same
45   statusTime = interval time for the stats file.
# Line 45 | Line 55 | def validate_md_time(sample_file, validate_file):
55    validate_status_time = 0
56    validate_sample_time = 0
57    validate_run_time = 0
58 <  
58 >  logger = logging.getLogger("tcpserver")
59 >
60    samplefh = open(sample_file, "r")
61    validatefh = open(validate_file, "r")
62    
# Line 86 | Line 97 | def validate_md_time(sample_file, validate_file):
97    if (sample_status_time > 0) or (validate_status_time > 0):
98      if sample_status_time == validate_status_time:
99        return True
89    else:
90      return False
100  
101    if (sample_sample_time > 0) or (validate_sample_time > 0):
102      if sample_sample_time == validate_sample_time:
103        return True
95    else:
96      return False
104  
105    if (sample_run_time > 0) or (validate_run_time > 0):
106      if sample_run_time == validate_run_time:
107        return True
101    else:
102      return False
108  
109 +  logger.warning("MD File: %s", "Sample/Validation times do not match.")
110    return False
111    
112   """
# Line 143 | Line 149 | def compare(fExpected, fNew, epsilon = 0.00001, ignore
149   @return boolean
150   """
151   def compare(fExpected, fNew, epsilon = 0.00001, ignore_sign=False):
152 +        logger = logging.getLogger("tcpserver")
153          fone = open(fExpected, 'r')
154          ftwo = open(fNew, 'r')
155  
# Line 162 | Line 169 | def compare(fExpected, fNew, epsilon = 0.00001, ignore
169  
170                  if lenone != lentwo:
171                          diffs = diffs + 1
172 <                        print "Line " + str(i) + " do not match in the files."
172 >                        logger.warning("Line: %d - %s", i, "no mach")
173                          return True
174                  else:
175                          for j in range(lenone):
# Line 219 | Line 226 | def runMdFiles():
226   @author Samuel Njoroge
227   """
228   def runMdFiles():
229 +        logger = logging.getLogger("tcpserver")
230          global dir_base, dir_openmd, dir_cwd
231          output = []
232          for x in range(0, len(fmd_list)):
233                  #subprocess.call(["export FORCE_PARAM_PATH=/Users/snjoroge/Documents/openmd/development/forceFields"])
234                  if "argon" in fmd_list[x]:
235 <                        print "Switching to Directory: " + os.path.dirname(fmd_list[x])
235 >                        logger.debug("Switching to Directory: %s", os.path.dirname(fmd_list[x]))
236                          os.chdir(os.path.dirname(fmd_list[x]))
237 <                        print "Running file: " + fmd_list[x]
237 >                        logger.debug("Running: %s", fmd_list[x])
238                          output = subprocess.call([dir_openmd + "/openmd", fmd_list[x]])
239                          if(os.path.exists(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat")):
240                                  #print "Renaming File: " + fmd_base_list[x] + ".stat - " + fmd_base_list[x] + "_v.stat"
241                                  #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"])
242 <                                print "Comparing: " + fmd_base_list[x] + ".stat <=> " + fmd_base_list[x] + "_v.stat"
242 >                                logger.debug("Comparing: %s", "Comparing: " + fmd_base_list[x] + ".stat <=> " + fmd_base_list[x] + "_v.stat")
243                                  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")):
244 <                                        print "Files Do not match."
244 >                                        logger.warning("Files: %s", "Files do not match.")
245                                  else:
246 <                                        print "Files match."
246 >                                        logger.debug("Files Match")
247                  os.chdir(dir_base)
248  
249   def cleanUp():
250 <        print "delete all files generated so not to commit"
250 >        print "Delete all files generated."
251          for x in range(0, len(fmd_list)):
252 <                print "DELETE:" + os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".eor"
253 <                os.remove(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".eor")
254 <                print "DELETE:" + os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat"
255 <                os.remove(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat")
256 <                print "DELETE:" + os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".dump"
257 <                os.remove(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".dump")
252 >                if(os.path.exists(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".eor")):
253 >                        print "DELETE:" + os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".eor"
254 >                        os.remove(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".eor")
255 >                if(os.path.exists(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat")):
256 >                        print "DELETE:" + os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat"
257 >                        os.remove(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".stat")
258 >                if(os.path.exists(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".dump")):
259 >                        print "DELETE:" + os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".dump"
260 >                        os.remove(os.path.dirname(fmd_list[x]) + "/" + fmd_base_list[x] + ".dump")
261          

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines