How to use the pyxtal.database.element.Element 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 / crystal.py View on Github external
def estimate_volume(self):
        """
        Estimates the volume of a unit cell based on the number and types of ions.
        Assumes each atom takes up a sphere with radius equal to its covalent bond
        radius.

        Returns:
            a float value for the estimated volume
        """
        volume = 0
        for numIon, specie in zip(self.numIons, self.species):
            r = random.uniform(
                Element(specie).covalent_radius, Element(specie).vdw_radius
            )
            volume += numIon * 4 / 3 * np.pi * r ** 3
        return self.factor * volume
github qzhu2017 / PyXtal / pyxtal / crystal.py View on Github external
priority=0,
                    )
                    self.valid = False
                    self.struct = None
                    return

            # to try to generate atomic coordinates
            for cycle2 in range(self.coord_attempts):
                self.cycle2 = cycle2
                output = self._generate_coords(cell_matrix)

                if output:
                    final_coords, final_species, wyckoff_sites = output
                    break
            if self.valid:
                final_number = [Element(ele).z for ele in final_species]
                final_coords = np.array(final_coords)
                cart_coords = np.dot(final_coords, cell_matrix)

                if self.dim != 0:
                    # Add space above and below a 2D or 1D crystals
                    cell_matrix, final_coords = add_vacuum(
                        cell_matrix, final_coords, PBC=self.PBC
                    )
                    self.struct = Structure(cell_matrix, final_species, final_coords)
                    self.spg_struct = (cell_matrix, final_coords, final_number)
                else:
                    self.species = final_species
                    # Clusters are handled as large molecules
                    self.molecule = Molecule(final_species, cart_coords)
                    # Calculate binding box
                    diffs = np.max(cart_coords, axis=0) - np.min(cart_coords, axis=0) + 10
github qzhu2017 / PyXtal / pyxtal / molecule.py View on Github external
Given a molecule, find a minimum orthorhombic box containing it.
        Size is calculated using min and max x, y, and z values, 
        plus the padding defined by the vdw radius
        For best results, call oriented_molecule first.
        
        Args:
            mol: a pymatgen Molecule object. Should be oriented along its principle axes.
    
        Returns:
            a Box object
        """
        mol, _ = reoriented_molecule(self.mol)
        minx, miny, minz, maxx, maxy, maxz = 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
        for p in mol:
            x, y, z = p.coords
            r = Element(p.species_string).vdw_radius
            if x - r < minx:
                minx = x - r
            if y - r < miny:
                miny = y - r
            if z - r < minz:
                minz = z - r
            if x + r > maxx:
                maxx = x + r
            if y + r > maxy:
                maxy = y + r
            if z + r > maxz:
                maxz = z + r
        self.box = Box(minx, maxx, miny, maxy, minz, maxz)
github qzhu2017 / PyXtal / pyxtal / molecular_crystal.py View on Github external
break
                    else:  # reset the coordinates and sites
                        molecular_coordinates_total = []
                        molecular_sites_total = []
                        wps_total = []
                # placing molecules here
                if good_structure:
                    final_lattice = cell_matrix
                    final_coor = []
                    final_site = []
                    final_number = []
                    self.mol_sites = []  # to regenerate the crystal

                    final_coor = deepcopy(coordinates_total)
                    final_site = deepcopy(species_total)
                    final_number = list(Element(ele).z for ele in species_total)
                    self.mol_sites = deepcopy(mol_sites_total)

                    final_coor = filtered_coords(final_coor, PBC=self.PBC)
                    lattice, coor = add_vacuum(final_lattice, final_coor, PBC=self.PBC)

                    self.lattice_matrix = lattice
                    self.frac_coords = np.array(coor)
                    self.cart_coords = np.dot(coor, lattice)
                    self.sites = final_site

                    # A pymatgen.core.structure.Structure object for
                    self.struct = Structure(lattice, self.sites, self.frac_coords)
                    # ASE/spglib structure
                    self.spg_struct = (lattice, self.frac_coords, final_number)
                    self.valid = True
github qzhu2017 / PyXtal / pyxtal / tolerance.py View on Github external
def print_all(self):
        print("--Tol_matrix class object--")
        print("  Prototype: " + str(self.prototype))
        print("  Atomic radius type: " + str(self.radius_type))
        print("  Radius scaling factor: " + str(self.f))
        if self.prototype == "single value":
            print("  Custom tolerance value: " + str(self.matrix([0][0])))
        else:
            if self.custom_values == []:
                print("  Custom tolerance values: None")
            else:
                print("  Custom tolerance values:")
                for tup in self.custom_values:
                    name1 = str(Element(tup[0]).short_name)
                    name2 = str(Element(tup[1]).short_name)
                    # print("    " + name1+ ", " + name2 + ": " +str(self.get_tol(tup[0],tup[1])))
                    s += "\n{:s}-{:s}: {:6.3f}".format(
                        name1, name2, self.get_tol(tup[0], tup[1])
                    )
                print(s)