How to use the pyiron.lammps.structure.UnfoldingPrism function in pyiron

To help you get started, we’ve selected a few pyiron examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyiron / pyiron / pyiron / atomistics / structure / pyscal.py View on Github external
def _get_steinhardt_parameter(cell, positions, cutoff=3.50, n_clusters=2, q=[4, 6]):
    sys = pc.System()
    prism = UnfoldingPrism(cell, digits=15)
    xhi, yhi, zhi, xy, xz, yz = prism.get_lammps_prism_str()
    coords = [prism.pos_to_lammps(position) for position in positions]
    sys.box = [[0.0, float(xhi)], [0.0, float(yhi)], [0.0, float(zhi)]]
    sys.atoms = [pc.Atom(pos=p, id=i) for i, p in enumerate(coords)]
    sys.find_neighbors(method='cutoff', cutoff=cutoff)
    sys.calculate_q(q, averaged=True)
    sysq = sys.get_qvals(q, averaged=True)
    cl = cluster.KMeans(n_clusters=n_clusters)
    ind = cl.fit(list(zip(*sysq))).labels_ == 0
    return sysq, ind
github pyiron / pyiron / pyiron / lammps / interactive.py View on Github external
def interactive_cells_setter(self, cell):
        self._prism = UnfoldingPrism(cell)
        lx, ly, lz, xy, xz, yz = self._prism.get_lammps_prism()
        if np.matrix.trace(self._prism.R) != 3:
            warnings.warn(
                "Warning: setting upper trangular matrix might slow down the calculation"
            )

        is_skewed = self._prism.is_skewed()
        is_scaled = self.structure._is_scaled

        if is_skewed and is_scaled:
            self._interactive_lib_command(
                "change_box all x final 0 %f y final 0 %f z final 0 %f \
                 xy final %f xz final %f yz final %f triclinic remap units box"
                % (lx, ly, lz, xy, xz, yz)
            )
        elif is_skewed and not is_scaled:
github pyiron / pyiron / pyiron / lammps / base.py View on Github external
def collect_h5md_file(self, file_name="dump.h5", cwd=None):
        """

        Args:
            file_name:
            cwd:

        Returns:

        """
        prism = UnfoldingPrism(self.structure.cell, digits=15)
        if np.matrix.trace(prism.R) != 3:
            raise RuntimeError("The Lammps output will not be mapped back to pyiron correctly.")
        file_name = self.job_file_name(file_name=file_name, cwd=cwd)
        with h5py.File(file_name, mode="r", libver="latest", swmr=True) as h5md:
            positions = [
                pos_i.tolist() for pos_i in h5md["/particles/all/position/value"]
            ]
            time = [time_i.tolist() for time_i in h5md["/particles/all/position/step"]]
            forces = [for_i.tolist() for for_i in h5md["/particles/all/force/value"]]
            # following the explanation at: http://nongnu.org/h5md/h5md.html
            cell = [
                np.eye(3) * np.array(cell_i.tolist())
                for cell_i in h5md["/particles/all/box/edges/value"]
            ]
            indices = [indices_i.tolist() for indices_i in h5md["/particles/all/indices/value"]]
        with self.project_hdf5.open("output/generic") as h5_file:
github pyiron / pyiron / pyiron / lammps / base.py View on Github external
def _modify_structure_to_allow_requested_deformation(structure, pressure, prism=None):
        """
        Lammps will not allow xy/xz/yz cell deformations in minimization or MD for non-triclinic cells. In case the
        requested pressure for a calculation has these non-diagonal entries, we need to make sure it will run. One way
        to do this is by invoking the lammps `change_box` command, but it is easier to just force our box to to be
        triclinic by adding a very small cell perturbation (in the case where it isn't triclinic already).

        Args:
            pressure (float/int/list/numpy.ndarray/tuple): Between three and six pressures for the x, y, z, xy, xz, and
                yz directions, in that order, or a single value.
        """
        if hasattr(pressure, '__len__'):
            non_diagonal_pressures = np.any([p is not None for p in pressure[3:]])

            if prism is None:
                prism = UnfoldingPrism(structure.cell)

            if non_diagonal_pressures:
                try:
                    if not prism.is_skewed():
                        skew_structure = structure.copy()
                        skew_structure.cell[0, 1] += 2 * prism.acc
                        return skew_structure
                except AttributeError:
                    warnings.warn(
                        "WARNING: Setting a calculation type which uses pressure before setting the structure risks " +
                        "constraining your cell shape evolution if non-diagonal pressures are used but the structure " +
                        "is not triclinic from the start of the calculation."
                    )
        return structure
github pyiron / pyiron / pyiron / lammps / interactive.py View on Github external
def interactive_structure_setter(self, structure):
        self._interactive_lib_command("clear")
        self._set_selective_dynamics()
        self._interactive_lib_command("units " + self.input.control["units"])
        self._interactive_lib_command(
            "dimension " + str(self.input.control["dimension"])
        )
        self._interactive_lib_command("boundary " + self.input.control["boundary"])
        self._interactive_lib_command("atom_style " + self.input.control["atom_style"])

        self._interactive_lib_command("atom_modify map array")
        self._prism = UnfoldingPrism(structure.cell)
        if np.matrix.trace(self._prism.R) != 3:
            warnings.warn(
                "Warning: setting upper trangular matrix might slow down the calculation"
            )
        xhi, yhi, zhi, xy, xz, yz = self._prism.get_lammps_prism()
        if self._prism.is_skewed():
            self._interactive_lib_command(
                "region 1 prism"
                + " 0.0 "
                + str(xhi)
                + " 0.0 "
                + str(yhi)
                + " 0.0 "
                + str(zhi)
                + " "
                + str(xy)
github pyiron / pyiron / pyiron / lammps / interface.py View on Github external
def interactive_structure_setter(self, job, structure):
        self._interactive_lib_command(job=job, command='clear')
        job._set_selective_dynamics()
        self._interactive_lib_command(job=job, command='units ' + job.input.control['units'])
        self._interactive_lib_command(job=job, command='dimension ' + str(job.input.control['dimension']))
        self._interactive_lib_command(job=job, command='boundary ' + job.input.control['boundary'])
        self._interactive_lib_command(job=job, command='atom_style ' + job.input.control['atom_style'])
        self._interactive_lib_command(job=job, command="atom_modify map array")
        self._interactive_prism = UnfoldingPrism(structure.cell)
        if np.matrix.trace(self._interactive_prism.R) != 3:
            print('Warning: setting upper trangular matrix might slow down the calculation')
        xhi, yhi, zhi, xy, xz, yz = self._interactive_prism.get_lammps_prism()
        if self._interactive_prism.is_skewed():
            self._interactive_lib_command(job=job, command='region 1 prism' +
                                          ' 0.0 ' + str(xhi) + ' 0.0 ' + str(yhi) + ' 0.0 ' + str(zhi) +
                                          ' ' + str(xy) + ' ' + str(xz) + ' ' + str(yz) + ' units box')
        else:
            self._interactive_lib_command(job=job, command='region 1 block' +
                                          ' 0.0 ' + str(xhi) + ' 0.0 ' + str(yhi) + ' 0.0 ' + str(zhi) + ' units box')
        el_struct_lst = job.structure.get_species_symbols()
        el_obj_lst = job.structure.get_species_objects()
        el_eam_lst = job.input.potential.get_element_lst()
        self._interactive_lib_command(job=job, command='create_box ' + str(len(el_eam_lst)) + ' 1')
        el_dict = {}
        for id_eam, el_eam in enumerate(el_eam_lst):
github pyiron / pyiron / pyiron / lammps / interactive.py View on Github external
def interactive_cells_setter(self, cell):
        self._prism = UnfoldingPrism(cell)
        lx, ly, lz, xy, xz, yz = self._prism.get_lammps_prism()
        if np.matrix.trace(self._prism.R) != 3:
            warnings.warn(
                "Warning: setting upper trangular matrix might slow down the calculation"
            )

        is_skewed = self._prism.is_skewed()
        is_scaled = self.structure._is_scaled

        if is_skewed and is_scaled:
            self._interactive_lib_command(
                "change_box all x final 0 %f y final 0 %f z final 0 %f \
                 xy final %f xz final %f yz final %f triclinic remap units box"
                % (lx, ly, lz, xy, xz, yz)
            )
        elif is_skewed and not is_scaled:
github pyiron / pyiron / pyiron / lammps / base.py View on Github external
def _get_rotation_matrix(self, pressure):
        """

        Args:
            pressure:

        Returns:

        """
        if self.structure is not None:
            if self._prism is None:
                self._prism = UnfoldingPrism(self.structure.cell)

            self.structure = self._modify_structure_to_allow_requested_deformation(
                pressure=pressure,
                structure=self.structure,
                prism=self._prism
            )
            rotation_matrix = self._prism.R
        else:
            warnings.warn(
                "No structure set, can not validate the simulation cell!"
            )
            rotation_matrix = None
        return rotation_matrix