pyxtal.util module

some utilities

pyxtal.util.Kgrid(struc, Kresol=0.1, dimension=3)[source]

Assign kpoints based on the lattice.

pyxtal.util.ase2pymatgen(struc)[source]

A short cut to convert between pymatgen to ase

pyxtal.util.check_upper_bounds(solutions: List[Tuple[int]], upper_bounds: List[int], total_bounds: list[int]) bool[source]

Check if the elementwise sum of the selected solutions respects upper bounds. and if the sums use the non-None upper bounds.

Example

solutions = [(6, 0, 0), (4, 1, 0), (2, 2, 0)] upper_bounds = [10, 2, None] # No upper limit for third element check_upper_bounds(solutions, upper_bounds) # Returns: True, since the sums are within the bounds

pyxtal.util.extract_ase_db(db_file, id)[source]

A short cut to extract the structural information from the ase db file by row id

pyxtal.util.find_dir(dirs)[source]

A short function to find the correct dir from a list.

pyxtal.util.generate_wp_lib(spg_list, composition, num_wp=(None, None), num_fu=(None, None), num_dof=(None, None), N_max=1000)[source]

Generate wps according to the composition constraint (e.g., SiO2)

Args;

spg_list: list of space group choices composition: chemical compositions [1, 2] num_wp: (min_wp, max_wp) num_fu: (min_fu, max_fu) num_dof: (min_dof, max_dof)

Returns:

a list of wps [spg, ([wp1, …], … [wp1, …]), dof]

pyxtal.util.get_pmg_dist(pmg1, pmg2, ltol=0.3, stol=0.3, angle_tol=5.0, scale=True)[source]

Get the rms distance between two pymatgen structures.

pyxtal.util.get_similar_cids_from_pubchem(base, MaxRecords)[source]
Parameters:
  • base – PubChem CID of Starting chemical

  • MaxRecords – Number of Similar Compounds

Returns:

List of the CIDs of PubChem compounds similar to the base compound.

pyxtal.util.get_struc_from__parser(p)[source]

A utility to get the pymatgen structure from the CifParser Sometimes the cif structure may have repeated atom entries.

Parameters:

p – pymatgen CifParser object

Returns:

a single pymatgen structure

pyxtal.util.get_symmetrized_pmg(pmg, tol=0.001, a_tol=5.0, style='pyxtal', hn=None)[source]

Get the symmetrized Pymatgen structure. A slight modification to ensure that the structure adopts the standard setting according to the Interational Crystallography Table.

Parameters:
  • pmg – input pymatgen structure

  • tol – symmetry tolerance

  • a_tol – angle tolerance

  • style – ‘pyxtal’ or spglib, differing in the choice of origin

  • hn – hall_number

Returns:

pymatgen structure with symmetrized lattice

pyxtal.util.get_wyc_from_comp(composition: int, base: List[int], upper_bounds: List[int], max_wyc=20, num_wp=(None, None), verbose=False) List[Tuple[int]][source]

Generate all valid wyc combinations for a single target value.

Parameters:
  • composition (int) – The target value to achieve by summing the products.

  • base (List[int]) – List of integers representing the base values.

  • upper_bounds (List[int]) – List of upper bounds for each element in base. If an element has no upper limit, use None.

  • max_wyc (int) – Maximum number of combinations to return.

  • verbose (bool) – If True, print the combinations found.

Example

get_wyc_from_comp([6], [1, 2, 3], [None, 2, None]) # Returns: [(6, 0, 0), (4, 1, 0), (2, 2, 0), …, etc.]

pyxtal.util.good_lattice(struc, maxvec=50.0, minvec=1.2, maxang=150, minang=30)[source]

check if the lattice has a good shape.

Parameters:

struc – pyxtal structure

pyxtal.util.listToString(s)[source]
pyxtal.util.new_struc(xtal, xtals)[source]

Check if this is a new structure.

Parameters:
  • xtal – input structure

  • xtals – list of reference structures

Returns:

None or the id of matched structure

pyxtal.util.new_struc_wo_energy(xtal, xtals, ltol=0.2, stol=0.3, angle_tol=5.0, verbose=False)[source]

check if this is a new structure

Parameters:
  • xtal – input structure

  • xtals – list of reference structures

  • ltol (float) – Fractional length tolerance. Default is 0.2.

  • stol (float) – Site tolerance. ( V / Nsites ) ** (1/3). Default is 0.3.

  • angle_tol (float) – Angle tolerance in degrees. Default is 5 degrees.

Returns:

None or the id of matched structure

pyxtal.util.parse_cif(filename, header=False, spg=False, eng=False, csd=False, sim=False, verbose=False)[source]

Read structures from a cif (our own format with #END)

Parameters:
  • filename – string

  • header – bool, whether or not return header

  • spg – bool, whether or not return the spg

pyxtal.util.prettify(elem)[source]

Return a pretty-printed XML string for the Element.

pyxtal.util.process_csd_cif(cif, remove_H=False)[source]

process cif from CSD, sometimes it contains multiple e.g., C2

pyxtal.util.pymatgen2ase(struc)[source]

A short cut to convert between pymatgen to ase

pyxtal.util.reset_lammps_cell(atoms0)[source]

Set the cell into lammps format.

pyxtal.util.search_csd_code_by_pubchem(cid)[source]
Parameters:

cid – PubChem cid.

Returns:

CIDs that have CCDC crystal structure data.

pyxtal.util.search_csd_entries_by_code(code)[source]
Parameters:

code – CSD code, e.g., ACSALA

Returns:

list of csd ids

pyxtal.util.sort_by_dimer(atoms, N_mols, id=10, tol=4.0)[source]

sort the ase atoms’ xyz according to dimer. so far only tested on aspirin.

Parameters:
  • atoms – atoms object from pyxtal

  • N_mols – number of molecules

  • id – the refrence atom id

  • tol – tolerence distance to check if it is a dimer

pyxtal.util.split_list_by_ratio(nums, ratio)[source]

Splits a list of integers into two groups such that the sum of each group satisfies a given ratio and returns all possible ways of combinations tracking the indices of the numbers.

Parameters:
  • nums (list of int) – The list of integers to split.

  • ratio (tuple of int) – A tuple of the desired ratio (e.g., (1, 1) ).

Returns:

A list of tuples where each contains two lists of indices.

Each pair of lists represents one possible way to split the numbers to satisfy the given ratio.

Return type:

list of tuple

pyxtal.util.symmetrize(pmg, tol=0.001, a_tol=5.0, style='pyxtal', hn=None)[source]

Symmetrize the structure from spglib.

Parameters:
  • pmg – pymatgen structure

  • tol – tolerance

  • a_tol – angle tolerance

  • style – ‘pyxtal’ or spglib, differing in the choice of origin

  • hn – hall_number

Returns:

pymatgen structure with symmetrized lattice

pyxtal.util.symmetrize_cell(struc, mode='C')[source]

Symmetrize structure from pymatgen, and return the struc in conventional or primitive setting.

Parameters:
  • struc – ase type

  • mode – output conventional or primitive cell