pyxtal package
PyXtal: A Python library for crystal structure generation and manipulation.
This module initializes the pyxtal package, providing essential imports and utility functions.
- class pyxtal.pyxtal(molecular=False, random_state=None)[source]
Bases:
objectClass for handling atomic crystals based on symmetry constraints
Examples
To create a new structure instance
>>> from pyxtal import pyxtal >>> struc = pyxtal()
one can either use pyxtal to generate a random symmetric structure
>>> struc.from_random(3, 227, ['C'], [8])
or load a structure from a file or ASE atoms or Pymatgen structure object
>>> struc.from_seed('diamond.cif') # as a string >>> struc.from_seed(diamond_ase) # as a ase atoms object >>> struc.from_seed(diamond_pymatgen) # as a pymatgen structure object
as long as the struc is created, you can check their symmetry as follows
>>> struc.get_site_labels() {'C': ['8a']} >>> struc ------Crystal from random------ Dimension: 3 Composition: C8 Group: Fd-3m (227) cubic lattice: 4.3529 4.3529 4.3529 90.0000 90.0000 90.0000 Wyckoff sites: C @ [0.1250 0.1250 0.1250], WP: 8a, Site symmetry: -4 3 m
The structure object can be easily manipulated via apply_perturbtation or subgroup function
>>> struc2 = struc.subgroup_once(H=141) >>> struc2 ------Crystal from Wyckoff Split------ Dimension: 3 Composition: C8 Group: I41/amd (141) tetragonal lattice: 3.3535 3.3535 4.6461 90.0000 90.0000 90.0000 Wyckoff sites: C @ [0.0000 0.2500 0.3750], WP: 4b, Site symmetry: -4 m 2
Alternatively, one can easily compute its XRD via the pyxtal.XRD class
>>> xrd = struc.get_XRD() >>> xrd 2theta d_hkl hkl Intensity Multi 32.706 2.738 [ 1 1 1] 100.00 8 54.745 1.677 [ 2 2 0] 40.95 12 65.249 1.430 [ 3 1 1] 20.65 24 81.116 1.186 [ 4 0 0] 5.15 6 90.236 1.088 [ 3 3 1] 8.24 24 105.566 0.968 [ 4 2 2] 14.44 24 115.271 0.913 [ 5 1 1] 10.03 24 133.720 0.838 [ 4 4 0] 9.80 12 148.177 0.802 [ 5 3 1] 28.27 48
One can also try to get the transition path between two pyxtals that are symmetry related via the get_transition function
>>> s1 = pyxtal() >>> s2 = pyxtal() >>> s1.from_seed("pyxtal/database/cifs/0-G62.cif") #structure with low symmetry >>> s2.from_seed("pyxtal/database/cifs/2-G71.cif") #structure with high symmetry >>> strucs, _, _, _, _ = s2.get_transition(s1) # get the transition from high to low >>> strucs [ ------Crystal from Transition 0 0.000------ Dimension: 3 Composition: O24Mg4W4Pb8 Group: Pnma (62) orthorhombic lattice: 11.6075 8.0526 5.8010 90.0000 90.0000 90.0000 Wyckoff sites: Mg @ [ 0.8750 0.2500 0.7500], WP [4c] Site [.m.] Pb @ [ 0.6406 0.0053 0.7856], WP [8d] Site [1] W @ [ 0.6119 0.2500 0.2483], WP [4c] Site [.m.] O @ [ 0.6292 0.0083 0.2235], WP [8d] Site [1] O @ [ 0.4966 0.2500 0.0093], WP [4c] Site [.m.] O @ [ 0.5055 0.2500 0.4897], WP [4c] Site [.m.] O @ [ 0.7308 0.2500 0.9717], WP [4c] Site [.m.] O @ [ 0.7467 0.2500 0.4570], WP [4c] Site [.m.], ------Crystal from Transition 1 0.323------ Dimension: 3 Composition: O24Mg4W4Pb8 Group: Pnma (62) orthorhombic lattice: 11.6020 8.0526 5.8038 90.0000 90.0000 90.0000 Wyckoff sites: Mg @ [ 0.8750 0.2500 0.7500], WP [4c] Site [.m.] Pb @ [ 0.6250 -0.0053 0.7500], WP [8d] Site [1] W @ [ 0.6250 0.2500 0.2500], WP [4c] Site [.m.] O @ [ 0.6250 0.0083 0.2500], WP [8d] Site [1] O @ [ 0.5158 0.2500 -0.0068], WP [4c] Site [.m.] O @ [ 0.5158 0.2500 0.5068], WP [4c] Site [.m.] O @ [ 0.7342 0.2500 0.9932], WP [4c] Site [.m.] O @ [ 0.7342 0.2500 0.5068], WP [4c] Site [.m.]]
Finally, the structure can be saved to different formats
>>> struc.to_file('my.cif') >>> struc.to_file('my_poscar', fmt='poscar')
or to Pymatgen/ASE structure object
>>> pmg_struc = struc.to_pymatgen() >>> ase_struc = struc.to_ase()
or to json file
>>> struc.to_json('1.json')
- apply_perturbation(d_lat=0.05, d_coor=0.05, d_rot=1)[source]
Perturb the structure without breaking the symmetry.
- Parameters:
d_coor (float) – Magnitude of perturbation on atomic coordinates (in Angstroms)
d_lat (float) – Magnitude of perturbation on lattice (in percentage)
d_rot (float) – Magnitude of rotational perturbation (in degrees)
- build(group, species, numIons, lattice, sites, tol=0.01, dim=3, use_hall=False)[source]
Build an atomic crystal based on input parameters.
- Parameters:
group (int) – Space group number (1-230), e.g. 225
species (list) – List of atomic species, e.g. [‘Na’, ‘Cl’]
numIons (list) – Number of atoms of each species, e.g. [4, 4]
lattice – Lattice object defining unit cell
sites (list) – List of Wyckoff position dictionaries, one per species e.g. [[{“4a”: [0.0, 0.0, 0.0]}], [{“4b”: [0.5, 0.5, 0.5]}]]
tol (float) – Tolerance for symmetry finding. Default 0.01
dim (int) – Dimensionality (0-3). Default 3
use_hall (bool) – Whether to use Hall number. Default False
Example
>>> from pyxtal.lattice import Lattice >>> xtal = pyxtal() >>> lat = Lattice.from_para(5.0, 5.0, 5.0, 90, 90, 90, ltype='Cubic') >>> xtal.build(225, ['Na', 'Cl'], [4, 4], ... lattice=lat, ... sites=[[{"4a": [0, 0, 0]}], [{"4b": [0.5, 0.5, 0.5]}]])
- check_H_coordination(r=1.12)[source]
A function to check if H is connected to more than one atom Mainly used for debug, powered by pymatgen
- Parameters:
r – the given cutoff distances
- Returns:
True or False
- check_mapping(ref_struc)[source]
Compute the displacement w.r.t. the reference structure
- Parameters:
ref_struc – reference pyxtal structure (assuming the same atom order)
- Returns:
True or False
- check_short_distances(r=0.7, exclude_H=True)[source]
A function to check short distance pairs Mainly used for debug, powered by pymatgen
- Parameters:
r (float) – the given cutoff distances
exclude_H (bool) – whether or not exclude the H atoms
- Returns:
list of pairs within the cutoff
- check_short_distances_by_dict(dicts)[source]
A function to check short distance pairs Mainly used for debug, powered by pymatgen
- Parameters:
dicts – e.g., {“H-H”: 1.0, “O-O”: 2.0}
- Returns:
number of atomic pairs within the cutoff
- Return type:
N_pairs
- check_validity(criteria, verbose=False)[source]
Check if the xtal is valid for a given list of criteria. Currently support the following keywords - MIN_Density (float) - CN: coordination number (int) - Dimension: (int)
- Parameters:
criteria (dict) – keywords and the threshhold values
verbose (bool) – whether or not print out details
- Returns:
bool value regarding the validity
- find_matched_lattice(ref_struc, d_tol=2.0, f_tol=0.15)[source]
Compute the displacement w.r.t. the reference structure
- Parameters:
ref_struc – reference pyxtal structure (assuming the same atomic ordering)
d_tol – tolerence of mismatch in the absolute scale
f_tol – tolerence of mismatch in the fractional scale
- Returns:
ref_struc with matched lattice
- from_1d_rep(x, sites, dim=3)[source]
Build a pyxtal structure from a 1D representation and sites list.
- Parameters:
x (array) – 1D array containing lattice parameters and coordinates
sites (list) – List of (element, wyckoff_position) tuples
dim (int) – Dimensionality of the crystal (default: 3)
Example
>>> from pyxtal.symmetry import Wyckoff_position >>> xtal = pyxtal() >>> x = [2.5, 8.75] # Lattice params and coords >>> wp = Wyckoff_position.from_group_and_letter(141, 'a') >>> sites = [("C", wp), ("C", wp)] # [C, 4a], [C, 4a] >>> xtal.from_1d_rep(, sites=[("C", wp), ("C", wp)])
- from_CSD(csd_code)[source]
Download the crystal from CCDC if csd_code is given, return the single pyxtal object if csd_family is given, do group analysis and ignore high pressure form
- Parameters:
csd_code – e.g.,
ACSALA01
- from_prototype(prototype)[source]
Load a template structure based on a prototype name for quick testing.
- Parameters:
prototype (str) –
Name of the crystal prototypes to load, such as ‘diamond’, ‘graphite’, etc.
’diamond’
’graphite’
’a-cristobalite’
’b-cristobalite’
’a-quartz’
’b-quartz’
’rocksalt’
’B1’
’B2’
Example
>>> xtal = pyxtal() >>> xtal.from_prototype('diamond') # Creates diamond structure >>> xtal.from_prototype('graphite') # Creates graphite structure
Note
A convenient shortcut to generate common crystal structures by directly specifying their space groups, Wyckoff positions, lattice parameters and atomic species. The structures are created with standard settings.
- from_random(dim=3, group=None, species=None, numIons=None, factor=1.1, thickness=None, area=None, lattice=None, sites=None, conventional=True, t_factor=1.0, max_count=10, torsions=None, force_pass=False, block=None, num_block=None, seed=None, random_state=None, tm=None, use_hall=False, use_asu=False)[source]
The main function to generate random crystals. It calls block_crystal or random_crystal internally.
- Parameters:
dim (int) – dimension (0, 1, 2, 3)
group (int) – the group number (1-56, 1-75, 1-80, 1-230)
species (list) – atomic symbols for each ion type, e.g., [“Ti”, “O”].
numIons (list) – the number of atoms within the unit cell, e.g., [4, 8].
factor (float, optional) – volume factor to generate the crystal. Default is 1.1
thickness (float, optional) – thickness for 2D materials
area (float, optional) – area for 1D/2D materials.
lattice (optional) – Lattice to define the cell.
sites (optional) – pre-assigned wyckoff sites (e.g., [[“4a”], [“2b”]])
conventional (bool) – whether use the conventional setting. Default is True
t_factor (float) – factor applied to tolerance matrix.
max_count (int) – maximum number of attempts to generate structure.
torsions (list, optional) – torsion angles for molecular crystals.
force_pass (bool, True) – whether force accept invalid structure.
block (optional) – molecular/atomic block for crystal building
num_block (optional) – number of blocks
seed (int, optional) – random seed
random_state (optional) – numpy random state
tm (optional) – Tol_matrix define the distances
use_hall (bool) – whether to use Hall number. Default is False
use_asu (bool) – whether to generate points within ASU. Default is False
- Returns:
Crystal structure object if successful
- Raises:
RuntimeError – If structure generation fails after max_count attempts
- from_seed(seed, molecules=None, tol=0.0001, a_tol=5.0, ignore_HH=True, add_H=False, backend='pymatgen', style='pyxtal', hn=None, standard=False)[source]
Load the seed structure from pymatgen/ase/POSCAR/cifs. Internally they will be handled by pymatgen.
- Parameters:
seed – cif/poscar file or a pymatgen Structure object
molecules – a list of reference molecule (xyz or Pyxtal molecule)
tol (float) – scale factor for covalent bond distance
ignore_HH (bool) – whether ignore short H-H distance in molecules
add_H (bool) – whether add H atoms
backend (str) – structure parser, default is pymatgen
style (str) –
pyxtalorspglibstandard (bool) – whether or not optimize lattice
hn (int, optional) – space group hall number
a_tol (float) – angle tolerance for pymatgen symmetry find.
standard – whether to use standard setting
- from_spg_wps_rep(spg, wps, x, elements=None)[source]
Build a pyxtal structure from Wyckoff positions and compact 1D representation.
- Parameters:
spg (int) – Space group number (1-230)
wps (list) – List of Wyckoff position strings (e.g. [‘6a’, ‘6a’])
x (array) – 1D array containing lattice parameters and coordinates
elements (list, optional) – List of element symbols. Defaults to [“C”]*len(wps)
Example
>>> xtal = pyxtal() >>> xtal.from_spg_wps_rep(141, ['6a', '6a'], [2.5019, 8.7514, 0.4614]) >>> xtal ------Crystal from Build------ Dimension: 3 Composition: C8 Group: I 41/a m d:2 (141) 2.5019, 2.5019, 8.7514, 90.0000, 90.0000, 90.0000, tetragonal Wyckoff sites: C @ [ 0.0000 0.7500 0.1250], WP [4a] Site [-4m2] C @ [ 0.0000 0.7500 0.1250], WP [4a] Site [-4m2]
- from_tabular_representation(rep, max_abc=50.0, max_angle=180, normalize=False, tol=0.1, discrete=False, discrete_cell=False, N_grids=50, verbose=False)[source]
Reconstruct crystal from 1D tabular representation. Currently assumes elemental composition like carbon.
- Parameters:
rep (array) – 1D array containing the tabular representation
max_abc (float) – Maximum lattice vector length for normalization
max_angle (float) – Maximum angle in degrees for normalization
normalize (bool) – Whether to normalize values between 0-1
tol (float) – Tolerance for Wyckoff position assignment
discrete (bool) – Whether to discretize atomic coordinates
discrete_cell (bool) – Whether to discretize cell parameters
N_grids (int) – Number of grid points for discretization
verbose (bool) – Whether to print detailed error messages
Note
For discrete coordinates, values are mapped onto integer grid indices. For normalized coordinates, values are scaled between 0 and 1.
- get_1D_comp()[source]
Get the molecular composition for 1D representation of molecular crystal.
- Returns:
Number of molecules of each type in the crystal
- Return type:
list
- get_1D_representation(standard=False)[source]
Get the 1D representation class for molecular crystals
- get_1d_rep_x()[source]
Get a simplified x representation for a crystal
Example
>>> Group: I 41/a m d:2 (141) 2.5019, 2.5019, 8.7534, 90.0000, 90.0000, 90.0000, tetragonal Wyckoff sites: C @ [ 0.0000 0.2500 0.4614], WP [8e] Site [2mm.] The above rep would be: [2.5019, 8.7514, 0.4614]
- get_Pearson_Symbol()[source]
Implementation of the Pearson symbol system for crystallographic notation. Based on https://en.wikipedia.org/wiki/Pearson_symbol, which is a notation that describes crystal structures using:
First letter: crystal system (a, m, o, t, h, c)
Second letter: centering type (P, I, F, etc.)
Number: number of atoms per unit cell
- get_XRD(**kwargs)[source]
Compute the PXRD object.
- Parameters:
**kwargs – Keyword arguments including:
wavelength (float) – X-ray wavelength, default 1.54184 Å
thetas (list) – 2θ angle range [min, max], default [0, 180]
preferred_orientation (bool) – Whether to apply preferred orientation, default False
march_parameter (float) – March parameter for preferred orientation, default None
- Returns:
A PyXtal XRD object containing powder diffraction data
- Return type:
- get_alternatives(include_self=True, same_letters=False, ref_lat=None, d_tol=2.0, f_tol=0.15)[source]
Get alternative structure representations.
- Parameters:
include_self (bool) – Whether to include the original structure in the return.
same_letters (bool) – Whether to require the same Wyckoff letters for alternatives.
ref_lat – Reference lattice for comparison.
d_tol (float) – Tolerance for lattice mismatch.
f_tol (float) – Tolerance for fractional coordinate mismatch.
- Returns:
List of alternative pyxtal structures.
- Return type:
list
- get_dimensionality(cutoff=None)[source]
A quick wrapper to compute dimensionality from pymatgen https://pymatgen.org/pymatgen.analysis.dimensionality.html The dimensionality of the structure can be 1/2/3
- get_disps_optim(ref_struc, trans, d_tol)[source]
- Parameters:
ref_struc – reference pyxtal structure (assuming the same atom order)
trans – translation vector
d_tol – tolerence of mismatch
- Returns:
Atomic displacements in np.array translation:
- get_disps_sets(ref_struc, d_tol, d_tol2=0.3, ld_tol=2.0, fd_tol=0.15, keep_lattice=False)[source]
Compute the displacement w.r.t. a reference structure (considering all wycsets)
- Parameters:
ref_struc – reference pyxtal structure (assuming the same atomic ordering)
d_tol – maximally allowed atomic displacement
d_tol2 – displacement that allows early termination
kepp_lattice – whether or not change the WP sets
- Returns:
Atomic displacements in np.array
- get_disps_single(ref_struc, trans, d_tol=1.2)[source]
Compute the displacement w.r.t. the reference structure
- Parameters:
ref_struc – reference pyxtal structure (assuming the same atom order)
trans – translation vector
d_tol – tolerence of mismatch
- Returns:
Atomic displacements in np.array translation:
- get_forcefield(ff_style='openff', code='lammps', chargemethod='am1bcc', parameters=None)[source]
An interface to create forcefield for molecular simulation with - Charmm - LAMMPS Note that the current approach generates charge with its own conformer, need to provide the option to use the conformer from the given molecule
- Parameters:
ff_style (-) –
gafforopenffcode (-) –
lammpsorcharmmcharge_method (-) –
am1bcc,am1-mulliken,mmff94,gasteigerparameters (-) – 1D-array of user-specified FF parameters
- Returns:
An ase_atoms_objects with force field information
- get_init_translations(ref_struc, tol=0.75)[source]
Compute the displacement w.r.t. the reference structure
- Parameters:
ref_struc – reference pyxtal structure (assuming the same atom order)
- Returns:
list of possible translations
- get_intermolecular_energy(factor=2.0, max_d=10.0)[source]
Get the intermolecular interactions for molecular crystals based on atom-atom potentials from:
- Reference:
A. Gavezzotti and G. Filippini, Journal of Physical Chemistry, vol. 98, no. 18, pp. 4831-4837 (1994)
- Parameters:
factor (float) – scaling factor applied to van der Waals radii
max_d (float) – maximum distance cutoff
- Returns:
Total intermolecular interaction energy
- Return type:
float
- get_neighboring_dists(site_id=0, factor=1.5, max_d=5.0)[source]
Get the neighboring molecules and contact pairs for a given Wyckoff position.
- Parameters:
site_id (int) – Index of reference molecular site. Defaults to 0
factor (float) – Scaling factor for van der Waals tolerance. Defaults to 1.5
max_d (float) – Maximum distance cutoff. Defaults to 5.0
- Returns:
engs (list): Contact energies from atom-atom potentials
pairs (list): List of short contact atom pairs
dists (list): Corresponding distances for each contact pair
- Return type:
tuple
- get_neighboring_molecules(site_id=0, factor=1.5, max_d=5.0, ignore_E=True)[source]
For molecular crystals, get the neighboring molecules for a given WP.
- Parameters:
site_id (int) – The index of reference molecular site to analyze
factor (float) – Scaling factor for van der Waals tolerance
max_d (float) – Maximum distance cutoff for finding neighbors
ignore_E (bool) – Whether to ignore energy calculations
- Returns:
Five lists containing neighbor information: min_ds (list): Shortest distances to neighboring molecules neighs (list): Cartesian coordinates of neighboring molecules comps (list): Molecular types of neighbors Ps (list): Binary flags indicating if neighbor is same site (0) or different site (1) engs (list): Interaction energies with neighboring molecules
- Return type:
tuple
- get_rep_bounds_from_spg_wps_cell(spg, wps, cell)[source]
Determine the bounds of rep from the given spg/wps/cell
Example
>>> c.get_rep_bounds_from_spg_wps_cell(180, [0, 2, 4], [8.0, 8.0, 10.0]) [8.0, 8.0, 10.0, 8.0, 8.0]
- get_rms_dist(xtal1, ltol=0.3, stol=0.3, angle_tol=5.0, scale=True)[source]
Compute the RMS distance between two crystal structures.
- Parameters:
xtal1 (pyxtal) – Second crystal structure to compare against
ltol (float) – Relative length tolerance for matching unit cells
stol (float) – Site tolerance for matching atomic positions
angle_tol (float) – Tolerance for matching cell angles in degrees
scale (bool) – Whether to scale the structures before comparing
- Returns:
Root mean square (RMS) distance between the structures
- Return type:
float
Note
Uses pymatgen’s structure matcher functionality internally
- get_separations(hkls=[[1, 0, 0], [0, 1, 0], [0, 0, 1]])[source]
Compute the separation for the given hkl plane
- get_spherical_images(**kwargs)[source]
Get the spherical image representation of the crystal structure.
- Parameters:
**kwargs
model (str) – ‘molecule’ or ‘contacts’
spherical_image() (Other arguments passed to)
- Returns:
Spherical image representation object
- Return type:
sph
- get_std_representation(trans)[source]
Perform cell transformation so that the symmetry operations follow standard space group notation
- get_structure_factor(hkl, coeffs=None)[source]
Compute the structure factor for a given hkl plane
- Parameters:
hkl (-) – three indices hkl plane
coeffs (-) – Atomic scatering factors
- get_tabular_representation(ids=None, normalize=False, N_wp=6, perturb=False, max_abc=50.0, max_angle=3.141592653589793, eps=0.05, standardize=True, discrete=False, discrete_cell=False, N_grids=50)[source]
Convert the xtal to a 1D reprsentation organized as
(space_group_number, a, b, c, alpha, beta, gamma, wp1, wp2, ....), where each wp is represented by 4 numbers(wp_id, x, y, z).- Parameters:
ids (list) – index of generators for each wp
normalize (bool) – whether or not normalize the data to (0, 1)
N_wp (int) – number of maximum wp sites
perturb (bool) – whether or not perturb the variables
max_abc (float) – maximum abc length for normalization
max_angle (float) – maximum angle in radian for normalization
eps (float) – the degree of perturbation
discrete (bool) – to discretize xyz
discrete_cell (bool) – to discretize cell_para
N_grids (int) – number of grids used for discretization
- Returns:
a 1D vector such as (141, 3, 3, 3, pi/2, pi/2, pi/2, wp_id, x, y, z)
- get_tabular_representations(N_max=200, N_wp=8, normalize=False, perturb=False, eps=0.05, discrete=False, discrete_cell=False, N_grids=50)[source]
Enumerate the equivalent representations for a give crystal. For example, 8a in space group 227 has 8 equivalent positions
- Parameters:
N_max (int) – the max number of samples from the enumeration
N_wp (int) – the maximum number of allowed WP sites
normalize (bool) – normalize all number to (0, 1)
perturb (bool) – whether or not perturb the variables
eps (float) – the degree of perturbation
discrete (bool) – to discretize xyz
N_grids (int) – number of grids used for discretization
- Returns:
a list of equivalent 1D tabular representations
- get_transition(ref_struc, d_tol=1.0, d_tol2=0.3, N_images=2, max_path=30, both=False)[source]
Get the splitted wyckoff information along a given path:
- Parameters:
ref_struc – structure with subgroup symmetry
d_tol – maximally allowed atomic displacement
d_tol2 – displacement that allows early termination
N_images – number of intermediate images
max_path – maximum number of paths
both – whether or not do interpolation along both sides
- Returns:
displacements:
cell translation:
the list of space groups along the path
the list of splitters along the path
- Return type:
strucs
- get_transition_by_path(ref_struc, path, d_tol, d_tol2=0.5, N_images=2, both=False)[source]
Get the splitted wyckoff information along a given path:
- Parameters:
ref_struc – structure with subgroup symmetry
path – a list of transition path
d_tol – maximally allowed atomic displacement
d_tol2 – displacement that allows early termination
N_images – number of intermediate images
both – interpolation on both sides
- Returns:
displacements:
cell translation:
- Return type:
strucs
- get_xtal_string(dicts=None, header=None)[source]
Get a string representation of the crystal structure.
- Parameters:
dicts (dict, optional) – Dictionary containing additional properties like similarity, energy, status etc
header (str, optional) – Additional header text to prepend
- Returns:
- Formatted string containing crystal information including:
Number of atoms
Degrees of freedom
Space group number and symbol
Density
Additional properties from dicts
Wyckoff positions
- Return type:
str
- make_transitions(disps, lattice=None, translation=None, N_images=3, both=False)[source]
Make pyxtals by following atomic displacements.
- Parameters:
disps (numpy.ndarray) – Nx3 array of atomic displacements in fractional coordinates
lattice (numpy.ndarray, optional) – 3x3 cell matrix. Defaults to self.lattice.matrix
translation (numpy.ndarray, optional) – Overall translation vector. Defaults to None
N_images (int) – Number of intermediate images to generate
both (bool) – Whether to interpolate on both sides of the path. Defaults to False
- Returns:
List of pyxtal structures along the transition path
- Return type:
list
- optimize_lattice(iterations=5, force=False, standard=False)[source]
Optimize the lattice if the cell has bad inclination angles.
- Parameters:
iterations (int) – Maximum number of iterations for optimization
force (bool) – Whether to continue optimization even if converged
standard (bool) – Whether to enforce standard crystallographic setting
Note
For monoclinic systems, first optimizes the angles to bring them within acceptable ranges. When standard=True, tries to find a transformation to put the structure into the standard crystallographic setting.
- optimize_lattice_and_rotation(iterations=3, verbose=False)[source]
Iteratively cut lattice and optimize molecular rotations.
- Parameters:
iterations (int) – Number of optimization cycles
verbose (bool) – Whether to print debug information
- resort_species(species)[source]
Resort the atomic species.
- Parameters:
species (list) – List of element symbols, e.g. [‘Si’, ‘O’]
- resymmetrize(tol=0.001)[source]
Recheck the symmetry with a given tolerance value. Useful to identify a higher space group symmetry.
- Parameters:
tol (float) – The tolerance value for symmetry finder
- Returns:
A new pyxtal object with resymmetrized structure
- Return type:
- set_cutoff(exclude_ii=False, value=None)[source]
get the cutoff dictionary
- Parameters:
exclude_ii (bool) – whether or not exclude A-A distance
value (float) – cutoff distance
- set_site_coordination(cutoff=None, verbose=False, exclude_ii=False)[source]
Compute the coordination number from each atomic site
- show_mol_cluster(id, factor=1.5, max_d=4.0, plot=True, ignore_E=False, cmap='YlGn', **kwargs)[source]
Display the local packing environment for a selected molecule.
- subgroup(perms=None, H=None, eps=0.05, idx=None, group_type='t', max_cell=4, min_cell=0, N_groups=None)[source]
Generate a structure with lower symmetry
- Parameters:
perms – e.g., {“Si”: “C”}
H – space group number (int)
eps – pertubation term (float)
idx – list
group_type (string) – t, k or t+k
max_cell (float) – maximum cell reconstruction
min_cell (float) – maximum cell reconstruction
max_subgroups (int) – maximum number of trial subgroups
- Returns:
a list of pyxtal structures with lower symmetries
- subgroup_by_path(gtypes, ids, eps=0, mut_lat=False)[source]
Generate a structure with lower symmetry (for atomic crystals only)
- Parameters:
g_types – [‘t’, ‘k’]
idx – list of ids for the splitter
eps – degree of displacement
mut_lat – mutate the lattice of not
- Returns:
a pyxtal structure with lower symmetries list of splitters
- subgroup_once(eps=0.1, H=None, perms=None, group_type='t', max_cell=4, min_cell=0, mut_lat=True, ignore_special=False, verbose=False)[source]
Generate a structure with lower symmetry (for atomic crystals only)
- Parameters:
eps (float) – perturbation term on atomic coordinates
H (int) – target space group number
perms (dict) – atomic permutations dictionary, e.g. {“Si”: “C”}
group_type (str) – ‘t’ or ‘k’ for translationengleiche or klassengleiche transitions
max_cell (float) – maximum cell enlargement
min_cell (float) – minimum cell enlargement
mut_lat (bool) – whether to mutate lattice parameters
ignore_special (bool) – whether to ignore sites with special positions
verbose (bool) – whether to print details
- Returns:
A new pyxtal structure with lower symmetry
- Return type:
Example
>>> xtal = pyxtal() >>> xtal.from_random(3, 230, ['Si'], [8]) >>> sub = xta.subgroup_once(H=141) >>> print(sub.group.number) 141
- substitute(dicts)[source]
Substitute atoms of one element with another element.
- Parameters:
dicts (dict) – Dictionary mapping original elements to substituted elements.
Example
>>> struc = pyxtal() >>> struc.from_prototype("rocksalt") >>> struc.substitute({"Cl": "F"})
- substitute_1_2(dicts, ratio=None, group_type='t+k', max_cell=4, min_cell=0, max_wp=None, N_groups=None, N_max=10, criteria=None)[source]
Derive the BC compounds from A via subgroup relation.
For example: - From C to BN - From SiO2 to AlPO3
The key is to split A’s Wyckoff positions to B and C with respect to composition relation. If the current parent crystal doesn’t allow splitting, look for the subgroup.
- Parameters:
dicts (dict) – Substitution dictionary, e.g. {“F”: “Cl”}
ratio (list) – Composition ratio list, e.g. [1, 1]
group_type (str) – Type of subgroup: - ‘t’: translationengleiche - ‘k’: klassengleiche - ‘t+k’: both
max_cell (float) – Maximum cell reconstruction allowed
min_cell (float) – Minimum cell reconstruction allowed
max_wp (int) – Maximum number of Wyckoff positions
N_groups (int) – Maximum number of trial subgroups
N_max (int) – Maximum number of output structures
criteria (dict) – Dictionary of validity criteria
- Returns:
List of pyxtal structures after substitution
- Return type:
list
- substitute_linear(dicts)[source]
Linear substitution between a single atom and a linear block. For example, substituting SiO2 with Zn(CN)2.
- Parameters:
dicts (dict) – Dictionary mapping original atoms to substituted atoms.
example (For) – {“Si”: [“Zn”], “O”: [“C”, “N”]}
- substitute_molecules(smiles)[source]
Substitute the molecules in the structure with new molecules based on SMILES strings.
- Parameters:
smiles (list) – List of SMILES strings for the new molecules.
- supergroup(G=None, d_tol=1.0)[source]
Generate a structure with higher symmetry
- Parameters:
G – super space group number (list of integers)
d_tol – maximum tolerance
- Returns:
a list of pyxtal structures with minimum super group symmetries
- supergroups(G=None, d_tol=1.0)[source]
Generate the structures with higher symmetry
- Parameters:
G – super space group number (list of integers)
d_tol – maximum tolerance
- Returns:
a list of pyxtal structures with minimum super group symmetries
- to_ase(resort=True, center_only=False, add_vaccum=True)[source]
Export to ASE Atoms object.
- Parameters:
resort (bool) – Whether to resort atoms by atomic number
center_only (bool) – Only output molecular centers for molecular crystals
add_vaccum (bool) – Whether to add vacuum layers for 0/1/2D systems
- Returns:
ASE Atoms object representing the structure
- Return type:
ase.Atoms
- Raises:
RuntimeError – If structure is not valid
- to_file(filename=None, fmt=None, permission='w', sym_num=None, header='from_pyxtal')[source]
Creates a file with the given name and type. By default, creates cif files for crystals and xyz files for clusters. For other formats, Pymatgen is used
- Parameters:
filename (string) – the file path
fmt (string) – the file type (cif, xyz, etc.)
permission (string) – w or a+
sym_num (int) – number of sym_ops, None will write all symops
header (string) – header
- Returns:
Nothing. Creates a file at the specified path
- to_molecular_xtal(molecules, oris=None, reflects=None)[source]
Convert the atomic xtal to molecular xtal the input molecules must have the same length of the self.atom_sites
- to_pymatgen(resort=True)[source]
Export to Pymatgen Structure object.
- Parameters:
resort (bool) – Whether to resort atoms by atomic number
- Returns:
Structure object representing the crystal
- Return type:
pymatgen.core.Structure
- Raises:
RuntimeError – If structure is not valid
- to_pyxtal_center()[source]
Export molecular crystal to a PyXtal object containing only molecular centers.
- Returns:
New PyXtal object with molecules represented as single atoms at their centers.
- Return type:
- Raises:
RuntimeError – If structure is not a valid molecular crystal.
- to_subgroup(path=None, t_only=True, iterate=False, species=None, verbose=False)[source]
Transform a crystal with special sites to a subgroup representation with general sites.
- Parameters:
path (list, optional) – List of paths to get the general sites. Defaults to None.
t_only (bool) – Whether to use only translationengleiche (t) transitions. Defaults to True.
iterate (bool) – Whether to transform iteratively until all sites are general. Defaults to False.
species (list, optional) – List of atomic species to transform. Defaults to None.
verbose (bool) – Whether to print detailed information during transformation. Defaults to False.
- Returns:
A new pyxtal structure in the subgroup setting with general Wyckoff positions
- Return type:
Note
If path is None, the function will compute the path to the general Wyckoff positions. If iterate is True, the function will keep transforming until all sites are general. Recommended for the use of transforming specical to general sites in molecular crystals.
- to_subgroup_zp2()[source]
Transform a crystal with zprime from 1 to 2 subgroup representation. This function is for molecular crystals only.
- Returns:
A new pyxtal structure in the subgroup setting with general Wyckoff positions
- Return type:
- transform(trans, lattice=None)[source]
Perform cell transformation and symmetry operation
- Parameters:
trans – 3*3 matrix
lattice – pyxtal lattice object
- translate(trans, reset_wp=False)[source]
Move the atomic sites along a translation vector.
- Parameters:
trans (array) – 1x3 translation vector array
reset_wp (bool) – Whether to reset Wyckoff positions after translation
Note
This operation may change the structure’s symmetry
- update_from_1d_rep(x)[source]
Update the crystal from a 1D representation.
The 1D representation combines lattice parameters and atomic coordinates into a single array. For example:
>>> Group I 41/a m d:2 (141) Lattice: 2.5019, 2.5019, 8.7534, 90.0000, 90.0000, 90.0000 Site: C @ [0.0000 0.2500 0.4614], WP [8e], Site [2mm.] Would be represented as: [2.5019, 8.7514, 0.4614]
- Parameters:
x (numpy.ndarray) – 1D array containing lattice parameters and atomic coordinates
Subpackages
- pyxtal.database package
- pyxtal.interface package
- pyxtal.lego package
- pyxtal.optimize package
- pyxtal.potentials package
Submodules
- pyxtal.XRD module
ProfileSimilarityXRDadd_peak()axial_div()axial_div_bak()check_pxrd_match()create_index()gaussian()gaussian_integrated()get_all_intensity()get_all_intensity_par()get_intensity()get_para_from_pxrd()is_multiple()lorentzian()map_intensity()mod_pseudo_voigt()pseudo_voigt()pxrd_refine()similarity_calculate()
- pyxtal.block_crystal module
- pyxtal.constants module
- pyxtal.crystal module
- pyxtal.db module
call_opt_single()databasedatabase_topologydatabase_topology.add_strucs_from_db()database_topology.add_xtal()database_topology.check_new_structure()database_topology.check_overlap()database_topology.clean_structures()database_topology.clean_structures_pmg()database_topology.clean_structures_spg_topology()database_topology.export_structures()database_topology.get_all_xtals()database_topology.get_db_unique()database_topology.get_db_unique_topology()database_topology.get_label()database_topology.get_max_id()database_topology.get_properties()database_topology.get_pyxtal()database_topology.get_row()database_topology.plot_histogram()database_topology.print_info()database_topology.print_memory_usage()database_topology.select_xtal()database_topology.select_xtals()database_topology.update_db_description()database_topology.update_row_energy()database_topology.update_row_energy_mproc()database_topology.update_row_energy_serial()database_topology.update_row_topology()database_topology.vacuum()
dftb_opt_single()gulp_opt_single()mace_opt_single()make_db_from_CSD()make_entry_from_CSD()make_entry_from_CSD_web()make_entry_from_pyxtal()opt_single()process_xtal()setup_worker_logger()vasp_opt_single()
- pyxtal.descriptor module
- pyxtal.elasticity module
CubicElasticModuliVoigt_6_to_full_3x3_strain()Voigt_6_to_full_3x3_stress()Voigt_6x6_to_cubic()Voigt_6x6_to_full_3x3x3x3()cubic_to_Voigt_6x6()elastic_moduli()elastic_properties()fit_elastic_constants()full_3x3_to_Voigt_6_index()full_3x3_to_Voigt_6_strain()full_3x3_to_Voigt_6_stress()full_3x3x3x3_to_Voigt_6x6()generate_strained_configs()invariants()measure_triclinic_elastic_constants()poisson_ratio()rotate_cubic_elastic_constants()rotate_elastic_constants()youngs_modulus()
- pyxtal.io module
- pyxtal.lattice module
LatticeLattice.add_vacuum()Lattice.apply_transformation()Lattice.check_mismatch()Lattice.copy()Lattice.encode()Lattice.find_transition_to_orthoslab()Lattice.from_1d_representation()Lattice.from_matrix()Lattice.from_para()Lattice.generate_matrix()Lattice.generate_para()Lattice.generate_point()Lattice.get_bounds()Lattice.get_diff()Lattice.get_dofs()Lattice.get_lengths()Lattice.get_matrix()Lattice.get_para()Lattice.get_permutation_matrices()Lattice.get_transformation_matrices()Lattice.get_worst_angle()Lattice.is_valid_lattice()Lattice.is_valid_matrix()Lattice.mutate()Lattice.optimize_multi()Lattice.optimize_once()Lattice.reset_matrix()Lattice.scale()Lattice.search_transformation()Lattice.search_transformations()Lattice.set_matrix()Lattice.set_para()Lattice.set_volume()Lattice.standardize()Lattice.swap_angle()Lattice.swap_axis()Lattice.transform()Lattice.transform_multi()Lattice.update_from_1d_representation()Lattice.update_para()
gaussian_random_variable()generate_cellpara()generate_cellpara_0D()generate_cellpara_1D()generate_cellpara_2D()matrix2para()para2matrix()random_shear_matrix()random_vector()
- pyxtal.molecular_crystal module
- pyxtal.molecule module
BoxOrientationcompare_mol_connectivity()find_rotor_from_smile()generate_molecules()get_inertia_tensor()has_non_aromatic_ring()is_compatible_symmetry()make_graph()pyxtal_moleculepyxtal_molecule.align()pyxtal_molecule.apply_inversion()pyxtal_molecule.copy()pyxtal_molecule.get_box()pyxtal_molecule.get_box_coordinates()pyxtal_molecule.get_center()pyxtal_molecule.get_coefs_matrix()pyxtal_molecule.get_energy()pyxtal_molecule.get_lengths()pyxtal_molecule.get_max_length()pyxtal_molecule.get_orientation()pyxtal_molecule.get_orientations_in_wp()pyxtal_molecule.get_orientations_in_wps()pyxtal_molecule.get_principle_axes()pyxtal_molecule.get_radius()pyxtal_molecule.get_rmsd()pyxtal_molecule.get_rmsd2()pyxtal_molecule.get_symbols()pyxtal_molecule.get_symmetry()pyxtal_molecule.get_tols_matrix()pyxtal_molecule.get_torsion_angles()pyxtal_molecule.list_molecules()pyxtal_molecule.load_str()pyxtal_molecule.perturb_torsion()pyxtal_molecule.rdkit_mol()pyxtal_molecule.rdkit_mol_init()pyxtal_molecule.relax()pyxtal_molecule.reset_positions()pyxtal_molecule.save_str()pyxtal_molecule.set_labels()pyxtal_molecule.set_torsion_angles()pyxtal_molecule.show()pyxtal_molecule.show_box()pyxtal_molecule.swap_axis()pyxtal_molecule.to_ase()
reoriented_molecule()
- pyxtal.msg module
- pyxtal.operations module
OperationAnalyzeraa2matrix()angle()apply_ops()apply_ops_diagonal()are_equal()check_distance()check_images()create_matrix()distance()distance_matrix()distance_matrix_no_PBC()filtered_coords()filtered_coords_euclidean()find_ids()get_best_match()get_inverse()get_inverse_ops()is_orthogonal()rotate_vector()verify_distances()
- pyxtal.plane module
- pyxtal.representation module
- pyxtal.supergroup module
find_mapping()find_mapping_per_element()find_xyz()new_path()new_structure()search_G1()search_G2()supergroupsupergroup.calc_disps()supergroup.get_coord_H()supergroup.get_initial_mask()supergroup.make_pyxtal_in_supergroup()supergroup.make_pyxtals_in_subgroup()supergroup.make_supergroup()supergroup.print_detail()supergroup.print_wp()supergroup.search_supergroup()supergroup.sort_solutions()supergroup.symmetrize()supergroup.symmetrize_dist()supergroup.symmetrize_site_double_k()supergroup.symmetrize_site_double_t()supergroup.symmetrize_site_multi()supergroup.symmetrize_site_single()
supergroupswrite_poscars()
- pyxtal.symmetry module
GroupGroup.add_k_transitions()Group.cellsize()Group.check_compatible()Group.check_hkl_in_list()Group.generate_hkl_guesses()Group.generate_possible_hkls()Group.get_ASU()Group.get_ASU_instance()Group.get_alternatives()Group.get_ferroelectric_groups()Group.get_free_axis()Group.get_index_by_letter()Group.get_lattice_dof()Group.get_lattice_id()Group.get_max_k_subgroup()Group.get_max_subgroup()Group.get_max_subgroup_numbers()Group.get_max_t_subgroup()Group.get_min_supergroup()Group.get_orders()Group.get_reflection_conditions()Group.get_site_dof()Group.get_spg_representation()Group.get_spg_symmetry_object()Group.get_splitters_from_relation()Group.get_splitters_from_structure()Group.get_subgroup_composition()Group.get_symmetry_directions()Group.get_valid_solutions()Group.get_wp_by_letter()Group.get_wp_list()Group.get_wyckoff_position()Group.get_wyckoff_position_from_xyz()Group.is_valid_combination()Group.is_valid_hkl()Group.list_groups()Group.list_wyckoff_combinations()Group.path_to_general_wp()Group.path_to_subgroup()Group.path_to_zp2()Group.reduce_hkl_guesses()Group.search_subgroup_paths()Group.search_supergroup_paths()Group.short_path_to_general_wp()
HallSymmetryDataSymmetryData.get_generator_lg()SymmetryData.get_generator_pg()SymmetryData.get_generator_rg()SymmetryData.get_generator_sg()SymmetryData.get_hall_table()SymmetryData.get_k_subgroup()SymmetryData.get_symmetry_lg()SymmetryData.get_symmetry_pg()SymmetryData.get_symmetry_rg()SymmetryData.get_symmetry_sg()SymmetryData.get_t_subgroup()SymmetryData.get_wyckoff_lg()SymmetryData.get_wyckoff_pg()SymmetryData.get_wyckoff_rg()SymmetryData.get_wyckoff_sg()
Wyckoff_positionWyckoff_position.apply_ops()Wyckoff_position.are_equivalent_pts()Wyckoff_position.copy()Wyckoff_position.distance_check()Wyckoff_position.equivalent_set()Wyckoff_position.from_dict()Wyckoff_position.from_discrete_grid()Wyckoff_position.from_group_and_index()Wyckoff_position.from_group_and_letter()Wyckoff_position.from_index_quick()Wyckoff_position.from_symops()Wyckoff_position.from_symops_wo_group()Wyckoff_position.gen_pos()Wyckoff_position.get_all_positions()Wyckoff_position.get_dof()Wyckoff_position.get_euclidean_generator()Wyckoff_position.get_euclidean_ops()Wyckoff_position.get_euclidean_symmetries()Wyckoff_position.get_free_xyzs()Wyckoff_position.get_frozen_axis()Wyckoff_position.get_hm_number()Wyckoff_position.get_hm_symbol()Wyckoff_position.get_label()Wyckoff_position.get_ops_from_transformation()Wyckoff_position.get_position_from_free_xyzs()Wyckoff_position.get_site_symm_ops()Wyckoff_position.get_site_symm_wo_translation()Wyckoff_position.get_site_symmetry()Wyckoff_position.get_site_symmetry_object()Wyckoff_position.has_equivalent_ops()Wyckoff_position.is_pure_translation()Wyckoff_position.is_standard_setting()Wyckoff_position.load_dict()Wyckoff_position.merge()Wyckoff_position.print_ops()Wyckoff_position.process_ops()Wyckoff_position.project()Wyckoff_position.save_dict()Wyckoff_position.search_all_generators()Wyckoff_position.search_generator()Wyckoff_position.search_generator_dist()Wyckoff_position.set_euclidean()Wyckoff_position.set_generators()Wyckoff_position.set_ops()Wyckoff_position.short_distances()Wyckoff_position.swap_axis()Wyckoff_position.to_discrete_grid()Wyckoff_position.transform_from_matrices()Wyckoff_position.transform_from_matrix()Wyckoff_position.update()Wyckoff_position.update_hall()Wyckoff_position.update_index()
abc2matrix()are_equivalent_ops()check_symmetry_and_dim()check_wyckoff_position()choose_wyckoff()choose_wyckoff_mol()find_axis_order()generate_possible_hkls()get_all_polar_space_groups()get_bravais_lattice()get_canonical_hkl()get_canonical_hkl_series()get_close_packed_groups()get_generators()get_lattice_type()get_pbc_and_lattice()get_point_group()get_symbol_and_number()get_symmetry_directions()get_symmetry_from_ops()get_wyckoff_symmetry()get_wyckoffs()identity_ops()index_from_letter()is_hkl_allowed()is_hkl_allowed_by_bravais()jk_from_i()letter_from_index()op_transform()op_translation()organized_wyckoffs()para2ferro()rf()search_cloest_wp()site_symm()site_symmetrysite_symmetry.correct_matrix()site_symmetry.get_highest_symmetry()site_symmetry.get_name()site_symmetry.ref_symmetry()site_symmetry.set_full_hm_symbols()site_symmetry.set_short_symbols()site_symmetry.set_table()site_symmetry.to_beautiful_matrix_representation()site_symmetry.to_matrix_representation()site_symmetry.to_one_hot()site_symmetry.unique_symmetry()
swap_xyz_ops()swap_xyz_string()symmetry_element_from_axis()transform_ops()trim_ops()
- pyxtal.tolerance module
- pyxtal.util module
Kgrid()ase2pymatgen()check_upper_bounds()extract_ase_db()find_dir()generate_wp_lib()get_pmg_dist()get_similar_cids_from_pubchem()get_struc_from__parser()get_symmetrized_pmg()get_wyc_from_comp()good_lattice()listToString()new_struc()new_struc_wo_energy()parse_cif()prettify()process_csd_cif()pymatgen2ase()reset_lammps_cell()search_csd_code_by_pubchem()search_csd_entries_by_code()sort_by_dimer()split_list_by_ratio()symmetrize()symmetrize_cell()
- pyxtal.version module
- pyxtal.viz module
- pyxtal.wyckoff_site module
atom_siteatom_site.check_with_ws2()atom_site.copy()atom_site.encode()atom_site.equivalent_set()atom_site.get_bounds()atom_site.get_disp()atom_site.get_translations()atom_site.load_dict()atom_site.perturbate()atom_site.save_dict()atom_site.search_position()atom_site.shift_by_swap()atom_site.substitute_with_linear()atom_site.substitute_with_single()atom_site.to_mol_site()atom_site.update()
mol_sitemol_site.molmol_site.positionmol_site.orientationmol_site.wpmol_site.latticemol_site.stypemol_site.symbolsmol_site.numbersmol_site.PBCmol_site.radiusmol_site.tols_matrixmol_site._get_dof()mol_site.cut_lattice()mol_site.encode()mol_site.extract_short_distances()mol_site.from_1D_dicts()mol_site.get_bounds()mol_site.get_coords_and_species()mol_site.get_dist_angle_AD()mol_site.get_dist_angle_DA()mol_site.get_distances()mol_site.get_dists_WP()mol_site.get_dists_WP2()mol_site.get_dists_auto()mol_site.get_energy()mol_site.get_ijk_lists()mol_site.get_min_dist()mol_site.get_mol_object()mol_site.get_neighbors_auto()mol_site.get_neighbors_wp2()mol_site.is_valid_orientation()mol_site.load_dict()mol_site.optimize_orientation_by_dist()mol_site.optimize_orientation_by_energy()mol_site.perturbate()mol_site.rotate()mol_site.save_dict()mol_site.short_dist()mol_site.short_dist_with_wp2()mol_site.show()mol_site.show_molecule_in_box()mol_site.to_1D_dicts()mol_site.to_atom_site()mol_site.translate()mol_site.update()mol_site.update_molecule()mol_site.update_orientation()
- pyxtal.wyckoff_split module