Beispiel #1
0
 def __repr__(self):
     """Represent the Poscar class."""
     header = (str(self.comment) + str("\n1.0\n") +
               str(self.atoms.lattice_mat[0][0]) + " " +
               str(self.atoms.lattice_mat[0][1]) + " " +
               str(self.atoms.lattice_mat[0][2]) + "\n" +
               str(self.atoms.lattice_mat[1][0]) + " " +
               str(self.atoms.lattice_mat[1][1]) + " " +
               str(self.atoms.lattice_mat[1][2]) + "\n" +
               str(self.atoms.lattice_mat[2][0]) + " " +
               str(self.atoms.lattice_mat[2][1]) + " " +
               str(self.atoms.lattice_mat[2][2]) + "\n")
     order = np.argsort(self.atoms.elements)
     coords = self.atoms.frac_coords
     coords_ordered = np.array(coords)[order]
     elements_ordered = np.array(self.atoms.elements)[order]
     props_ordered = np.array(self.atoms.props)[order]
     # check_selective_dynamics = False
     counts = get_counts(elements_ordered)
     if "T" in "".join(map(str, self.atoms.props[0])):
         middle = (" ".join(map(str, counts.keys())) + "\n" +
                   " ".join(map(str, counts.values())) +
                   "\nSelective dynamics\n" + "Direct\n")
     else:
         middle = (" ".join(map(str, counts.keys())) + "\n" +
                   " ".join(map(str, counts.values())) + "\ndirect\n")
     rest = ""
     # print ('repr',self.frac_coords, self.frac_coords.shape)
     for ii, i in enumerate(coords_ordered):
         p_ordered = str(props_ordered[ii])
         rest = rest + " ".join(map(str, i)) + " " + str(p_ordered) + "\n"
     result = header + middle + rest
     return result
Beispiel #2
0
    def write_file(self, filename):
        """Write the Poscar object to a file."""
        f = open(filename, "w")
        header = (str(self.comment) + str("\n1.0\n") +
                  str(self.atoms.lattice_mat[0][0]) + " " +
                  str(self.atoms.lattice_mat[0][1]) + " " +
                  str(self.atoms.lattice_mat[0][2]) + "\n" +
                  str(self.atoms.lattice_mat[1][0]) + " " +
                  str(self.atoms.lattice_mat[1][1]) + " " +
                  str(self.atoms.lattice_mat[1][2]) + "\n" +
                  str(self.atoms.lattice_mat[2][0]) + " " +
                  str(self.atoms.lattice_mat[2][1]) + " " +
                  str(self.atoms.lattice_mat[2][2]) + "\n")
        # order = np.argsort(self.atoms.elements)
        coords = self.atoms.frac_coords
        # DO NOT USE ORDER
        coords_ordered = np.array(coords)  # [order]
        elements_ordered = np.array(self.atoms.elements)  # [order]
        props_ordered = np.array(self.atoms.props)  # [order]
        # check_selective_dynamics = False
        counts = get_counts(elements_ordered)
        if "T" in "".join(map(str, self.atoms.props[0])):
            middle = (" ".join(map(str, counts.keys())) + "\n" +
                      " ".join(map(str, counts.values())) +
                      "\nSelective dynamics\n" + "Direct\n")
        else:
            middle = (" ".join(map(str, counts.keys())) + "\n" +
                      " ".join(map(str, counts.values())) + "\ndirect\n")
        rest = ""
        # print ('repr',self.frac_coords, self.frac_coords.shape)
        for ii, i in enumerate(coords_ordered):
            p_ordered = str(props_ordered[ii])
            rest = rest + " ".join(map(str, i)) + " " + str(p_ordered) + "\n"

        result = header + middle + rest

        f.write(result)
        f.close()
Beispiel #3
0
    def get_string(self, cart=True, sort_order="X"):
        """
        Convert Atoms to string.

        Optional arguments below.

        Args:
          cart:True/False for cartesian/fractional coords.

          sort_order: sort by chemical properties of
                    elements. Default electronegativity.
        """
        system = str(self.composition.formula)
        header = (str(system) + str("\n1.0\n") + str(self.lattice_mat[0][0]) +
                  " " + str(self.lattice_mat[0][1]) + " " +
                  str(self.lattice_mat[0][2]) + "\n" +
                  str(self.lattice_mat[1][0]) + " " +
                  str(self.lattice_mat[1][1]) + " " +
                  str(self.lattice_mat[1][2]) + "\n" +
                  str(self.lattice_mat[2][0]) + " " +
                  str(self.lattice_mat[2][1]) + " " +
                  str(self.lattice_mat[2][2]) + "\n")
        if sort_order is None:
            order = np.argsort(self.elements)
        else:
            order = np.argsort([
                Specie(i).element_property(sort_order) for i in self.elements
            ])
        if cart:
            coords = self.cart_coords
        else:
            coords = self.frac_coords
        coords_ordered = np.array(coords)[order]
        elements_ordered = np.array(self.elements)[order]
        props_ordered = np.array(self.props)[order]
        # check_selective_dynamics = False # TODO
        counts = get_counts(elements_ordered)
        cart_frac = ""
        if cart:
            cart_frac = "\nCartesian\n"
        else:
            cart_frac = "\nDirect\n"

        if "T" in "".join(map(str, self.props[0])):
            middle = (" ".join(map(str, counts.keys())) + "\n" +
                      " ".join(map(str, counts.values())) +
                      "\nSelective dynamics\n" + cart_frac)
        else:
            middle = (" ".join(map(str, counts.keys())) + "\n" +
                      " ".join(map(str, counts.values())) + cart_frac)
        rest = ""

        for ii, i in enumerate(coords_ordered):
            if self.show_props:
                rest = (rest + " ".join(map(str, i)) + " " +
                        str(props_ordered[ii]) + "\n")
            else:
                rest = rest + " ".join(map(str, i)) + "\n"

        result = header + middle + rest
        return result