Beispiel #1
0
def open_with_pygmx(topology, trajectory, cached=False, reindex=False,
                    ignore_index_timestamps=False, index_file=None):
    """Open a topology and trajectory with pygmx."""
    try:
        rd = pygmx.open(trajectory, ignore_index_timestamps=ignore_index_timestamps)
    except InvalidMagicException:
        raise InvalidIndexException('This is not a valid index file: {}'.format(trajectory))
    except InvalidIndexException:
        if reindex:
            try:
                os.remove(pygmx.index_filename_for_xtc(trajectory))
            except FileNotFoundError:
                pass
            rd = pygmx.open(trajectory)
        else:
            raise InvalidIndexException('Index file is invalid, us reindex=True to regenerate.')

    if cached is not False:
        if isinstance(cached, bool):
            maxsize = 128
        else:
            maxsize = cached
        reader = CachedReader(rd, maxsize)
    else:
        reader = BaseReader(rd)
    if topology.endswith('.tpr'):
        atms = atoms.from_tprfile(topology, index_file=index_file)
    elif topology.endswith('.gro'):
        atms = atoms.from_grofile(topology, index_file=index_file)
    return atms, reader
Beispiel #2
0
 def __init__(self, edrfile):
     """
     Args:
         edrfile: Filename of the energy file
         topology (opt.): Filename of the topology, speeds up file io since the length of the energy file is known
     """
     edr = pygmx.open(edrfile)
     self.time, data = edr.read()
     self.types, self.units = zip(*edr.types)
     self.data = data.T