How to use the pyxtal.tolerance.Tol_matrix function in pyxtal

To help you get started, we’ve selected a few pyxtal 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 qzhu2017 / PyXtal / pyxtal / molecule.py View on Github external
    def __init__(self, mol, tm=Tol_matrix(prototype="molecular")):
        mo = None
        if type(mol) == str:
            # Parse molecules: either file or molecule name
            tmp = mol.split(".")
            if len(tmp) > 1:
                # Load the molecule from the given file
                if tmp[-1] in ["xyz", "gjf", "g03", "json"]:
                    if os.path.exists(mol):
                        mo = Molecule.from_file(mol)
                    else:
                        raise NameError("{:s} is not a valid path".format(mol))
                else:
                    raise NameError("{:s} is not a supported format".format(tmp[-1]))
            else:
                # print('\nLoad the molecule {:s} from collections'.format(mol))
                mo = molecule_collection[mol]
github qzhu2017 / PyXtal / pyxtal / molecular_crystal.py View on Github external
numMols = np.array(numMols)  # must convert it to np.array
        self.numMols0 = numMols  # in the PRIMITIVE cell
        self.numMols = self.numMols0 * cellsize(self.group)  # in the CONVENTIONAL cell

        # boolean numbers
        self.check_atomic_distances = check_atomic_distances
        self.allow_inversion = allow_inversion
        self.select_high = select_high

        # Set the tolerance matrix
        # The Tol_matrix object for checking inter-atomic distances within the structure.
        if type(tm) == Tol_matrix:
            self.tol_matrix = tm
        else:
            try:
                self.tol_matrix = Tol_matrix(prototype=tm)
            # TODO remove bare except
            except:
                msg = "Error: tm must either be a Tol_matrix object +\n"
                msg += "or a prototype string for initializing one."
                printx(msg, priority=1)
                self.valid = False
                self.struct = None
                return

        self.molecules = []  # A pyxtal_molecule objects,
        for mol in molecules:
            self.molecules.append(pyxtal_molecule(mol, self.tol_matrix))

        """
        The valid orientations for each molecule and Wyckoff position.
        May be copied when generating a new molecular_crystal to save a
github qzhu2017 / PyXtal / pyxtal / tolerance.py View on Github external
def from_single_value(self, value):
        """
        Creates a Tol_matrix which only has a single tolerance value. Using get_tol will
        always return the same value.

        Args:
            value: the tolerance value to use

        Returns:
            a Tol_matrix object whose methods are overridden to use a single tolerance value
        """
        tm = Tol_matrix()
        tm.prototype = "single value"
        tm.matrix = np.array([[value]])
        tm.custom_values = [(1, 1)]
        tm.radius_type = "N/A"
        return tm
github qzhu2017 / PyXtal / pyxtal / crystal.py View on Github external
def __init__(
        self,
        group,
        species,
        numIons,
        factor,
        lattice=None,
        sites = None,
        tm=Tol_matrix(prototype="atomic", factor=0.7),
    ):
        # NOTE tol_m unused?
        tol_m = 0.1
        self.dim = 0
        self.PBC = [0, 0, 0]
        self.sg = None
        self.init_common(species, numIons, factor, group, lattice, sites, tm)
github qzhu2017 / PyXtal / pyxtal / molecular_crystal.py View on Github external
def __init__(
        self,
        group,
        molecules,
        numMols,
        volume_factor,
        select_high=True,
        allow_inversion=True,
        orientations=None,
        check_atomic_distances=True,
        fmt="xyz",
        thickness=None,
        lattice=None,
        tm=Tol_matrix(prototype="molecular"),
    ):

        self.dim = 2
        self.numattempts = 0
        if type(group) != Group:
            group = Group(group, self.dim)
        number = group.number  # The layer group number of the crystal."""
        self.thickness = thickness  # the thickness in Angstroms
        self.PBC = [1, 1, 0]
        self.init_common(
            molecules,
            numMols,
            volume_factor,
            select_high,
            allow_inversion,
            orientations,
github qzhu2017 / PyXtal / pyxtal / crystal.py View on Github external
)
            elif self.dim == 1:
                self.lattice = Lattice(
                    self.group.lattice_type,
                    self.volume,
                    PBC=self.PBC,
                    unique_axis=unique_axis,
                    # NOTE self.area is part of 1D class
                    area=self.area,
                )
        # Set the tolerance matrix for checking inter-atomic distances
        if type(tm) == Tol_matrix:
            self.tol_matrix = tm
        else:
            try:
                self.tol_matrix = Tol_matrix(prototype=tm)
            # TODO Remove bare except
            except:
                printx(
                    (
                        "Error: tm must either be a Tol_matrix object or "
                        "a prototype string for initializing one."
                    ),
                    priority=1,
                )
                self.valid = False
                self.struct = None
                return
        
        self.sites = {}
        for i, specie in enumerate(self.species):
            if sites is not None and sites[i] is not None:
github qzhu2017 / PyXtal / pyxtal / crystal.py View on Github external
def __init__(
        self,
        group,
        species,
        numIons,
        factor,
        thickness=None,
        lattice=None,
        sites = None,
        tm=Tol_matrix(prototype="atomic"),
    ):
        self.dim = 2
        self.PBC = [1, 1, 0]

        if type(group) != Group:
            group = Group(group, self.dim)
        number = group.number  # The layer group number of the crystal
        self.thickness = thickness  # in Angstroms, in the 3rd dimenion of unit cell
        self.init_common(species, numIons, factor, number, lattice, sites, tm)
github qzhu2017 / PyXtal / pyxtal / operations.py View on Github external
def check_distance(
    coord1,
    coord2,
    species1,
    species2,
    lattice,
    PBC=[1, 1, 1],
    tm=Tol_matrix(prototype="atomic"),
    d_factor=1.0,
):
    """
    Check the distances between two set of atoms. Distances between coordinates
    within the first set are not checked, and distances between coordinates within
    the second set are not checked. Only distances between points from different
    sets are checked.

    Args:
        coord1: a list of fractional coordinates e.g. [[.1,.6,.4]
            [.3,.8,.2]]
        coord2: a list of new fractional coordinates e.g. [[.7,.8,.9],
            [.4,.5,.6]]
        species1: a list of atomic species or numbers for coord1
        species2: a list of atomic species or numbers for coord2
        lattice: matrix describing the unit cell vectors
github qzhu2017 / PyXtal / pyxtal / tolerance.py View on Github external
def from_file(self, filename):
        try:
            tm = np.load(filename)[0]
            if type(tm) == Tol_matrix:
                return tm
            else:
                printx("Error: invalid file for Tol_matrix.", priority=0)
                return
        except:
            printx("Error: Could not load Tol_matrix from file.", priority=0)
            return