123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020 |
- import os
- from testutils import assertFileExists
- from testutils import assertFileNotExists
- from testutils import assertFileNonempty
- from testutils import assertFileSymlink
- from testutils import assertFileDir
- from testutils import safe_concat
- ###################################################################
- # Give an error if the specified ASCII viz file is invalid, according to the
- # specified parameters.
- #
- # Parameters:
- # fname - the filename to check
- # sstates - allowed surface states, or None to skip id validation
- # vstates - allowed volume states, or None to skip id validation
- #
- # Example usage:
- # assertValidVizFileAscii("viz_dat/molecules.0.dat", [1, 2, 3], [3, 4, 5])
- #
- # This will complain if the ASCII-format viz output file is
- # malformed, or if any surface molecules are emitted with states
- # other than 1, 2, or 3 (or, alternatively, if any volume molecules
- # are emitted with a normal vector). Likewise, it will complain if
- # any volume molecules are emitted with states other than 3, 4, or 5,
- # or if any surface molecules are emitted with normals of 0, 0, 0.
- #
- # assertValidVizFileAscii("viz_dat/molecules.0.dat")
- #
- # The above invocation will check only for validity, ignoring the
- # molecule state values.
- ###################################################################
- def assertValidVizFileAscii(fname, sstates=None, vstates=None):
- try:
- got_contents = open(fname).read()
- except:
- assert False, "Expected ASCII viz output file '%s' was not created" % fname
- # Rend file into tiny pieces
- lines = [l for l in got_contents.split('\n') if l != '']
- # Check each line
- idx = 1
- for idx in range(len(lines)):
- l = lines[idx]
- v = l.split()
- # Check number of columns
- assert len(v) == 8, "In ASCII viz output file '%s', line %d is malformed (%d columns instead of 8)" % (fname, idx + 1, len(v))
- # Check format of columns
- try:
- float(v[1])
- float(v[2])
- float(v[3])
- except:
- 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])
- try:
- float(v[4])
- float(v[5])
- float(v[6])
- except:
- 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])
- # Maybe check states
- if sstates is not None or vstates is not None:
- id = v[0]
- if sstates is not None:
- if type(id) == int:
- 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)
- if vstates is not None:
- if type(id) == int:
- 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)
- class RequireVizAscii:
- def __init__(self, basename, iters, sstates=None, vstates=None, astates=None):
- self.basename = basename
- self.iters = iters
- self.args = {}
- if sstates is not None:
- self.args["sstates"] = safe_concat(sstates, astates)
- if vstates is not None:
- self.args["vstates"] = safe_concat(vstates, astates)
- def check(self):
- for i in self.iters:
- assertValidVizFileAscii(self.basename + ".ascii.%03d" % i + ".dat", **self.args)
- ###################################################################
- # Give an error if the specified RK mode viz file is invalid, according to the
- # specified parameters.
- #
- # Parameters:
- # fname - the filename to check
- # n_iters - number of iterations worth of output, or None to skip check
- ###################################################################
- def assertValidVizFileRK(fname, n_iters=None):
- try:
- got_contents = open(fname).read()
- except:
- assert False, "Expected RK-mode viz output file '%s' was not created" % fname
- if n_iters is not None:
- # Rend file into tiny pieces
- lines = [l for l in got_contents.split('\n') if l != '']
- 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)
- class RequireVizRK:
- def __init__(self, name, n_iters=None):
- self.name = name
- self.n_iters = n_iters
- def check(self):
- assertValidVizFileRK(self.name, self.n_iters)
- ###################################################################
- # Give an error if the specified DX mode viz file is invalid, according to the
- # specified parameters.
- #
- # Note: Currently, this test does NOT validate that unexpected outputs were
- # NOT produced -- only that the expected outputs WERE produced. Ideally, it
- # should check that we only got the output types we expected, and only on the
- # iterations where we expected them.
- #
- # Parameters:
- # dir - the directory containing the output files
- # molfile - MOLECULE_FILE_PREFIX from viz output block
- # objprefixes - OBJECT_FILE_PREFIXES from viz output block
- # alliters - iteration numbers where all types of output were produced
- # mpositers - iteration numbers where vol mol position was produced
- # mstateiters - iteration numbers where vol mol state was produced
- # epositers - iteration numbers where grid mol position was produced
- # estateiters - iteration numbers where grid mol state was produced
- # opositers - iteration numbers where mesh position was produced
- # ostateiters - iteration numbers where mesh state was produced
- ###################################################################
- def assertValidVizFilesDx(dir, molfile=None, objprefixes=None, alliters=None, mpositers=None, mstateiters=None, epositers=None, estateiters=None, opositers=None, ostateiters=None):
- if mpositers is None:
- mpositers = []
- if mstateiters is None:
- mstateiters = []
- if epositers is None:
- epositers = []
- if estateiters is None:
- estateiters = []
- if opositers is None:
- opositers = []
- if ostateiters is None:
- ostateiters = []
- if alliters is not None:
- mpositers.extend(alliters)
- mstateiters.extend(alliters)
- epositers.extend(alliters)
- estateiters.extend(alliters)
- opositers.extend(alliters)
- ostateiters.extend(alliters)
- assertFileDir(dir)
- if molfile is not None:
- for i in mpositers:
- assertFileNonempty(os.path.join(dir, "%s.molecule_positions.%d.dx" % (molfile, i)))
- for i in mstateiters:
- assertFileNonempty(os.path.join(dir, "%s.molecule_states.%d.dx" % (molfile, i)))
- if objprefixes is not None:
- for b in objprefixes:
- for i in epositers:
- assertFileNonempty(os.path.join(dir, "%s.effector_site_positions.%d.dx" % (b, i)))
- for i in estateiters:
- assertFileNonempty(os.path.join(dir, "%s.effector_site_states.%d.dx" % (b, i)))
- for i in opositers:
- assertFileNonempty(os.path.join(dir, "%s.mesh_elements.%d.dx" % (b, i)))
- for i in ostateiters:
- assertFileNonempty(os.path.join(dir, "%s.mesh_element_states.%d.dx" % (b, i)))
- class RequireVizDX:
- def __init__(self, dir, molfile=None, objprefixes=None, alliters=None, mpositers=None, mstateiters=None, epositers=None, estateiters=None, opositers=None, ostateiters=None):
- self.dir = dir
- self.molfile = molfile
- self.objprefixes = objprefixes
- self.mpositers = mpositers
- self.mstateiters = mstateiters
- self.epositers = epositers
- self.estateiters = estateiters
- self.opositers = opositers
- self.ostateiters = ostateiters
- self.alliters = alliters
- def check(self):
- assertValidVizFilesDx(self.dir,
- molfile=self.molfile,
- objprefixes=self.objprefixes,
- alliters=self.alliters,
- mpositers=self.mpositers, mstateiters=self.mstateiters,
- epositers=self.epositers, estateiters=self.estateiters,
- opositers=self.opositers, ostateiters=self.ostateiters)
- ###################################################################
- # Give an error if the specified DREAMM V3 (non-grouped) mode viz output set is
- # invalid, according to the specified parameters. This only checks the
- # top-level files, not the frame data. The frame data will be checked by
- # separate assertions which vary for binary and ascii output formats.
- #
- # Note: Currently, this test does NOT validate that unexpected outputs were
- # NOT produced -- only that the expected outputs WERE produced. Ideally, it
- # should check that we only got the output types we expected, and only on the
- # iterations where we expected them.
- #
- # Parameters:
- # dir - the directory containing the output files
- # name - name of the output file set
- # n_iters - number of output iterations, or None to not check
- # n_times - number of distinct output times, or None to not check
- ###################################################################
- def assertValidVizFilesDreammV3(dir, name, n_iters=None, n_times=None):
- assertFileNonempty(os.path.join(dir, name + ".dx"))
- if n_iters is not None:
- assertFileNonempty(os.path.join(dir, name + ".iteration_numbers.bin"), 12*n_iters)
- else:
- assertFileNonempty(os.path.join(dir, name + ".iteration_numbers.bin"))
- if n_times is not None:
- assertFileNonempty(os.path.join(dir, name + ".time_values.bin"), 8*n_times)
- else:
- assertFileNonempty(os.path.join(dir, name + ".time_values.bin"))
- class RequireVizDreammV3:
- def __init__(self, dir, name, n_iters=None, n_times=None):
- self.dir = dir
- self.name = name
- self.args = {}
- if n_iters is not None:
- self.args["n_iters"] = n_iters
- if n_times is not None:
- self.args["n_times"] = n_times
- def check(self):
- assertValidVizFilesDreammV3(self.dir, self.name, **self.args)
- ###################################################################
- # Give an error if the specified DREAMM V3 (non-grouped) mode viz output set
- # contains invalid (or fails to contain valid) binary molecule data files.
- #
- # Parameters:
- # dir - the directory containing the output files
- # alliters - sorted iteration numbers where any output was
- # produced
- # surfpositers - iters producing surface mol positions
- # surforientiters - iters producing surface mol orientations
- # surfstateiters - iters producing surface mol states
- # surfnonempty - expect at least one surface molecule
- # volpositers - iters producing volume mol positions
- # volorientiters - iters producing volume mol orientations
- # volstateiters - iters producing volume mol states
- # volnonempty - expect at least one volume molecule
- ###################################################################
- def assertValidVizFilesDreammV3MolsBin(dir, alliters,
- surfpositers=None,
- surforientiters=None,
- surfstateiters=[],
- surfnonempty=True,
- volpositers=None,
- volorientiters=None,
- volstateiters=[],
- volnonempty=True):
- last_spos = [None]
- last_sorients = [None]
- last_sstate = [None]
- last_vpos = [None]
- last_vorients = [None]
- last_vstate = [None]
- # Reset last iterations if our output types are not totally synchronized
- def check_unset(s):
- if last_spos[0] != s:
- last_spos[0] = None
- if last_sorients[0] != s:
- last_sorients[0] = None
- if last_sstate[0] != s:
- last_sstate[0] = None
- if last_vpos[0] != s:
- last_vpos[0] = None
- if last_vorients[0] != s:
- last_vorients[0] = None
- if last_vstate[0] != s:
- last_vstate[0] = None
- # Make sure iteration list is sorted, create sets for quick searching
- alliters.sort()
- if surfpositers is None:
- surfpositers = alliters
- surfpositers = set(surfpositers)
- if surforientiters is None:
- surforientiters = alliters
- surforientiters = set(surforientiters)
- if surfstateiters is None:
- surfstateiters = alliters
- surfstateiters = set(surfstateiters)
- if volpositers is None:
- volpositers = alliters
- volpositers = set(volpositers)
- if volorientiters is None:
- volorientiters = alliters
- volorientiters = set(volorientiters)
- if volstateiters is None:
- volstateiters = alliters
- volstateiters = set(volstateiters)
- surfiters = surfpositers.union(surforientiters).union(surfstateiters)
- voliters = volpositers.union(volorientiters).union(volstateiters)
- moliters = surfiters.union(voliters)
- # Check each iteration
- for iter in alliters:
- basedir = os.path.join(dir, "frame_data")
- basedir = os.path.join(basedir, "iteration_%d" % iter)
- had_sframe = 0
- had_vframe = 0
- surf_pos = os.path.join(basedir, "surface_molecules_positions.bin")
- surf_orient = os.path.join(basedir, "surface_molecules_orientations.bin")
- surf_states = os.path.join(basedir, "surface_molecules_states.bin")
- surf_header = os.path.join(basedir, "surface_molecules.dx")
- vol_pos = os.path.join(basedir, "volume_molecules_positions.bin")
- vol_orient = os.path.join(basedir, "volume_molecules_orientations.bin")
- vol_states = os.path.join(basedir, "volume_molecules_states.bin")
- vol_header = os.path.join(basedir, "volume_molecules.dx")
- if iter in surfpositers:
- had_sframe = 1
- last_spos[0] = iter
- check_unset(iter)
- if surfnonempty:
- assertFileNonempty(surf_pos)
- else:
- assertFileExists(surf_pos)
- elif last_spos[0] is not None and iter not in moliters:
- assertFileSymlink(surf_pos, "../iteration_%d/surface_molecules_positions.bin" % last_spos[0])
- else:
- assertFileNotExists(surf_pos)
- if iter in surforientiters:
- had_sframe = 1
- last_sorients[0] = iter
- check_unset(iter)
- if surfnonempty:
- assertFileNonempty(surf_orient)
- else:
- assertFileExists(surf_orient)
- elif last_sorients[0] is not None and iter not in moliters:
- assertFileSymlink(surf_orient, "../iteration_%d/surface_molecules_orientations.bin" % last_sorients[0])
- else:
- assertFileNotExists(surf_orient)
- if iter in surfstateiters:
- had_sframe = 1
- last_sstate[0] = iter
- check_unset(iter)
- if surfnonempty:
- assertFileNonempty(surf_states)
- else:
- assertFileExists(surf_states)
- elif last_sstate[0] is not None and iter not in moliters:
- assertFileSymlink(surf_states, "../iteration_%d/surface_molecules_states.bin" % last_sstate[0])
- else:
- assertFileNotExists(surf_states)
- if had_sframe:
- assertFileNonempty(surf_header)
- elif last_spos[0] is not None:
- assertFileSymlink(surf_header, "../iteration_%d/surface_molecules.dx" % last_spos[0])
- elif last_sorients[0] is not None:
- assertFileSymlink(surf_header, "../iteration_%d/surface_molecules.dx" % last_sorients[0])
- elif last_sstate[0] is not None:
- assertFileSymlink(surf_header, "../iteration_%d/surface_molecules.dx" % last_sstate[0])
- else:
- assertFileNotExists(surf_header)
- if iter in volpositers:
- had_vframe = 1
- last_vpos[0] = iter
- check_unset(iter)
- if volnonempty:
- assertFileNonempty(vol_pos)
- else:
- assertFileExists(vol_pos)
- elif last_vpos[0] is not None and iter not in moliters:
- assertFileSymlink(vol_pos, "../iteration_%d/volume_molecules_positions.bin" % last_vpos[0])
- else:
- assertFileNotExists(vol_pos)
- if iter in volorientiters:
- had_vframe = 1
- last_vorients[0] = iter
- check_unset(iter)
- if volnonempty:
- assertFileNonempty(vol_orient)
- else:
- assertFileExists(vol_orient)
- elif last_vorients[0] is not None and iter not in moliters:
- assertFileSymlink(vol_orient, "../iteration_%d/volume_molecules_orientations.bin" % last_vorients[0])
- else:
- assertFileNotExists(vol_orient)
- if iter in volstateiters:
- had_vframe = 1
- last_vstate[0] = iter
- check_unset(iter)
- if volnonempty:
- assertFileNonempty(vol_states)
- else:
- assertFileExists(vol_states)
- elif last_vstate[0] is not None and iter not in moliters:
- assertFileSymlink(vol_states, "../iteration_%d/volume_molecules_states.bin" % last_vstate[0])
- else:
- assertFileNotExists(vol_states)
- if had_vframe:
- assertFileNonempty(vol_header)
- elif last_vpos[0] is not None:
- assertFileSymlink(vol_header, "../iteration_%d/volume_molecules.dx" % last_vpos[0])
- elif last_vorients[0] is not None:
- assertFileSymlink(vol_header, "../iteration_%d/volume_molecules.dx" % last_vorients[0])
- elif last_vstate[0] is not None:
- assertFileSymlink(vol_header, "../iteration_%d/volume_molecules.dx" % last_vstate[0])
- else:
- assertFileNotExists(vol_header)
- class RequireVizDreammV3MolsBin:
- def __init__(self, dir, alliters,
- surfpositers=None,
- surforientiters=None,
- surfstateiters=None,
- surfnonempty=None,
- volpositers=None,
- volorientiters=None,
- volstateiterss=None,
- volnonempty=None):
- self.dir = dir
- self.alliters = alliters
- self.args = {}
- if surfpositers is not None:
- self.args["surfpositers"] = surfpositers
- if surforientiters is not None:
- self.args["surforientiters"] = surforientiters
- if surfstateiters is not None:
- self.args["surfstateiters"] = surfstateiters
- if surfnonempty is not None:
- self.args["surfnonempty"] = surfnonempty
- if volpositers is not None:
- self.args["volpositers"] = volpositers
- if volorientiters is not None:
- self.args["volorientiters"] = volorientiters
- if volstateiterss is not None:
- self.args["volstateiterss"] = volstateiterss
- if volnonempty is not None:
- self.args["volnonempty"] = volnonempty
- def check(self):
- assertValidVizFilesDreammV3MolsBin(self.dir, self.alliters, **self.args)
- ###################################################################
- # Give an error if the specified DREAMM V3 (non-grouped) mode viz output set
- # contains invalid (or fails to contain valid) ascii molecule data files.
- #
- # Parameters:
- # dir - the directory containing the output files
- # alliters - sorted iteration numbers where any output was
- # produced
- # molnames - list of molecule names to be written
- # positers - iters producing surface mol positions
- # orientiters - iters producing surface mol orientations
- # stateiters - iters producing surface mol states
- ###################################################################
- def assertValidVizFilesDreammV3MolsAscii(dir, alliters,
- molnames,
- positers=None,
- orientiters=None,
- stateiters=[]):
- last_pos = [None]
- last_orients = [None]
- last_state = [None]
- # Reset last iterations if our output types are not totally synchronized
- def check_unset(s):
- if last_pos[0] != s:
- last_pos[0] = None
- if last_orients[0] != s:
- last_orients[0] = None
- if last_state[0] != s:
- last_state[0] = None
- # Make sure iteration list is sorted, create sets for quick searching
- alliters.sort()
- if positers is None:
- positers = alliters
- positers = set(positers)
- if orientiters is None:
- orientiters = alliters
- orientiters = set(orientiters)
- if stateiters is None:
- stateiters = alliters
- stateiters = set(stateiters)
- moliters = positers.union(orientiters).union(stateiters)
- # Check each iteration
- for iter in alliters:
- basedir = os.path.join(dir, "frame_data")
- basedir = os.path.join(basedir, "iteration_%d" % iter)
- had_sframe = 0
- had_vframe = 0
- surf_header = os.path.join(basedir, "surface_molecules.dx")
- vol_header = os.path.join(basedir, "volume_molecules.dx")
- if iter in positers:
- had_sframe = 1
- last_pos[0] = iter
- check_unset(iter)
- for mol in molnames:
- pos = os.path.join(basedir, "%s.positions.dat" % mol)
- assertFileExists(pos)
- elif last_pos[0] is not None and iter not in moliters:
- for mol in molnames:
- pos = os.path.join(basedir, "%s.positions.dat" % mol)
- assertFileSymlink(pos, "../iteration_%d/%s.positions.dat" % (last_pos[0], mol))
- else:
- for mol in molnames:
- pos = os.path.join(basedir, "%s.positions.dat" % mol)
- assertFileNotExists(pos)
- f_orient = os.path.join(basedir, "orientations.dat")
- f_states = os.path.join(basedir, "states.dat")
- if iter in orientiters:
- had_sframe = 1
- last_orients[0] = iter
- check_unset(iter)
- for mol in molnames:
- orient = os.path.join(basedir, "%s.orientations.dat" % mol)
- assertFileExists(orient)
- elif last_orients[0] is not None and iter not in moliters:
- for mol in molnames:
- orient = os.path.join(basedir, "%s.orientations.dat" % mol)
- assertFileSymlink(orient, "../iteration_%d/%s.orientations.dat" % (last_orients[0], mol))
- else:
- for mol in molnames:
- orient = os.path.join(basedir, "%s.orientations.dat" % mol)
- assertFileNotExists(orient)
- if iter in stateiters:
- had_sframe = 1
- last_state[0] = iter
- check_unset(iter)
- for mol in molnames:
- states = os.path.join(basedir, "%s.states.dat" % mol)
- assertFileNonempty(states)
- elif last_state[0] is not None and iter not in moliters:
- for mol in molnames:
- states = os.path.join(basedir, "%s.states.dat" % mol)
- assertFileSymlink(states, "../iteration_%d/%s.states.dat" % (last_state[0], mol))
- else:
- for mol in molnames:
- states = os.path.join(basedir, "%s.states.dat" % mol)
- assertFileNotExists(states)
- if had_sframe:
- assertFileExists(surf_header)
- assertFileExists(vol_header)
- elif last_pos[0] is not None:
- assertFileSymlink(surf_header, "../iteration_%d/surface_molecules.dx" % last_pos[0])
- assertFileSymlink(vol_header, "../iteration_%d/volume_molecules.dx" % last_pos[0])
- elif last_orients[0] is not None:
- assertFileSymlink(surf_header, "../iteration_%d/surface_molecules.dx" % last_orients[0])
- assertFileSymlink(vol_header, "../iteration_%d/volume_molecules.dx" % last_orients[0])
- elif last_state[0] is not None:
- assertFileSymlink(surf_header, "../iteration_%d/surface_molecules.dx" % last_state[0])
- assertFileSymlink(vol_header, "../iteration_%d/volume_molecules.dx" % last_state[0])
- else:
- assertFileNotExists(surf_header)
- assertFileNotExists(vol_header)
- class RequireVizDreammV3MolsAscii:
- def __init__(self, dir, alliters,
- molnames,
- positers=None,
- orientiters=None,
- stateiters=None):
- self.dir = dir
- self.alliters = alliters
- self.molnames = molnames
- self.args = {}
- if positers is not None:
- self.args["positers"] = positers
- if orientiters is not None:
- self.args["orientiters"] = orientiters
- if stateiters is not None:
- self.args["stateiters"] = stateiters
- def check(self):
- assertValidVizFilesDreammV3MolsAscii(self.dir, self.alliters, self.molnames, **self.args)
- ###################################################################
- # Give an error if the specified DREAMM V3 (non-grouped) mode viz output set
- # contains invalid (or fails to contain valid) binary mesh data files.
- #
- # Parameters:
- # dir - the directory containing the output files
- # alliters - iteration numbers where any output was produced
- # positers - iteration numbers where mesh pos output was produced, if
- # different from alliters
- # regioniters - iteration numbers where region data output was produced,
- # if different from alliters
- # stateiters - iteration numbers where mesh state was produced, if any
- # (it is assumed that no mesh state data was produced,
- # otherwise)
- # meshnonempty - expect at least one mesh
- ###################################################################
- def assertValidVizFilesDreammV3MeshBin(dir, alliters, positers=None, regioniters=None, stateiters=[], meshnonempty=True):
- last_pos = [None]
- last_rgn = [None]
- last_state = [None]
- # Reset last iterations if our output types are not totally synchronized
- def check_unset(s):
- if last_pos[0] != s:
- last_pos[0] = None
- if last_rgn[0] != s:
- last_rgn[0] = None
- if last_state[0] != s:
- last_state[0] = None
- alliters.sort()
- if positers is None:
- positers = alliters
- positers = set(positers)
- if regioniters is None:
- regioniters = alliters
- regioniters = set(regioniters)
- if stateiters is None:
- stateiters = alliters
- stateiters = set(stateiters)
- for iter in alliters:
- basedir = os.path.join(dir, "frame_data")
- basedir = os.path.join(basedir, "iteration_%d" % iter)
- had_frame = 0
- mesh_pos = os.path.join(basedir, "mesh_positions.bin")
- mesh_rgn = os.path.join(basedir, "region_indices.bin")
- mesh_state = os.path.join(basedir, "mesh_states.bin")
- mesh_header = os.path.join(basedir, "meshes.dx")
- # Check for positions file or symlink
- if iter in positers:
- had_frame = 1
- last_pos[0] = iter
- check_unset(iter)
- if meshnonempty:
- assertFileNonempty(mesh_pos)
- else:
- assertFileExists(mesh_pos)
- elif last_pos[0] is not None and iter not in regioniters and iter not in stateiters:
- assertFileSymlink(mesh_pos, "../iteration_%d/mesh_positions.bin" % last_pos[0])
- else:
- assertFileNotExists(mesh_pos)
- # Check for regions file or symlink
- if iter in regioniters:
- had_frame = 1
- last_rgn[0] = iter
- check_unset(iter)
- if meshnonempty:
- assertFileNonempty(mesh_rgn)
- else:
- assertFileExists(mesh_rgn)
- elif last_rgn[0] is not None and iter not in stateiters:
- assertFileSymlink(mesh_rgn, "../iteration_%d/region_indices.bin" % last_rgn[0])
- else:
- assertFileNotExists(mesh_rgn)
- # Check for states file or symlink
- if iter in stateiters:
- had_frame = 1
- last_state[0] = iter
- check_unset(iter)
- if meshnonempty:
- assertFileNonempty(mesh_state)
- else:
- assertFileExists(mesh_state)
- elif last_state[0] is not None:
- assertFileSymlink(mesh_state, "../iteration_%d/mesh_states.bin" % last_state[0])
- else:
- assertFileNotExists(mesh_state)
- # Check for meshes file or symlink
- if had_frame:
- assertFileNonempty(mesh_header)
- elif last_pos[0] is not None:
- assertFileSymlink(mesh_header, "../iteration_%d/meshes.dx" % last_pos[0])
- elif last_rgn[0] is not None:
- assertFileSymlink(mesh_header, "../iteration_%d/meshes.dx" % last_rgn[0])
- elif last_state[0] is not None:
- assertFileSymlink(mesh_header, "../iteration_%d/meshes.dx" % last_state[0])
- else:
- assertFileNotExists(mesh_header)
- class RequireVizDreammV3MeshBin:
- def __init__(self, dir, alliters, positers=None, regioniters=None, stateiters=None, meshnonempty=None):
- self.dir = dir
- self.alliters = alliters
- self.args = {}
- if positers is not None:
- self.args["positers"] = positers
- if regioniters is not None:
- self.args["regioniters"] = regioniters
- if stateiters is not None:
- self.args["stateiters"] = stateiters
- if meshnonempty is not None:
- self.args["meshnonempty"] = meshnonempty
- def check(self):
- assertValidVizFilesDreammV3MeshBin(self.dir, self.alliters, **self.args)
- ###################################################################
- # Give an error if the specified DREAMM V3 (non-grouped) mode viz output set
- # contains invalid (or fails to contain valid) ascii mesh data files.
- #
- # Parameters:
- # dir - the directory containing the output files
- # alliters - iteration numbers where any output was produced
- # objnames - names of objects whose files to look for
- # objswithregions - names of objects which have regions other than ALL
- # positers - iteration numbers where mesh pos output was produced, if
- # different from alliters
- # regioniters - iteration numbers where region data output was produced,
- # if different from alliters
- # stateiters - iteration numbers where mesh state was produced, if any
- # (it is assumed that no mesh state data was produced,
- # otherwise)
- # meshnonempty - expect at least one mesh
- ###################################################################
- def assertValidVizFilesDreammV3MeshAscii(dir, alliters, objnames, objswithregions=None, positers=None, regioniters=None, stateiters=[], meshnonempty=True):
- last_pos = [None]
- last_rgn = [None]
- last_state = [None]
- # Reset last iterations if our output types are not totally synchronized
- def check_unset(s):
- if last_pos[0] != s:
- last_pos[0] = None
- if last_rgn[0] != s:
- last_rgn[0] = None
- if last_state[0] != s:
- last_state[0] = None
- alliters.sort()
- if positers is None:
- positers = alliters
- positers = set(positers)
- if regioniters is None:
- regioniters = alliters
- regioniters = set(regioniters)
- if stateiters is None:
- stateiters = alliters
- stateiters = set(stateiters)
- if objswithregions is None:
- objswithregions = objnames
- for iter in alliters:
- basedir = os.path.join(dir, "frame_data")
- basedir = os.path.join(basedir, "iteration_%d" % iter)
- had_frame = 0
- mesh_header = os.path.join(basedir, "meshes.dx")
- # Check for positions file or symlink
- if iter in positers:
- had_frame = 1
- last_pos[0] = iter
- check_unset(iter)
- for obj in objnames:
- mesh_pos = os.path.join(basedir, obj + ".positions.dat")
- mesh_conn = os.path.join(basedir, obj + ".connections.dat")
- assertFileNonempty(mesh_pos)
- assertFileNonempty(mesh_conn)
- elif last_pos[0] is not None and iter not in regioniters and iter not in stateiters:
- for obj in objnames:
- mesh_pos = os.path.join(basedir, obj + ".positions.dat")
- mesh_conn = os.path.join(basedir, obj + ".connections.dat")
- assertFileSymlink(mesh_pos, "../iteration_%d/%s.positions.dat" % (last_pos[0], obj))
- assertFileSymlink(mesh_conn, "../iteration_%d/%s.connections.dat" % (last_pos[0], obj))
- else:
- for obj in objnames:
- mesh_pos = os.path.join(basedir, obj + ".positions.dat")
- mesh_conn = os.path.join(basedir, obj + ".connections.dat")
- assertFileNotExists(mesh_pos)
- assertFileNotExists(mesh_conn)
- # Check for regions file or symlink
- if iter in regioniters:
- had_frame = 1
- last_rgn[0] = iter
- check_unset(iter)
- for obj in objswithregions:
- mesh_rgn = os.path.join(basedir, obj + ".region_indices.dat")
- assertFileExists(mesh_rgn)
- elif last_rgn[0] is not None and iter not in stateiters:
- for obj in objswithregions:
- mesh_rgn = os.path.join(basedir, obj + ".region_indices.dat")
- assertFileSymlink(mesh_rgn, "../iteration_%d/%s.region_indices.dat" % (last_rgn[0], obj))
- else:
- for obj in objswithregions:
- mesh_rgn = os.path.join(basedir, obj + ".region_indices.dat")
- assertFileNotExists(mesh_rgn)
- # Check for states file or symlink
- if iter in stateiters:
- had_frame = 1
- last_state[0] = iter
- check_unset(iter)
- for obj in objnames:
- mesh_state = os.path.join(basedir, obj + ".states.dat")
- assertFileNonempty(mesh_state)
- elif last_state[0] is not None:
- for obj in objnames:
- mesh_state = os.path.join(basedir, obj + ".states.dat")
- assertFileSymlink(mesh_state, "../iteration_%d/%s.states.dat" % (last_state[0], obj))
- else:
- for obj in objnames:
- mesh_state = os.path.join(basedir, obj + ".states.dat")
- assertFileNotExists(mesh_state)
- # Check for meshes file or symlink
- if had_frame:
- assertFileNonempty(mesh_header)
- elif last_pos[0] is not None:
- assertFileSymlink(mesh_header, "../iteration_%d/meshes.dx" % last_pos[0])
- elif last_rgn[0] is not None:
- assertFileSymlink(mesh_header, "../iteration_%d/meshes.dx" % last_rgn[0])
- elif last_state[0] is not None:
- assertFileSymlink(mesh_header, "../iteration_%d/meshes.dx" % last_state[0])
- else:
- assertFileNotExists(mesh_header)
- class RequireVizDreammV3MeshAscii:
- def __init__(self, dir, alliters, objnames, objswithregions=None, positers=None, regioniters=None, stateiters=None, meshnonempty=None):
- self.dir = dir
- self.alliters = alliters
- self.objnames = objnames
- self.args = {}
- if objswithregions is not None:
- self.args["objswithregions"] = objswithregions
- if positers is not None:
- self.args["positers"] = positers
- if regioniters is not None:
- self.args["regioniters"] = regioniters
- if stateiters is not None:
- self.args["stateiters"] = stateiters
- if meshnonempty is not None:
- self.args["meshnonempty"] = meshnonempty
- def check(self):
- assertValidVizFilesDreammV3MeshAscii(self.dir, self.alliters, self.objnames, **self.args)
- ###################################################################
- # Give an error if the specified DREAMM V3 (grouped) mode viz output set is
- # invalid.
- #
- # Parameters:
- # dir - the directory containing the output files
- # name - name of the output set
- # cpno - checkpoint sequence number (assumed to be 1 otherwise)
- # n_iters - total number of iterations with output (None to skip
- # check)
- # n_times - total number of distinct time points with output (None to
- # skip check)
- # meshpos - true to expect mesh pos file, false to not
- # rgnindx - true to expect region indices file, false to not
- # meshstate - true to expect mesh state file, false to not
- # meshnonempty - true to expect at least 1 mesh
- # molpos - true to expect mol pos file, false to not
- # molorient - true to expect mol orient file, false to not
- # molstate - true to expect mol state file, false to not
- # molsnonempty - true to expect at least 1 molecule
- ###################################################################
- def assertValidVizFilesDreammV3Grouped(dir, name,
- cpno=1,
- n_iters=None,
- n_times=None,
- meshpos=True,
- rgnindx=True,
- meshstate=False,
- meshnonempty=True,
- molpos=True,
- molorient=True,
- molstate=False,
- molsnonempty=True):
- fmtargs = name, cpno
- assertFileNonempty(os.path.join(dir, "%s.%d.dx" % fmtargs))
- path = os.path.join(dir, "%s.mesh_positions.%d.bin" % fmtargs)
- if meshpos:
- if meshnonempty:
- assertFileNonempty(path)
- else:
- assertFileExists(path)
- else:
- assertFileNotExists(path)
- path = os.path.join(dir, "%s.region_indices.%d.bin" % fmtargs)
- if rgnindx:
- assertFileExists(path)
- else:
- assertFileNotExists(path)
- path = os.path.join(dir, "%s.mesh_states.%d.bin" % fmtargs)
- if meshstate:
- if meshnonempty:
- assertFileNonempty(path)
- else:
- assertFileExists(path)
- else:
- assertFileNotExists(path)
- path = os.path.join(dir, "%s.molecule_positions.%d.bin" % fmtargs)
- if molpos:
- if molsnonempty:
- assertFileNonempty(path)
- else:
- assertFileExists(path)
- else:
- assertFileNotExists(path)
- path = os.path.join(dir, "%s.molecule_orientations.%d.bin" % fmtargs)
- if molorient:
- if molsnonempty:
- assertFileNonempty(path)
- else:
- assertFileExists(path)
- else:
- assertFileNotExists(path)
- path = os.path.join(dir, "%s.molecule_states.%d.bin" % fmtargs)
- if molstate:
- if molsnonempty:
- assertFileNonempty(path)
- else:
- assertFileExists(path)
- else:
- assertFileNotExists(path)
- ipath = os.path.join(dir, "%s.iteration_numbers.%d.bin" % fmtargs)
- tpath = os.path.join(dir, "%s.time_values.%d.bin" % fmtargs)
- if n_iters is not None:
- assertFileNonempty(ipath, 12*n_iters)
- else:
- assertFileNonempty(ipath)
- if n_times is not None:
- assertFileNonempty(tpath, 8*n_times)
- else:
- assertFileNonempty(tpath)
- class RequireVizDreammV3Grouped:
- def __init__(self, dir, name,
- cpno=None,
- n_iters=None,
- n_times=None,
- meshpos=None,
- rgnindx=None,
- meshstate=None,
- meshnonempty=None,
- molpos=None,
- molorient=None,
- molstate=None,
- molsnonempty=None):
- self.dir = dir
- self.name = name
- self.args = {}
- if cpno is not None:
- self.args["cpno"] = cpno
- if n_iters is not None:
- self.args["n_iters"] = n_iters
- if n_times is not None:
- self.args["n_times"] = n_times
- if meshpos is not None:
- self.args["meshpos"] = meshpos
- if rgnindx is not None:
- self.args["rgnindx"] = rgnindx
- if meshstate is not None:
- self.args["meshstate"] = meshstate
- if meshnonempty is not None:
- self.args["meshnonempty"] = meshnonempty
- if molpos is not None:
- self.args["molpos"] = molpos
- if molorient is not None:
- self.args["molorient"] = molorient
- if molstate is not None:
- self.args["molstate"] = molstate
- if molsnonempty is not None:
- self.args["molsnonempty"] = molsnonempty
- def check(self):
- assertValidVizFilesDreammV3Grouped(self.dir, self.name, **self.args)
|