viz_output.py 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  1. import os
  2. from testutils import assertFileExists
  3. from testutils import assertFileNotExists
  4. from testutils import assertFileNonempty
  5. from testutils import assertFileSymlink
  6. from testutils import assertFileDir
  7. from testutils import safe_concat
  8. ###################################################################
  9. # Give an error if the specified ASCII viz file is invalid, according to the
  10. # specified parameters.
  11. #
  12. # Parameters:
  13. # fname - the filename to check
  14. # sstates - allowed surface states, or None to skip id validation
  15. # vstates - allowed volume states, or None to skip id validation
  16. #
  17. # Example usage:
  18. # assertValidVizFileAscii("viz_dat/molecules.0.dat", [1, 2, 3], [3, 4, 5])
  19. #
  20. # This will complain if the ASCII-format viz output file is
  21. # malformed, or if any surface molecules are emitted with states
  22. # other than 1, 2, or 3 (or, alternatively, if any volume molecules
  23. # are emitted with a normal vector). Likewise, it will complain if
  24. # any volume molecules are emitted with states other than 3, 4, or 5,
  25. # or if any surface molecules are emitted with normals of 0, 0, 0.
  26. #
  27. # assertValidVizFileAscii("viz_dat/molecules.0.dat")
  28. #
  29. # The above invocation will check only for validity, ignoring the
  30. # molecule state values.
  31. ###################################################################
  32. def assertValidVizFileAscii(fname, sstates=None, vstates=None):
  33. try:
  34. got_contents = open(fname).read()
  35. except:
  36. assert False, "Expected ASCII viz output file '%s' was not created" % fname
  37. # Rend file into tiny pieces
  38. lines = [l for l in got_contents.split('\n') if l != '']
  39. # Check each line
  40. idx = 1
  41. for idx in range(len(lines)):
  42. l = lines[idx]
  43. v = l.split()
  44. # Check number of columns
  45. assert len(v) == 8, "In ASCII viz output file '%s', line %d is malformed (%d columns instead of 8)" % (fname, idx + 1, len(v))
  46. # Check format of columns
  47. try:
  48. float(v[1])
  49. float(v[2])
  50. float(v[3])
  51. except:
  52. assert False, "In ASCII viz output file '%s', line %d, position is malformed (was %s %s %s, should be a triple of floating point values)" % (fname, idx + 1, v[1], v[2], v[3])
  53. try:
  54. float(v[4])
  55. float(v[5])
  56. float(v[6])
  57. except:
  58. assert False, "In ASCII viz output file '%s', line %d, normal vector is malformed (was %s %s %s, should be a triple of floating point values)" % (fname, idx + 1, v[4], v[5], v[6])
  59. # Maybe check states
  60. if sstates is not None or vstates is not None:
  61. id = v[0]
  62. if sstates is not None:
  63. if type(id) == int:
  64. assert id in sstates, "In ASCII viz output file '%s', line %d looks like a surface molecule, but has the state of a volume molecule (state=%d)" % (fname, idx + 1, id)
  65. if vstates is not None:
  66. if type(id) == int:
  67. assert id in vstates, "In ASCII viz output file '%s', line %d looks like a volume molecule, but has the state of a surface molecule (state=%d)" % (fname, idx + 1, id)
  68. class RequireVizAscii:
  69. def __init__(self, basename, iters, sstates=None, vstates=None, astates=None):
  70. self.basename = basename
  71. self.iters = iters
  72. self.args = {}
  73. if sstates is not None:
  74. self.args["sstates"] = safe_concat(sstates, astates)
  75. if vstates is not None:
  76. self.args["vstates"] = safe_concat(vstates, astates)
  77. def check(self):
  78. for i in self.iters:
  79. assertValidVizFileAscii(self.basename + ".ascii.%03d" % i + ".dat", **self.args)
  80. ###################################################################
  81. # Give an error if the specified RK mode viz file is invalid, according to the
  82. # specified parameters.
  83. #
  84. # Parameters:
  85. # fname - the filename to check
  86. # n_iters - number of iterations worth of output, or None to skip check
  87. ###################################################################
  88. def assertValidVizFileRK(fname, n_iters=None):
  89. try:
  90. got_contents = open(fname).read()
  91. except:
  92. assert False, "Expected RK-mode viz output file '%s' was not created" % fname
  93. if n_iters is not None:
  94. # Rend file into tiny pieces
  95. lines = [l for l in got_contents.split('\n') if l != '']
  96. assert len(lines) == n_iters, "RK-mode viz output file '%s' has incorrect number of lines (%d instead of %d)" % (fname, len(lines), n_iters)
  97. class RequireVizRK:
  98. def __init__(self, name, n_iters=None):
  99. self.name = name
  100. self.n_iters = n_iters
  101. def check(self):
  102. assertValidVizFileRK(self.name, self.n_iters)
  103. ###################################################################
  104. # Give an error if the specified DX mode viz file is invalid, according to the
  105. # specified parameters.
  106. #
  107. # Note: Currently, this test does NOT validate that unexpected outputs were
  108. # NOT produced -- only that the expected outputs WERE produced. Ideally, it
  109. # should check that we only got the output types we expected, and only on the
  110. # iterations where we expected them.
  111. #
  112. # Parameters:
  113. # dir - the directory containing the output files
  114. # molfile - MOLECULE_FILE_PREFIX from viz output block
  115. # objprefixes - OBJECT_FILE_PREFIXES from viz output block
  116. # alliters - iteration numbers where all types of output were produced
  117. # mpositers - iteration numbers where vol mol position was produced
  118. # mstateiters - iteration numbers where vol mol state was produced
  119. # epositers - iteration numbers where grid mol position was produced
  120. # estateiters - iteration numbers where grid mol state was produced
  121. # opositers - iteration numbers where mesh position was produced
  122. # ostateiters - iteration numbers where mesh state was produced
  123. ###################################################################
  124. def assertValidVizFilesDx(dir, molfile=None, objprefixes=None, alliters=None, mpositers=None, mstateiters=None, epositers=None, estateiters=None, opositers=None, ostateiters=None):
  125. if mpositers is None:
  126. mpositers = []
  127. if mstateiters is None:
  128. mstateiters = []
  129. if epositers is None:
  130. epositers = []
  131. if estateiters is None:
  132. estateiters = []
  133. if opositers is None:
  134. opositers = []
  135. if ostateiters is None:
  136. ostateiters = []
  137. if alliters is not None:
  138. mpositers.extend(alliters)
  139. mstateiters.extend(alliters)
  140. epositers.extend(alliters)
  141. estateiters.extend(alliters)
  142. opositers.extend(alliters)
  143. ostateiters.extend(alliters)
  144. assertFileDir(dir)
  145. if molfile is not None:
  146. for i in mpositers:
  147. assertFileNonempty(os.path.join(dir, "%s.molecule_positions.%d.dx" % (molfile, i)))
  148. for i in mstateiters:
  149. assertFileNonempty(os.path.join(dir, "%s.molecule_states.%d.dx" % (molfile, i)))
  150. if objprefixes is not None:
  151. for b in objprefixes:
  152. for i in epositers:
  153. assertFileNonempty(os.path.join(dir, "%s.effector_site_positions.%d.dx" % (b, i)))
  154. for i in estateiters:
  155. assertFileNonempty(os.path.join(dir, "%s.effector_site_states.%d.dx" % (b, i)))
  156. for i in opositers:
  157. assertFileNonempty(os.path.join(dir, "%s.mesh_elements.%d.dx" % (b, i)))
  158. for i in ostateiters:
  159. assertFileNonempty(os.path.join(dir, "%s.mesh_element_states.%d.dx" % (b, i)))
  160. class RequireVizDX:
  161. def __init__(self, dir, molfile=None, objprefixes=None, alliters=None, mpositers=None, mstateiters=None, epositers=None, estateiters=None, opositers=None, ostateiters=None):
  162. self.dir = dir
  163. self.molfile = molfile
  164. self.objprefixes = objprefixes
  165. self.mpositers = mpositers
  166. self.mstateiters = mstateiters
  167. self.epositers = epositers
  168. self.estateiters = estateiters
  169. self.opositers = opositers
  170. self.ostateiters = ostateiters
  171. self.alliters = alliters
  172. def check(self):
  173. assertValidVizFilesDx(self.dir,
  174. molfile=self.molfile,
  175. objprefixes=self.objprefixes,
  176. alliters=self.alliters,
  177. mpositers=self.mpositers, mstateiters=self.mstateiters,
  178. epositers=self.epositers, estateiters=self.estateiters,
  179. opositers=self.opositers, ostateiters=self.ostateiters)
  180. ###################################################################
  181. # Give an error if the specified DREAMM V3 (non-grouped) mode viz output set is
  182. # invalid, according to the specified parameters. This only checks the
  183. # top-level files, not the frame data. The frame data will be checked by
  184. # separate assertions which vary for binary and ascii output formats.
  185. #
  186. # Note: Currently, this test does NOT validate that unexpected outputs were
  187. # NOT produced -- only that the expected outputs WERE produced. Ideally, it
  188. # should check that we only got the output types we expected, and only on the
  189. # iterations where we expected them.
  190. #
  191. # Parameters:
  192. # dir - the directory containing the output files
  193. # name - name of the output file set
  194. # n_iters - number of output iterations, or None to not check
  195. # n_times - number of distinct output times, or None to not check
  196. ###################################################################
  197. def assertValidVizFilesDreammV3(dir, name, n_iters=None, n_times=None):
  198. assertFileNonempty(os.path.join(dir, name + ".dx"))
  199. if n_iters is not None:
  200. assertFileNonempty(os.path.join(dir, name + ".iteration_numbers.bin"), 12*n_iters)
  201. else:
  202. assertFileNonempty(os.path.join(dir, name + ".iteration_numbers.bin"))
  203. if n_times is not None:
  204. assertFileNonempty(os.path.join(dir, name + ".time_values.bin"), 8*n_times)
  205. else:
  206. assertFileNonempty(os.path.join(dir, name + ".time_values.bin"))
  207. class RequireVizDreammV3:
  208. def __init__(self, dir, name, n_iters=None, n_times=None):
  209. self.dir = dir
  210. self.name = name
  211. self.args = {}
  212. if n_iters is not None:
  213. self.args["n_iters"] = n_iters
  214. if n_times is not None:
  215. self.args["n_times"] = n_times
  216. def check(self):
  217. assertValidVizFilesDreammV3(self.dir, self.name, **self.args)
  218. ###################################################################
  219. # Give an error if the specified DREAMM V3 (non-grouped) mode viz output set
  220. # contains invalid (or fails to contain valid) binary molecule data files.
  221. #
  222. # Parameters:
  223. # dir - the directory containing the output files
  224. # alliters - sorted iteration numbers where any output was
  225. # produced
  226. # surfpositers - iters producing surface mol positions
  227. # surforientiters - iters producing surface mol orientations
  228. # surfstateiters - iters producing surface mol states
  229. # surfnonempty - expect at least one surface molecule
  230. # volpositers - iters producing volume mol positions
  231. # volorientiters - iters producing volume mol orientations
  232. # volstateiters - iters producing volume mol states
  233. # volnonempty - expect at least one volume molecule
  234. ###################################################################
  235. def assertValidVizFilesDreammV3MolsBin(dir, alliters,
  236. surfpositers=None,
  237. surforientiters=None,
  238. surfstateiters=[],
  239. surfnonempty=True,
  240. volpositers=None,
  241. volorientiters=None,
  242. volstateiters=[],
  243. volnonempty=True):
  244. last_spos = [None]
  245. last_sorients = [None]
  246. last_sstate = [None]
  247. last_vpos = [None]
  248. last_vorients = [None]
  249. last_vstate = [None]
  250. # Reset last iterations if our output types are not totally synchronized
  251. def check_unset(s):
  252. if last_spos[0] != s:
  253. last_spos[0] = None
  254. if last_sorients[0] != s:
  255. last_sorients[0] = None
  256. if last_sstate[0] != s:
  257. last_sstate[0] = None
  258. if last_vpos[0] != s:
  259. last_vpos[0] = None
  260. if last_vorients[0] != s:
  261. last_vorients[0] = None
  262. if last_vstate[0] != s:
  263. last_vstate[0] = None
  264. # Make sure iteration list is sorted, create sets for quick searching
  265. alliters.sort()
  266. if surfpositers is None:
  267. surfpositers = alliters
  268. surfpositers = set(surfpositers)
  269. if surforientiters is None:
  270. surforientiters = alliters
  271. surforientiters = set(surforientiters)
  272. if surfstateiters is None:
  273. surfstateiters = alliters
  274. surfstateiters = set(surfstateiters)
  275. if volpositers is None:
  276. volpositers = alliters
  277. volpositers = set(volpositers)
  278. if volorientiters is None:
  279. volorientiters = alliters
  280. volorientiters = set(volorientiters)
  281. if volstateiters is None:
  282. volstateiters = alliters
  283. volstateiters = set(volstateiters)
  284. surfiters = surfpositers.union(surforientiters).union(surfstateiters)
  285. voliters = volpositers.union(volorientiters).union(volstateiters)
  286. moliters = surfiters.union(voliters)
  287. # Check each iteration
  288. for iter in alliters:
  289. basedir = os.path.join(dir, "frame_data")
  290. basedir = os.path.join(basedir, "iteration_%d" % iter)
  291. had_sframe = 0
  292. had_vframe = 0
  293. surf_pos = os.path.join(basedir, "surface_molecules_positions.bin")
  294. surf_orient = os.path.join(basedir, "surface_molecules_orientations.bin")
  295. surf_states = os.path.join(basedir, "surface_molecules_states.bin")
  296. surf_header = os.path.join(basedir, "surface_molecules.dx")
  297. vol_pos = os.path.join(basedir, "volume_molecules_positions.bin")
  298. vol_orient = os.path.join(basedir, "volume_molecules_orientations.bin")
  299. vol_states = os.path.join(basedir, "volume_molecules_states.bin")
  300. vol_header = os.path.join(basedir, "volume_molecules.dx")
  301. if iter in surfpositers:
  302. had_sframe = 1
  303. last_spos[0] = iter
  304. check_unset(iter)
  305. if surfnonempty:
  306. assertFileNonempty(surf_pos)
  307. else:
  308. assertFileExists(surf_pos)
  309. elif last_spos[0] is not None and iter not in moliters:
  310. assertFileSymlink(surf_pos, "../iteration_%d/surface_molecules_positions.bin" % last_spos[0])
  311. else:
  312. assertFileNotExists(surf_pos)
  313. if iter in surforientiters:
  314. had_sframe = 1
  315. last_sorients[0] = iter
  316. check_unset(iter)
  317. if surfnonempty:
  318. assertFileNonempty(surf_orient)
  319. else:
  320. assertFileExists(surf_orient)
  321. elif last_sorients[0] is not None and iter not in moliters:
  322. assertFileSymlink(surf_orient, "../iteration_%d/surface_molecules_orientations.bin" % last_sorients[0])
  323. else:
  324. assertFileNotExists(surf_orient)
  325. if iter in surfstateiters:
  326. had_sframe = 1
  327. last_sstate[0] = iter
  328. check_unset(iter)
  329. if surfnonempty:
  330. assertFileNonempty(surf_states)
  331. else:
  332. assertFileExists(surf_states)
  333. elif last_sstate[0] is not None and iter not in moliters:
  334. assertFileSymlink(surf_states, "../iteration_%d/surface_molecules_states.bin" % last_sstate[0])
  335. else:
  336. assertFileNotExists(surf_states)
  337. if had_sframe:
  338. assertFileNonempty(surf_header)
  339. elif last_spos[0] is not None:
  340. assertFileSymlink(surf_header, "../iteration_%d/surface_molecules.dx" % last_spos[0])
  341. elif last_sorients[0] is not None:
  342. assertFileSymlink(surf_header, "../iteration_%d/surface_molecules.dx" % last_sorients[0])
  343. elif last_sstate[0] is not None:
  344. assertFileSymlink(surf_header, "../iteration_%d/surface_molecules.dx" % last_sstate[0])
  345. else:
  346. assertFileNotExists(surf_header)
  347. if iter in volpositers:
  348. had_vframe = 1
  349. last_vpos[0] = iter
  350. check_unset(iter)
  351. if volnonempty:
  352. assertFileNonempty(vol_pos)
  353. else:
  354. assertFileExists(vol_pos)
  355. elif last_vpos[0] is not None and iter not in moliters:
  356. assertFileSymlink(vol_pos, "../iteration_%d/volume_molecules_positions.bin" % last_vpos[0])
  357. else:
  358. assertFileNotExists(vol_pos)
  359. if iter in volorientiters:
  360. had_vframe = 1
  361. last_vorients[0] = iter
  362. check_unset(iter)
  363. if volnonempty:
  364. assertFileNonempty(vol_orient)
  365. else:
  366. assertFileExists(vol_orient)
  367. elif last_vorients[0] is not None and iter not in moliters:
  368. assertFileSymlink(vol_orient, "../iteration_%d/volume_molecules_orientations.bin" % last_vorients[0])
  369. else:
  370. assertFileNotExists(vol_orient)
  371. if iter in volstateiters:
  372. had_vframe = 1
  373. last_vstate[0] = iter
  374. check_unset(iter)
  375. if volnonempty:
  376. assertFileNonempty(vol_states)
  377. else:
  378. assertFileExists(vol_states)
  379. elif last_vstate[0] is not None and iter not in moliters:
  380. assertFileSymlink(vol_states, "../iteration_%d/volume_molecules_states.bin" % last_vstate[0])
  381. else:
  382. assertFileNotExists(vol_states)
  383. if had_vframe:
  384. assertFileNonempty(vol_header)
  385. elif last_vpos[0] is not None:
  386. assertFileSymlink(vol_header, "../iteration_%d/volume_molecules.dx" % last_vpos[0])
  387. elif last_vorients[0] is not None:
  388. assertFileSymlink(vol_header, "../iteration_%d/volume_molecules.dx" % last_vorients[0])
  389. elif last_vstate[0] is not None:
  390. assertFileSymlink(vol_header, "../iteration_%d/volume_molecules.dx" % last_vstate[0])
  391. else:
  392. assertFileNotExists(vol_header)
  393. class RequireVizDreammV3MolsBin:
  394. def __init__(self, dir, alliters,
  395. surfpositers=None,
  396. surforientiters=None,
  397. surfstateiters=None,
  398. surfnonempty=None,
  399. volpositers=None,
  400. volorientiters=None,
  401. volstateiterss=None,
  402. volnonempty=None):
  403. self.dir = dir
  404. self.alliters = alliters
  405. self.args = {}
  406. if surfpositers is not None:
  407. self.args["surfpositers"] = surfpositers
  408. if surforientiters is not None:
  409. self.args["surforientiters"] = surforientiters
  410. if surfstateiters is not None:
  411. self.args["surfstateiters"] = surfstateiters
  412. if surfnonempty is not None:
  413. self.args["surfnonempty"] = surfnonempty
  414. if volpositers is not None:
  415. self.args["volpositers"] = volpositers
  416. if volorientiters is not None:
  417. self.args["volorientiters"] = volorientiters
  418. if volstateiterss is not None:
  419. self.args["volstateiterss"] = volstateiterss
  420. if volnonempty is not None:
  421. self.args["volnonempty"] = volnonempty
  422. def check(self):
  423. assertValidVizFilesDreammV3MolsBin(self.dir, self.alliters, **self.args)
  424. ###################################################################
  425. # Give an error if the specified DREAMM V3 (non-grouped) mode viz output set
  426. # contains invalid (or fails to contain valid) ascii molecule data files.
  427. #
  428. # Parameters:
  429. # dir - the directory containing the output files
  430. # alliters - sorted iteration numbers where any output was
  431. # produced
  432. # molnames - list of molecule names to be written
  433. # positers - iters producing surface mol positions
  434. # orientiters - iters producing surface mol orientations
  435. # stateiters - iters producing surface mol states
  436. ###################################################################
  437. def assertValidVizFilesDreammV3MolsAscii(dir, alliters,
  438. molnames,
  439. positers=None,
  440. orientiters=None,
  441. stateiters=[]):
  442. last_pos = [None]
  443. last_orients = [None]
  444. last_state = [None]
  445. # Reset last iterations if our output types are not totally synchronized
  446. def check_unset(s):
  447. if last_pos[0] != s:
  448. last_pos[0] = None
  449. if last_orients[0] != s:
  450. last_orients[0] = None
  451. if last_state[0] != s:
  452. last_state[0] = None
  453. # Make sure iteration list is sorted, create sets for quick searching
  454. alliters.sort()
  455. if positers is None:
  456. positers = alliters
  457. positers = set(positers)
  458. if orientiters is None:
  459. orientiters = alliters
  460. orientiters = set(orientiters)
  461. if stateiters is None:
  462. stateiters = alliters
  463. stateiters = set(stateiters)
  464. moliters = positers.union(orientiters).union(stateiters)
  465. # Check each iteration
  466. for iter in alliters:
  467. basedir = os.path.join(dir, "frame_data")
  468. basedir = os.path.join(basedir, "iteration_%d" % iter)
  469. had_sframe = 0
  470. had_vframe = 0
  471. surf_header = os.path.join(basedir, "surface_molecules.dx")
  472. vol_header = os.path.join(basedir, "volume_molecules.dx")
  473. if iter in positers:
  474. had_sframe = 1
  475. last_pos[0] = iter
  476. check_unset(iter)
  477. for mol in molnames:
  478. pos = os.path.join(basedir, "%s.positions.dat" % mol)
  479. assertFileExists(pos)
  480. elif last_pos[0] is not None and iter not in moliters:
  481. for mol in molnames:
  482. pos = os.path.join(basedir, "%s.positions.dat" % mol)
  483. assertFileSymlink(pos, "../iteration_%d/%s.positions.dat" % (last_pos[0], mol))
  484. else:
  485. for mol in molnames:
  486. pos = os.path.join(basedir, "%s.positions.dat" % mol)
  487. assertFileNotExists(pos)
  488. f_orient = os.path.join(basedir, "orientations.dat")
  489. f_states = os.path.join(basedir, "states.dat")
  490. if iter in orientiters:
  491. had_sframe = 1
  492. last_orients[0] = iter
  493. check_unset(iter)
  494. for mol in molnames:
  495. orient = os.path.join(basedir, "%s.orientations.dat" % mol)
  496. assertFileExists(orient)
  497. elif last_orients[0] is not None and iter not in moliters:
  498. for mol in molnames:
  499. orient = os.path.join(basedir, "%s.orientations.dat" % mol)
  500. assertFileSymlink(orient, "../iteration_%d/%s.orientations.dat" % (last_orients[0], mol))
  501. else:
  502. for mol in molnames:
  503. orient = os.path.join(basedir, "%s.orientations.dat" % mol)
  504. assertFileNotExists(orient)
  505. if iter in stateiters:
  506. had_sframe = 1
  507. last_state[0] = iter
  508. check_unset(iter)
  509. for mol in molnames:
  510. states = os.path.join(basedir, "%s.states.dat" % mol)
  511. assertFileNonempty(states)
  512. elif last_state[0] is not None and iter not in moliters:
  513. for mol in molnames:
  514. states = os.path.join(basedir, "%s.states.dat" % mol)
  515. assertFileSymlink(states, "../iteration_%d/%s.states.dat" % (last_state[0], mol))
  516. else:
  517. for mol in molnames:
  518. states = os.path.join(basedir, "%s.states.dat" % mol)
  519. assertFileNotExists(states)
  520. if had_sframe:
  521. assertFileExists(surf_header)
  522. assertFileExists(vol_header)
  523. elif last_pos[0] is not None:
  524. assertFileSymlink(surf_header, "../iteration_%d/surface_molecules.dx" % last_pos[0])
  525. assertFileSymlink(vol_header, "../iteration_%d/volume_molecules.dx" % last_pos[0])
  526. elif last_orients[0] is not None:
  527. assertFileSymlink(surf_header, "../iteration_%d/surface_molecules.dx" % last_orients[0])
  528. assertFileSymlink(vol_header, "../iteration_%d/volume_molecules.dx" % last_orients[0])
  529. elif last_state[0] is not None:
  530. assertFileSymlink(surf_header, "../iteration_%d/surface_molecules.dx" % last_state[0])
  531. assertFileSymlink(vol_header, "../iteration_%d/volume_molecules.dx" % last_state[0])
  532. else:
  533. assertFileNotExists(surf_header)
  534. assertFileNotExists(vol_header)
  535. class RequireVizDreammV3MolsAscii:
  536. def __init__(self, dir, alliters,
  537. molnames,
  538. positers=None,
  539. orientiters=None,
  540. stateiters=None):
  541. self.dir = dir
  542. self.alliters = alliters
  543. self.molnames = molnames
  544. self.args = {}
  545. if positers is not None:
  546. self.args["positers"] = positers
  547. if orientiters is not None:
  548. self.args["orientiters"] = orientiters
  549. if stateiters is not None:
  550. self.args["stateiters"] = stateiters
  551. def check(self):
  552. assertValidVizFilesDreammV3MolsAscii(self.dir, self.alliters, self.molnames, **self.args)
  553. ###################################################################
  554. # Give an error if the specified DREAMM V3 (non-grouped) mode viz output set
  555. # contains invalid (or fails to contain valid) binary mesh data files.
  556. #
  557. # Parameters:
  558. # dir - the directory containing the output files
  559. # alliters - iteration numbers where any output was produced
  560. # positers - iteration numbers where mesh pos output was produced, if
  561. # different from alliters
  562. # regioniters - iteration numbers where region data output was produced,
  563. # if different from alliters
  564. # stateiters - iteration numbers where mesh state was produced, if any
  565. # (it is assumed that no mesh state data was produced,
  566. # otherwise)
  567. # meshnonempty - expect at least one mesh
  568. ###################################################################
  569. def assertValidVizFilesDreammV3MeshBin(dir, alliters, positers=None, regioniters=None, stateiters=[], meshnonempty=True):
  570. last_pos = [None]
  571. last_rgn = [None]
  572. last_state = [None]
  573. # Reset last iterations if our output types are not totally synchronized
  574. def check_unset(s):
  575. if last_pos[0] != s:
  576. last_pos[0] = None
  577. if last_rgn[0] != s:
  578. last_rgn[0] = None
  579. if last_state[0] != s:
  580. last_state[0] = None
  581. alliters.sort()
  582. if positers is None:
  583. positers = alliters
  584. positers = set(positers)
  585. if regioniters is None:
  586. regioniters = alliters
  587. regioniters = set(regioniters)
  588. if stateiters is None:
  589. stateiters = alliters
  590. stateiters = set(stateiters)
  591. for iter in alliters:
  592. basedir = os.path.join(dir, "frame_data")
  593. basedir = os.path.join(basedir, "iteration_%d" % iter)
  594. had_frame = 0
  595. mesh_pos = os.path.join(basedir, "mesh_positions.bin")
  596. mesh_rgn = os.path.join(basedir, "region_indices.bin")
  597. mesh_state = os.path.join(basedir, "mesh_states.bin")
  598. mesh_header = os.path.join(basedir, "meshes.dx")
  599. # Check for positions file or symlink
  600. if iter in positers:
  601. had_frame = 1
  602. last_pos[0] = iter
  603. check_unset(iter)
  604. if meshnonempty:
  605. assertFileNonempty(mesh_pos)
  606. else:
  607. assertFileExists(mesh_pos)
  608. elif last_pos[0] is not None and iter not in regioniters and iter not in stateiters:
  609. assertFileSymlink(mesh_pos, "../iteration_%d/mesh_positions.bin" % last_pos[0])
  610. else:
  611. assertFileNotExists(mesh_pos)
  612. # Check for regions file or symlink
  613. if iter in regioniters:
  614. had_frame = 1
  615. last_rgn[0] = iter
  616. check_unset(iter)
  617. if meshnonempty:
  618. assertFileNonempty(mesh_rgn)
  619. else:
  620. assertFileExists(mesh_rgn)
  621. elif last_rgn[0] is not None and iter not in stateiters:
  622. assertFileSymlink(mesh_rgn, "../iteration_%d/region_indices.bin" % last_rgn[0])
  623. else:
  624. assertFileNotExists(mesh_rgn)
  625. # Check for states file or symlink
  626. if iter in stateiters:
  627. had_frame = 1
  628. last_state[0] = iter
  629. check_unset(iter)
  630. if meshnonempty:
  631. assertFileNonempty(mesh_state)
  632. else:
  633. assertFileExists(mesh_state)
  634. elif last_state[0] is not None:
  635. assertFileSymlink(mesh_state, "../iteration_%d/mesh_states.bin" % last_state[0])
  636. else:
  637. assertFileNotExists(mesh_state)
  638. # Check for meshes file or symlink
  639. if had_frame:
  640. assertFileNonempty(mesh_header)
  641. elif last_pos[0] is not None:
  642. assertFileSymlink(mesh_header, "../iteration_%d/meshes.dx" % last_pos[0])
  643. elif last_rgn[0] is not None:
  644. assertFileSymlink(mesh_header, "../iteration_%d/meshes.dx" % last_rgn[0])
  645. elif last_state[0] is not None:
  646. assertFileSymlink(mesh_header, "../iteration_%d/meshes.dx" % last_state[0])
  647. else:
  648. assertFileNotExists(mesh_header)
  649. class RequireVizDreammV3MeshBin:
  650. def __init__(self, dir, alliters, positers=None, regioniters=None, stateiters=None, meshnonempty=None):
  651. self.dir = dir
  652. self.alliters = alliters
  653. self.args = {}
  654. if positers is not None:
  655. self.args["positers"] = positers
  656. if regioniters is not None:
  657. self.args["regioniters"] = regioniters
  658. if stateiters is not None:
  659. self.args["stateiters"] = stateiters
  660. if meshnonempty is not None:
  661. self.args["meshnonempty"] = meshnonempty
  662. def check(self):
  663. assertValidVizFilesDreammV3MeshBin(self.dir, self.alliters, **self.args)
  664. ###################################################################
  665. # Give an error if the specified DREAMM V3 (non-grouped) mode viz output set
  666. # contains invalid (or fails to contain valid) ascii mesh data files.
  667. #
  668. # Parameters:
  669. # dir - the directory containing the output files
  670. # alliters - iteration numbers where any output was produced
  671. # objnames - names of objects whose files to look for
  672. # objswithregions - names of objects which have regions other than ALL
  673. # positers - iteration numbers where mesh pos output was produced, if
  674. # different from alliters
  675. # regioniters - iteration numbers where region data output was produced,
  676. # if different from alliters
  677. # stateiters - iteration numbers where mesh state was produced, if any
  678. # (it is assumed that no mesh state data was produced,
  679. # otherwise)
  680. # meshnonempty - expect at least one mesh
  681. ###################################################################
  682. def assertValidVizFilesDreammV3MeshAscii(dir, alliters, objnames, objswithregions=None, positers=None, regioniters=None, stateiters=[], meshnonempty=True):
  683. last_pos = [None]
  684. last_rgn = [None]
  685. last_state = [None]
  686. # Reset last iterations if our output types are not totally synchronized
  687. def check_unset(s):
  688. if last_pos[0] != s:
  689. last_pos[0] = None
  690. if last_rgn[0] != s:
  691. last_rgn[0] = None
  692. if last_state[0] != s:
  693. last_state[0] = None
  694. alliters.sort()
  695. if positers is None:
  696. positers = alliters
  697. positers = set(positers)
  698. if regioniters is None:
  699. regioniters = alliters
  700. regioniters = set(regioniters)
  701. if stateiters is None:
  702. stateiters = alliters
  703. stateiters = set(stateiters)
  704. if objswithregions is None:
  705. objswithregions = objnames
  706. for iter in alliters:
  707. basedir = os.path.join(dir, "frame_data")
  708. basedir = os.path.join(basedir, "iteration_%d" % iter)
  709. had_frame = 0
  710. mesh_header = os.path.join(basedir, "meshes.dx")
  711. # Check for positions file or symlink
  712. if iter in positers:
  713. had_frame = 1
  714. last_pos[0] = iter
  715. check_unset(iter)
  716. for obj in objnames:
  717. mesh_pos = os.path.join(basedir, obj + ".positions.dat")
  718. mesh_conn = os.path.join(basedir, obj + ".connections.dat")
  719. assertFileNonempty(mesh_pos)
  720. assertFileNonempty(mesh_conn)
  721. elif last_pos[0] is not None and iter not in regioniters and iter not in stateiters:
  722. for obj in objnames:
  723. mesh_pos = os.path.join(basedir, obj + ".positions.dat")
  724. mesh_conn = os.path.join(basedir, obj + ".connections.dat")
  725. assertFileSymlink(mesh_pos, "../iteration_%d/%s.positions.dat" % (last_pos[0], obj))
  726. assertFileSymlink(mesh_conn, "../iteration_%d/%s.connections.dat" % (last_pos[0], obj))
  727. else:
  728. for obj in objnames:
  729. mesh_pos = os.path.join(basedir, obj + ".positions.dat")
  730. mesh_conn = os.path.join(basedir, obj + ".connections.dat")
  731. assertFileNotExists(mesh_pos)
  732. assertFileNotExists(mesh_conn)
  733. # Check for regions file or symlink
  734. if iter in regioniters:
  735. had_frame = 1
  736. last_rgn[0] = iter
  737. check_unset(iter)
  738. for obj in objswithregions:
  739. mesh_rgn = os.path.join(basedir, obj + ".region_indices.dat")
  740. assertFileExists(mesh_rgn)
  741. elif last_rgn[0] is not None and iter not in stateiters:
  742. for obj in objswithregions:
  743. mesh_rgn = os.path.join(basedir, obj + ".region_indices.dat")
  744. assertFileSymlink(mesh_rgn, "../iteration_%d/%s.region_indices.dat" % (last_rgn[0], obj))
  745. else:
  746. for obj in objswithregions:
  747. mesh_rgn = os.path.join(basedir, obj + ".region_indices.dat")
  748. assertFileNotExists(mesh_rgn)
  749. # Check for states file or symlink
  750. if iter in stateiters:
  751. had_frame = 1
  752. last_state[0] = iter
  753. check_unset(iter)
  754. for obj in objnames:
  755. mesh_state = os.path.join(basedir, obj + ".states.dat")
  756. assertFileNonempty(mesh_state)
  757. elif last_state[0] is not None:
  758. for obj in objnames:
  759. mesh_state = os.path.join(basedir, obj + ".states.dat")
  760. assertFileSymlink(mesh_state, "../iteration_%d/%s.states.dat" % (last_state[0], obj))
  761. else:
  762. for obj in objnames:
  763. mesh_state = os.path.join(basedir, obj + ".states.dat")
  764. assertFileNotExists(mesh_state)
  765. # Check for meshes file or symlink
  766. if had_frame:
  767. assertFileNonempty(mesh_header)
  768. elif last_pos[0] is not None:
  769. assertFileSymlink(mesh_header, "../iteration_%d/meshes.dx" % last_pos[0])
  770. elif last_rgn[0] is not None:
  771. assertFileSymlink(mesh_header, "../iteration_%d/meshes.dx" % last_rgn[0])
  772. elif last_state[0] is not None:
  773. assertFileSymlink(mesh_header, "../iteration_%d/meshes.dx" % last_state[0])
  774. else:
  775. assertFileNotExists(mesh_header)
  776. class RequireVizDreammV3MeshAscii:
  777. def __init__(self, dir, alliters, objnames, objswithregions=None, positers=None, regioniters=None, stateiters=None, meshnonempty=None):
  778. self.dir = dir
  779. self.alliters = alliters
  780. self.objnames = objnames
  781. self.args = {}
  782. if objswithregions is not None:
  783. self.args["objswithregions"] = objswithregions
  784. if positers is not None:
  785. self.args["positers"] = positers
  786. if regioniters is not None:
  787. self.args["regioniters"] = regioniters
  788. if stateiters is not None:
  789. self.args["stateiters"] = stateiters
  790. if meshnonempty is not None:
  791. self.args["meshnonempty"] = meshnonempty
  792. def check(self):
  793. assertValidVizFilesDreammV3MeshAscii(self.dir, self.alliters, self.objnames, **self.args)
  794. ###################################################################
  795. # Give an error if the specified DREAMM V3 (grouped) mode viz output set is
  796. # invalid.
  797. #
  798. # Parameters:
  799. # dir - the directory containing the output files
  800. # name - name of the output set
  801. # cpno - checkpoint sequence number (assumed to be 1 otherwise)
  802. # n_iters - total number of iterations with output (None to skip
  803. # check)
  804. # n_times - total number of distinct time points with output (None to
  805. # skip check)
  806. # meshpos - true to expect mesh pos file, false to not
  807. # rgnindx - true to expect region indices file, false to not
  808. # meshstate - true to expect mesh state file, false to not
  809. # meshnonempty - true to expect at least 1 mesh
  810. # molpos - true to expect mol pos file, false to not
  811. # molorient - true to expect mol orient file, false to not
  812. # molstate - true to expect mol state file, false to not
  813. # molsnonempty - true to expect at least 1 molecule
  814. ###################################################################
  815. def assertValidVizFilesDreammV3Grouped(dir, name,
  816. cpno=1,
  817. n_iters=None,
  818. n_times=None,
  819. meshpos=True,
  820. rgnindx=True,
  821. meshstate=False,
  822. meshnonempty=True,
  823. molpos=True,
  824. molorient=True,
  825. molstate=False,
  826. molsnonempty=True):
  827. fmtargs = name, cpno
  828. assertFileNonempty(os.path.join(dir, "%s.%d.dx" % fmtargs))
  829. path = os.path.join(dir, "%s.mesh_positions.%d.bin" % fmtargs)
  830. if meshpos:
  831. if meshnonempty:
  832. assertFileNonempty(path)
  833. else:
  834. assertFileExists(path)
  835. else:
  836. assertFileNotExists(path)
  837. path = os.path.join(dir, "%s.region_indices.%d.bin" % fmtargs)
  838. if rgnindx:
  839. assertFileExists(path)
  840. else:
  841. assertFileNotExists(path)
  842. path = os.path.join(dir, "%s.mesh_states.%d.bin" % fmtargs)
  843. if meshstate:
  844. if meshnonempty:
  845. assertFileNonempty(path)
  846. else:
  847. assertFileExists(path)
  848. else:
  849. assertFileNotExists(path)
  850. path = os.path.join(dir, "%s.molecule_positions.%d.bin" % fmtargs)
  851. if molpos:
  852. if molsnonempty:
  853. assertFileNonempty(path)
  854. else:
  855. assertFileExists(path)
  856. else:
  857. assertFileNotExists(path)
  858. path = os.path.join(dir, "%s.molecule_orientations.%d.bin" % fmtargs)
  859. if molorient:
  860. if molsnonempty:
  861. assertFileNonempty(path)
  862. else:
  863. assertFileExists(path)
  864. else:
  865. assertFileNotExists(path)
  866. path = os.path.join(dir, "%s.molecule_states.%d.bin" % fmtargs)
  867. if molstate:
  868. if molsnonempty:
  869. assertFileNonempty(path)
  870. else:
  871. assertFileExists(path)
  872. else:
  873. assertFileNotExists(path)
  874. ipath = os.path.join(dir, "%s.iteration_numbers.%d.bin" % fmtargs)
  875. tpath = os.path.join(dir, "%s.time_values.%d.bin" % fmtargs)
  876. if n_iters is not None:
  877. assertFileNonempty(ipath, 12*n_iters)
  878. else:
  879. assertFileNonempty(ipath)
  880. if n_times is not None:
  881. assertFileNonempty(tpath, 8*n_times)
  882. else:
  883. assertFileNonempty(tpath)
  884. class RequireVizDreammV3Grouped:
  885. def __init__(self, dir, name,
  886. cpno=None,
  887. n_iters=None,
  888. n_times=None,
  889. meshpos=None,
  890. rgnindx=None,
  891. meshstate=None,
  892. meshnonempty=None,
  893. molpos=None,
  894. molorient=None,
  895. molstate=None,
  896. molsnonempty=None):
  897. self.dir = dir
  898. self.name = name
  899. self.args = {}
  900. if cpno is not None:
  901. self.args["cpno"] = cpno
  902. if n_iters is not None:
  903. self.args["n_iters"] = n_iters
  904. if n_times is not None:
  905. self.args["n_times"] = n_times
  906. if meshpos is not None:
  907. self.args["meshpos"] = meshpos
  908. if rgnindx is not None:
  909. self.args["rgnindx"] = rgnindx
  910. if meshstate is not None:
  911. self.args["meshstate"] = meshstate
  912. if meshnonempty is not None:
  913. self.args["meshnonempty"] = meshnonempty
  914. if molpos is not None:
  915. self.args["molpos"] = molpos
  916. if molorient is not None:
  917. self.args["molorient"] = molorient
  918. if molstate is not None:
  919. self.args["molstate"] = molstate
  920. if molsnonempty is not None:
  921. self.args["molsnonempty"] = molsnonempty
  922. def check(self):
  923. assertValidVizFilesDreammV3Grouped(self.dir, self.name, **self.args)