Creates an Xr object from a string representation.

        Args:
            string (str): string representation of an Xr object.
            use_cores (bool): use core positions and discard shell
                    positions if set to True (default).  Otherwise,
                    use shell positions and discard core positions.
            thresh (float): relative threshold for consistency check
                    between cell parameters (lengths and angles) from
                    header information and cell vectors, respectively.

        Returns:
            xr (Xr): Xr object corresponding to the input
                    string representation.

def from_string(string, use_cores=True, thresh=1.e-4):
        """
        Creates an Xr object from a string representation.

        Args:
            string (str): string representation of an Xr object.
            use_cores (bool): use core positions and discard shell
                    positions if set to True (default).  Otherwise,
                    use shell positions and discard core positions.
            thresh (float): relative threshold for consistency check
                    between cell parameters (lengths and angles) from
                    header information and cell vectors, respectively.

        Returns:
            xr (Xr): Xr object corresponding to the input
                    string representation.
        """
        lines = string.split("\n")
        toks = lines[0].split()
        lengths = [float(toks[i]) for i in range(1, len(toks))]
        toks = lines[1].split()
        angles = [float(i) for i in toks[0:3]]
        toks = lines[2].split()
        nsites = int(toks[0])
        mat = np.zeros((3,3), dtype=float)
        for i in range(3):
            toks = lines[4+nsites+i].split()
            toks2 = lines[4+nsites+i+3].split()
            for j, item in enumerate(toks):
                if item != toks2[j]:
                    raise RuntimeError("expected both matrices"
                            " to be the same in xr file")
            mat[i] = np.array([float(w) for w in toks])
        lat = Lattice(mat)
        if fabs(lat.a-lengths[0])/fabs(lat.a) > thresh or \
                fabs(lat.b-lengths[1])/fabs(lat.b) > thresh or \
                fabs(lat.c-lengths[2])/fabs(lat.c) > thresh or \
                fabs(lat.alpha-angles[0])/fabs(lat.alpha) > thresh or \
                fabs(lat.beta-angles[1])/fabs(lat.beta) > thresh or \
                fabs(lat.gamma-angles[2])/fabs(lat.gamma) > thresh:
            raise RuntimeError("cell parameters in header ("+str(lengths)+\
                    ", "+str(angles)+") are not consistent with Cartesian"+\
                    " lattice vectors ("+str(lat.abc)+", "+\
                    str(lat.angles)+")")
        # Ignore line w/ index 3.
        sp = []
        coords = []
        for j in range(nsites):
            m = re.match(r"\d+\s+(\w+)\s+([0-9\-\.]+)\s+([0-9\-\.]+)\s+" +
                         r"([0-9\-\.]+)", lines[4+j].strip())
            if m:
                tmp_sp = m.group(1)
                if use_cores and tmp_sp[len(tmp_sp)-2:] == "_s":
                    continue
                if not use_cores and tmp_sp[len(tmp_sp)-2:] == "_c":
                    continue
                if tmp_sp[len(tmp_sp)-2] == "_":
                    sp.append(tmp_sp[0:len(tmp_sp)-2])
                else:
                    sp.append(tmp_sp)
                coords.append([float(m.group(i)) for i in range(2, 5)])
        return Xr(Structure(lat, sp, coords, coords_are_cartesian=True))