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.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_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.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)[source]

read structures from a cif (our own format with #END) :param filename: string :param header: bool, whether or not return header :param 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) for 1:1 ratio).

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