Example #1
0
 def from_cell_str(cls, unit_cell_str, sub=slice(None)):
     sub = fix_slice(sub)
     if "," in unit_cell_str:
         parameters = list(parse_unit(word) for word in unit_cell_str.split(",") if len(word) > 0)
         if len(parameters) == 1:
             a = parameters[0]
             single = numpy.array([[a,0,0],[0,a,0],[0,0,a]], float)
         elif len(parameters) == 3:
             a,b,c = parameters
             single = numpy.array([[[a,0,0],[0,b,0],[0,0,c]]], float)
         elif len(parameters) == 6:
             a,b,c,alpha,beta,gamma = parameters
             uc = UnitCell(
                 numpy.array([[1,0,0],[0,1,0],[0,0,1]], float),
                 numpy.array([True, True, True]),
             )
             uc.set_parameterst(numpy.array([a,b,c]), numpy.array([alpha,beta,gamma]))
             single = uc.cell
         elif len(parameters) == 9:
             single = numpy.array(parameters,float).reshape((3,3)).transpose()
         else:
             raise ValueError("If the --cell option contains comma's, one, three, six or nine value(s) are expected.")
         data = single.reshape((3,3,1))
     else:
         data = [
             [
                 load_track("%s.%s.%s" % (unit_cell_str, v, c), sub)
                 for v in "abc"
             ]
             for c in "xyz"
         ]
     return cls(data)
Example #2
0
 def read_into(self, destination, sub=None):
     sub = fix_slice(sub)
     dtype, f = self._get_read_buffer(sub.start)
     stop_bytes = min(sub.stop*dtype.itemsize, self._get_data_size())
     length = stop_bytes/dtype.itemsize - sub.start
     tmp = numpy.fromfile(f, dtype, length, '')[::sub.step]
     length = (length-1)/sub.step+1
     destination[:length] = tmp
     f.close()
     return length
Example #3
0
 def read(self, sub=None):
     sub = fix_slice(sub)
     dtype, f = self._get_read_buffer(sub.start)
     stop_bytes = min(sub.stop*dtype.itemsize, self._get_data_size())
     length = stop_bytes/dtype.itemsize - sub.start
     result = numpy.fromfile(f, dtype, length, '')[::sub.step]
     if not result.flags["C_CONTIGUOUS"]:
         result = result.copy()
     f.close()
     return result
Example #4
0
    def __init__(self, filenames, dtype, buffer_size=None, dot_interval=None, sub=slice(None)):
        MultiTrackBase.__init__(self)
        if buffer_size is None:
            buffer_size = context.default_buffer_size
        if dot_interval is None:
            dot_interval = context.default_dot_interval

        # some residual parameters
        self.dot_interval = dot_interval
        self.row_counter = 0
        self.sub = fix_slice(sub)

        self.init_buffer(buffer_size, dtype)
        self.init_tracks(filenames, dtype)
        self.init_shortest()
Example #5
0
def iter_unit_cells(unit_cell_str, sub=None):
    sub = fix_slice(sub)
    if len(unit_cell_str) == 0:
        uc = UnitCell(
            numpy.array([[1,0,0],[0,1,0],[0,0,1]], float),
            numpy.array([False,False,False]),
        )
        while True:
            yield uc
    if "," in unit_cell_str:
        parameters = list(parse_unit(word) for word in unit_cell_str.split(",") if len(word) > 0)
        if len(parameters) == 1:
            a= parameters[0]
            uc = UnitCell(
                numpy.array([[a,0,0],[0,a,0],[0,0,a]], float),
                numpy.array([True, True, True]),
            )
        elif len(parameters) == 3:
            a,b,c = parameters
            uc = UnitCell(
                numpy.array([[a,0,0],[0,b,0],[0,0,c]], float),
                numpy.array([True, True, True]),
            )
        elif len(parameters) == 6:
            a,b,c,alpha,beta,gamma = parameters
            uc = UnitCell.from_parameters3(
                numpy.array([a,b,c]),
                numpy.array([alpha,beta,gamma])
            )
        elif len(parameters) == 9:
            uc = UnitCell(
                numpy.array(parameters, float).reshape((3,3)),
                numpy.array([True, True, True]),
            )
        else:
            raise ValueError("If the --cell option contains comma's, one, three, six or nine value(s) are expected.")
        while True:
            yield uc
    else:
        filenames = ["%s.%s" % (unit_cell_str, suffix) for suffix in ["a.x", "a.y", "a.z", "b.x", "b.y", "b.z", "c.x", "c.y", "c.z"]]
        dtype = numpy.dtype([("cell", float, (3,3))])
        mtr = MultiTracksReader(filenames, dtype, sub=sub)
        for row in mtr:
            yield UnitCell(
                numpy.array(row["cell"], float),
                numpy.array([True, True, True]),
            )