def fetch(self):
        """Creates a cell initializer object.

        Note that the cell can be initialized from the lengths of the sides and
        the angles between them instead of by a vector, as specified by the
        'abc' or 'abcABC' modes.
        """

        mode = self.mode.fetch()

        ibase = super(InputInitCell, self).fetch()
        if mode == "abc" or mode == "abcABC":

            h = io_xml.read_array(np.float, ibase.value)

            if mode == "abc":
                if h.size != 3:
                    raise ValueError(
                        "If you are initializing cell from cell side lengths you must pass the 'cell' tag an array of 3 floats."
                    )
                else:
                    h = mt.abc2h(h[0], h[1], h[2], np.pi / 2, np.pi / 2,
                                 np.pi / 2)
            elif mode == "abcABC":
                if h.size != 6:
                    raise ValueError(
                        "If you are initializing cell from cell side lengths and angles you must pass the 'cell' tag an array of 6 floats."
                    )
                else:
                    h = mt.abc2h(
                        h[0],
                        h[1],
                        h[2],
                        h[3] * np.pi / 180.0,
                        h[4] * np.pi / 180.0,
                        h[5] * np.pi / 180.0,
                    )

            h.shape = (9, )
            ibase.value = h
            mode = "manual"

        if mode == "manual":
            h = ibase.value
            if h.size != 9:
                raise ValueError(
                    "Cell objects must contain a 3x3 matrix describing the cell vectors."
                )

            if not (h[3] == 0.0 and h[6] == 0.0 and h[7] == 0.0):
                warning(
                    "Cell vector matrix must be upper triangular, all elements below the diagonal being set to zero.",
                    verbosity.low,
                )
                h[3] = h[6] = h[7] = 0
            ibase.value = h

        return self._initclass(value=ibase.value,
                               mode=mode,
                               units=self.units.fetch())
    def getval(self):
        """Calculates the value from the data supplied in the xml file.

        Either reads the string from the input file as an array of numbers,
        or as a string specifying either a file name or a single value.
        """

        value = super(InputInitBase, self).fetch()
        if self.mode.fetch() == "manual":
            if "[" in value and "]" in value:  # value appears to be a list
                if self._storageclass is float:
                    value = io_xml.read_array(np.float, value)
                else:
                    value = io_xml.read_list(value)
            else:
                value = io_xml.read_type(self._storageclass, value)
        else:
            value = str(value)  # typically this will be a no-op
        return value
Exemple #3
0
    def getval(self):
        """Calculates the value from the data supplied in the xml file.

        Either reads the string from the input file as an array of numbers,
        or as a string specifying either a file name or a single value.
        """

        value = super(InputInitBase, self).fetch()
        if self.mode.fetch() == "manual":
            if '[' in value and ']' in value:  # value appears to be a list
                if self._storageclass is float:
                    value = io_xml.read_array(np.float, value)
                else:
                    value = io_xml.read_list(value)
            else:
                value = io_xml.read_type(self._storageclass, value)
        else:
            value = str(value)  # typically this will be a no-op
        return value
Exemple #4
0
    def fetch(self):
        """Creates a cell initializer object.

        Note that the cell can be initialized from the lengths of the sides and
        the angles between them instead of by a vector, as specified by the
        'abc' or 'abcABC' modes.
        """

        mode = self.mode.fetch()

        ibase = super(InputInitCell, self).fetch()
        if mode == "abc" or mode == "abcABC":

            h = io_xml.read_array(np.float, ibase.value)

            if mode == "abc":
                if h.size != 3:
                    raise ValueError("If you are initializing cell from cell side lengths you must pass the 'cell' tag an array of 3 floats.")
                else:
                    h = mt.abc2h(h[0], h[1], h[2], np.pi / 2, np.pi / 2, np.pi / 2)
            elif mode == "abcABC":
                if h.size != 6:
                    raise ValueError("If you are initializing cell from cell side lengths and angles you must pass the 'cell' tag an array of 6 floats.")
                else:
                    h = mt.abc2h(h[0], h[1], h[2], h[3] * np.pi / 180.0, h[4] * np.pi / 180.0, h[5] * np.pi / 180.0)

            h.shape = (9,)
            ibase.value = h
            mode = "manual"

        if mode == "manual":
            h = ibase.value
            if h.size != 9:
                raise ValueError("Cell objects must contain a 3x3 matrix describing the cell vectors.")

            if not (h[3] == 0.0 and h[6] == 0.0 and h[7] == 0.0):
                warning("Cell vector matrix must be upper triangular, all elements below the diagonal being set to zero.", verbosity.low)
                h[3] = h[6] = h[7] = 0
            ibase.value = h

        return self._initclass(value=ibase.value, mode=mode, units=self.units.fetch())