qstack.compound¶
Molecular structure parsing and manipulation.
- qstack.compound.basis_flatten(mol, return_both=True, return_shells=False)[source]¶
Flatten a basis set definition for AOs.
- Parameters:
mol (pyscf.gto.Mole) – pyscf Mole object.
return_both (bool) – Whether to return both AO info and primitive Gaussian info. Defaults to True.
return_shells (bool) – Whether to return angular momenta and starting indices per shell (2l+1-sized group of orbitals that share a radial function and l value). Defaults to False.
- Returns:
- 3×mol.nao int array where each column corresponds to an AO and rows are:
0: atom index,
1: angular momentum quantum number l,
2: magnetic quantum number m.
If return_both is True, also returns: - numpy.ndarray: 2×mol.nao×max_n float array where index (i,j,k) means:
i: 0 for exponent, 1 for contraction coefficient of a primitive Gaussian,
j: AO index,
k: radial function index (padded with zeros if necessary).
If return_shells is True, also returns: - numpy.ndarray: starting AO indices for each shell.
- Return type:
numpy.ndarray
- qstack.compound.fragment_partitioning(fragments, prop_atom_inp, normalize=True)[source]¶
Compute the contribution of each fragment.
- Parameters:
fragments (list) – Fragment definition as list of numpy arrays.
prop_atom_inp (numpy.ndarray or list of numpy.ndarray) – Atomic contributions to property(ies).
normalize (bool) – Whether to normalize fragment partitioning. Defaults to True.
- Returns:
Contribution of each fragment. Returns list if input was list, array otherwise.
- Return type:
list or numpy.ndarray
- qstack.compound.fragments_read(frag_file)[source]¶
Load fragment definition from a file.
- Parameters:
frag_file (str) – Path to the fragment file containing space-separated atom indices (1-based).
- Returns:
List of numpy arrays containing the fragment indices.
- Return type:
list
- qstack.compound.make_atom(q, basis, ecp=None)[source]¶
Create a single-atom molecule at the origin.
- Parameters:
q (str) – Element symbol.
basis (str or dict) – Basis set.
ecp (str) – ECP to use. Defaults to None.
- Returns:
Single-atom pyscf Mole object.
- Return type:
pyscf.gto.Mole
- qstack.compound.make_auxmol(mol, basis, copy_ecp=False)[source]¶
Build an auxiliary Mole object given a basis set and a pyscf Mole object.
- Parameters:
mol (pyscf.gto.Mole) – Original pyscf Mole object.
basis (str or dict) – Basis set.
copy_ecp (bool) – Whether to copy ECP from original molecule. Defaults to False.
- Returns:
Auxiliary pyscf Mole object.
- Return type:
pyscf.gto.Mole
- qstack.compound.mol_to_xyz(mol, fout, fmt='xyz')[source]¶
Convert a pyscf Mole object into a molecular file in xyz format.
- Parameters:
mol (pyscf.gto.Mole) – pyscf Mole object.
fout (str) – Name (including path) of the xyz file to write.
fmt (str) – Output format. Defaults to “xyz”.
- Returns:
String containing the xyz formatted data.
- Return type:
str
- Raises:
NotImplementedError – If fmt is not “xyz”.
- qstack.compound.numbers(mol)[source]¶
Get atom numbers of a molecule.
Use this function to get atomic NUMBERS to index elements. Use mol.atom_charges() to get CHARGES (it returns effective charges when ECP are used).
- Parameters:
mol (pyscf.gto.Mole) – pyscf Mole object.
- Returns:
Array of atomic numbers.
- Return type:
numpy.ndarray
- qstack.compound.rotate_molecule(mol, a, b, g, rad=False)[source]¶
Rotate a molecule: transform nuclear coordinates given a set of Cardan angles.
- Parameters:
mol (pyscf.gto.Mole) – Original pyscf Mole object.
a (float) – Alpha Euler angle.
b (float) – Beta Euler angle.
g (float) – Gamma Euler angle.
rad (bool) – Whether the angles are in radians. Defaults to False (degrees).
- Returns:
pyscf Mole object with transformed coordinates.
- Return type:
pyscf.gto.Mole
- qstack.compound.xyz_comment_line_parser(line)[source]¶
Read the ‘comment’ line of a XYZ file and tries to infer its meaning.
- Parameters:
line (str) – Comment line from XYZ file.
- Returns:
Dictionary containing parsed properties (charge, spin, etc.).
- Return type:
dict
- qstack.compound.xyz_to_mol(inp, basis='def2-svp', charge=None, spin=None, ignore=False, unit=None, ecp=None, parse_comment=False)[source]¶
Read a molecular file in xyz format and returns a pyscf Mole object.
- Parameters:
inp (str) – Path of the xyz file to read, or xyz file contents.
basis (str or dict) – Basis set. Defaults to “def2-svp”.
charge (int) – Provide/override charge of the molecule. Defaults to None.
spin (int) – Provide/override spin of the molecule (alpha electrons - beta electrons). Defaults to None.
ignore (bool) – If True, assume molecule is closed-shell and assign charge either 0 or -1. Defaults to False.
unit (str) – Provide/override units (Ang or Bohr). Defaults to None.
ecp (str) – ECP to use. Defaults to None.
parse_comment (bool) – Whether to parse the comment line for properties. Defaults to False.
- Returns:
pyscf Mole object containing the molecule information.
- Return type:
pyscf.gto.Mole
- Raises:
RuntimeError – If units are not recognized or if minao basis requires ECP for heavy atoms.